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

local and output evaluation fails when referencing a destroy node #17425

Closed
jbardin opened this issue Feb 24, 2018 · 2 comments · Fixed by #17765
Closed

local and output evaluation fails when referencing a destroy node #17425

jbardin opened this issue Feb 24, 2018 · 2 comments · Fixed by #17765

Comments

@jbardin
Copy link
Member

jbardin commented Feb 24, 2018

The pattern users have used to create "optional" resources is to dynamically set a count value to 0. In order to prevent interpolation errors in outputs (and locals), the suggested pattern has been to use the list from the splat (*) operator, along with an additional element to ensure there is always a value for interpolation:

"${element(concat(resource.name.*.attr, list("")), 0)}"

This works when the resource remains present in the graph, but can fail when the count is later changed to 0.

Using the following config:

variable "count" {}


resource "null_resource" "one" {
  count = "${var.count}"
}

locals {
  "one_id" = "${element(concat(null_resource.one.*.id, list("")), 0)}"
}

resource "null_resource" "two" {
  triggers = {
    required = "${local.one_id}"
  }
}

We can reproduce this with

$ terraform apply -auto-approve -var count=1
Apply complete! Resources: 2 added, 0 changed, 0 destroyed.

$ terraform apply -auto-approve -var count=0
Error: Error applying plan:

1 error(s) occurred:

* local.one_id: local.one_id: Resource 'null_resource.one' does not have attribute 'id' for variable 'null_resource.one.*.id'
@saedalavinia
Copy link

I am seeing the exact same issue, not mention how hard was to catch this error.

@ghost
Copy link

ghost commented Apr 4, 2020

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 Apr 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants