【问题标题】:Error: Incorrect attribute value type - Terraform datasource(aws_ip_ranges)错误:属性值类型不正确 - Terraform 数据源(aws_ip_ranges)
【发布时间】: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


【解决方案1】:

在 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
  }
}

【讨论】:

    猜你喜欢
    • 2021-12-24
    • 2021-01-16
    • 1970-01-01
    • 2020-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多