Terraform Associate Exam QuestionsBrowse all questions from this exam

Terraform Associate Exam - Question 57


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

Show Answer
Correct Answer: B

In Terraform, when using the count argument in a resource block, the instances are indexed starting from 0. To reference the 'name' value of the second instance, you would use the 1-based index, which corresponds to the 0-based index used internally by Terraform. Therefore, the correct reference to the 'name' value of the second instance would be aws_instance.web[1].name, utilizing the appropriate index.

Discussion

17 comments
Sign in to comment
franksoulOption: B
Jun 9, 2022

Dear ALL, tested in Lab and Answer is : B

bigboi23Option: B
May 18, 2022

B!!!!!!!!

NunyabiznesOption: B
Mar 20, 2023

The count.index starts from 0. Therefore, the second instance would have an index of 1. In that case, the correct answer would be B. aws_instance.web[1].name.

BereOption: B
Aug 7, 2023

Example: resource "aws_instance" "web" { count = 2 name = "terraform-${count.index}" } output "second_instance_name" { value = aws_instance.web[1].name }

Bluemoon22Option: B
Apr 24, 2023

The answer is B, aws_instance.web[1].name

Ell89Option: B
Mar 12, 2023

its B - people who answer incorrectly with such conviction and belief are dangerous.

samimshaikhOption: B
Dec 29, 2023

because the index starts from 0 so second instance name will be at 1

debabrata6983Option: B
Aug 26, 2023

This is the very basics of terraform resource referencing

nhaastrupOption: B
Apr 30, 2024

To reference the "name" value of the second instance of the fictitious resource "aws_instance" named "server", you can use the element index notation in Terraform. The element index notation allows you to access elements in a list or collection by their index. Given that the index in Terraform starts from 0, the second instance has an index of 1. Therefore, to reference the "name" value of the second instance = B

Power123Option: B
Mar 30, 2023

B is correct

kingfighersOption: D
Apr 2, 2024

A. element(aws_instance.web, 2) is correct if we want to access the 3rd one, but there is no "the third one"

asudhinOption: B
Oct 3, 2022

It is B

adoubanOption: B
Dec 9, 2022

B is the correct answer

BebinsOption: B
Dec 28, 2022

The output of A won't return the name of the 2nd instance. So here the answer is "B"

oab720Option: B
Jan 8, 2023

Tried and tested, definitely B

thor7Option: B
Mar 29, 2023

B is a correct answer, checked.

gofavad926Option: B
Sep 29, 2023

B for sure