【发布时间】:2019-12-21 14:30:58
【问题描述】:
当我尝试使用 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
请帮助解决这个问题。
【问题讨论】:
-
虽然您尝试获取
eu-west-1区域资源,但您的默认 AWS 区域设置为ap-south-1似乎有点奇怪 -
试试
cidr_blocks = data.aws_ip_ranges.european_ec2.cidr_blocks -
@Andremoniy - 抱歉错字错误,实际上我改变了它但不是在这里。现在进行了更改
标签: amazon-web-services terraform aws-security-group