QuestionQ34

VerifiedTerraform configuration

A resource block appears in the Exhibit area of this page.

resource “aws_instance” “web” \{  
  count = 2  
  name = “terraform-$\{count.index\}”  
\}  

How do you refer to the name value for the second instance of this resource?

Explanation

Terraform indexes resource instances created with count starting at 0. The second aws_instance.web instance therefore has index 1, and its name attribute is accessed as aws_instance.web[1].name.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!