Error: Incorrect attribute value type - Terraform datasource(aws_ip_ranges)
Error: Incorrect attribute value type - Terraform datasource(aws_ip_ranges)
当我尝试使用 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 中,参数的冗余数组大括号语法从必需变为错误。您可以更新代码并相应地使用第一个 class 变量表达式来解决问题:
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
}
}
当我尝试使用 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 中,参数的冗余数组大括号语法从必需变为错误。您可以更新代码并相应地使用第一个 class 变量表达式来解决问题:
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
}
}