Method: Awspec::Helper::Finder::Ec2#find_nat_gateway

Defined in:
lib/awspec/helper/finder/ec2.rb

#find_nat_gateway(gateway_id) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/awspec/helper/finder/ec2.rb', line 117

def find_nat_gateway(gateway_id)
  # nat_gateway_id or tag:Name
  begin
    res = ec2_client.describe_nat_gateways({
                                             nat_gateway_ids: [gateway_id]
                                           })
  rescue StandardError
    res = ec2_client.describe_nat_gateways({
                                             filter: [{ name: 'tag:Name', values: [gateway_id] }]
                                           })
  end
  if res.nat_gateways.count == 1
    res.nat_gateways.single_resource(gateway_id)
  elsif res.nat_gateways.count > 1
    raise Awspec::DuplicatedResourceTypeError, "Duplicate nat_gateways matching id or tag #{gateway_id}"
  end
end