Terraform v0.12.1错误属性值不合适;cidr“U块”:元素0:需要字符串

Terraform v0.12.1错误属性值不合适;cidr“U块”:元素0:需要字符串,terraform,terraform-provider-aws,terraform0.12+,Terraform,Terraform Provider Aws,Terraform0.12+,我刚刚从Terraform v0.11.11更新到v0.12.1,现在我看到了这些问题。我在一个列表中得到了整个列表,但我已经尝试了各种方法来解决这个问题,但没有成功。我在cidr_块=[之后移除了LBracket,但没有运气我尝试了在${}中进行扭曲。我尝试了在var.cidr_组之后移除LBracket。就像这样,没有运气var.cidr_组“main office”我哪里出了问题 resource "aws_security_group" "common_ac

我刚刚从Terraform v0.11.11更新到v0.12.1,现在我看到了这些问题。我在一个列表中得到了整个列表,但我已经尝试了各种方法来解决这个问题,但没有成功。我在cidr_块=[之后移除了LBracket,但没有运气我尝试了在${}中进行扭曲。我尝试了在var.cidr_组之后移除LBracket。就像这样,没有运气var.cidr_组“main office”我哪里出了问题

resource "aws_security_group" "common_access" {
  name        = "common_access"
  description = "common_access"
  vpc_id      = "${aws_vpc.myvcp.id}"

  ingress {
    from_port = 0
    to_port   = 0
    protocol  = "-1"
    cidr_blocks = [ 
      var.cidr_groups["mainoffice"],
      var.cidr_groups["manchester"],
      var.cidr_groups["singapore"],
      var.cidr_groups["jena"],
      var.cidr_groups["fremont"],
      var.cidr_groups["indianapolis"],
    ]
  }

  egress {
    from_port = 0
    to_port   = 0
    protocol  = "-1"

# TF-UPGRADE-TODO: In Terraform v0.10 and earlier, it was sometimes necessary to
    # force an interpolation expression to be interpreted as a list by wrapping it
    # in an extra set of list brackets. That form was supported for compatibilty in
    # v0.11, but is no longer supported in Terraform v0.12.
    #
    # If the expression in the following list itself returns a list, remove the
    # brackets to avoid interpretation as a list of lists. If the expression
    # returns a single list item then leave it as-is and remove this TODO comment.

    cidr_blocks = var.cidr_groups["PublicAll"]
  }

  tags = {
    Name      = "common_access"
    owner     = var.contact
    terraform = true
  }
}
var.cidr\u组的Vairables文件如下所示

variable "cidr_groups" {
  default = {
    mainoffice              = ["10.200.0.0/15"]
    manchester              = ["10.201.0.0/16"]
    singapore               = ["10.202.0.0/16"]
    jena                    = ["10.203.0.0/16"]
    fremont                 = ["10.204.0.0/16"]
    indianapolis            = ["10.205.0.0/16"]
     
  }
}

您似乎缺少未定义的
var.cidr_组[“PublicAll”]
。请尝试使用此选项

我从
var.cidr_组中删除了方括号
,并添加了
PublicAll

variable "cidr_groups" {
  default = {
    mainoffice   = "10.200.0.0/15"
    manchester   = "10.201.0.0/16"
    singapore    = "10.202.0.0/16"
    jena         = "10.203.0.0/16"
    fremont      = "10.204.0.0/16"
    indianapolis = "10.205.0.0/16"
    PublicAll    = "0.0.0.0/0"
  }
}
保持入口
cidr_块
相同,然后将其用于出口

  cidr_blocks = [var.cidr_groups["PublicAll"]]