Skip to content

Commit

Permalink
Merge pull request #575 from alpineriveredge/vpngw_vpc
Browse files Browse the repository at this point in the history
Make vpn_gateway searchable by name
  • Loading branch information
k1LoW authored Oct 24, 2022
2 parents 9a6a12d + 4ab0167 commit 57863ae
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 20 deletions.
9 changes: 8 additions & 1 deletion doc/_resource_types/vpn_gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,11 @@ describe vpn_gateway('my-vpn-gateway') do
end
```

### its(:vpn_gateway_id), its(:state), its(:type), its(:availability_zone)
### belong_to_vpc

```ruby
describe vpn_gateway('my-vpn-gateway') do
it { should belong_to_vpc('vpc-ab123cde') }
it { should belong_to_vpc('my-vpc') }
end
```
11 changes: 10 additions & 1 deletion doc/resource_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -4101,7 +4101,16 @@ end
```


### its(:availability_zone), its(:state), its(:type), its(:vpc_attachments), its(:vpn_gateway_id), its(:amazon_side_asn), its(:tags)
### belong_to_vpc

```ruby
describe vpn_gateway('my-vpn-gateway') do
it { should belong_to_vpc('vpc-ab123cde') }
it { should belong_to_vpc('my-vpc') }
end
```

### its(:availability_zone), its(:state), its(:type), its(:vpn_gateway_id), its(:amazon_side_asn)
## <a name="waf_web_acl">waf_web_acl</a>

WafWebAcl resource type.
Expand Down
3 changes: 2 additions & 1 deletion lib/awspec/generator/doc/type/vpn_gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ def initialize
@type = Awspec::Type::VpnGateway.new('my-vpn-gateway')
@ret = @type.resource_via_client
@matchers = [
Awspec::Type::VpnGateway::STATES.map { |state| "be_#{state.tr('-', '_')}" }.join(', ')
Awspec::Type::VpnGateway::STATES.map { |state| "be_#{state.tr('-', '_')}" }.join(', '),
'belong_to_vpc'
]
@ignore_matchers = Awspec::Type::VpnGateway::STATES.map { |state| "be_#{state.tr('-', '_')}" }
@describes = []
Expand Down
16 changes: 10 additions & 6 deletions lib/awspec/helper/finder/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,16 @@ def find_ec2_status(id)
define_method "find_#{type}_gateway" do |*args|
gateway_id = args.first
method_name = "describe_#{type}_gateways"
res = ec2_client.send(
method_name,
{ filters: [{ name: "#{type}-gateway-id", values: [gateway_id] }] }
)
resource = res["#{type}_gateways"].single_resource(gateway_id)
return resource if resource
begin
res = ec2_client.send(
method_name,
{ filters: [{ name: "#{type}-gateway-id", values: [gateway_id] }] }
)
resource = res["#{type}_gateways"].single_resource(gateway_id)
return resource if resource
rescue StandardError
resource = nil
end

res = ec2_client.send(
method_name,
Expand Down
15 changes: 14 additions & 1 deletion lib/awspec/stub/vpn_gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,20 @@
vpn_gateway_id: 'vgw-cg5692g4',
availability_zone: 'us-east-1a',
state: 'available',
type: "ipsec.1"
type: "ipsec.1",
vpc_attachments: [
{
state: 'attached',
vpc_id: 'vpc-ab123cde'
}
],
amazon_side_asn: 64512,
tags: [
{
key: 'Name',
value: 'my-vpn-gateway'
}
]
}
]
}
Expand Down
12 changes: 2 additions & 10 deletions lib/awspec/type/vpn_gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,8 @@ def id
end
end

def availability_zone
resource_via_client.availability_zone
end

def vpc_attachments
resource_via_client.vpc_attachments
end

def type
resource_via_client.type
def vpc_id
resource_via_client.vpc_attachments.first.vpc_id
end
end
end
10 changes: 10 additions & 0 deletions spec/type/vpn_gateway_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,13 @@
its(:availability_zone) { should eq 'us-east-1a' }
its(:type) { should eq 'ipsec.1' }
end

describe vpn_gateway('my-vpn-gateway') do
it { should exist }
it { should be_available }
its(:availability_zone) { should eq 'us-east-1a' }
its(:type) { should eq 'ipsec.1' }
it { should belong_to_vpc('vpc-ab123cde') }
its(:amazon_side_asn) { should eq 64_512 }
it { should have_tag('Name').value('my-vpn-gateway') }
end

0 comments on commit 57863ae

Please sign in to comment.