설명
AWS::EC2::SecurityGroup에서 VpcId를 생략하면 CloudFormation은 해당 리전의 기본 VPC를 사용합니다.
잠재적 영향
리전에 기본 VPC가 없으면 그룹 생성에 실패합니다. 기본 VPC가 있더라도 대상 리소스와 다른 VPC에 그룹이 생성될 수 있습니다.
해결 방법
VpcId에 그룹을 사용할 리소스의 VPC를 지정하세요. 기존 그룹의 VPC를 바꾸면 그룹이 교체되므로 연결 중단에 대비하세요.
예시
myVPC에는 대상 VPC를, AdminCidr에는 SSH를 허용할 관리용 주소 범위를 지정하세요.
변경 전
yaml
Resources:
InstanceSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupName: My Group Name
# 22번 포트로 SSH 접근 허용
GroupDescription: Enable SSH access via port 22
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: !Ref AdminCidr
변경 후
yaml
Resources:
InstanceSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupName: My Group Name
# 22번 포트로 SSH 접근 허용
GroupDescription: Enable SSH access via port 22
VpcId:
Ref: myVPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: !Ref AdminCidr