LoginSignup
1
1

More than 5 years have passed since last update.

CloudFormationでSecurityGroupを作るときにYou may not define rules between a VPC group and a non-VPC groupとエラーが出るときの対応

Posted at

CloudFormationでSecurityGroupを作るときにYou may not define rules between a VPC group and a non-VPC groupとエラーが出るときの対応

解決まで地味に30分程度掛かったのでメモ。

CloudFormationで次のような感じでSecurityGroupを作ろうとすると、You may not define rules between a VPC group and a non-VPC groupとエラーが出てSecurityGroupが作れない。

  DBEC2SecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: "Allow access from specific SecurityGroup"
      SecurityGroupIngress:
      - IpProtocol: tcp
        FromPort: '3306'
        ToPort: '3306'
        SourceSecurityGroupId: !Ref 'EC2SecurityGroup'

これはSourceSecurityGroupにVPCのSecurityGroupが指定されているのに、(VpcIdが指定されていないため)EC2 Classic環境にSecurityGroupが作られようとしているため出たエラーである(言葉にするとややこしい)。

ドキュメントにもあるが正しくはこんな感じ。

  DBEC2SecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      VpcId: !Ref VPC
      GroupDescription: "Allow access from specific SecurityGroup"
      SecurityGroupIngress:
      - IpProtocol: tcp
        FromPort: '3306'
        ToPort: '3306'
        SourceSecurityGroupId: !Ref 'EC2SecurityGroup'

ドキュメントは見ていたけど眠かったのとエラーメッセージに惑わされて解決まで時間掛かってしまった…。

1
1
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
1
1