nerdexam
HashiCorp

TA-002-P · Question #239

Given the below resource configuration - resource "aws_instance" "web" { # ... count = 4 } What does the terraform resource address aws_instance.web refer to?

The correct answer is A. It refers to all 4 web instances , together , for further individual segregation , indexing is. When the 'count' meta-argument is used, Terraform creates multiple instances indexed from 0 to N-1. The bare reference 'aws_instance.web' (without an index) refers to the entire collection of all 4 instances as a list. To target a specific instance, you use index notation…

Understand Terraform basics

Question

Given the below resource configuration - resource "aws_instance" "web" { # ... count = 4 } What does the terraform resource address aws_instance.web refer to?

Options

  • AIt refers to all 4 web instances , together , for further individual segregation , indexing is
  • BIt refers to the last web EC2 instance , as by default , if no index is provided , the last / N-
  • CIt refers to the first web EC2 instance out of the 4 ,as by default , if no index is provided ,
  • DThe above will result in a syntax error , as it is not syntactically correct . Resources

How the community answered

(49 responses)
  • A
    92% (45)
  • B
    4% (2)
  • C
    2% (1)
  • D
    2% (1)

Explanation

When the 'count' meta-argument is used, Terraform creates multiple instances indexed from 0 to N-1. The bare reference 'aws_instance.web' (without an index) refers to the entire collection of all 4 instances as a list. To target a specific instance, you use index notation: aws_instance.web[0], aws_instance.web[1], etc. This collective reference is useful in expressions like 'for_each' or when passing the full list to another resource.

Topics

#count meta-argument#resource addressing#resource collection#Terraform language basics

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice