Terraform: Referencing Attributes from "Data Source" with count = 0 , issuing "unknown resource" error.

Created on 20 Nov 2017  ยท  3Comments  ยท  Source: hashicorp/terraform

Terraform Version

Terraform v0.11.0

  • provider.aws v1.3.0

Terraform Configuration Files


# external DNS zone. not managed by TF
data "aws_route53_zone" "external_dns" {
  count = "${var.global["use_route53"] ? 1 : 0 }"
  name  = "myfoobar.net"
}

output "external_dns_zone_id" {
  value = "${element(concat(aws_route53_zone.external_dns.*.zone_id, list("")), 0)}"
}

Expected Behavior

This should work as documented in the 0.11 upgrade guide. https://www.terraform.io/upgrade-guides/0-11.html

Actual Behavior

Error: module root:
module ayla_tf.root: 1 error(s) occurred:

  • output 'external_dns_zone_id': unknown resource 'aws_route53_zone.external_dns' referenced in variable aws_route53_zone.external_dns.*.zone_id

Steps to Reproduce

  1. terraform init
  2. terraform apply

Important Factoids

  1. This domain is not controlled by TF. So I use it as a Data, not a Resource.

  2. AWS China doesn't have Route 53, so I have to exclude it (if you are curious about the use case.)

  3. For Resource, this idiom does work. But for Data Source, it doesn't work. I have not been able to find a workaround yet. Staying with 0.10.8 is probably the only way out.

References

  • #16681
config question

Most helpful comment

Hi @hoffmannliu-ayla,

The example in the upgrade guide is for a resource block. Data resources (declared withdata blocks) are a separate namespace that needs a data. prefix to be included when referencing it, like this:

output "external_dns_zone_id" {
  value = "${element(concat(data.aws_route53_zone.external_dns.*.zone_id, list("")), 0)}"
}

All 3 comments

Hi @hoffmannliu-ayla,

The example in the upgrade guide is for a resource block. Data resources (declared withdata blocks) are a separate namespace that needs a data. prefix to be included when referencing it, like this:

output "external_dns_zone_id" {
  value = "${element(concat(data.aws_route53_zone.external_dns.*.zone_id, list("")), 0)}"
}

Yes. You are right. My bad. Didn't notice that.

Thanks for your help and clarification. It works with 0.11.0. I can close this "issue" now.

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings