chef-provisioning-aws 1.1.1 → 1.2.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 +237 -12
- data/lib/chef/provider/aws_dhcp_options.rb +4 -1
- data/lib/chef/provider/aws_load_balancer.rb +1 -1
- data/lib/chef/provider/aws_route_table.rb +40 -6
- data/lib/chef/provider/aws_security_group.rb +1 -1
- data/lib/chef/provider/aws_subnet.rb +8 -1
- data/lib/chef/provider/aws_vpc.rb +47 -15
- data/lib/chef/provisioning/aws_driver/aws_provider.rb +41 -0
- data/lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb +7 -0
- data/lib/chef/provisioning/aws_driver/driver.rb +114 -43
- data/lib/chef/provisioning/aws_driver/exceptions.rb +16 -0
- data/lib/chef/provisioning/aws_driver/super_lwrp.rb +1 -1
- data/lib/chef/provisioning/aws_driver/version.rb +1 -1
- data/lib/chef/resource/aws_ebs_volume.rb +2 -2
- data/lib/chef/resource/aws_eip_address.rb +3 -0
- data/lib/chef/resource/aws_route_table.rb +31 -0
- data/lib/chef/resource/aws_security_group.rb +29 -5
- data/spec/aws_support.rb +5 -1
- data/spec/aws_support/matchers/have_aws_object_tags.rb +63 -0
- data/spec/integration/aws_ebs_volume_spec.rb +8 -8
- data/spec/integration/aws_route_table_spec.rb +33 -0
- data/spec/integration/aws_security_group_spec.rb +86 -0
- data/spec/integration/aws_tagged_items_spec.rb +160 -0
- data/spec/integration/aws_vpc_spec.rb +2 -2
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c249f182469f97f148ae38d524c4d968cdd8f1e3
|
4
|
+
data.tar.gz: da61c4cfe294ca2f50605e63ff77042feffb1b74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cce99948b3f6f240fddae731ce3de418c9a239761a8a18776629e27e0b8c82843b202d4b91061d4cd002344c03e14ad36e02f6eecd4437fbbadd0347558affb
|
7
|
+
data.tar.gz: 28e75762b4b912ff030150ea2c9ca09290286b9eda36d6efbe0ed5e15b93f31ba16ffec6657220eabf0fbd85452a2ea9e8439cfd3f78082c10f7c1b6a2c230e6
|
data/README.md
CHANGED
@@ -1,17 +1,190 @@
|
|
1
|
-
#
|
1
|
+
# Chef Provisioning AWS
|
2
2
|
|
3
|
-
|
3
|
+
This README is a work in progress. Please add to it!
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
5
|
+
# Resources
|
6
|
+
|
7
|
+
TODO: List out weird/unique things about resources here. We don't need to document every resource
|
8
|
+
because users can look at the resource model.
|
9
|
+
|
10
|
+
## aws_vpc
|
11
|
+
|
12
|
+
If you specify `internet_gateway true` the VPC will create and manage its own internet gateway.
|
13
|
+
Specifying `internet_gateway false` will delete that managed internet gateway.
|
14
|
+
|
15
|
+
Specifying `main_routes` without `main_route_table` will update the 'default' route table
|
16
|
+
that is created when AWS creates the VPC.
|
17
|
+
|
18
|
+
Specifying `main_route_table` without specifying `main_routes` will update the main route
|
19
|
+
association to point to the provided route table.
|
20
|
+
|
21
|
+
If you specify both `main_routes` and `main_route_table` we will update the `main_route_table`
|
22
|
+
to have the specified `main_routes`. IE, running
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
aws_route_table 'ref-main-route-table' do
|
26
|
+
vpc 'ref-vpc'
|
27
|
+
routes '0.0.0.0/0' => :internet_gateway
|
28
|
+
end
|
29
|
+
|
30
|
+
aws_vpc 'ref-vpc' do
|
31
|
+
main_route_table 'ref-main-route-table'
|
32
|
+
main_routes '0.0.0.0/1' => :internet_gateway
|
33
|
+
end
|
34
|
+
|
35
|
+
aws_vpc 'ref-vpc' do
|
36
|
+
main_routes '0.0.0.0/2' => :internet_gateway
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
will cause resource flapping. The `ref-main-route-table` resource will set the routes to `/0`
|
41
|
+
and then the vpc will set the routes to `/1`. Then because `ref-main-route-table` is set
|
42
|
+
to the main route for `ref-vpc` the third resource will set the routes to `/2`.
|
43
|
+
|
44
|
+
The takeaway from this is that you should either specify `main_routes` on your VPC and only
|
45
|
+
manage the routes through that, OR only specify `main_route_table` and manage the routes
|
46
|
+
through the `aws_route_table` resource.
|
47
|
+
|
48
|
+
### Purging
|
49
|
+
|
50
|
+
If you specify `action :purge` on the VPC it will attempt to delete ALL resources contained in this
|
51
|
+
VPC before deleting the actual VPC.
|
52
|
+
|
53
|
+
A potential danger of this is that it does not delete the data bag entries for tracked AWS objects.
|
54
|
+
If you `:purge` a VPC and it has `aws_route_table[ref-route]` in it, the data bag entry for
|
55
|
+
`ref-route` is not automatically destroyed. Purge is most useful for testing to ensure no objects
|
56
|
+
are left that AWS can charge for.
|
57
|
+
|
58
|
+
## aws_key_pair
|
59
|
+
|
60
|
+
TODO - document how to specify an existing local key
|
61
|
+
|
62
|
+
## Machine Options
|
63
|
+
|
64
|
+
You can pass machine options that will be used by `machine`, `machine_batch` and `machine_image` to
|
65
|
+
configure the machine. These are all the available options:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
with_machine_options({
|
69
|
+
bootstrap_options: {
|
70
|
+
key_name: 'ref-key-pair',
|
71
|
+
...
|
72
|
+
},
|
73
|
+
...
|
74
|
+
})
|
75
|
+
```
|
76
|
+
|
77
|
+
This options hash can be supplied to either `with_machine_options` or directly into the `machine_options`
|
78
|
+
attribute.
|
79
|
+
|
80
|
+
## Looking up AWS objects
|
81
|
+
|
82
|
+
### \#aws\_object
|
83
|
+
|
84
|
+
All chef-provisioning-aws resources have a `aws_object` method that will return the AWS object. The AWS
|
85
|
+
object won't exist until the resource converges, however. An example of how to do this looks like:
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
my_vpc = aws_vpc 'my_vpc' do
|
89
|
+
cidr_block '10.0.0.0/24'
|
90
|
+
main_routes '0.0.0.0/0' => :internet_gateway
|
91
|
+
internet_gateway true
|
92
|
+
end
|
93
|
+
|
94
|
+
my_sg = aws_security_group 'my_sg' do
|
95
|
+
vpc lazy { my_vpc.aws_object.id }
|
96
|
+
inbound_rules '0.0.0.0/0' => [ 22, 80 ]
|
97
|
+
end
|
98
|
+
|
99
|
+
my_subnet = aws_subnet 'my_subnet' do
|
100
|
+
vpc lazy { my_vpc.aws_object.id }
|
101
|
+
cidr_block '10.0.0.0/24'
|
102
|
+
availability_zone 'eu-west-1a'
|
103
|
+
map_public_ip_on_launch true
|
104
|
+
end
|
105
|
+
|
106
|
+
machine 'my_machine' do
|
107
|
+
machine_options(
|
108
|
+
lazy do
|
109
|
+
{
|
110
|
+
bootstrap_options: {
|
111
|
+
subnet_id: my_subnet.aws_object.id,
|
112
|
+
security_group_ids: [my_sg.aws_object.id]
|
113
|
+
}
|
114
|
+
}
|
115
|
+
end
|
116
|
+
)
|
117
|
+
end
|
118
|
+
```
|
119
|
+
|
120
|
+
Note the use of the `lazy` attribute modifier. This is necessary because when the resources are compiled
|
121
|
+
the aws_objects do not exist yet, so we must wait to reference them until the converge phase.
|
122
|
+
|
123
|
+
### \#lookup\_options
|
124
|
+
|
125
|
+
You have access to the aws object when necessary, but often it isn't needed. The above example is better
|
126
|
+
written as:
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
aws_vpc 'my_vpc' do
|
130
|
+
cidr_block '10.0.0.0/24'
|
131
|
+
main_routes '0.0.0.0/0' => :internet_gateway
|
132
|
+
internet_gateway true
|
133
|
+
end
|
134
|
+
|
135
|
+
aws_security_group 'my_sg' do
|
136
|
+
vpc 'my_vpc'
|
137
|
+
inbound_rules '0.0.0.0/0' => [ 22, 80 ]
|
138
|
+
end
|
139
|
+
|
140
|
+
aws_subnet 'my_subnet' do
|
141
|
+
vpc 'my_vpc'
|
142
|
+
cidr_block '10.0.0.0/24'
|
143
|
+
availability_zone 'eu-west-1a'
|
144
|
+
map_public_ip_on_launch true
|
145
|
+
end
|
146
|
+
|
147
|
+
machine 'my_machine' do
|
148
|
+
machine_options bootstrap_options: {
|
149
|
+
subnet_id: 'my_subnet',
|
150
|
+
security_group_ids: ['my_sg']
|
151
|
+
}
|
152
|
+
end
|
153
|
+
```
|
154
|
+
|
155
|
+
When specifying `bootstrap_options` and any attributes which reference another aws resource, we
|
156
|
+
perform [lookup_options](https://github.com/chef/chef-provisioning-aws/blob/master/lib/chef/provisioning/aws_driver/aws_resource.rb#L63-L91).
|
157
|
+
This tries to turn elements with names like `vpc`, `security_group_ids`, `machines`, `launch_configurations`,
|
158
|
+
`load_balancers`, etc. to the correct AWS object.
|
159
|
+
|
160
|
+
### Looking up chef-provisioning resources
|
161
|
+
|
162
|
+
The base chef-provisioning resources (machine, machine_batch, load_balancer, machine_image) don't
|
163
|
+
have the `aws_object` method defined on them because they are not `AWSResource` classes. To
|
164
|
+
look them up use the class method `get_aws_object` defined on the chef-provisioning-aws specific
|
165
|
+
resource:
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
machine_image 'my_image' do
|
169
|
+
...
|
170
|
+
end
|
171
|
+
|
172
|
+
ruby_block "look up machine_image object" do
|
173
|
+
aws_object = Chef::Resource::AwsImage.get_aws_object(
|
174
|
+
'my_image',
|
175
|
+
run_context: run_context,
|
176
|
+
driver: run_context.chef_provisioning.current_driver,
|
177
|
+
managed_entry_store: Chef::Provisioning.chef_managed_entry_store(self.chef_server)
|
178
|
+
)
|
179
|
+
end
|
180
|
+
```
|
181
|
+
|
182
|
+
To look up a machine, use the `AwsInstance` class, to look up a load balancer use the `AwsLoadBalancer`
|
183
|
+
class, etc. The first parameter you pass should be the same resource name as used in the base
|
184
|
+
chef-provisioning resource.
|
185
|
+
|
186
|
+
Again, the AWS object will not exist until the converge phase, so the aws_object will only be
|
187
|
+
available using a `lazy` attribute modifier or in a `ruby_block`.
|
15
188
|
|
16
189
|
# Running Integration Tests
|
17
190
|
|
@@ -30,3 +203,55 @@ you!
|
|
30
203
|
If you find the tests leaving behind resources during normal conditions (IE, not when there is an
|
31
204
|
unexpected exception) please file a bug. Most objects can be cleaned up by deleting the `test_vpc`
|
32
205
|
from within the AWS browser console.
|
206
|
+
|
207
|
+
# Tagging Resources
|
208
|
+
|
209
|
+
## Aws Resources
|
210
|
+
|
211
|
+
All resources which extend Chef::Provisioning::AWSDriver::AWSResourceWithEntry support the ability
|
212
|
+
to add tags, except AwsEipAddress. AWS does not support tagging on AwsEipAddress. To add a tag
|
213
|
+
to any aws resource, us the `aws_tags` attribute and provide it a hash:
|
214
|
+
|
215
|
+
```ruby
|
216
|
+
aws_ebs_volume 'ref-volume' do
|
217
|
+
aws_tags company: 'my_company', 'key_as_string' => :value_as_symbol
|
218
|
+
end
|
219
|
+
|
220
|
+
aws_vpc 'ref-vpc' do
|
221
|
+
aws_tags 'Name' => 'custom-vpc-name'
|
222
|
+
end
|
223
|
+
```
|
224
|
+
|
225
|
+
The hash of tags can use symbols or strings for both keys and values. The tags will be converged
|
226
|
+
idempotently, meaning no write will occur if no tags are changing.
|
227
|
+
|
228
|
+
We will not touch the `'Name'` tag UNLESS you specifically pass it. If you do not pass it, we
|
229
|
+
leave it alone.
|
230
|
+
|
231
|
+
## Base Resources
|
232
|
+
|
233
|
+
Because base resources from chef-provisioning do not have the `aws_tag` attribute, they must be
|
234
|
+
tagged in their options:
|
235
|
+
|
236
|
+
```ruby
|
237
|
+
machine 'ref-machine-1' do
|
238
|
+
machine_options :aws_tags => {:marco => 'polo', :happyhappy => 'joyjoy'}
|
239
|
+
end
|
240
|
+
|
241
|
+
machine_batch "ref-batch" do
|
242
|
+
machine 'ref-machine-2' do
|
243
|
+
machine_options :aws_tags => {:marco => 'polo', :happyhappy => 'joyjoy'}
|
244
|
+
converge false
|
245
|
+
end
|
246
|
+
machine 'ref-machine-3' do
|
247
|
+
machine_options :aws_tags => {:othercustomtags => 'byebye'}
|
248
|
+
converge false
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
load_balancer 'ref-elb' do
|
253
|
+
load_balancer_options :aws_tags => {:marco => 'polo', :happyhappy => 'joyjoy'}
|
254
|
+
end
|
255
|
+
```
|
256
|
+
|
257
|
+
See `docs/examples/aws_tags.rb` for further examples.
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'chef/provisioning/aws_driver/aws_provider'
|
2
|
+
require 'retryable'
|
2
3
|
|
3
4
|
class Chef::Provider::AwsDhcpOptions < Chef::Provisioning::AWSDriver::AWSProvider
|
4
5
|
protected
|
@@ -11,7 +12,9 @@ class Chef::Provider::AwsDhcpOptions < Chef::Provisioning::AWSDriver::AWSProvide
|
|
11
12
|
|
12
13
|
converge_by "create new dhcp_options #{new_resource.name} in #{region}" do
|
13
14
|
dhcp_options = new_resource.driver.ec2.dhcp_options.create(options)
|
14
|
-
|
15
|
+
Retryable.retryable(:tries => 15, :sleep => 1, :on => AWS::EC2::Errors::InvalidDhcpOptionsID::NotFound) do
|
16
|
+
dhcp_options.tags['Name'] = new_resource.name
|
17
|
+
end
|
15
18
|
dhcp_options
|
16
19
|
end
|
17
20
|
end
|
@@ -2,7 +2,7 @@ require 'chef/provisioning/aws_driver/aws_provider'
|
|
2
2
|
|
3
3
|
class Chef::Provider::AwsLoadBalancer < Chef::Provisioning::AWSDriver::AWSProvider
|
4
4
|
def destroy_aws_object(load_balancer)
|
5
|
-
converge_by "delete load balancer #{new_resource.name} (#{load_balancer.
|
5
|
+
converge_by "delete load balancer #{new_resource.name} (#{load_balancer.name}) in #{region}" do
|
6
6
|
load_balancer.delete
|
7
7
|
end
|
8
8
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'chef/provisioning/aws_driver/aws_provider'
|
2
|
+
require 'retryable'
|
2
3
|
|
3
4
|
class Chef::Provider::AwsRouteTable < Chef::Provisioning::AWSDriver::AWSProvider
|
4
5
|
|
@@ -6,8 +7,10 @@ class Chef::Provider::AwsRouteTable < Chef::Provisioning::AWSDriver::AWSProvider
|
|
6
7
|
route_table = super
|
7
8
|
|
8
9
|
if !new_resource.routes.nil?
|
9
|
-
update_routes(vpc, route_table)
|
10
|
+
update_routes(vpc, route_table, new_resource.ignore_route_targets)
|
10
11
|
end
|
12
|
+
|
13
|
+
update_virtual_private_gateways(route_table, new_resource.virtual_private_gateways)
|
11
14
|
end
|
12
15
|
|
13
16
|
protected
|
@@ -20,7 +23,9 @@ class Chef::Provider::AwsRouteTable < Chef::Provisioning::AWSDriver::AWSProvider
|
|
20
23
|
|
21
24
|
converge_by "create new route table #{new_resource.name} in VPC #{new_resource.vpc} (#{vpc.id}) and region #{region}" do
|
22
25
|
route_table = new_resource.driver.ec2.route_tables.create(options)
|
23
|
-
|
26
|
+
Retryable.retryable(:tries => 15, :sleep => 1, :on => AWS::EC2::Errors::InvalidRouteTableID::NotFound) do
|
27
|
+
route_table.tags['Name'] = new_resource.name
|
28
|
+
end
|
24
29
|
route_table
|
25
30
|
end
|
26
31
|
end
|
@@ -31,14 +36,18 @@ class Chef::Provider::AwsRouteTable < Chef::Provisioning::AWSDriver::AWSProvider
|
|
31
36
|
if new_resource.vpc
|
32
37
|
desired_vpc = Chef::Resource::AwsVpc.get_aws_object(new_resource.vpc, resource: new_resource)
|
33
38
|
if vpc != desired_vpc
|
34
|
-
raise "VPC of route table #{new_resource.
|
39
|
+
raise "VPC of route table #{new_resource.to_s} is #{route_table.vpc.id}, but desired vpc is #{new_resource.vpc}! The AWS SDK does not support updating the main route table except by creating a new route table."
|
35
40
|
end
|
36
41
|
end
|
37
42
|
end
|
38
43
|
|
39
44
|
def destroy_aws_object(route_table)
|
40
|
-
converge_by "delete
|
41
|
-
|
45
|
+
converge_by "delete #{new_resource.to_s} in #{region}" do
|
46
|
+
begin
|
47
|
+
route_table.delete
|
48
|
+
rescue AWS::EC2::Errors::DependencyViolation
|
49
|
+
raise "#{new_resource.to_s} could not be deleted because it is the main route table for #{route_table.vpc.id} or it is being used by a subnet"
|
50
|
+
end
|
42
51
|
end
|
43
52
|
end
|
44
53
|
|
@@ -46,12 +55,13 @@ class Chef::Provider::AwsRouteTable < Chef::Provisioning::AWSDriver::AWSProvider
|
|
46
55
|
|
47
56
|
attr_accessor :vpc
|
48
57
|
|
49
|
-
def update_routes(vpc, route_table)
|
58
|
+
def update_routes(vpc, route_table, ignore_route_targets = [])
|
50
59
|
# Collect current routes
|
51
60
|
current_routes = {}
|
52
61
|
route_table.routes.each do |route|
|
53
62
|
# Ignore the automatic local route
|
54
63
|
next if route.target.id == 'local'
|
64
|
+
next if ignore_route_targets.find { |target| route.target.id.match(/#{target}/) }
|
55
65
|
current_routes[route.destination_cidr_block] = route
|
56
66
|
end
|
57
67
|
|
@@ -82,6 +92,30 @@ class Chef::Provider::AwsRouteTable < Chef::Provisioning::AWSDriver::AWSProvider
|
|
82
92
|
end
|
83
93
|
end
|
84
94
|
|
95
|
+
def update_virtual_private_gateways(route_table, gateway_ids)
|
96
|
+
current_propagating_vgw_set = route_table.client.describe_route_tables(route_table_ids: [route_table.id]).route_table_set.first.propagating_vgw_set
|
97
|
+
|
98
|
+
# Add propagated routes
|
99
|
+
if gateway_ids
|
100
|
+
gateway_ids.each do |gateway_id|
|
101
|
+
if !current_propagating_vgw_set.reject! { |vgw_set| vgw_set[:gateway_id] == gateway_id }
|
102
|
+
action_handler.perform_action "enable route propagation for route table #{route_table.id} to virtual private gateway #{gateway_id}" do
|
103
|
+
route_table.client.enable_vgw_route_propagation(route_table_id: route_table.id, gateway_id: gateway_id)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Delete anything that's left
|
110
|
+
if current_propagating_vgw_set
|
111
|
+
current_propagating_vgw_set.each do |vgw_set|
|
112
|
+
action_handler.perform_action "disabling route propagation for route table #{route_table.id} from virtual private gateway #{vgw_set[:gateway_id]}" do
|
113
|
+
route_table.client.disable_vgw_route_propagation(route_table_id: route_table.id, gateway_id: vgw_set[:gateway_id])
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
85
119
|
def get_route_target(vpc, route_target)
|
86
120
|
case route_target
|
87
121
|
when :internet_gateway
|
@@ -38,7 +38,7 @@ class Chef::Provider::AwsSecurityGroup < Chef::Provisioning::AWSDriver::AWSProvi
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def destroy_aws_object(sg)
|
41
|
-
converge_by "
|
41
|
+
converge_by "delete #{new_resource.to_s} in #{region}" do
|
42
42
|
sg.delete
|
43
43
|
end
|
44
44
|
end
|
@@ -61,8 +61,15 @@ class Chef::Provider::AwsSubnet < Chef::Provisioning::AWSDriver::AWSProvider
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
64
|
+
p.parallel_do(subnet.network_interfaces.to_a) do |network|
|
65
|
+
Cheffish.inline_resource(self, action) do
|
66
|
+
aws_network_interface network do
|
67
|
+
action :purge
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
64
71
|
end
|
65
|
-
converge_by "delete
|
72
|
+
converge_by "delete #{new_resource.to_s} in VPC #{new_resource.vpc} in #{region}" do
|
66
73
|
# If the subnet doesn't exist we can't check state on it - state can only be :pending or :available
|
67
74
|
begin
|
68
75
|
subnet.delete
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'chef/provisioning/aws_driver/aws_provider'
|
2
2
|
require 'date'
|
3
|
+
require 'chef/provisioning'
|
4
|
+
require 'retryable'
|
3
5
|
|
4
6
|
class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
|
5
7
|
|
@@ -18,12 +20,12 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
|
|
18
20
|
|
19
21
|
# Replace the main route table for the VPC
|
20
22
|
if !new_resource.main_route_table.nil?
|
21
|
-
|
23
|
+
update_main_route_table(vpc)
|
22
24
|
end
|
23
25
|
|
24
26
|
# Update the main route table
|
25
27
|
if !new_resource.main_routes.nil?
|
26
|
-
update_main_routes(vpc, main_route_table)
|
28
|
+
update_main_routes(vpc, new_resource.main_route_table)
|
27
29
|
end
|
28
30
|
|
29
31
|
# Update DHCP options
|
@@ -57,7 +59,7 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
|
|
57
59
|
def destroy_aws_object(vpc)
|
58
60
|
if purging
|
59
61
|
vpc.subnets.each do |s|
|
60
|
-
Cheffish.inline_resource(self, action) do
|
62
|
+
Cheffish.inline_resource(self, action) do
|
61
63
|
aws_subnet s do
|
62
64
|
action :purge
|
63
65
|
end
|
@@ -66,27 +68,49 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
|
|
66
68
|
# If any of the below resources start needing complicated delete logic (dependent resources needing to
|
67
69
|
# be deleted) move that logic into `delete_aws_resource` and add the purging logic to the resource
|
68
70
|
vpc.network_acls.each { |o| o.delete unless o.default? }
|
69
|
-
vpc.network_interfaces.each
|
70
|
-
|
71
|
-
|
71
|
+
vpc.network_interfaces.each do |ni|
|
72
|
+
Cheffish.inline_resource(self, action) do
|
73
|
+
aws_network_interface ni do
|
74
|
+
action :purge
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
vpc.route_tables.each do |rt|
|
79
|
+
unless rt.main?
|
80
|
+
Cheffish.inline_resource(self, action) do
|
81
|
+
aws_route_table rt do
|
82
|
+
action :purge
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
vpc.security_groups.each do |sg|
|
88
|
+
unless sg.name == 'default'
|
89
|
+
Cheffish.inline_resource(self, action) do
|
90
|
+
aws_security_group sg do
|
91
|
+
action :purge
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
72
96
|
end
|
73
97
|
|
74
98
|
# Detach or destroy the internet gateway
|
75
99
|
ig = vpc.internet_gateway
|
76
100
|
if ig
|
77
|
-
converge_by "detach Internet Gateway #{ig.id} in #{region} from
|
101
|
+
converge_by "detach Internet Gateway #{ig.id} in #{region} from #{new_resource.to_s}" do
|
78
102
|
ig.detach(vpc.id)
|
79
103
|
end
|
80
104
|
if ig.tags['OwnedByVPC'] == vpc.id
|
81
|
-
converge_by "destroy Internet Gateway #{ig.id} in #{region} (owned by
|
105
|
+
converge_by "destroy Internet Gateway #{ig.id} in #{region} (owned by #{new_resource.to_s})" do
|
82
106
|
ig.delete
|
83
107
|
end
|
84
108
|
end
|
85
109
|
end
|
86
110
|
|
87
|
-
#
|
111
|
+
# We cannot delete the main route table, and it will be deleted when the VPC is deleted anyways
|
88
112
|
|
89
|
-
converge_by "delete
|
113
|
+
converge_by "delete #{new_resource.to_s} in #{region}" do
|
90
114
|
vpc.delete
|
91
115
|
end
|
92
116
|
end
|
@@ -140,6 +164,9 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
|
|
140
164
|
if !current_ig
|
141
165
|
converge_by "attach new Internet Gateway to VPC #{vpc.id}" do
|
142
166
|
current_ig = AWS.ec2(config: vpc.config).internet_gateways.create
|
167
|
+
Retryable.retryable(:tries => 15, :sleep => 1, :matching => /never obtained existence/) do
|
168
|
+
raise "internet gateway for VPC #{vpc.id} never obtained existence" unless current_ig.exists?
|
169
|
+
end
|
143
170
|
action_handler.report_progress "create Internet Gateway #{current_ig.id}"
|
144
171
|
current_ig.tags['OwnedByVPC'] = vpc.id
|
145
172
|
action_handler.report_progress "tag Internet Gateway #{current_ig.id} as OwnedByVpc: #{vpc.id}"
|
@@ -166,22 +193,27 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
|
|
166
193
|
if current_route_table != desired_route_table
|
167
194
|
main_association = current_route_table.associations.select { |a| a.main? }.first
|
168
195
|
if !main_association
|
169
|
-
raise "No main route table association found for
|
196
|
+
raise "No main route table association found for #{new_resource.to_s} current main route table #{current_route_table.id}: error! Probably a race condition."
|
170
197
|
end
|
171
|
-
converge_by "change main route table for
|
198
|
+
converge_by "change main route table for #{new_resource.to_s} to #{desired_route_table.id} (was #{current_route_table.id})" do
|
172
199
|
vpc.client.replace_route_table_association(
|
173
200
|
association_id: main_association.id,
|
174
|
-
route_table_id: desired_route_table.id
|
201
|
+
route_table_id: desired_route_table.id
|
202
|
+
)
|
175
203
|
end
|
176
204
|
end
|
177
205
|
desired_route_table
|
178
206
|
end
|
179
207
|
|
180
208
|
def update_main_routes(vpc, main_route_table)
|
209
|
+
# If no route table is provided and we fetch the current main one from AWS,
|
210
|
+
# there is no guarantee that is the 'default' route table created when
|
211
|
+
# creating the VPC
|
181
212
|
main_route_table ||= vpc.route_tables.main_route_table
|
213
|
+
main_routes = new_resource.main_routes
|
182
214
|
aws_route_table main_route_table do
|
183
215
|
vpc vpc
|
184
|
-
routes
|
216
|
+
routes main_routes
|
185
217
|
end
|
186
218
|
main_route_table
|
187
219
|
end
|
@@ -190,7 +222,7 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
|
|
190
222
|
dhcp_options = vpc.dhcp_options
|
191
223
|
desired_dhcp_options = Chef::Resource::AwsDhcpOptions.get_aws_object(new_resource.dhcp_options, resource: new_resource)
|
192
224
|
if dhcp_options != desired_dhcp_options
|
193
|
-
converge_by "change DHCP options for
|
225
|
+
converge_by "change DHCP options for #{new_resource.to_s} to #{new_resource.dhcp_options} (#{desired_dhcp_options.id}) - was #{dhcp_options.id}" do
|
194
226
|
vpc.dhcp_options = desired_dhcp_options
|
195
227
|
end
|
196
228
|
end
|