Terraform Associate Exam QuestionsBrowse all questions from this exam

Terraform Associate Exam - Question 222


How would you refer to the indexing instance from the below configuration?

Show Answer
Correct Answer: D

To refer to the “indexing” instance in Terraform using for_each, you must access the resource by including the key within square brackets. The correct syntax to refer to a specific instance when using for_each is to write the resource type, the resource name, and then the key in square brackets. Therefore, aws_instance.web[“indexing”] is the correct way to refer to the “indexing” instance.

Discussion

8 comments
Sign in to comment
NunyabiznesOption: D
Oct 3, 2023

aws_instance.web["indexing"]

kareem_ashrafOption: D
May 25, 2024

Referring to Instances with multiple instances are prefixed with module.<NAME>[<KEY>] when displayed in plan output and elsewhere in the UI. For a module without count or for_each, the address will not contain the module index as the module's name suffices to reference the module.

ArnaldoW
Oct 4, 2023

The correct one is D. It's involving for_each. In summary, both notations refer to the same resource instance but use different syntax to access it. The bracket notation is used for dynamic access, whereas the dot notation is used for direct access.

March2023Option: D
Dec 15, 2023

Just tested, the answer is D

d9iceguyOption: D
Jun 29, 2024

D is correct https://developer.hashicorp.com/terraform/language/meta-arguments/for_each#referring-to-instances

hahanoOption: B
Oct 1, 2023

the answer is B

tbhtp
Oct 1, 2023

The correct answer is B.

styroOption: D
Oct 1, 2023

D. aws_instance.web[“indexing”] To refer to the “indexing” instance in the given configuration, you would use the resource type followed by the resource name, and then use the index key in square brackets. The correct syntax is: aws_instance.web["indexing"] This refers to the “indexing” instance created by the aws_instance resource named “web”. The other options provided do not use the correct syntax for referencing resources with for_each keys in Terraform.