1
votes

Using Terraform version 0.11.7 the code below I get this error:

    * output.aws_runner_private_ip_addresses: Resource 'aws_spot_instance_request.runner' does not have attribute 'private_ip' for variable 'aws_spot_instance_request.runner.*.private_ip'
    * output.aws_walker_private_ip_addresses: Resource 'aws_spot_instance_request.walker' does not have attribute 'private_ip' for variable 'aws_spot_instance_request.walker.*.private_ip

The output syntax looks correct according the documentation from Terraform

And terraform spot instance request does have the attribute of private_ip which is stated in Terraform documentation here.

resource "aws_spot_instance_request" "walker" {
  count = 2
  instance_type = "t2.micro"
  ami = "ami-0922553b7b0369273"
  spot_price = "1"
}

resource "aws_spot_instance_request" "runner" {
  count = 2
  instance_type = "t2.micro"
  ami = "ami-0922553b7b0369273"
  spot_price = "1"

}

output "aws_walker_private_ip_addresses" {
    value = ["${aws_spot_instance_request.walker.*.private_ip}"]
}

output "aws_runner_private_ip_addresses" {
    value = ["${aws_spot_instance_request.runner.*.private_ip}"]
}

However, if I remove the square brackets from the code, it works and there is no error, but the Terraform document seems to be saying I need to use the square brackets since the value would be a list type of returning list of private_ip addresses for each instance. What am I doing wrong here or misunderstanding?

This works, but seems to contradict the document:

output "aws_walker_private_ip_addresses" {
    value = "${aws_spot_instance_request.walker.*.private_ip}"
}

output "aws_runner_private_ip_addresses" {
    value = "${aws_spot_instance_request.runner.*.private_ip}"
}
2

2 Answers

1
votes

This should work.

wait_for_fulfillment = true
0
votes

This looks like a bug in the AWS provider for Terraform, similar to issue #4313. I suggest filing a new issue.

I tested your code and found the same issue. However, once I ran terraform refresh after the apply, the outputs looked fine. E.g.:

Outputs:

aws_runner_private_ip_addresses = [
  172.31.79.186,
  172.31.71.22
]
aws_walker_private_ip_addresses = [
  172.31.69.119,
  172.31.66.50
]