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 }
B is correct. resource "aws_iam_user" "lb" { name = "terraform-${count.index}" count = 2 path = "/system/" } output "testing" { value = aws_iam_user.lb[1].name } ===== output ====== Plan: 2 to add, 0 to change, 0 to destroy. Changes to Outputs: + testing = "terraform-1"
B for sure
B..it is
The answer is B, aws_instance.web[1].name
I vote for B also. There is no reference to "name" in A
it must be B.
Answer is option B .Index starts at 0 , so name[1] is equivalent to second resource . SO this should be the answer
B - aws_instance.web[1].name !!! Index starts at 0 so the second instance would be 1 - the link below confirms this: https://www.terraform.io/language/meta-arguments/count#referring-to-instances
its B - people who answer incorrectly with such conviction and belief are dangerous.
because the index starts from 0 so second instance name will be at 1
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
Why no B?
It is correct, really is letter A, following the offcial answer above: element(list, index) - Returns a single element from a list at the given index. If the index is greater than the number of elements, this function will wrap using a standard mod algorithm. This function only works on flat lists. Examples: element(aws_subnet.foo.*.id, count.index) element(var.list_of_strings, 2)
B from doc
B, aws_instance.web[1].name
B is correct
A. element(aws_instance.web, 2) is correct if we want to access the 3rd one, but there is no "the third one"
D for sure
Index start with [0], so the second instance will be aws_instance.web[1]. Answer is B
Yes your're right
Yes your're right
They are two values of the name. name = terraform-1 name = terraform-2 The index is not assigned to the key (name) but to the value (terraform-$(count.index). Remember this is not a list assigned to a variable, don't reference it as a list. So you can't call the resource by specifying the index directly onto the key like name[1] simply because the the index is assigned to a part of the value which is a string not a list. The only way I think is to use the element function to call the resource after which specify the index number as an argument to the function - element(resource, index)
Option A is wrong because the element (list, index) is zero-based, so if at all we should use this function, the index ought to be 1, not 2 https://www.terraform.io/language/functions/element
Don't understand why you are suggesting A. Surely there will be two ec2 instances created here, you can just get the name property for those instances using B. The code terraform-${count.index} has no bearing on execution of the loop or anything to do with list's indexes.
B is correct answer.
B is the correct answer no doubt.
B is the right fromat
It is B
B is the correct answer
The output of A won't return the name of the 2nd instance. So here the answer is "B"
Tried and tested, definitely B
B is a correct answer, checked.
B for sure
why is it index number AND name, though? i would have thought that specifying the index number is enough