nerdexam
HashiCorp

TERRAFORM-ASSOCIATE-003 · Question #177

How would you reference the "name'' value of the second instance of this resource?

The correct answer is D. aws_instance_web(1),name. In Terraform, when you use the count meta-argument, you can reference individual instances using an index. The indexing starts at 0, so to reference the "name" value of the second instance, you would use aws_instance.web[1].name. This syntax allows you to access the properties…

Read, generate, and modify configuration

Question

How would you reference the "name'' value of the second instance of this resource?

Options

  • Aaws_instance.web(2),name
  • Belement(aws_instance.web, 2)
  • Caws_instance-web(1)
  • Daws_instance_web(1),name
  • EAws_instance,web,* , name

How the community answered

(31 responses)
  • A
    10% (3)
  • B
    13% (4)
  • C
    3% (1)
  • D
    71% (22)
  • E
    3% (1)

Explanation

In Terraform, when you use the count meta-argument, you can reference individual instances using an index. The indexing starts at 0, so to reference the "name" value of the second instance, you would use aws_instance.web[1].name. This syntax allows you to access the properties of specific instances in a list generated by the count argument.

Topics

#count meta-argument#resource indexing#resource references#HCL syntax

Community Discussion

No community discussion yet for this question.

Full TERRAFORM-ASSOCIATE-003 Practice