awspec 0.21.4 → 0.21.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/doc/_resource_types/route_table.md +3 -2
- data/doc/resource_types.md +3 -2
- data/lib/awspec/generator/spec/route_table.rb +17 -0
- data/lib/awspec/helper/finder/ec2.rb +3 -3
- data/lib/awspec/helper/finder/vpc.rb +21 -0
- data/lib/awspec/matcher/have_route.rb +3 -2
- data/lib/awspec/stub/route_table.rb +23 -0
- data/lib/awspec/type/route_table.rb +37 -16
- data/lib/awspec/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e44bd4bb2ec33c8a5a4d3b8bce4b2fbb43409ffa
|
4
|
+
data.tar.gz: d7ea14e25e72ca1f046a0e9abd002fa392d6dd1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01e646ea517ce961c384b55ed2e48d62129cd126f408eb55dd5b84899b5b7652c6643dad1aaf9ab2972f9f5c0f66fe6ccc17a40b9e4c5feb889e1f45e899f883
|
7
|
+
data.tar.gz: 9338f1bb61b580d8fe958a996ec953bf86a47704f7fe61048a4aaa36e877a329a4d23bda8b3472d4b6ab64c1ff896c11aae61c1810f52f6f467a95d4e2886129
|
@@ -3,7 +3,8 @@
|
|
3
3
|
```ruby
|
4
4
|
describe route_table('my-route-table') do
|
5
5
|
it { should have_route('10.0.0.0/16').target(gateway: 'local') }
|
6
|
-
it { should have_route('0.0.0.0/0').target(gateway: '
|
7
|
-
it { should have_route('192.168.1.0/24').target(instance: 'my-
|
6
|
+
it { should have_route('0.0.0.0/0').target(gateway: 'igw-1ab2345c') }
|
7
|
+
it { should have_route('192.168.1.0/24').target(instance: 'my-ec2') }
|
8
|
+
it { should have_route('192.168.2.0/24').target(vpc_peering_connection: 'my-pcx') }
|
8
9
|
end
|
9
10
|
```
|
data/doc/resource_types.md
CHANGED
@@ -222,8 +222,9 @@ RouteTable resource type.
|
|
222
222
|
```ruby
|
223
223
|
describe route_table('my-route-table') do
|
224
224
|
it { should have_route('10.0.0.0/16').target(gateway: 'local') }
|
225
|
-
it { should have_route('0.0.0.0/0').target(gateway: '
|
226
|
-
it { should have_route('192.168.1.0/24').target(instance: 'my-
|
225
|
+
it { should have_route('0.0.0.0/0').target(gateway: 'igw-1ab2345c') }
|
226
|
+
it { should have_route('192.168.1.0/24').target(instance: 'my-ec2') }
|
227
|
+
it { should have_route('192.168.2.0/24').target(vpc_peering_connection: 'my-pcx') }
|
227
228
|
end
|
228
229
|
```
|
229
230
|
|
@@ -28,6 +28,10 @@ module Awspec::Generator
|
|
28
28
|
instance = find_ec2(route.instance_id)
|
29
29
|
linespecs.push(ERB.new(route_table_spec_instance_linetemplate, nil, '-').result(binding)) if instance
|
30
30
|
end
|
31
|
+
if route.vpc_peering_connection_id
|
32
|
+
connection = find_vpc_peering_connection(route.vpc_peering_connection_id)
|
33
|
+
linespecs.push(ERB.new(route_table_spec_connection_linetemplate, nil, '-').result(binding)) if connection
|
34
|
+
end
|
31
35
|
end
|
32
36
|
linespecs
|
33
37
|
end
|
@@ -59,6 +63,19 @@ EOF
|
|
59
63
|
template
|
60
64
|
end
|
61
65
|
|
66
|
+
# rubocop:disable Metrics/LineLength
|
67
|
+
def route_table_spec_connection_linetemplate
|
68
|
+
template = <<-'EOF'
|
69
|
+
<%- if connection.tag_name -%>
|
70
|
+
it { should have_route('<%= route.destination_cidr_block %>').target(vpc_peering_connection: '<%= connection.tag_name %>') }
|
71
|
+
<%- else -%>
|
72
|
+
it { should have_route('<%= route.destination_cidr_block %>').target(vpc_peering_connection: '<%= route.vpc_peering_connection_id %>') }
|
73
|
+
<%- end -%>
|
74
|
+
EOF
|
75
|
+
template
|
76
|
+
end
|
77
|
+
# rubocop:enable Metrics/LineLength
|
78
|
+
|
62
79
|
def route_table_spec_subnet_linetemplate
|
63
80
|
template = <<-'EOF'
|
64
81
|
<%- if subnet.tag_name -%>
|
@@ -42,15 +42,15 @@ module Awspec::Helper
|
|
42
42
|
})
|
43
43
|
end
|
44
44
|
|
45
|
-
# fine_internet_gateway
|
46
|
-
gateway_types = %w(internet
|
45
|
+
# fine_internet_gateway fine_vpn_gateway fine_customer_gateway
|
46
|
+
gateway_types = %w(internet vpn cutromer)
|
47
47
|
gateway_types.each do |type|
|
48
48
|
define_method 'find_' + type + '_gateway' do |*args|
|
49
49
|
gateway_id = args.first
|
50
50
|
res = @ec2_client.method('describe_' + type + '_gateways').call({
|
51
51
|
filters: [
|
52
52
|
{
|
53
|
-
name: '
|
53
|
+
name: type + '-gateway-id',
|
54
54
|
values: [gateway_id]
|
55
55
|
}
|
56
56
|
]
|
@@ -65,6 +65,27 @@ module Awspec::Helper
|
|
65
65
|
})
|
66
66
|
res[:subnets]
|
67
67
|
end
|
68
|
+
|
69
|
+
def find_vpc_peering_connection(vpc_peering_connection_id)
|
70
|
+
res = @ec2_client.describe_vpc_peering_connections({
|
71
|
+
filters: [
|
72
|
+
{
|
73
|
+
name: 'vpc-peering-connection-id',
|
74
|
+
values: [vpc_peering_connection_id]
|
75
|
+
}
|
76
|
+
]
|
77
|
+
})
|
78
|
+
return res[:vpc_peering_connections].first if res[:vpc_peering_connections].count == 1
|
79
|
+
res = @ec2_client.describe_vpc_peering_connections({
|
80
|
+
filters: [
|
81
|
+
{
|
82
|
+
name: 'tag:Name',
|
83
|
+
values: [vpc_peering_connection_id]
|
84
|
+
}
|
85
|
+
]
|
86
|
+
})
|
87
|
+
return res[:vpc_peering_connections].first if res[:vpc_peering_connections].count == 1
|
88
|
+
end
|
68
89
|
end
|
69
90
|
end
|
70
91
|
end
|
@@ -7,12 +7,13 @@ RSpec::Matchers.define :have_route do |destination|
|
|
7
7
|
else
|
8
8
|
@destination = destination
|
9
9
|
end
|
10
|
-
route_table.has_route?(@destination, @gateway_id, @instance_id)
|
10
|
+
route_table.has_route?(@destination, @gateway_id, @instance_id, @vpc_peering_connection_id)
|
11
11
|
end
|
12
12
|
|
13
13
|
chain :target do |target|
|
14
14
|
@gateway_id = target[:gateway]
|
15
|
-
@
|
15
|
+
@instance_id = target[:instance]
|
16
|
+
@vpc_peering_connection_id = target[:vpc_peering_connection]
|
16
17
|
end
|
17
18
|
|
18
19
|
chain :destination do |dest|
|
@@ -90,6 +90,16 @@ Aws.config[:ec2] = {
|
|
90
90
|
network_interface_id: nil,
|
91
91
|
vpc_peering_connection_id: nil,
|
92
92
|
state: 'active'
|
93
|
+
},
|
94
|
+
{
|
95
|
+
destination_cidr_block: '192.168.2.0/24',
|
96
|
+
destination_prefix_list_id: nil,
|
97
|
+
gateway_id: nil,
|
98
|
+
instance_id: nil,
|
99
|
+
instance_owner_id: nil,
|
100
|
+
network_interface_id: nil,
|
101
|
+
vpc_peering_connection_id: 'pcx-c56789de',
|
102
|
+
state: 'active'
|
93
103
|
}
|
94
104
|
],
|
95
105
|
associations: [
|
@@ -144,6 +154,19 @@ Aws.config[:ec2] = {
|
|
144
154
|
]
|
145
155
|
}
|
146
156
|
]
|
157
|
+
},
|
158
|
+
describe_vpc_peering_connections: {
|
159
|
+
vpc_peering_connections: [
|
160
|
+
{
|
161
|
+
vpc_peering_connection_id: 'pcx-c56789de',
|
162
|
+
tags: [
|
163
|
+
{
|
164
|
+
key: 'Name',
|
165
|
+
value: 'my-pcx'
|
166
|
+
}
|
167
|
+
]
|
168
|
+
}
|
169
|
+
]
|
147
170
|
}
|
148
171
|
}
|
149
172
|
}
|
@@ -6,26 +6,14 @@ module Awspec::Type
|
|
6
6
|
@id = @resource[:route_table_id] if @resource
|
7
7
|
end
|
8
8
|
|
9
|
-
def has_route?(destination, gateway_id = nil, instance_id = nil)
|
9
|
+
def has_route?(destination, gateway_id = nil, instance_id = nil, vpc_peering_connection_id = nil)
|
10
10
|
@resource.routes.find do |route|
|
11
11
|
if destination
|
12
12
|
next false unless route.destination_cidr_block == destination
|
13
13
|
end
|
14
|
-
|
15
|
-
next
|
16
|
-
|
17
|
-
igw = find_internet_gateway(gateway_id)
|
18
|
-
next true if igw && igw.tag_name == gateway_id
|
19
|
-
# virtual gateway
|
20
|
-
vgw = find_virtual_gateway(gateway_id)
|
21
|
-
next true if vgw && vgw.tag_name == gateway_id
|
22
|
-
# customer gateway
|
23
|
-
cgw = find_customer_gateway(gateway_id)
|
24
|
-
next true if cgw && cgw.tag_name == gateway_id
|
25
|
-
# instance
|
26
|
-
next true if route.instance_id == instance_id
|
27
|
-
instance = find_ec2(instance_id)
|
28
|
-
next true if instance && instance.tag_name == instance_id
|
14
|
+
next target_gateway?(route, gateway_id) if gateway_id
|
15
|
+
next target_instance?(route, instance_id) if instance_id
|
16
|
+
next target_vpc_peering_connection?(route, vpc_peering_connection_id) if vpc_peering_connection_id
|
29
17
|
end
|
30
18
|
end
|
31
19
|
|
@@ -36,5 +24,38 @@ module Awspec::Type
|
|
36
24
|
a[:subnet_id] == subnet[:subnet_id]
|
37
25
|
end
|
38
26
|
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def target_gateway?(route, gateway_id)
|
31
|
+
# * gateway
|
32
|
+
return true if route.gateway_id == gateway_id
|
33
|
+
# internet gateway
|
34
|
+
igw = find_internet_gateway(gateway_id)
|
35
|
+
return true if igw && igw.tag_name == gateway_id
|
36
|
+
# vpn gateway
|
37
|
+
vgw = find_vpn_gateway(gateway_id)
|
38
|
+
return true if vgw && vgw.tag_name == gateway_id
|
39
|
+
# customer gateway
|
40
|
+
cgw = find_customer_gateway(gateway_id)
|
41
|
+
return true if cgw && cgw.tag_name == gateway_id
|
42
|
+
false
|
43
|
+
end
|
44
|
+
|
45
|
+
def target_instance?(route, instance_id)
|
46
|
+
# instance
|
47
|
+
return true if route.instance_id == instance_id
|
48
|
+
instance = find_ec2(instance_id)
|
49
|
+
return true if instance && instance.tag_name == instance_id
|
50
|
+
false
|
51
|
+
end
|
52
|
+
|
53
|
+
def target_vpc_peering_connection?(route, vpc_peering_connection_id)
|
54
|
+
# vpc_peering_connection_id
|
55
|
+
return true if route.vpc_peering_connection_id == vpc_peering_connection_id
|
56
|
+
connection = find_vpc_peering_connection(vpc_peering_connection_id)
|
57
|
+
return true if connection && connection.tag_name == vpc_peering_connection_id
|
58
|
+
false
|
59
|
+
end
|
39
60
|
end
|
40
61
|
end
|
data/lib/awspec/version.rb
CHANGED