当我尝试使用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
请帮助解决此问题。
答案 0 :(得分:1)
在Terraform 0.12中,用于参数的冗余数组大括号语法从必需变为错误。您可以更新代码并相应地利用一流的变量表达式来解决此问题:
mounted()