tl;dr
æä½æ¥ã§æ§ç¯ãã AWS ãªã½ã¼ã¹ã®ç®¡çã«ã¯ä»¥åããæ°ã«ãªã£ã¦ãã awspec ãè¯ãã¨æã£ãã®ã§ã¡ã¢ã
äºå°ãä¸å°ã®ã¤ã³ã¹ã¿ã³ã¹ãªã...ã¨ãã£ããã¨æä½æ¥ã§æ§ç¯ããã¤ã³ã¹ã¿ã³ã¹ããã©ããªè¨å®ã§ä½ã£ããå¤ããªããã©ããªãã¨ãªãå©ç¨ããã¦ãã S3 Bucket ã®ç®¡çãã©ããããããªã¨æã£ã¦ããã awspec ã® generate
ã³ãã³ãããªã½ã¼ã¹æ
å ±ãçæãã¦ãããã®ã§è©¦ãã¦ã¿ãã
åè
memo
ã¤ã³ã¹ãã¼ã«
$ cat Gemfile source "https://rubygems.org" gem 'awspec' gem 'rake' $ bundle
åæå
$ bundle exec awspec init
+ spec/
+ spec/spec_helper.rb
+ Rakefile
+ spec/.gitignore
+ .rspec
awspec generate
以ä¸ã®ããã«ãµãã¼ãããã¦ãããªã½ã¼ã¹ã§ããã°åãªã½ã¼ã¹ã®æ å ±ãå©ç¨ãã¦ãã¹ããçæãã¦ãããã¨ããæãé£ãæ©è½ã
$ bundle exec awspec generate Commands: awspec generate cloudwatch_alarm # Generate cloudwatch_alarm spec awspec generate directconnect # Generate directconnect spec awspec generate ebs # Generate attached ebs spec awspec generate ec2 [vpc_id] # Generate ec2 spec from VPC ID (or VPC "Name" tag) awspec generate elb [vpc_id] # Generate elb spec from VPC ID (or VPC "Name" tag) awspec generate help [COMMAND] # Describe subcommands or one specific subcommand awspec generate iam_policy # Generate attached iam_policy spec awspec generate nat_gateway [vpc_id] # Generate nat_gateway spec from VPC ID (or VPC "Name" tag) awspec generate network_acl [vpc_id] # Generate network_acl spec from VPC ID (or VPC "Name" tag) awspec generate rds [vpc_id] # Generate rds spec from VPC ID (or VPC "Name" tag) awspec generate route53_hosted_zone [example.com.] # Generate route53_hosted_zone spec from Domain name awspec generate route_table [vpc_id] # Generate route_table spec from VPC ID (or VPC "Name" tag) awspec generate s3_bucket [backet_name] # Generate s3_bucket spec from S3 bucket name. if NO args, Generate all. awspec generate security_group [vpc_id] # Generate security_group spec from VPC ID (or VPC "Name" tag) awspec generate subnet [vpc_id] # Generate subnet spec from VPC ID (or VPC "Name" tag) awspec generate vpc [vpc_id] # Generate vpc spec from VPC ID (or VPC "Name" tag) Options: [--profile=PROFILE]
EC2 ã®æ å ±ãçæãã
以ä¸ã®ããã« generate
ã³ãã³ããå©ç¨ã㦠vpc-xxxxxxxx
å
ã® EC2 æ
å ±ãçæãã¦ã¿ãã
$ echo "require 'spec_helper'" > spec/ec2_spec.rb $ bundle exec awspec generate ec2 vpc-xxxxxxxx >> spec/ec2_spec.rb
以ä¸ã®ãããªå 容ãåºåãããã
require 'spec_helper' describe ec2('oreno-instance01') do it { should exist } it { should be_stopped } its(:instance_id) { should eq 'i-xxxxxxxxx' } its(:image_id) { should eq 'ami-xxxxxxxx' } its(:private_dns_name) { should eq 'ip-10-0-x-xxx.ap-northeast-1.compute.internal' } its(:public_dns_name) { should eq '' } its(:instance_type) { should eq 't1.micro' } its(:private_ip_address) { should eq '10.0.x.xxx' } it { should have_security_group('test') } it { should belong_to_vpc('vpc-xxxxxxxx') } it { should belong_to_subnet('subnet-xxxxxxxxxxx') } it { should have_ebs('vol-xxxxxxxxxx') } end
çæãããæ å ±ãå ã«ãã¹ããã¦ã¿ãã
$ bundle exec rake spec
以ä¸ã®ããã«åºåãããã
ããã
ãã®ãã±ããã£ã¦ã©ããªè¨å®ã ã£ã
S3 ãã±ããã®è¨å®ãçæãã¦ããã
$ echo "require 'spec_helper'" > spec/s3_bucket_spec.rb $ bundle exec awspec generate s3 inokara-sandbox >> spec/s3_bucket_spec.rb
以ä¸ã®ããã«çæãããã
$ cat spec/s3_bucket_spec.rb require 'spec_helper' describe s3_bucket('inokara-sandbox') do it { should exist } its(:acl_owner) { should eq 'xxxxxxxxx' } its(:acl_grants_count) { should eq 1 } it { should have_acl_grant(grantee: 'xxxxxxxx', permission: 'FULL_CONTROL') } end
ãã¹ããã¦ã¿ãã
VPC ã®è¨å®ãè¦ã¦ã¿ãã
VPC ã®è¨å®ãçæãã¦ããã
$ echo "require 'spec_helper'" > spec/vpc_spec.rb $ bundle exec awspec generate vpc vpc-xxxxxxxx >> spec/vpc_spec.rb
以ä¸ã®ããã«çæãããã
$ cat spec/vpc_spec.rb require 'spec_helper' describe vpc('vpc-xxxxxxxxx') do it { should exist } it { should be_available } its(:vpc_id) { should eq 'vpc-xxxxxxxxx' } its(:cidr_block) { should eq '10.0.0.0/16' } it { should have_route_table('rtb-xxxxxxxxx') } it { should have_route_table('rtb-xxxxxxxxx') } it { should have_network_acl('acl-xxxxxxxxx') } end
ãã¹ããã¦ã¿ãã
æå¾ã«
generate ãã¨ã¦ãæãé£ã
æä½æ¥ã§æ§ç¯ãã AWS ãªã½ã¼ã¹ã¯ generate
ã³ãã³ããå©ç¨ãã¦ãªã½ã¼ã¹ãã³ã¼ãã«åãåºããã¨ã§ããã¹ããã¼ã¹ã§ç®¡çåºæ¥ãã®ãå¬ãããæã§ä¿®æ£ãå ããã generate ã§åãåºããããªéç¨ãããã°è¯ããããï¼generate ã§åãåºãã®ãå¿ããå¯è½æ§ã...ï¼
ã¨ãããã¨ã§
æ§ç¯åã«ãã¹ããæ¸ãã¦ãæ§ç¯å¾ã®ãã§ãã¯ã§å©ç¨ã¨ããå´é¢ãããã¨æãããæä½æ¥ã§æ§ç¯ãããªã½ã¼ã¹ã®è³ç£ç®¡çã¨ã㦠awspec ã使ã£ã¦ããããã¨æã£ãã
以ä¸ã