diff --git a/README.md b/README.md index 3296eac3c..8f447ceed 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_api_termination } end ``` diff --git a/doc/resource_types.md b/doc/resource_types.md index 4783dd2f6..9a8854b32 100644 --- a/doc/resource_types.md +++ b/doc/resource_types.md @@ -31,6 +31,8 @@ end ``` +### be_disabled_api_termination + ### be_pending ### be_running diff --git a/lib/awspec/helper/finder/ec2.rb b/lib/awspec/helper/finder/ec2.rb index 49bb4859e..80bdf8023 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..e65f6677a 100644 --- a/lib/awspec/type/ec2.rb +++ b/lib/awspec/type/ec2.rb @@ -20,6 +20,11 @@ def initialize(id) end end + def disabled_api_termination? + ret = find_ec2_attribute(@id, 'disableApiTermination') + 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..c5e8456a3 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_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') }