Replies: 1 comment
-
|
This proposal is very hard to follow because of invalid syntax in the examples. An ideal example is minimal and runnable. That means no indirection through That said, no plans to implement anything like this, but converting to a discussion for any future comments. TFLint can only enforce things that can be determined statically. The issue here arises when Separately, this ruleset is focused on automating guidance from the Terraform documentation, and not trying to detect potential footguns. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Introduction
Resources can be created with
for_eachusing aset()ormap()A resource created with
for_eachwith aset()uses thevalueA resource created with
for_eachwith amap()uses thekeyIf we have resources, and attempt to use the resulting attributes witihin a
for_each, it will result in an error if the resource has not yet been createdThis issue goes unnotticed if a module is within development, and hasn't been tested on an empty workspace
Example:
The above would work, if
resource.thingAssociationwas added afterresource.thing1andresource.thing2were craetedHowever, it can't be deployed on a new workspace, because the
for_eachuses thevalueof theset()to determine the new reference/id that will be stored in the Terraform StateSo we get the error:
But, if a
map()is used, eg:Example:
It will now use the
keyfor the determine the new reference/id that will be stored in the Terraform State - which is staticProposal
Warn against the use of resource attributes within
for_each, unless they are used as amap("thing" = *.id)rather thanset[*.id]Beta Was this translation helpful? Give feedback.
All reactions