当我尝试使用 terraform 数据源 (aws_ip_ranges) 获取服务“ec2”的可用 IP 地址范围时,出现错误。
provider "aws" {
region = "${var.AWS_REGION}"
}
variable "AWS_REGION" {
default = "eu-west-1"
}
data "aws_ip_ranges" "european_ec2" {
regions = [ "eu-west-1" ]
services = [ "ec2" ]
}
resource "aws_security_group" "from_europe" {
name = "from_europe"
ingress {
from_port = "443"
to_port = "443"
protocol = "tcp"
cidr_blocks = [ "${data.aws_ip_ranges.european_ec2.cidr_blocks}" ]
}
tags = {
CreateDate = "${data.aws_ip_ranges.european_ec2.create_date}"
SyncToken = "${data.aws_ip_ranges.european_ec2.sync_token}"
}
}
执行“terraform apply”时出现以下错误
Error: Incorrect attribute value type
on securitygroups.tf line 13, in resource "aws_security_group"
"from_europe":
13: cidr_blocks =
["${data.aws_ip_ranges.european_ec2.cidr_blocks}"]
Inappropriate value for attribute "cidr_blocks": element 0: string
required.
版本: Terraform v0.12.6 +provider.aws v2.23.0
请帮忙解决这个问题。
最佳答案
在 Terraform 0.12 中,参数的冗余数组大括号语法从必需变为错误。您可以更新代码并相应地利用一流变量表达式来解决问题:
resource "aws_security_group" "from_europe" {
name = "from_europe"
ingress {
from_port = "443"
to_port = "443"
protocol = "tcp"
cidr_blocks = data.aws_ip_ranges.european_ec2.cidr_blocks
}
}
关于amazon-web-services - 错误: Incorrect attribute value type - Terraform datasource(aws_ip_ranges),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57504755/