错误:属性“ cidr_blocks”的值不合适:所需的字符串列表

时间:2019-08-22 19:37:58

标签: terraform-provider-aws

在创建安全组时,我不断收到以下错误消息

  

属性“ cidr_blocks”的值不合适:字符串列表   必填。

这是 main.tf

的摘录
resource "aws_security_group" "sg_sagum" {
  name        = var.sg_sagum1
  vpc_id      = data.aws_vpc.vpcname.id
  description = var.sg_sagum1
  tags = {
    Name = var.sg_sagum1
  }    
  dynamic "ingress" {
    for_each = [for s in var.sg_sagum_ports : {
      from_port = s.from_port
      to_port   = s.to_port
      desc = s.desc
      cidrs = s.cidr
    }]
    content {
      from_port   = ingress.value.from_port
      to_port     = ingress.value.to_port
      cidr_blocks = ingress.value.cidrs
      protocol    = "tcp"
      description = ingress.value.desc
    }
  }
}

variables.tf

variable "sg_sagum_ports" {    
  description = "Ports to be opened on SAGUM SG"    
  type        = list(map(string))    
  default     = []  
  }

terraform.tfvars

sg_sagum_ports = [
  { from_port = "9000",
    to_port   = "9000",
    cidr      = "10.22.9.11/32"
    desc      = "SAGBPMS"
  }
]
  

属性“ cidr_blocks”的值不合适:字符串列表   必填。

1 个答案:

答案 0 :(得分:0)

terraform.tfvars中,您需要将cidr更改为

cidr      = "10.22.9.11/32"

cidr      = ["10.22.9.11/32"]