Rationale for Correct Answer:When using count, Terraform creates resources indexed starting at 0.With count = 2, the instances are indexed as:
First instance → aws_instance.web[0]
Second instance → aws_instance.web[1]
To reference the name attribute of the second instance, the correct syntax is:
aws_instance.web[1].name
Analysis of Incorrect Options (Distractors):
A. [2]: Incorrect because indexing starts at 0 and only indices 0 and 1 exist.
B. *.name: Returns a list of all names, not a single instance value.
D. [1]: References the whole resource object, not the name attribute.
E. element(...): Incorrect syntax and wrong index; also unnecessary when direct indexing is available.
Key Concept:Understanding resource indexing with count and zero-based indexing in Terraform.
[Reference:Terraform Exam Objective – Read, Generate, and Modify Configurations, , ]