From 79a47c363f98905a15be4200e954cb989e3c6d9d Mon Sep 17 00:00:00 2001 From: tanaka masato Date: Mon, 14 Sep 2015 10:08:55 +0900 Subject: [PATCH 1/4] Add disable_api_termination into ec2 --- README.md | 1 + doc/resource_types.md | 2 ++ lib/awspec/helper/finder/ec2.rb | 6 ++++++ lib/awspec/stub/ec2.rb | 6 ++++++ lib/awspec/type/ec2.rb | 5 +++++ spec/type/ec2_spec.rb | 1 + 6 files changed, 21 insertions(+) diff --git a/README.md b/README.md index 3296eac3c..611738785 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ describe ec2('my-ec2-tag-name') do it { should belong_to_vpc('my-vpc') } it { should belong_to_subnet('subnet-1234a567') } it { should have_eip('123.0.456.789') } + it { should be_disabled_termination } end ``` diff --git a/doc/resource_types.md b/doc/resource_types.md index 4783dd2f6..a013cd5de 100644 --- a/doc/resource_types.md +++ b/doc/resource_types.md @@ -59,6 +59,8 @@ end ### belong_to_vpc +### be_disabled_termination + #### its(:instance_id), its(:image_id), its(:private_dns_name), its(:public_dns_name), its(:state_transition_reason), its(:key_name), its(:ami_launch_index), its(:instance_type), its(:launch_time), its(:placement), its(:kernel_id), its(:ramdisk_id), its(:platform), its(:monitoring), its(:subnet_id), its(:vpc_id), its(:private_ip_address), its(:public_ip_address), its(:state_reason), its(:architecture), its(:root_device_type), its(:root_device_name), its(:virtualization_type), its(:instance_lifecycle), its(:spot_instance_request_id), its(:client_token), its(:source_dest_check), its(:hypervisor), its(:iam_instance_profile), its(:ebs_optimized), its(:sriov_net_support) ## rds diff --git a/lib/awspec/helper/finder/ec2.rb b/lib/awspec/helper/finder/ec2.rb index 49bb4859e..4855ab1e2 100644 --- a/lib/awspec/helper/finder/ec2.rb +++ b/lib/awspec/helper/finder/ec2.rb @@ -36,6 +36,12 @@ def find_ec2(id) res[:reservations].first[:instances].count == 1 end + def find_ec2_attribute(id, attribute) + res = @ec2_client.describe_instance_attribute({ + instance_id: id, attribute: attribute + }) + end + def find_subnet(subnet_id) res = @ec2_client.describe_subnets({ filters: [{ name: 'subnet-id', values: [subnet_id] }] diff --git a/lib/awspec/stub/ec2.rb b/lib/awspec/stub/ec2.rb index 4affa3f65..af65cb69a 100644 --- a/lib/awspec/stub/ec2.rb +++ b/lib/awspec/stub/ec2.rb @@ -40,6 +40,12 @@ } ] }, + describe_instance_attribute: { + instance_id: 'i-ec12345a', + disable_api_termination: { + value: true + } + }, describe_vpcs: { vpcs: [ { diff --git a/lib/awspec/type/ec2.rb b/lib/awspec/type/ec2.rb index ad40a43b4..5c7284345 100644 --- a/lib/awspec/type/ec2.rb +++ b/lib/awspec/type/ec2.rb @@ -20,6 +20,11 @@ def initialize(id) end end + def disabled_termination? + ret = find_ec2_attribute(@id, 'disableApiTermination') + return ret[:disable_api_termination][:value] + end + def has_eip?(ip_address = nil) option = { filters: [{ name: 'instance-id', values: [@id] }] diff --git a/spec/type/ec2_spec.rb b/spec/type/ec2_spec.rb index e9f669822..1fc4ad6e2 100644 --- a/spec/type/ec2_spec.rb +++ b/spec/type/ec2_spec.rb @@ -9,6 +9,7 @@ its(:image_id) { should eq 'ami-abc12def' } its(:public_ip_address) { should eq '123.0.456.789' } its(:private_ip_address) { should eq '10.0.1.1' } + it { should be_disabled_termination } it { should have_security_group('sg-1a2b3cd4') } it { should have_security_group('my-security-group-name') } it { should have_security_group('my-security-group-tag-name') } From 559e4e238495c87b6a0e63fd640dcb60c4835b48 Mon Sep 17 00:00:00 2001 From: tanaka masato Date: Mon, 14 Sep 2015 12:08:21 +0900 Subject: [PATCH 2/4] $ bundle exec ./lib/awspec/bin/toolbox docgen > doc/resource_types.md --- doc/resource_types.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/resource_types.md b/doc/resource_types.md index a013cd5de..3b8837ee7 100644 --- a/doc/resource_types.md +++ b/doc/resource_types.md @@ -31,6 +31,8 @@ end ``` +### be_disabled_termination + ### be_pending ### be_running @@ -59,8 +61,6 @@ end ### belong_to_vpc -### be_disabled_termination - #### its(:instance_id), its(:image_id), its(:private_dns_name), its(:public_dns_name), its(:state_transition_reason), its(:key_name), its(:ami_launch_index), its(:instance_type), its(:launch_time), its(:placement), its(:kernel_id), its(:ramdisk_id), its(:platform), its(:monitoring), its(:subnet_id), its(:vpc_id), its(:private_ip_address), its(:public_ip_address), its(:state_reason), its(:architecture), its(:root_device_type), its(:root_device_name), its(:virtualization_type), its(:instance_lifecycle), its(:spot_instance_request_id), its(:client_token), its(:source_dest_check), its(:hypervisor), its(:iam_instance_profile), its(:ebs_optimized), its(:sriov_net_support) ## rds From 3364401870728c4795c22794b3164c6ea23af7d1 Mon Sep 17 00:00:00 2001 From: tanaka masato Date: Mon, 14 Sep 2015 12:15:16 +0900 Subject: [PATCH 3/4] Fix syntax by rubocop --- lib/awspec/helper/finder/ec2.rb | 4 ++-- lib/awspec/type/ec2.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/awspec/helper/finder/ec2.rb b/lib/awspec/helper/finder/ec2.rb index 4855ab1e2..80bdf8023 100644 --- a/lib/awspec/helper/finder/ec2.rb +++ b/lib/awspec/helper/finder/ec2.rb @@ -38,8 +38,8 @@ def find_ec2(id) def find_ec2_attribute(id, attribute) res = @ec2_client.describe_instance_attribute({ - instance_id: id, attribute: attribute - }) + instance_id: id, attribute: attribute + }) end def find_subnet(subnet_id) diff --git a/lib/awspec/type/ec2.rb b/lib/awspec/type/ec2.rb index 5c7284345..1ffe2ffab 100644 --- a/lib/awspec/type/ec2.rb +++ b/lib/awspec/type/ec2.rb @@ -22,7 +22,7 @@ def initialize(id) def disabled_termination? ret = find_ec2_attribute(@id, 'disableApiTermination') - return ret[:disable_api_termination][:value] + ret[:disable_api_termination][:value] end def has_eip?(ip_address = nil) From 445a9f976f97bd7c88da56160282de7f21645420 Mon Sep 17 00:00:00 2001 From: tanaka masato Date: Mon, 14 Sep 2015 15:04:50 +0900 Subject: [PATCH 4/4] Rename type to disabled_api_termination --- README.md | 2 +- doc/resource_types.md | 2 +- lib/awspec/type/ec2.rb | 2 +- spec/type/ec2_spec.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 611738785..8f447ceed 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ describe ec2('my-ec2-tag-name') do it { should belong_to_vpc('my-vpc') } it { should belong_to_subnet('subnet-1234a567') } it { should have_eip('123.0.456.789') } - it { should be_disabled_termination } + it { should be_disabled_api_termination } end ``` diff --git a/doc/resource_types.md b/doc/resource_types.md index 3b8837ee7..9a8854b32 100644 --- a/doc/resource_types.md +++ b/doc/resource_types.md @@ -31,7 +31,7 @@ end ``` -### be_disabled_termination +### be_disabled_api_termination ### be_pending diff --git a/lib/awspec/type/ec2.rb b/lib/awspec/type/ec2.rb index 1ffe2ffab..e65f6677a 100644 --- a/lib/awspec/type/ec2.rb +++ b/lib/awspec/type/ec2.rb @@ -20,7 +20,7 @@ def initialize(id) end end - def disabled_termination? + def disabled_api_termination? ret = find_ec2_attribute(@id, 'disableApiTermination') ret[:disable_api_termination][:value] end diff --git a/spec/type/ec2_spec.rb b/spec/type/ec2_spec.rb index 1fc4ad6e2..c5e8456a3 100644 --- a/spec/type/ec2_spec.rb +++ b/spec/type/ec2_spec.rb @@ -9,7 +9,7 @@ its(:image_id) { should eq 'ami-abc12def' } its(:public_ip_address) { should eq '123.0.456.789' } its(:private_ip_address) { should eq '10.0.1.1' } - it { should be_disabled_termination } + it { should be_disabled_api_termination } it { should have_security_group('sg-1a2b3cd4') } it { should have_security_group('my-security-group-name') } it { should have_security_group('my-security-group-tag-name') }