Terraform basic, lab variables exercise 10 - question

Hello,
Lab “Variables”, exercise n. 10

My tf apply is successful, even though my main.tf is different from what is reported in the “suggestion” tab.

variable jedi definition:
image

Could you please explain the differences in the code (yours vs. mine) and why it works anyway? Thank you in advance.

The difference that I see between your main.tf and the one in Solution is the way in which attributes are accessed.
You’ve used dot notation instead of square-bracket notation that is used in the Solution, both are correct in this case, hence it worked.

Check docs

Map/object attributes with names that are valid identifiers can also be accessed using the dot-separated attribute notation, like local.object.attrname . In cases where a map might contain arbitrary user-specified keys, we recommend using only the square-bracket index notation (local.map["keyname"] )

2 Likes

Thank you very much for explaining!