VPC のガワを作るソレ
とりあえず雛形ってことで色々検討してみた。手順としては以下かな、と。
- Create VPC
- Create Subnet
- Create Internet Gateway
- Create Security Group
- Create Route Table (ガワのみ)
- Create ELB
- Create DB Subnet Group
本当は Route Table 作る前に EC2 なリソース (NAT な AMIなヤツ) を確保しておいて、とか色々あるんですが当座はガワのみ。
しかも VPC の中の RDS は DB Subnet Group が云々なのですが手元の aws-sdk なソレを見てみるに対象範疇外な模様です。ここは手動になりますね。
ざくっと確認したとこでは基本的に *Collection#create で作る模様。おそらくは
AWS::EC2::VPC.new だとスデに AWS に存在しているインスタンスの参照を取得する形で、実際インスタンスを生成 (?) する場合、AWS::EC2::VPCCollection#create というメソドを使う形なのかな、という理解です。
つうか、AWS::EC2::VPCCollection なオブジェクトはどうやって作るんでしょ。spec 見てるんだけどよく分からんな。て、
it 'calls #create_vpc on the client' do client.should_receive(:create_vpc). with(:cidr_block => '10.0.0.0/16', :instance_tenancy => 'default'). and_return(response) vpcs.create('10.0.0.0/16') end
な vpcs て lib/aws/ec2.rb で定義されてる
# @return [VPCCollection] A collection representing # all VPCs in your account. def vpcs VPCCollection.new(:config => config) end
つーことで良いのかな。あ、それで lib/aws/ec2/vpc_collection.rb のコメントは
# Creates a VPC with the CIDR block you specify. The smallest VPC you # can create uses a /28 netmask (16 IP addresses), and the largest # uses a /16 netmask (65,536 IP addresses). # # vpc = ec2.vpcs.create('10.0.0.0/16')
ってなってたのか。あるいは EC2 なオブジェクトは
# ec2 = AWS::EC2.new( # :access_key_id => 'YOUR_ACCESS_KEY_ID', # :secret_access_key => 'YOUR_SECRET_ACCESS_KEY')
つーナニで大丈夫なのか。ふむ。
Subnets
これも、
subnets = ec2.subnets.create('10.0.0.0/20')
とかで OK なカンジ。あら、おかしいな、vpc に、なカンジにしないとマズい。こうか
subnets = ec2.subnets.create('10.0.0.0/20', {:vpc => vpc.vpd_id, :availability_zone => 'xxxx'})
みたいにするんかな。
Internet Gateway
こっちは後で割り付けるカンジ。
internet_gateway = ec2.internet_gateways.create
して
internet_gateway.attach(vpc)
で良いのかどうか。
Security Group
こちらは
security_group = ec2.security_groups.create('AP', {:description => 'AP', :vpc => vpc})
で良いらしい。ガワのみ、だと楽ちんだなぁ。
Route Table
route_table = ec2.route_tables.create({:vpc => vpc})
なんか微妙。でもガワのみ、だものねぇ。
ELB
で、ELB もガワのみ作成して、って思ったらここだけちょと違う。と思ったら LoadBalancerCollection というソレがありましたw
コメントに例示されてるソレを引用。
load_balancer = elb.load_balancers.create('my-load-balancer', :availability_zones => %w(us-east-1a us-east-1b), :listeners => [{ :port => 80, :protocol => :http, :instance_port => 80, :instance_protocol => :http, }])
あら、ELB も後から割り付け、なのかな。あるいは以下なパラメータか。
# @option options [Array] :subnets An list of VPC subets to attach the # load balancer to. This can be an array of subnet ids (strings) or # {EC2::Subnet} objects. VPC only.
こっちかな。
とりあえず今日はへろへろなのでこれで終わりにしたい。