-
-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #522 from AndyMoore/add-type-vpc_endpoints
create vpc_endpoints resource
- Loading branch information
Showing
9 changed files
with
312 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
### exist | ||
|
||
```ruby | ||
describe vpc_endpoints('my-vpc-endpoint') do | ||
it { should exist } | ||
end | ||
``` | ||
|
||
describe vpc_endpoints('vpce-05907f23265b25f20'), region: $tfvars["region"]["value"] do | ||
it { should exist } | ||
it { should be_available } | ||
it { should have_subnet('subnet-040e19eabf3226f99') } | ||
it { should belong_to_vpc('vpc-00af9dcc0134b48e0') } | ||
its(:private_dns_enabled) { should eq true } | ||
its(:vpc_endpoint_type) { should eq 'Interface' } | ||
its(:service_name) { should eq 'com.amazonaws.eu-west-1.codebuild' } | ||
end | ||
|
||
### be_pendingacceptance, be_pending, be_available, be_deleting, be_deleted, be_rejected, be_failed, be_expired | ||
|
||
```ruby | ||
describe ami('my-ami') do | ||
it { should be_available } | ||
end | ||
``` | ||
|
||
### belong_to_vpc | ||
|
||
```ruby | ||
describe vpc_endpoints('my-vpc-endpoint') do | ||
it { should belong_to_vpc('my-vpc') } | ||
end | ||
``` | ||
|
||
### have_route_table | ||
|
||
```ruby | ||
describe vpc_endpoints('my-vpc-endpoint') do | ||
it { should have_route_table('rtb-abc123') } | ||
end | ||
``` | ||
|
||
### have_subnet | ||
|
||
```ruby | ||
describe vpc_endpoints('my-vpc-endpoint') do | ||
it { should have_subnet('subnet-abc123') } | ||
end | ||
``` | ||
|
||
### have_tag | ||
|
||
```ruby | ||
describe vpc_endpoints('my-vpc-endpoint') do | ||
it { should have_tag('env').value('dev') } | ||
end | ||
``` | ||
|
||
### advanced | ||
|
||
`vpc_endpoints` can use `Aws::EC2::Types::VpcEndpoint` resource (see https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/EC2/Types/VpcEndpoint.html). | ||
|
||
```ruby | ||
describe vpc_endpoints('my-vpc-endpoint') do | ||
its(:private_dns_enabled) { should eq true } | ||
its(:vpc_endpoint_type) { should eq 'Interface' } | ||
its(:service_name) { should eq 'com.amazonaws.eu-west-1.codebuild' } | ||
end | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Awspec::Generator | ||
module Doc | ||
module Type | ||
class VpcEndpoints < Base | ||
def initialize | ||
super | ||
@type_name = 'VpcEndpoints' | ||
@type = Awspec::Type::VpcEndpoints.new('my-vpc-endpoint') | ||
@ret = @type.resource_via_client | ||
@matchers = [] | ||
@ignore_matchers = [] | ||
@describes = [] | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Awspec::Helper | ||
module Finder | ||
module VpcEndpoints | ||
def find_vpc_endpoint(id) | ||
res = ec2_client.describe_vpc_endpoints({ vpc_endpoint_ids: [id] }) | ||
|
||
ret = res.vpc_endpoints.select do |vpce| | ||
vpce.vpc_endpoint_id == id | ||
end | ||
|
||
ret.single_resource(id) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
Aws.config[:ec2] = { | ||
stub_responses: { | ||
describe_vpc_endpoints: { | ||
vpc_endpoints: [ | ||
{ | ||
vpc_endpoint_id: 'vpce-abc123', | ||
vpc_endpoint_type: 'Gateway', | ||
vpc_id: 'vpc-12345678', | ||
service_name: 'com.amazonaws.us-east-1.s3', | ||
state: 'available', | ||
policy_document: '{"Version": "2008-10-17", "Statement": [{' \ | ||
'"Effect": "Allow", "Principal": "*", "Action": "*",' \ | ||
'"Resource": "*"}]}', | ||
route_table_ids: ['rtb-0123456789abcdefg'], | ||
subnet_ids: [], | ||
groups: [], | ||
private_dns_enabled: false, | ||
requester_managed: false, | ||
network_interface_ids: [], | ||
dns_entries: [], | ||
creation_timestamp: Time.new(2020, 8, 13, 9, 00, 00, '+00:00'), | ||
tags: [ | ||
{ | ||
key: 'Name', | ||
value: 'my_vpc_endpoint' | ||
} | ||
], | ||
owner_id: '112233445566' | ||
}, | ||
{ | ||
vpc_endpoint_id: 'vpce-abc124', | ||
vpc_endpoint_type: 'Interface', | ||
vpc_id: 'vpc-12345678', | ||
service_name: 'com.amazonaws.eu-west-1.codebuild', | ||
state: 'available', | ||
policy_document: '{"Version": "2008-10-17", "Statement": [{' \ | ||
'"Effect": "Allow", "Principal": "*", "Action": "*",' \ | ||
'"Resource": "*"}]}', | ||
route_table_ids: [], | ||
subnet_ids: ['subnet-abc123'], | ||
groups: [{ group_id: 'sg-abc123', group_name: 'default' }], | ||
private_dns_enabled: true, | ||
requester_managed: false, | ||
network_interface_ids: ['eni-06f28a949cb88b84c'], | ||
dns_entries: [ | ||
{ | ||
dns_name: 'vpce-05907f23265b25f20-wwafshom.codebuild.eu-west-1.vpce.amazonaws.com', | ||
hosted_zone_id: 'Z38GZ743OKFT7T' | ||
} | ||
], | ||
creation_timestamp: Time.new(2020, 8, 13, 9, 00, 00, '+00:00'), | ||
tags: [ | ||
{ | ||
key: 'Name', | ||
value: 'my_vpc_endpoint' | ||
} | ||
], | ||
owner_id: '112233445566' | ||
} | ||
], | ||
next_token: nil | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module Awspec::Type | ||
class VpcEndpoints < ResourceBase | ||
aws_resource Aws::EC2::Types::VpcEndpoint | ||
tags_allowed | ||
|
||
def resource_via_client | ||
@resource_via_client ||= find_vpc_endpoint(@display_name) | ||
end | ||
|
||
def id | ||
@id ||= resource_via_client.vpc_endpoint_id if resource_via_client | ||
end | ||
|
||
STATES = %w( | ||
pendingacceptance pending available deleting | ||
deleted rejected failed expired | ||
) | ||
|
||
STATES.each do |state| | ||
define_method state + '?' do | ||
resource_via_client.state == state | ||
end | ||
end | ||
|
||
def has_route_table?(route_table_id) | ||
rts = resource_via_client.route_table_ids | ||
|
||
ret = rts.find do |rt| | ||
rt == route_table_id | ||
end | ||
return true if ret | ||
end | ||
|
||
def has_subnet?(subnet_id) | ||
subnets = resource_via_client.subnet_ids | ||
|
||
ret = subnets.find do |subnet| | ||
subnet == subnet_id | ||
end | ||
return true if ret | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'spec_helper' | ||
Awspec::Stub.load 'vpc_endpoints' | ||
|
||
describe vpc_endpoints('vpce-abc123') do | ||
it { should exist } | ||
it { should be_available } | ||
it { should belong_to_vpc('vpc-12345678') } | ||
it { should have_route_table('rtb-0123456789abcdefg') } | ||
its(:vpc_endpoint_type) { should eq 'Gateway' } | ||
end | ||
|
||
describe vpc_endpoints('vpce-abc124') do | ||
it { should exist } | ||
it { should be_available } | ||
it { should belong_to_vpc('vpc-12345678') } | ||
it { should have_subnet('subnet-abc123') } | ||
its(:vpc_endpoint_type) { should eq 'Interface' } | ||
end |