awspec 0.21.4 → 0.21.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 09e60bc83f5157418e4a14d041c76512bcfd44c1
4
- data.tar.gz: f54755018644fcde5c9b3d3dcef7e7ca2761172b
3
+ metadata.gz: e44bd4bb2ec33c8a5a4d3b8bce4b2fbb43409ffa
4
+ data.tar.gz: d7ea14e25e72ca1f046a0e9abd002fa392d6dd1e
5
5
  SHA512:
6
- metadata.gz: 0f294f242b82340589654c4049c2072c52aa7a692fc9178175e8ff8b4c0f4578da85dac58685ba70151870b4284c03729c237694fe5453b074459d6a8d377913
7
- data.tar.gz: 004e2bbbd525e7c29330ec31f095133daa9bee8cb414a7fbaf1717448b4b67f6cd3e118d715fab3abf15fd11cc5385f683d445856e9a3d80ad67bbb13ebf1b57
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: 'my-igw') }
7
- it { should have_route('192.168.1.0/24').target(instance: 'my-instance') }
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
  ```
@@ -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: 'my-igw') }
226
- it { should have_route('192.168.1.0/24').target(instance: 'my-instance') }
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 fine_virtual_gateway fine_customer_gateway
46
- gateway_types = %w(internet virtual cutromer)
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: 'internet-gateway-id',
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
- @intance_id = target[:instance]
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
- # * gateway
15
- next true if route.gateway_id == gateway_id
16
- # internet gateway
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
@@ -1,3 +1,3 @@
1
1
  module Awspec
2
- VERSION = '0.21.4'
2
+ VERSION = '0.21.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.4
4
+ version: 0.21.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - k1LoW