Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional output errors when evaluation expression based on an elasticache resource #19964

Closed
adybuxton opened this issue Jan 10, 2019 · 2 comments

Comments

@adybuxton
Copy link

Terraform Version

0.11.8

Terraform Configuration Files

output "redis_endpoint" {
  value = "${ join("", aws_elasticache_cluster.redis.*.cache_nodes.0.address) }" 
}

resource "aws_elasticache_cluster" "redis" {
  count = "${var.redis_install}"
  ...
}

variable "redis_install" {
  default = true
}

Expected Behavior

The output value should be lazy evaluated correctly and return either an empty string or the elasticache address depending on if the resource was created. This is a known and well documented hack people are recommending until v0.12 is released which will allow ternary expressions to evaluate correctly with potentially missing resources. This behaviour does work as expected with other resources such as EC2 ip addresses and RDS SQL endpoints.

Actual Behavior

Error: Error running plan: 1 error(s) occurred:

* module.redis.output.redis_endpoint: Resource 'aws_elasticache_cluster.redis' does not have attribute 'cache_nodes.0.address' for variable 'aws_elasticache_cluster.redis.*.cache_nodes.0.address'

Steps to Reproduce

Running terraform apply when the install_redis variable is set to true returns the error.
Running terraform apply when the install_redis variable is set to false returns the correct behaviour of an empty string outputted.
Commenting out the output block, running 'terraform apply', then adding the output back, running 'terraform apply' a second time correctly returns the elasticache endpoint address.

Additional Context

Alternatively trying

output "redis_endpoint" {
  value = "${ join("", aws_elasticache_cluster.redis.*.cache_nodes.*.address) }" 
}

returns

* module.redis.output.redis_endpoint: Resource 'aws_elasticache_cluster.redis' does not have attribute 'cache_nodes.*.address' for variable 'aws_elasticache_cluster.redis.*.cache_nodes.*.address'

It appears the evaluation of the expression differs depending on if terraform knows the resource will be created or not and the evaluation appears to work differently due to the nested lists. Are there alternative recommended approaches/hacks to conditionally output the elasticache endpoint address ?

@hashibot
Copy link
Contributor

Hello! 🤖

This issue relates to an older version of Terraform that is no longer in active development, and because the area of Terraform it relates to has changed significantly since the issue was opened we suspect that the issue is either fixed or that the circumstances around it have changed enough that we'd need an updated issue report in order to reproduce and address it.

If you're still seeing this or a similar issue in the latest version of Terraform, please do feel free to open a new bug report! Please be sure to include all of the information requested in the template, even if it might seem redundant with the information already shared in this issue, because the internal details relating to this problem are likely to be different in the current version of Terraform.

Thanks!

@ghost
Copy link

ghost commented Sep 27, 2019

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.

@ghost ghost locked and limited conversation to collaborators Sep 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants