繁体   English   中英

我应该如何使用 terraform 在入口安全组中定义范围?

[英]How should I define ranges in ingress security group using terraform?

我找不到如何在入口安全组中使用 terraform 定义范围。 检查文档字段to_portfrom_port范围端口。 但是,我找不到如何配置它。

使用 aws CLI 的工作示例:

aws ec2 authorize-security-group-ingress \
    --region $REGION \
    --group-name test \
    --protocol tcp \
    --port 50000-50001 \
    --cidr 0.0.0.0/0

但我无法使用 terraform 做同样的事情。 我尝试在安全组资源中配置相同的内容:

resource "aws_security_group" "allow_tls" {
  name        = "allow_tls"
  description = "Allow TLS inbound traffic"
  vpc_id      = aws_vpc.main.id

  ingress {
    description      = "allow_tls"
    from_port        = 50000-50001
    to_port          = 50000-50001
    protocol         = "tcp"
    cidr_blocks      = ["0.0.0.0/0"]
  }

  tags = {
    Name = "allow_tls"
  }
}

我遇到的问题是它会自动将to_portfrom_port设置为-1值。

# from terraform plan output
              + cidr_blocks      = [
                  + "0.0.0.0/0",
                ]
              + description      = "allow_tls"
              + from_port        = -1
              + ipv6_cidr_blocks = []
              + prefix_list_ids  = []
              + protocol         = "tcp"
              + security_groups  = []
              + self             = false
              + to_port          = -1
            }

也尝试使用aws_security_group_rule并且它具有相同的行为。 知道如何解决吗?

它应该是:

    from_port        = 50000
    to_port          = 50001

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM