-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Disambiguate between lists and sets in the CLI plan output #35170
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
Comments
Hi @EugenKon, The plan renderer here is operating as designed. The HCL language doesn't have a distinct syntax for a set, but rather you would use the same Thanks! |
We have decided to show What makes this situation slightly different is that Terraform handles the conversion to set silently when a list or tuple is assigned to this argument, because Terraform knows the provider's schema and so hides that complexity from the user by performing the type conversion automatically. I think the question to ponder here, then, is whether it's actually valid to hide this detail if the difference between the two is important to how Terraform understands references, as we can see with this error message. I could appreciate the argument that showing I expect that answering this will require some research to understand how often this confusion arises, and thus how many people would be helped by including this extra information in the plan output. 🤔 |
Thank you for for the detailed answer. It is a bit clear to me now. If you are on the way to change the Terraform output, then the best to display information ASIS, without additional guessing, which could make a confusion. For example, from the output:
It is not clear how to access underlying elements. Eg.:
hm... Ok. The value is not known, so we can not dump its value as the "key". From now, I believe, the most important thing missed in the dump above is the field name which should be used to access an underlied data. I propose to dump the name of a such field if the value still not known: + domain_validation_options = [
+ key: resource_record_name # Just for the purpose of the example, lets count this field as its key.
+ {
+ domain_name = "xxx.gr"
+ resource_record_name = (known after apply) # For the purpose of example lets use "A" as its value
+ resource_record_type = (known after apply) # B
+ resource_record_value = (known after apply) # C
}, Or dump the key's value if it is already known: + domain_validation_options = [
- + {
+ + "xxx.gr" => {
+ domain_name = "xxx.gr"
+ resource_record_name = (known after apply) # For the purpose of example lets use "A" as its value
+ resource_record_type = (known after apply) # B
+ resource_record_value = (known after apply) # C
}, @apparentlymart @jbardin What do you think? |
@EugenKon, a set data structure doesn't have a key, so I'm not sure what |
Ouch. I was thinking about this structure as a map. I see now, that Ok. Terraform has a
|
Set elements don't have indices, because there is no stored order for set elements. Sets represent the relatively common case in many remote APIs where there's just a collection of objects (or other values) that exist but aren't considered to be in any particular order. When working with sets the only operations that typically make sense are:
I understood this as a request to show more clearly in the plan output when an attribute is a set, so that it's clearer to the reader that they need to use the value in one of the ways I described above. We can't support indexing into a set because the whole purpose of sets is to deal with situations where the remote API does not provide any single identifier for the objects itself, and so Terraform pretending that it does would be fragile if the API happens to return the items in a different order on a future request, causing all of the derived values to be invalidated. |
This seems related to #31102, which was caused by a similar ambiguity between tuple types and list types. Considering that this has now caused at least two different variations of confusion, I personally feel more inclined to change the plan output to include |
Terraform Core Version
v1.8.2
AWS Provider Version
v4.67.0
Affected Resource(s)
Expected Behavior
It should be shown as set, and not as an array:
Actual Behavior
If I try to access to it by index
aws_acm_certificate.dns-url-redirects.domain_validation_options[0].resource_record_name
I get the error:Documentation also says that it is the set: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/acm_certificate#domain_validation_options

Relevant Error/Panic Output Snippet
No response
Terraform Configuration Files
I am trying to access it like described here:azavea/terraform-aws-acm-certificate#3 (comment)
Steps to Reproduce
Run
terraform plan
for the configuration above.Debug Output
No response
Panic Output
No response
Important Factoids
No response
References
hashicorp/terraform-provider-aws#37544
Would you like to implement a fix?
None
The text was updated successfully, but these errors were encountered: