Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

Limit elastic IP association to pending, running instances #188

Merged
merged 1 commit into from Dec 9, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/puppet/provider/ec2_elastic_ip/v2.rb
Expand Up @@ -56,11 +56,12 @@ def create
Puppet.info("Creating association for #{name}")
ec2 = ec2_client(resource[:region])
response = ec2.describe_instances(filters: [
{name: 'tag:Name', values: [resource[:instance]]}
{name: 'tag:Name', values: [resource[:instance]]},
{name: 'instance-state-name', values: ['pending','running']}
])
instance_ids = response.reservations.map(&:instances).flatten.map(&:instance_id)

fail "No instance found named #{resource[:instance]}" if instance_ids.empty?
fail "No pending or running instance found named #{resource[:instance]}" if instance_ids.empty?
if instance_ids.count > 1
Puppet.warning "Multiple instances found named #{resource[:instance]}, using #{instance_ids.first}"
end
Expand Down