Ignore error from data source

How do you make output shut up and carry on if there’s nothing to return?
I’m getting:

│ Error: reading EC2 Network Interface: empty result
│   with data.aws_network_interface.netiface,
│   on main.tf line 55, in data "aws_network_interface" "netiface":
│   55: data "aws_network_interface" "netiface" {


data "aws_network_interface" "netiface" {
  filter {
    name   = "tag:aws:ecs:serviceName"
    values = ["my-service"]


Managed to work around missing resource by count = var.first_run ? 0 : count but when resources are there it doesn’t work. Is it possible to do what I want?

Hi @playbutton,

What you’ve described in this second message seems to be on the right track.

A data block represents a dependency on something that is managed outside of the current Terraform configuration, so if you declare an unconditional one then you are telling Terraform that the other object must exist in order for the current configuration to be valid.

You can use the count argument to choose separately for each call of your module whether it ought to depend on that existing object. However, the value you use to make that decision should be something that remains set consistently for as long as that external dependency exists.

Your name “first run” suggests that you are intending to introduce this dependency only after you’ve run terraform apply without it at least once. That can be a valid strategy sometimes, but it’s rare. There’s usually some way to describe a situation to Terraform so that it can understand all of the relationships between objects on the first run, without withholding any objects until the second run.

In particular, if you are trying to do this because you also have a resource block somewhere else in the same configuration that’s managing this same network interface object, then you should typically pass the data from that resource block directly to what uses it, rather than trying to read back the same object Terraform has just created or updated via another API call.