In Terraform HCL, how do you reference the indexing attribute of the AWS instance resource named 'web'?

Prepare for the HashiCorp Terraform Associate Exam with quizzes, flashcards, and multiple-choice questions. Each question includes hints and explanations. Boost your confidence and ace your exam!

Multiple Choice

In Terraform HCL, how do you reference the indexing attribute of the AWS instance resource named 'web'?

Explanation:
When a Terraform resource is created with for_each, you address a specific instance by combining the resource type, the resource name, and the key in brackets. The key identifies which instance you’re referring to. So to reference the particular instance of AWS instance named web that corresponds to the key "indexing," you use aws_instance.web["indexing"]. From there you can access its attributes like aws_instance.web["indexing"].id, aws_instance.web["indexing"].private_ip, etc. The other forms don't fit because they either assume a single instance (aws_instance.web.id), try to index the resource name inappropriately (aws_instance["web"]["indexing"]), or use invalid syntax (aws_instance-web["indexing"]).

When a Terraform resource is created with for_each, you address a specific instance by combining the resource type, the resource name, and the key in brackets. The key identifies which instance you’re referring to. So to reference the particular instance of AWS instance named web that corresponds to the key "indexing," you use aws_instance.web["indexing"]. From there you can access its attributes like aws_instance.web["indexing"].id, aws_instance.web["indexing"].private_ip, etc.

The other forms don't fit because they either assume a single instance (aws_instance.web.id), try to index the resource name inappropriately (aws_instance["web"]["indexing"]), or use invalid syntax (aws_instance-web["indexing"]).

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy