Problem with count variable after upgrading to 11.14 from 10.x

I have a variable count set as count = “${test_cache_instance_count}” and variable “test_cache_instance_count” { default = 1 }

I have Output set as:

output “test_api_cache_host” {
value = “${aws_elasticache_cluster.test_cache.cache_nodes.0.address}”
}

My tfvars file has test_cache_instance_count = “0”

This worked fine in 10.x, but in 11.14 I got the following error:

Error: Error running plan: 1 error occurred:

  • output.test_api_cache_host: Resource ‘aws_elasticache_cluster.test_cache’ not found for variable ‘aws_elasticache_cluster.test_cache.cache_nodes.0.address’

Any ideas on how to fix this?

Hi @cptcrush!

In 0.10, we suppressed the error when count = 0 and the output was non-existent, as a result. In 0.11, this was updated such that it would show the actual error of resource not found, in anticipation of richer typing for 0.12. To fix, you can update the configuration to look like below:

output “test_api_cache_host” {
  value = "${element(concat(aws_elasticache_cluster.test_cache.*.cache_nodes.0.address, list("")), 0)}"
}

This will allow the plan to complete when count = 0 by outputting all resources as a string, and thus non-null. For more information about this change, check out this section in the upgrading to 0.11 guide.

Hello @joatmon08,

I have tried this syntax and am still getting the same error with make plan. Any other ideas?

Interesting! Could you paste the entire resource, variable, and output declaration with the markdown format? You’ll need to prepend the section with ```hcl and end it with three backticks. It will greatly help with debugging!