LoginSignup
13
15

More than 5 years have passed since last update.

piculetで管理するAWSセキュリティグループ

Last updated at Posted at 2014-09-09

Piculet

AWSのセキュリティグループの設定をRubyのDSLで管理できるCLIツール。

作成者サイト
http://so-wh.at/entry/20131105/p1

Github
https://github.com/winebarrel/piculet

インストール

インストール

gem install piculet --no-ri --no-rdoc

確認

➜  piculet -v 
piculet 0.2.3

➜  piculet
Usage: piculet [options]
    -p, --profile PROFILE_NAME
    -k, --access-key ACCESS_KEY
    -s, --secret-key SECRET_KEY
    -r, --region REGION
    -a, --apply
    -f, --file FILE
    -n, --names SG_LIST
        --ec2s VPC_IDS
        --dry-run
    -e, --export
    -o, --output FILE
        --split
        --no-color
        --debug

security credentialsを記載

➜  vim ~/.aws/credentials
[default]
aws_access_key_id=AKIxxxxxxxxxxxxxxxx
aws_secret_access_key=xxxxxxxxxxxxxxxxxxxxx

セキュリティグループを取得

piculet -e -o Groupfile -r ap-northeast-1
➜ cat Groupfile
ec2 "vpc-[vpc-id]" do
  security_group "default" do
    description "default VPC security group"

    ingress do
      permission :any do
        groups(
          "default"
        )
      end
    end

    egress do
      permission :any do
        ip_ranges(
          "0.0.0.0/0"
        )
      end
    end
  end
end

セキュリティグループが多い場合はsplitオプションを使用すると、
ファイルを分けてくれるため管理がし易い。

➜   piculet -e -o Groupfile -r ap-northeast-1 --split
Export SecurityGroup
  write `./vpc-xxxxxxx.group`
  write `./vpc-xxxxxxx.group`
  write `Groupfile`

セキュリティグループの適用

他のVPCへの移行やセキュリティグループの編集を行う場合の手順

移行先のcredentials追加

➜  vim ~/.aws/credentials
[hoge]
aws_access_key_id=AKIxxxxxxxxxxxxxxxx
aws_secret_access_key=xxxxxxxxxxxxxxxxxxxxx

Groupfile編集

require 'vpc-[移行先もしくは編集先のVPC-ID].group'                                                                       

テスト

piculet -a -r ap-northeast-1  -p hoge --dry-run

適用

piculet -a -r ap-northeast-1  -p hoge

etc

お手軽なセキュリティグループの管理と移行が可能になった!

13
15
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
13
15