使用Terraform版本0.11.7,下面的代码出现此错误:
* 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
根据Terraform的文档,输出语法看起来正确
并且Terraform竞价型实例请求的确具有private_ip的属性,该属性在Terraform文档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}"]
}
但是,如果我从代码中删除了方括号,它可以工作并且没有错误,但是Terraform文档似乎在说我需要使用方括号,因为该值将是返回列表的列表类型每个实例的private_ip地址。我在这里做错了什么还是误会?
这可行,但似乎与文档矛盾:
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}"
}
答案 0 :(得分:1)
这应该有效。
wait_for_fulfillment = true
答案 1 :(得分:0)
这似乎是AWS提供程序中Terraform的一个错误,类似于issue #4313。我建议提出一个新的问题。
我测试了您的代码,发现了同样的问题。但是,一旦我在 apply 之后运行terraform refresh
,输出就很好了。
例如:
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
]