awspec 0.27.2 → 0.28.0
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/README.md +5 -5
- data/doc/_resource_types/nat_gateway.md +31 -0
- data/doc/_resource_types/route_table.md +1 -0
- data/doc/resource_types.md +42 -0
- data/lib/awspec/command/generate.rb +1 -1
- data/lib/awspec/generator.rb +1 -0
- data/lib/awspec/generator/doc/type/nat_gateway.rb +20 -0
- data/lib/awspec/generator/spec/nat_gateway.rb +39 -0
- data/lib/awspec/generator/template.rb +1 -1
- data/lib/awspec/helper/finder/ec2.rb +24 -18
- data/lib/awspec/helper/type.rb +1 -0
- data/lib/awspec/stub/nat_gateway.rb +35 -0
- data/lib/awspec/type/nat_gateway.rb +25 -0
- data/lib/awspec/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f73c5f63d506b9942d39232be4d5d3ed4459ba8
|
4
|
+
data.tar.gz: bc58760a303309b3699ac78c8b5f91bd7a214562
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33982233fcd1c9b6014f958911146d9d53d2ecfc6561d61164cf7c87e1cb45e0d3838c447725170ddd579bcab99a69720cce4c457323828efe30be042f65c72d
|
7
|
+
data.tar.gz: 1859a5181cbba64c2dcce3840af265fce99a362c6c26eba903dfee19b315ab1ae5ce56d9e864921a82fdfa4425234d741bb754ae7ca6de383e8e6da57e8bec3c
|
data/README.md
CHANGED
@@ -26,11 +26,11 @@ Or install it yourself as:
|
|
26
26
|
|
27
27
|
## Getting Started
|
28
28
|
|
29
|
-
### 1. Generate awspec init files
|
29
|
+
### STEP 1. Generate awspec init files
|
30
30
|
|
31
31
|
$ awspec init
|
32
32
|
|
33
|
-
### 2. Set AWS credentials
|
33
|
+
### STEP 2. Set AWS credentials
|
34
34
|
|
35
35
|
#### 2-1. Use Shared Credentials
|
36
36
|
|
@@ -50,7 +50,7 @@ aws_secret_access_key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
|
50
50
|
EOF
|
51
51
|
```
|
52
52
|
|
53
|
-
### 3. Write spec/*_spec.rb
|
53
|
+
### STEP 3. Write spec/*_spec.rb
|
54
54
|
|
55
55
|
```ruby
|
56
56
|
require 'spec_helper'
|
@@ -68,7 +68,7 @@ describe ec2('my-ec2-tag-name') do
|
|
68
68
|
end
|
69
69
|
```
|
70
70
|
|
71
|
-
### 4. Run tests
|
71
|
+
### STEP 4. Run tests
|
72
72
|
|
73
73
|
$ bundle exec rake spec
|
74
74
|
|
@@ -87,7 +87,7 @@ $ awspec generate ec2 vpc-ab123cde --profile mycreds
|
|
87
87
|
```
|
88
88
|
|
89
89
|
```sh
|
90
|
-
$
|
90
|
+
$ AWS_PROFILE=mycreds bundle exec rake spec
|
91
91
|
```
|
92
92
|
|
93
93
|
## Support AWS Resources
|
@@ -0,0 +1,31 @@
|
|
1
|
+
### exist
|
2
|
+
|
3
|
+
```ruby
|
4
|
+
describe nat_gateway('nat-7ff7777f') do
|
5
|
+
it { should exist }
|
6
|
+
end
|
7
|
+
```
|
8
|
+
|
9
|
+
### be_pending, be_failed, be_available, be_deleting, be_deleted
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
describe nat_gateway('nat-7ff7777f') do
|
13
|
+
it { should be_available }
|
14
|
+
end
|
15
|
+
```
|
16
|
+
|
17
|
+
### have_eip
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
describe nat_gateway('nat-7ff7777f') do
|
21
|
+
it { should have_eip('123.0.456.789') }
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
### belong_to_vpc
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
describe nat_gateway('nat-7ff7777f') do
|
29
|
+
it { should belong_to_vpc('my-vpc') }
|
30
|
+
end
|
31
|
+
```
|
@@ -14,6 +14,7 @@ describe route_table('my-route-table') do
|
|
14
14
|
it { should have_route('0.0.0.0/0').target(gateway: 'igw-1ab2345c') }
|
15
15
|
it { should have_route('192.168.1.0/24').target(instance: 'my-ec2') }
|
16
16
|
it { should have_route('192.168.2.0/24').target(vpc_peering_connection: 'my-pcx') }
|
17
|
+
it { should have_route('192.168.3.0/24').target(nat: 'nat-7ff7777f') }
|
17
18
|
end
|
18
19
|
```
|
19
20
|
|
data/doc/resource_types.md
CHANGED
@@ -23,6 +23,7 @@
|
|
23
23
|
| [ses_identity](#ses_identity)
|
24
24
|
| [network_acl](#network_acl)
|
25
25
|
| [directconnect_virtual_interface](#directconnect_virtual_interface)
|
26
|
+
| [nat_gateway](#nat_gateway)
|
26
27
|
|
27
28
|
## <a name="ec2">ec2</a>
|
28
29
|
|
@@ -571,6 +572,7 @@ describe route_table('my-route-table') do
|
|
571
572
|
it { should have_route('0.0.0.0/0').target(gateway: 'igw-1ab2345c') }
|
572
573
|
it { should have_route('192.168.1.0/24').target(instance: 'my-ec2') }
|
573
574
|
it { should have_route('192.168.2.0/24').target(vpc_peering_connection: 'my-pcx') }
|
575
|
+
it { should have_route('192.168.3.0/24').target(nat: 'nat-7ff7777f') }
|
574
576
|
end
|
575
577
|
```
|
576
578
|
|
@@ -1147,3 +1149,43 @@ end
|
|
1147
1149
|
```
|
1148
1150
|
|
1149
1151
|
### its(:owner_account), its(:virtual_interface_id), its(:location), its(:connection_id), its(:virtual_interface_type), its(:virtual_interface_name), its(:vlan), its(:asn), its(:auth_key), its(:amazon_address), its(:customer_address), its(:virtual_interface_state), its(:customer_router_config), its(:virtual_gateway_id)
|
1152
|
+
## <a name="nat_gateway">nat_gateway</a>
|
1153
|
+
|
1154
|
+
NatGateway resource type.
|
1155
|
+
|
1156
|
+
### exist
|
1157
|
+
|
1158
|
+
```ruby
|
1159
|
+
describe nat_gateway('nat-7ff7777f') do
|
1160
|
+
it { should exist }
|
1161
|
+
end
|
1162
|
+
```
|
1163
|
+
|
1164
|
+
|
1165
|
+
### be_pending, be_failed, be_available, be_deleting, be_deleted
|
1166
|
+
|
1167
|
+
```ruby
|
1168
|
+
describe nat_gateway('nat-7ff7777f') do
|
1169
|
+
it { should be_available }
|
1170
|
+
end
|
1171
|
+
```
|
1172
|
+
|
1173
|
+
|
1174
|
+
### have_eip
|
1175
|
+
|
1176
|
+
```ruby
|
1177
|
+
describe nat_gateway('nat-7ff7777f') do
|
1178
|
+
it { should have_eip('123.0.456.789') }
|
1179
|
+
end
|
1180
|
+
```
|
1181
|
+
|
1182
|
+
|
1183
|
+
### belong_to_vpc
|
1184
|
+
|
1185
|
+
```ruby
|
1186
|
+
describe nat_gateway('nat-7ff7777f') do
|
1187
|
+
it { should belong_to_vpc('my-vpc') }
|
1188
|
+
end
|
1189
|
+
```
|
1190
|
+
|
1191
|
+
### its(:vpc_id), its(:subnet_id), its(:nat_gateway_id), its(:create_time), its(:delete_time), its(:state), its(:failure_code), its(:failure_message)
|
data/lib/awspec/generator.rb
CHANGED
@@ -15,6 +15,7 @@ require 'awspec/generator/spec/subnet'
|
|
15
15
|
require 'awspec/generator/spec/directconnect'
|
16
16
|
require 'awspec/generator/spec/ebs'
|
17
17
|
require 'awspec/generator/spec/s3_bucket'
|
18
|
+
require 'awspec/generator/spec/nat_gateway'
|
18
19
|
|
19
20
|
# Doc
|
20
21
|
require 'awspec/generator/doc/type'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Awspec::Generator
|
2
|
+
module Doc
|
3
|
+
module Type
|
4
|
+
class NatGateway < Base
|
5
|
+
def initialize
|
6
|
+
super
|
7
|
+
@type_name = 'NatGateway'
|
8
|
+
@type = Awspec::Type::NatGateway.new('nat-7ff7777f')
|
9
|
+
@ret = @type.resource_via_client
|
10
|
+
@matchers = [
|
11
|
+
Awspec::Type::NatGateway::STATES.map { |state| 'be_' + state.tr('-', '_') }.join(', '),
|
12
|
+
'belong_to_vpc'
|
13
|
+
]
|
14
|
+
@ignore_matchers = Awspec::Type::NatGateway::STATES.map { |state| 'be_' + state.tr('-', '_') }
|
15
|
+
@describes = []
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Awspec::Generator
|
2
|
+
module Spec
|
3
|
+
class NatGateway
|
4
|
+
include Awspec::Helper::Finder
|
5
|
+
def generate_by_vpc_id(vpc_id)
|
6
|
+
describes = %w(
|
7
|
+
)
|
8
|
+
vpc = find_vpc(vpc_id)
|
9
|
+
fail 'Not Found VPC' unless vpc
|
10
|
+
@vpc_id = vpc[:vpc_id]
|
11
|
+
@vpc_tag_name = vpc.tag_name
|
12
|
+
nat_gateways = select_nat_gateway_by_vpc_id(@vpc_id)
|
13
|
+
specs = nat_gateways.map do |nat_gateway|
|
14
|
+
nat_gateway_id = nat_gateway[:nat_gateway_id]
|
15
|
+
content = ERB.new(nat_gateway_spec_template, nil, '-').result(binding).gsub(/^\n/, '')
|
16
|
+
end
|
17
|
+
specs.join("\n")
|
18
|
+
end
|
19
|
+
|
20
|
+
def nat_gateway_spec_template
|
21
|
+
template = <<-'EOF'
|
22
|
+
describe nat_gateway('<%= nat_gateway_id %>') do
|
23
|
+
it { should exist }
|
24
|
+
it { should be_<%= nat_gateway.state %> }
|
25
|
+
<%- if @vpc_tag_name -%>
|
26
|
+
it { should belong_to_vpc('<%= @vpc_tag_name %>') }
|
27
|
+
<%- else -%>
|
28
|
+
it { should belong_to_vpc('<%= @vpc_id %>') }
|
29
|
+
<%- end -%>
|
30
|
+
<% nat_gateway.nat_gateway_addresses.each do |address| %>
|
31
|
+
it { should have_eip('<%= address.public_ip %>') }
|
32
|
+
<% end %>
|
33
|
+
end
|
34
|
+
EOF
|
35
|
+
template
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -86,7 +86,7 @@ EOF
|
|
86
86
|
|
87
87
|
Genarate #{@type.camelize} template files.
|
88
88
|
|
89
|
-
* !! AND add '#{@type.underscore}' to Awspec::Helper::Type::TYPES in awspec/
|
89
|
+
* !! AND add '#{@type.underscore}' to Awspec::Helper::Type::TYPES in lib/awspec/helper/type.rb *
|
90
90
|
|
91
91
|
EOF
|
92
92
|
end
|
@@ -42,32 +42,31 @@ module Awspec::Helper
|
|
42
42
|
})
|
43
43
|
end
|
44
44
|
|
45
|
-
# find_internet_gateway find_vpn_gateway find_customer_gateway
|
46
|
-
gateway_types = %w(internet vpn customer
|
45
|
+
# find_internet_gateway find_vpn_gateway find_customer_gateway
|
46
|
+
gateway_types = %w(internet vpn customer)
|
47
47
|
gateway_types.each do |type|
|
48
48
|
define_method 'find_' + type + '_gateway' do |*args|
|
49
49
|
gateway_id = args.first
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
}
|
56
|
-
]
|
57
|
-
})
|
50
|
+
method_name = 'describe_' + type + '_gateways'
|
51
|
+
res = ec2_client.method(method_name).call({
|
52
|
+
filters: [{ name: type + '-gateway-id', values: [gateway_id] }]
|
53
|
+
})
|
54
|
+
|
58
55
|
return res[type + '_gateways'].first if res[type + '_gateways'].count == 1
|
59
|
-
res = ec2_client.method(
|
60
|
-
|
61
|
-
|
62
|
-
name: 'tag:Name',
|
63
|
-
values: [gateway_id]
|
64
|
-
}
|
65
|
-
]
|
66
|
-
})
|
56
|
+
res = ec2_client.method(method_name).call({
|
57
|
+
filters: [{ name: 'tag:Name', values: [gateway_id] }]
|
58
|
+
})
|
67
59
|
return res[type + '_gateways'].first if res[type + '_gateways'].count == 1
|
68
60
|
end
|
69
61
|
end
|
70
62
|
|
63
|
+
def find_nat_gateway(gateway_id)
|
64
|
+
res = ec2_client.describe_nat_gateways({
|
65
|
+
filter: [{ name: 'nat-gateway-id', values: [gateway_id] }]
|
66
|
+
})
|
67
|
+
return res['nat_gateways'].first if res['nat_gateways'].count == 1
|
68
|
+
end
|
69
|
+
|
71
70
|
def find_security_group(sg_id)
|
72
71
|
res = ec2_client.describe_security_groups({
|
73
72
|
filters: [{ name: 'group-id', values: [sg_id] }]
|
@@ -104,6 +103,13 @@ module Awspec::Helper
|
|
104
103
|
return [] unless res[:addresses].count > 0
|
105
104
|
res[:addresses]
|
106
105
|
end
|
106
|
+
|
107
|
+
def select_nat_gateway_by_vpc_id(vpc_id)
|
108
|
+
res = ec2_client.describe_nat_gateways({
|
109
|
+
filter: [{ name: 'vpc-id', values: [vpc_id] }]
|
110
|
+
})
|
111
|
+
res[:nat_gateways]
|
112
|
+
end
|
107
113
|
end
|
108
114
|
end
|
109
115
|
end
|
data/lib/awspec/helper/type.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
Aws.config[:ec2] = {
|
2
|
+
stub_responses: {
|
3
|
+
describe_nat_gateways: {
|
4
|
+
nat_gateways: [
|
5
|
+
{
|
6
|
+
nat_gateway_id: 'nat-7ff7777f',
|
7
|
+
vpc_id: 'vpc-ab123cde',
|
8
|
+
state: 'available',
|
9
|
+
nat_gateway_addresses: [
|
10
|
+
public_ip: '123.0.456.789',
|
11
|
+
allocation_id: 'unknown',
|
12
|
+
private_ip: 'unknown',
|
13
|
+
network_interface_id: 'unknown'
|
14
|
+
]
|
15
|
+
}
|
16
|
+
],
|
17
|
+
next_token: nil
|
18
|
+
},
|
19
|
+
describe_vpcs: {
|
20
|
+
vpcs: [
|
21
|
+
{
|
22
|
+
vpc_id: 'vpc-ab123cde',
|
23
|
+
state: 'available',
|
24
|
+
cidr_block: '10.0.0.0/16',
|
25
|
+
tags: [
|
26
|
+
{
|
27
|
+
key: 'Name',
|
28
|
+
value: 'my-vpc'
|
29
|
+
}
|
30
|
+
]
|
31
|
+
}
|
32
|
+
]
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Awspec::Type
|
2
|
+
class NatGateway < Base
|
3
|
+
def initialize(id)
|
4
|
+
super
|
5
|
+
@resource_via_client = find_nat_gateway(id)
|
6
|
+
@id = @resource_via_client[:nat_gateway_id] if @resource_via_client
|
7
|
+
end
|
8
|
+
|
9
|
+
STATES = %w(
|
10
|
+
pending failed available deleting deleted
|
11
|
+
)
|
12
|
+
|
13
|
+
STATES.each do |state|
|
14
|
+
define_method state.tr('-', '_') + '?' do
|
15
|
+
@resource_via_client[:state] == state
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def has_eip?(ip_address = nil)
|
20
|
+
@resource_via_client.nat_gateway_addresses.find do |address|
|
21
|
+
return address.public_ip == ip_address
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/awspec/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: awspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.28.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- k1LoW
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -213,6 +213,7 @@ files:
|
|
213
213
|
- doc/_resource_types/iam_role.md
|
214
214
|
- doc/_resource_types/iam_user.md
|
215
215
|
- doc/_resource_types/lambda.md
|
216
|
+
- doc/_resource_types/nat_gateway.md
|
216
217
|
- doc/_resource_types/network_acl.md
|
217
218
|
- doc/_resource_types/rds.md
|
218
219
|
- doc/_resource_types/rds_db_parameter_group.md
|
@@ -247,6 +248,7 @@ files:
|
|
247
248
|
- lib/awspec/generator/doc/type/iam_role.rb
|
248
249
|
- lib/awspec/generator/doc/type/iam_user.rb
|
249
250
|
- lib/awspec/generator/doc/type/lambda.rb
|
251
|
+
- lib/awspec/generator/doc/type/nat_gateway.rb
|
250
252
|
- lib/awspec/generator/doc/type/network_acl.rb
|
251
253
|
- lib/awspec/generator/doc/type/rds.rb
|
252
254
|
- lib/awspec/generator/doc/type/rds_db_parameter_group.rb
|
@@ -263,6 +265,7 @@ files:
|
|
263
265
|
- lib/awspec/generator/spec/ec2.rb
|
264
266
|
- lib/awspec/generator/spec/elb.rb
|
265
267
|
- lib/awspec/generator/spec/iam_policy.rb
|
268
|
+
- lib/awspec/generator/spec/nat_gateway.rb
|
266
269
|
- lib/awspec/generator/spec/network_acl.rb
|
267
270
|
- lib/awspec/generator/spec/rds.rb
|
268
271
|
- lib/awspec/generator/spec/route53_hosted_zone.rb
|
@@ -322,6 +325,7 @@ files:
|
|
322
325
|
- lib/awspec/stub/iam_role.rb
|
323
326
|
- lib/awspec/stub/iam_user.rb
|
324
327
|
- lib/awspec/stub/lambda.rb
|
328
|
+
- lib/awspec/stub/nat_gateway.rb
|
325
329
|
- lib/awspec/stub/network_acl.rb
|
326
330
|
- lib/awspec/stub/rds.rb
|
327
331
|
- lib/awspec/stub/rds_db_parameter_group.rb
|
@@ -347,6 +351,7 @@ files:
|
|
347
351
|
- lib/awspec/type/iam_role.rb
|
348
352
|
- lib/awspec/type/iam_user.rb
|
349
353
|
- lib/awspec/type/lambda.rb
|
354
|
+
- lib/awspec/type/nat_gateway.rb
|
350
355
|
- lib/awspec/type/network_acl.rb
|
351
356
|
- lib/awspec/type/rds.rb
|
352
357
|
- lib/awspec/type/rds_db_parameter_group.rb
|