0
0

AWS cdkでの自己参照セキュリティグループの作成

Posted at

aws glueを利用するときに自己参照のセキュリティグループを作成するのですが、
ちょいと詰まったので備忘録として

自己参照のセキュリティグループはセキュリティーグループのソースが自分自身のちょっと変なやつ
参考はこちら
https://qiita.com/kodai_ari/items/33e6f31006277debbf76

こんな感じで書くとエラーになりました。

const connectionSG = new ec2.SecurityGroup(this, 'connectionSG', {
    vpc,
    description: 'connectionSG',
    allowAllOutbound: true,
    disableInlineRules: true,
});

connectionSG.addIngressRule(
    ec2.Peer.securityGroupId(connectionSG.securityGroupId),
    ec2.Port.allTcp()
);

エラー内容はこちら

failed: Error [ValidationError]: Circular dependency between resources

多分こちらの記事みたいなことが起きていると思われ、、
https://yomon.hatenablog.com/entry/2019/10/securitygroupselfref

この書き方でもルールの追加なんだからいいじゃんと思うがだめらしい、
正しい書き方はこちら⇩

const connectionSG = new ec2.SecurityGroup(this, 'connectionSG', {
    vpc,
    description: 'connectionSG',
    allowAllOutbound: true,
    disableInlineRules: true,
});

connectionSG.addIngressRule(
    ec2.Peer.securityGroupId(connectionSG.securityGroupId),
    ec2.Port.allTcp()
);

最初にセキュリティグループを作成するときにdisableInlineRulesをtrueにするとうまくできた。
これをtrueに設定すると、ingressルールとegressルールはcloudformationのSecurityGroupの下で宣言されず、別の要素になるらしい。
おそらく、セキュリティグループを作成して自己参照のルールを設定するcloudFormationに変わる(と思ってる)

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