安全组定义中不允许使用自引用

问题描述 投票:10回答:1

我正在尝试使用Terraform创建sg。

我希望特定SG的所有实例之间都允许所有通信,因此我将SG本身添加到入口规则中,如下所示:

resource "aws_security_group" "rancher-server-sg" {
  vpc_id = "${aws_vpc.rancher-vpc.id}"
  name = "rancher-server-sg"
  description = "security group for rancher server"

  ingress {
      from_port = 0
      to_port = 0
      protocol = -1
      security_groups = ["${aws_security_group.rancher-server-sg.id}"]              
  }

但是运行terraform plan时,我得到:


但是,在AWS控制台中,我被允许在入站规则中添加一个SG名称,并且看到可以添加组本身(即,自我引用)。

为什么?

我也尝试了这个但没有成功:

security_groups = ["${self.id}"]
amazon-web-services terraform aws-security-group terraform-provider-aws
1个回答
26
投票

引用the manual

self-(可选)如果为true,则将安全组本身添加为此入口规则的来源。

  ingress {
      from_port = 0
      to_port = 0
      protocol = -1
      self = true
  }
© www.soinside.com 2019 - 2024. All rights reserved.