【问题标题】:Terraform v0.12.1 error Inappropriate value for attribute "cidr_blocks": element 0: string requiredTerraform v0.12.1 错误属性“cidr_blocks”的值不合适:元素 0:需要字符串
【发布时间】:2021-07-17 20:56:05
【问题描述】:

我刚刚从 Terraform v0.11.11 更新到 v0.12.1,我现在看到了这些问题。我将整个列表放在一个列表中,但我已经尝试了各种方法来解决这个问题,但没有运气。我在 cidr_blocks = [ 之后删除了 LBracket,但没有成功我尝试在 ${} 中进行变形,不行.我尝试在 var.cidr_groups 之后删除 lbrackets.. 就像没有运气 var.cidr_groups"mainoffice"。我哪里错了?

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_groups 的 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"]
     
  }
}

【问题讨论】:

    标签: terraform terraform-provider-aws terraform0.12+


    【解决方案1】:

    您似乎缺少未定义的var.cidr_groups["PublicAll"]。请尝试改用它。

    我从var.cidr_groups 中删除了方括号并添加了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_blocks 不变,然后将其用于出口。

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

    【讨论】:

      猜你喜欢
      • 2020-04-09
      • 2019-12-28
      • 1970-01-01
      • 2021-06-23
      • 2021-11-27
      • 2020-08-09
      • 2021-03-26
      • 1970-01-01
      • 2021-02-09
      相关资源
      最近更新 更多