2 개의 VPC 보안 그룹을 만들고 싶습니다.Terraform을 사용하여 AWS VPC 보안 그룹을 만들 때 순환 오류가 발생했습니다.
VPC의 요새 호스트 용이고 개인 서브넷 용입니다.
# 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`**
는 계획이 잘 실행됩니다.
또한 BastionSG에서 PrivateSG에 대한 출력 규칙을 주석 처리하면 정상적으로 실행됩니다.
AWS Scenario 2 for building a VPC with Public/Private subnets and Bastion host에는 설정하려는 아키텍처가 나와 있습니다.
AWS 콘솔을 통해 정확히 동일한 설정이 구성되었으며 정상적으로 작동합니다.
왜 Terraform은 그것을 받아들이지 않습니까? Bastion 보안 그룹을 개인 보안 그룹에 연결하는 다른 방법이 있습니까?
어떻게 든 AWS에서 유효하더라도 휴식을 필요로하는 두 개의 초 그룹 간의 순환 참조가 알고있는 것처럼
편집 할 수 있습니다.
그래서 Bastion sec 그룹의 모든 아웃 바운드 트래픽 (0.0.0.0/0)을 허용하고 개별 보안 그룹에 지정하지 않을 것입니다.
보안에 영향이 있습니까?
terraform GitHub에서 서로에 따라 보안 그룹을 설명하는 데 문제가 있습니다. 스레드의 끝에있는 권장 솔루션이 귀하의 경우에 효과가 있습니까? https://github.com/hashicorp/terraform/issues/539 – jbird
@jbird를 지적 해 주셔서 감사합니다. 나는 이것을 CIDR 블록으로 교체했고 더 이상 불평하지 않고있다. 그러나 명확하고 설명적인 코드를 원한다면 ydaetskcoR의 대답을 선호 할 것입니다. –