LoginSignup
1
1

More than 5 years have passed since last update.

Piculetで出力された情報より、SecurityGroup別のファイルへ分割するワンライナー

Posted at

元同僚さん=先人の知見を見て思いつきました。
Piculetで出力された結果より、VPC_IDを拾い上げた上でSecurityGroup別にrbファイルを作ってくれます。
VPC別管理以外にもSG別に管理する場面もあるかと思います(ありました)ので作ってみました。

for vpc_rb in $(ls -1 vpc-*.rb);do for sg in `grep security_group ${vpc_rb}| gsed -e 's/[[:space:]]security_group[[:space:]]"\(.*\)" do/\1/g'`;do gsed -n -e '/^ec2[[:space:]]"\(.*\)"[[:space:]]do/p;/^end/p;/^\(. \)security_group[[:space:]]"'${sg}'"/,/^\(. \)end/p;' ${vpc_rb} > ${sg}.rb ;done;done

前提: vpc-*.rb というファイル名でpiculet向けrbがVPC単位で作成されている必要があります。
複数のVPCが1つのrbで混在していた場合はうまく動作しません。

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