2 つの VPC セキュリティ グループを作成したいと考えています。
1 つは VPC の Bastion ホスト用で、もう 1 つはプライベート サブネット用です。
# BASTION #
resource "aws_security_group" "VPC-BastionSG" {
name = "VPC-BastionSG"
description = "The sec group for the Bastion instance"
vpc_id = "aws_vpc.VPC.id"
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["my.super.ip/32"]
}
egress {
# Access to the Private subnet from the bastion host[ssh]
from_port = 22
to_port = 22
protocol = "tcp"
security_groups = ["${aws_security_group.VPC-PrivateSG.id}"]
}
egress {
# Access to the Private subnet from the bastion host[jenkins]
from_port = 8686
to_port = 8686
protocol = "tcp"
security_groups = ["${aws_security_group.VPC-PrivateSG.id}"]
}
tags = {
Name = "VPC-BastionSG"
}
}
# PRIVATE #
resource "aws_security_group" "VPC-PrivateSG" {
name = "VPC-PrivateSG"
description = "The sec group for the private subnet"
vpc_id = "aws_vpc.VPC.id"
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
security_groups = ["${aws_security_group.VPC-BastionSG.id}"]
}
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
security_groups = ["${aws_security_group.VPC-PublicSG.id}"]
}
ingress {
from_port = 443
to_port = 443
protocol = "tcp"
security_groups = ["${aws_security_group.VPC-PublicSG.id}"]
}
ingress {
from_port = 3306
to_port = 3306
protocol = "tcp"
security_groups = ["${aws_security_group.VPC-PublicSG.id}"]
}
ingress {
from_port = 8686
to_port = 8686
protocol = "tcp"
security_groups = ["${aws_security_group.VPC-BastionSG.id}"]
}
ingress {
# ALL TRAFFIC from the same subnet
from_port = 0
to_port = 0
protocol = "-1"
self = true
}
egress {
# ALL TRAFFIC to outside world
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "VPC-PrivateSG"
}
}
するとterraform plan
、次のエラーが返されます。
**`Error configuring: 1 error(s) occurred:
* Cycle: aws_security_group.VPC-BastionSG, aws_security_group.VPC-PrivateSG`**
PrivateSG から BastionSG のイングレス ルールをコメント アウトすると、プランは正常に実行されます。
また、BastionSG から PrivateSG のエグレス ルールをコメント アウトすると、正常に実行されます。
パブリック/プライベート サブネットと Bastion ホストを使用して VPC を構築するためのAWS シナリオ 2 では、セットアップしようとしているアーキテクチャについて説明しています。
AWS コンソールを介して構成されたまったく同じ設定があり、正常に再生されます。
Terraform がそれを受け入れないのはなぜですか? Bastion セキュリティ グループを Private セキュリティ グループに接続する別の方法はありますか?
編集
私が理解しているように、2 つの秒グループの間に循環参照があり、AWS では有効であっても何らかの形で中断する必要があります。
そこで、Bastion sec グループからのすべてのアウトバウンド トラフィック (0.0.0.0/0) を許可し、個々のセキュリティ グループには指定しないことを考えました。
セキュリティに悪影響を与えるでしょうか?