Terraform v0.11.1
aws_instance
<applicable snippet>
resource "aws_instance" "guacamole" {
count = "${var.how_many}"
ami = "${data.aws_ami.guac_ami.id}"
instance_type = "t2.small"
key_name = "${var.key_name}"
connection {
type = "ssh"
user = "ubuntu"
private_key = "${file("${var.key_name}.pem")}"
timeout = "3m"
}
# Our Security group to allow HTTP and SSH access
vpc_security_group_ids = ["${aws_security_group.landshark.id}"]
subnet_id = "${element(aws_subnet.aw_sub.*.id, count.index)}"
private_ip = "10.0.${count.index + 1}.70"
#Instance tags
tags {
Name = "${var.identifier}_${var.image_base}_guacamole_${count.index + 1}"
LANDSHARK = "GUAC"
STUDENT = "${count.index + 1}"
UUID= "${random_id.rval.hex}"
"dlpx:Project" = "${var.project_name}"
"dlpx:Owner" = "${var.identifier}"
"dlpx:Expiration" = "${var.expiration}"
}
}
output "GUACAMOLE" {
value = "${
formatlist(
"Jumpbox [%s] - Public IP: %s Private IP: %s\n Access via vnc http://%s:8080/labs\n",
aws_instance.de.*.tags.STUDENT,
aws_instance.guacamole.*.public_ip,
aws_instance.guacamole.*.private_ip,
aws_instance.guacamole.*.public_ip
)}"
}
</applicable snippet>
https://gist.github.com/CloudSurgeon/222ca814d8600fff4986e6faeb112ac3
Output that looks like this should be printed (as it works with 10.8):
GUACAMOLE = [
Jumpbox [1] - Public IP: 34.205.191.218 Private IP: 10.0.1.70
Access via vnc http://34.205.191.218:8080/labs
]
Got an error message stating that aws_instance.de does not have tags.STUDENT
Error: Error running plan: 4 error(s) occurred:
terraform plan
This has worked, and still does with 10.8. If I plan/apply the same blueprints and plugin versions with 10.8, this works. Just upgrading to 11.1 has surfaced this problem.
This seems to be applicable specifically to aws_instance. I was able to output the same tag information from my aws_subnet resources, but failed on attempting all tags applied to my aws_instance (ie. Name, STUDENT, LANDSHARK, etc)
I suspect your are experiencing this
https://www.terraform.io/upgrade-guides/0-11.html#referencing-attributes-from-resources-with-count-0
Unfortunately not. 1) The count isn't 0. 2) I get the same result with the following HCL. The aws_instance throws an error, the aws_subnet does not. They both use the same count=${var.how_many} ```output "TEST_1" {
value = "${aws_subnet.aw_sub.0.tags.Name}"
}
output "TEST_2" {
value = "${aws_instance.guacamole.0.tags.Name}"
}```
gist for that here: https://gist.github.com/CloudSurgeon/1a18ad8a82eab93724a272d629b87c37
Also, to cover all bases, I also created a third clause to test the solution:
output "TEST_3" {
value = "${element(concat(aws_instance.guacamole.*.tags.Name, list("")), 0)}"
}
Results in this error:
This output
output "SHOW TAGS" {
value = "${aws_instance.guacamole.0.tags}"
}
yields
SHOW TAGS = {
LANDSHARK = GUAC
Name = testuser_landshark-sdlc_v2-5.2.2.0-jet_stream_guacamole_1
STUDENT = 1
UUID = 473c7db242067b6e
dlpx:Expiration = 2017-12-21
dlpx:Owner = testuser
dlpx:Project = Presales Demo
}
can you try aws_instance.guacamole.*.tags["Name"] instead?
Error:
Error running plan: 1 error(s) occurred:*
output.SHOW TAGS: __builtin_StringToInt: strconv.ParseInt: parsing
"Name": invalid syntax in:*
${aws_instance.guacamole.*.tags["Name"]}
but this works
output "SHOW TAGS" {
value = "${aws_instance.guacamole.0.tags["Name"]}"
}
Outputs:
SHOW TAGS = testuser_landshark-sdlc_v2-5.2.2.0-jet_stream_guacamole_1
That gets me closer (I think), but doesn't solve the situation.
i hit the same issue with the following sample configuration
resource "random_id" "foo" {
byte_length = 8
}
resource "aws_security_group" "foo" {
vpc_id = "vpc-3bb49742"
tags {
XYZ = "${random_id.foo.hex}"
}
}
output "foo" {
value = "${aws_security_group.foo.tags.XYZ}"
}
Output:
Error: Error running plan: 1 error(s) occurred:
* output.foo: Resource 'aws_security_group.foo' does not have attribute 'tags.XYZ' for variable 'aws_secur
ity_group.foo.tags.XYZ'
If tag XYZ is hardcoded then there is no issue.
I'm started hitting this same issue with a plugin that I wrote. Any updates on what is causing this? I tried changing to the recommended ${element(concat(aws_instance.example.*.id, list("")), 0)} to pull the values, but that didn't fix it. I also tried adding the export TF_WARN_OUTPUT_ERRORS=1 and it is still having issues.
Here is my error: Resource 'csgcloud_catalog_service.chef-infra' does not have attribute 'vm_host_name' for variable 'csgcloud_catalog_service.chef-infra.*.vm_host_name'
I echo the value out in the debugs and the value is being set.
I also updated to 0.11.3 and I am still having the issue.
Hi @CloudSurgeon! Thanks for taking the time to submit this issue. I had a look at this with the most recent versions of Terraform and the AWS Provider and was unable to reproduce this behavior. We’re going to close this issue for now, but if you run into this again with the latest Terraform and Provider versions, please feel free to open a new issue. 🙂
I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.
If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!
Most helpful comment
I'm started hitting this same issue with a plugin that I wrote. Any updates on what is causing this? I tried changing to the recommended ${element(concat(aws_instance.example.*.id, list("")), 0)} to pull the values, but that didn't fix it. I also tried adding the export TF_WARN_OUTPUT_ERRORS=1 and it is still having issues.
Here is my error: Resource 'csgcloud_catalog_service.chef-infra' does not have attribute 'vm_host_name' for variable 'csgcloud_catalog_service.chef-infra.*.vm_host_name'
I echo the value out in the debugs and the value is being set.
I also updated to 0.11.3 and I am still having the issue.