How would you reference the "name" value of the second instance of this fictitious resource?
How would you reference the "name" value of the second instance of this fictitious resource?
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.
Dear ALL, tested in Lab and Answer is : B
B!!!!!!!!
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.
Example: resource "aws_instance" "web" { count = 2 name = "terraform-${count.index}" } output "second_instance_name" { value = aws_instance.web[1].name }
The answer is B, aws_instance.web[1].name
because the index starts from 0 so second instance name will be at 1
its B - people who answer incorrectly with such conviction and belief are dangerous.
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
This is the very basics of terraform resource referencing
A. element(aws_instance.web, 2) is correct if we want to access the 3rd one, but there is no "the third one"
B is correct
B for sure
B is a correct answer, checked.
Tried and tested, definitely B
The output of A won't return the name of the 2nd instance. So here the answer is "B"
B is the correct answer
It is B