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

时间:2018-04-24 07:08:59

标签: amazon-web-services terraform aws-security-group terraform-provider-aws

我正在尝试使用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时,我得到:

Error: aws_security_group.rancher-server-sg: aws_security_group.rancher-server-sg: self reference not allowed: "aws_security_group.rancher-server-sg.id"

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

为什么?

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

security_groups = ["${self.id}"]

1 个答案:

答案 0 :(得分:11)

引用the manual

  

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

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