Skip to content

Commit

Permalink
Merge pull request #44 from tjinjin/add_ec2_termination_protection
Browse files Browse the repository at this point in the history
Add disable_api_termination into ec2
  • Loading branch information
k1LoW committed Sep 14, 2015
2 parents b830343 + 445a9f9 commit cef61e7
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
2 changes: 2 additions & 0 deletions doc/resource_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ end
```


### be_disabled_api_termination

### be_pending

### be_running
Expand Down
6 changes: 6 additions & 0 deletions lib/awspec/helper/finder/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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] }]
Expand Down
6 changes: 6 additions & 0 deletions lib/awspec/stub/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
}
]
},
describe_instance_attribute: {
instance_id: 'i-ec12345a',
disable_api_termination: {
value: true
}
},
describe_vpcs: {
vpcs: [
{
Expand Down
5 changes: 5 additions & 0 deletions lib/awspec/type/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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] }]
Expand Down
1 change: 1 addition & 0 deletions spec/type/ec2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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') }
Expand Down

0 comments on commit cef61e7

Please sign in to comment.