0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

TerraformでSGを作成する際、ルールにSGを指定する方法

Posted at

1.概要

Terraformでセキュリティグループのルールを作成する際に、セキュリティグループを指定する方法を記述した記事が公式以外で見当たらなかったので記事にしました。

2.記述方法

CIDRブロックで指定する場合

cidr_blocks = ["0.0.0.0/0"]

セキュリティグループで指定する場合

security_groups = ["sg-xxxxxxxxx"]

全体の記述

resource "aws_security_group" "test-sg" {
  name        = "test-sg"
  vpc_id      = aws_vpc.main.id

  ingress {
    from_port   = 80
    to_port     = 80
    protocol    = "tcp"
    security_groups = ["sg-xxxxxxxxx"]
  }

  egress {
    from_port = 0
    to_port   = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }
}

3.公式記事

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?