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.