代码之家  ›  专栏  ›  技术社区  ›  pkaramol

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

  •  17
  • pkaramol  · 技术社区  · 7 年前

    我正在尝试用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}"]
    
    1 回复  |  直到 5 年前
        1
  •  49
  •   Jakub Kania    7 年前

    引用 the manual :

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

      ingress {
          from_port = 0
          to_port = 0
          protocol = -1
          self = true
      }