17

我正在尝试使用 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}"]
4

1 回答 1

48

引用手册

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

  ingress {
      from_port = 0
      to_port = 0
      protocol = -1
      self = true
  }
于 2018-04-24T07:28:21.587 回答