chef-provisioning-aws 3.0.4 → 3.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +16 -5
- data/Rakefile +15 -6
- data/chef-provisioning-aws.gemspec +17 -17
- data/lib/chef/provider/aws_auto_scaling_group.rb +5 -6
- data/lib/chef/provider/aws_cache_cluster.rb +21 -15
- data/lib/chef/provider/aws_cache_replication_group.rb +12 -8
- data/lib/chef/provider/aws_cache_subnet_group.rb +3 -3
- data/lib/chef/provider/aws_cloudsearch_domain.rb +9 -13
- data/lib/chef/provider/aws_cloudwatch_alarm.rb +10 -12
- data/lib/chef/provider/aws_dhcp_options.rb +18 -21
- data/lib/chef/provider/aws_ebs_volume.rb +24 -26
- data/lib/chef/provider/aws_eip_address.rb +10 -13
- data/lib/chef/provider/aws_elasticsearch_domain.rb +19 -18
- data/lib/chef/provider/aws_iam_instance_profile.rb +5 -7
- data/lib/chef/provider/aws_iam_role.rb +14 -17
- data/lib/chef/provider/aws_image.rb +6 -6
- data/lib/chef/provider/aws_instance.rb +5 -5
- data/lib/chef/provider/aws_internet_gateway.rb +8 -11
- data/lib/chef/provider/aws_key_pair.rb +15 -17
- data/lib/chef/provider/aws_launch_configuration.rb +11 -14
- data/lib/chef/provider/aws_load_balancer.rb +1 -2
- data/lib/chef/provider/aws_nat_gateway.rb +6 -7
- data/lib/chef/provider/aws_network_acl.rb +28 -29
- data/lib/chef/provider/aws_network_interface.rb +25 -27
- data/lib/chef/provider/aws_rds_instance.rb +12 -13
- data/lib/chef/provider/aws_rds_parameter_group.rb +8 -8
- data/lib/chef/provider/aws_rds_subnet_group.rb +8 -9
- data/lib/chef/provider/aws_route_table.rb +19 -20
- data/lib/chef/provider/aws_s3_bucket.rb +22 -25
- data/lib/chef/provider/aws_security_group.rb +268 -285
- data/lib/chef/provider/aws_server_certificate.rb +6 -5
- data/lib/chef/provider/aws_sns_topic.rb +4 -6
- data/lib/chef/provider/aws_sqs_queue.rb +3 -4
- data/lib/chef/provider/aws_subnet.rb +29 -34
- data/lib/chef/provider/aws_vpc.rb +108 -116
- data/lib/chef/provider/aws_vpc_peering_connection.rb +11 -11
- data/lib/chef/provisioning/aws_driver.rb +4 -2
- data/lib/chef/provisioning/aws_driver/aws_provider.rb +234 -241
- data/lib/chef/provisioning/aws_driver/aws_rds_resource.rb +5 -7
- data/lib/chef/provisioning/aws_driver/aws_resource.rb +182 -185
- data/lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb +17 -17
- data/lib/chef/provisioning/aws_driver/aws_taggable.rb +13 -15
- data/lib/chef/provisioning/aws_driver/aws_tagger.rb +47 -48
- data/lib/chef/provisioning/aws_driver/credentials.rb +96 -100
- data/lib/chef/provisioning/aws_driver/credentials2.rb +42 -45
- data/lib/chef/provisioning/aws_driver/driver.rb +1349 -1362
- data/lib/chef/provisioning/aws_driver/exceptions.rb +10 -12
- data/lib/chef/provisioning/aws_driver/super_lwrp.rb +60 -60
- data/lib/chef/provisioning/aws_driver/tagging_strategy/auto_scaling.rb +49 -50
- data/lib/chef/provisioning/aws_driver/tagging_strategy/ec2.rb +37 -38
- data/lib/chef/provisioning/aws_driver/tagging_strategy/elasticsearch.rb +14 -15
- data/lib/chef/provisioning/aws_driver/tagging_strategy/elb.rb +29 -31
- data/lib/chef/provisioning/aws_driver/tagging_strategy/rds.rb +39 -40
- data/lib/chef/provisioning/aws_driver/tagging_strategy/s3.rb +41 -43
- data/lib/chef/provisioning/aws_driver/version.rb +5 -5
- data/lib/chef/provisioning/driver_init/aws.rb +2 -2
- data/lib/chef/resource/aws_auto_scaling_group.rb +1 -1
- data/lib/chef/resource/aws_cache_cluster.rb +9 -12
- data/lib/chef/resource/aws_cache_replication_group.rb +9 -11
- data/lib/chef/resource/aws_cache_subnet_group.rb +8 -10
- data/lib/chef/resource/aws_cloudsearch_domain.rb +4 -5
- data/lib/chef/resource/aws_cloudwatch_alarm.rb +17 -18
- data/lib/chef/resource/aws_dhcp_options.rb +2 -2
- data/lib/chef/resource/aws_ebs_volume.rb +10 -10
- data/lib/chef/resource/aws_eip_address.rb +5 -5
- data/lib/chef/resource/aws_elasticsearch_domain.rb +4 -4
- data/lib/chef/resource/aws_iam_instance_profile.rb +4 -5
- data/lib/chef/resource/aws_iam_role.rb +2 -3
- data/lib/chef/resource/aws_image.rb +3 -3
- data/lib/chef/resource/aws_instance.rb +4 -4
- data/lib/chef/resource/aws_internet_gateway.rb +3 -3
- data/lib/chef/resource/aws_key_pair.rb +7 -7
- data/lib/chef/resource/aws_launch_configuration.rb +4 -4
- data/lib/chef/resource/aws_load_balancer.rb +7 -7
- data/lib/chef/resource/aws_nat_gateway.rb +11 -11
- data/lib/chef/resource/aws_network_acl.rb +7 -8
- data/lib/chef/resource/aws_network_interface.rb +9 -9
- data/lib/chef/resource/aws_rds_instance.rb +4 -4
- data/lib/chef/resource/aws_rds_parameter_group.rb +3 -3
- data/lib/chef/resource/aws_rds_subnet_group.rb +4 -4
- data/lib/chef/resource/aws_route53_hosted_zone.rb +37 -40
- data/lib/chef/resource/aws_route53_record_set.rb +22 -24
- data/lib/chef/resource/aws_route_table.rb +7 -7
- data/lib/chef/resource/aws_s3_bucket.rb +7 -7
- data/lib/chef/resource/aws_security_group.rb +10 -10
- data/lib/chef/resource/aws_server_certificate.rb +6 -8
- data/lib/chef/resource/aws_sns_topic.rb +2 -2
- data/lib/chef/resource/aws_sqs_queue.rb +5 -7
- data/lib/chef/resource/aws_subnet.rb +9 -9
- data/lib/chef/resource/aws_vpc.rb +11 -11
- data/lib/chef/resource/aws_vpc_peering_connection.rb +4 -4
- data/spec/aws_support.rb +44 -45
- data/spec/aws_support/aws_resource_run_wrapper.rb +2 -2
- data/spec/aws_support/deep_matcher.rb +2 -3
- data/spec/aws_support/deep_matcher/fuzzy_match_objects.rb +6 -9
- data/spec/aws_support/deep_matcher/match_values_failure_messages.rb +30 -37
- data/spec/aws_support/deep_matcher/matchable_array.rb +0 -1
- data/spec/aws_support/deep_matcher/matchable_object.rb +1 -2
- data/spec/aws_support/deep_matcher/rspec_monkeypatches.rb +4 -4
- data/spec/aws_support/delayed_stream.rb +2 -2
- data/spec/aws_support/matchers/create_an_aws_object.rb +6 -6
- data/spec/aws_support/matchers/destroy_an_aws_object.rb +6 -6
- data/spec/aws_support/matchers/have_aws_object_tags.rb +4 -5
- data/spec/aws_support/matchers/match_an_aws_object.rb +5 -6
- data/spec/aws_support/matchers/update_an_aws_object.rb +6 -7
- data/spec/integration/aws_auto_scaling_group_spec.rb +56 -64
- data/spec/integration/aws_cache_cluster_spec.rb +70 -71
- data/spec/integration/aws_cache_subnet_group_spec.rb +13 -14
- data/spec/integration/aws_cloudsearch_domain_spec.rb +6 -8
- data/spec/integration/aws_cloudwatch_alarm_spec.rb +200 -208
- data/spec/integration/aws_dhcp_options_spec.rb +32 -43
- data/spec/integration/aws_ebs_volume_spec.rb +52 -73
- data/spec/integration/aws_eip_address_spec.rb +24 -31
- data/spec/integration/aws_elasticsearch_domain_spec.rb +31 -33
- data/spec/integration/aws_iam_instance_profile_spec.rb +36 -45
- data/spec/integration/aws_iam_role_spec.rb +39 -46
- data/spec/integration/aws_internet_gateway_spec.rb +64 -75
- data/spec/integration/aws_key_pair_spec.rb +6 -6
- data/spec/integration/aws_launch_configuration_spec.rb +17 -18
- data/spec/integration/aws_nat_gateway_spec.rb +21 -24
- data/spec/integration/aws_network_acl_spec.rb +81 -95
- data/spec/integration/aws_network_interface_spec.rb +28 -43
- data/spec/integration/aws_rds_instance_spec.rb +29 -40
- data/spec/integration/aws_rds_parameter_group_spec.rb +32 -35
- data/spec/integration/aws_rds_subnet_group_spec.rb +30 -40
- data/spec/integration/aws_route53_hosted_zone_spec.rb +205 -205
- data/spec/integration/aws_route_table_spec.rb +118 -136
- data/spec/integration/aws_s3_bucket_spec.rb +19 -27
- data/spec/integration/aws_security_group_spec.rb +369 -388
- data/spec/integration/aws_server_certificate_spec.rb +16 -18
- data/spec/integration/aws_subnet_spec.rb +44 -58
- data/spec/integration/aws_vpc_peering_connection_spec.rb +43 -50
- data/spec/integration/aws_vpc_spec.rb +99 -115
- data/spec/integration/load_balancer_spec.rb +169 -183
- data/spec/integration/machine_batch_spec.rb +24 -31
- data/spec/integration/machine_image_spec.rb +54 -66
- data/spec/integration/machine_spec.rb +216 -237
- data/spec/persistence_file.txt +219 -0
- data/spec/spec_helper.rb +16 -17
- data/spec/unit/chef/provisioning/aws_driver/credentials_spec.rb +67 -74
- data/spec/unit/chef/provisioning/aws_driver/driver_spec.rb +29 -29
- data/spec/unit/chef/provisioning/aws_driver/route53_spec.rb +13 -15
- metadata +4 -3
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "chef/provisioning/aws_driver/aws_provider"
|
2
|
+
require "retryable"
|
3
3
|
|
4
4
|
class Chef::Provider::AwsVpcPeeringConnection < Chef::Provisioning::AWSDriver::AWSProvider
|
5
5
|
provides :aws_vpc_peering_connection
|
@@ -36,15 +36,15 @@ class Chef::Provider::AwsVpcPeeringConnection < Chef::Provisioning::AWSDriver::A
|
|
36
36
|
vpc_peering_connection = vpc.request_vpc_peering_connection(options)
|
37
37
|
|
38
38
|
retry_with_backoff(::Aws::EC2::Errors::ServiceError) do
|
39
|
-
ec2_resource.create_tags(
|
40
|
-
:
|
41
|
-
:
|
39
|
+
ec2_resource.create_tags(
|
40
|
+
resources: [vpc_peering_connection.id],
|
41
|
+
tags: [
|
42
42
|
{
|
43
|
-
:
|
44
|
-
:
|
43
|
+
key: "Name",
|
44
|
+
value: new_resource.name
|
45
45
|
}
|
46
46
|
]
|
47
|
-
|
47
|
+
)
|
48
48
|
end
|
49
49
|
vpc_peering_connection
|
50
50
|
end
|
@@ -71,8 +71,8 @@ class Chef::Provider::AwsVpcPeeringConnection < Chef::Provisioning::AWSDriver::A
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def destroy_aws_object(vpc_peering_connection)
|
74
|
-
converge_by "delete #{new_resource
|
75
|
-
unless
|
74
|
+
converge_by "delete #{new_resource} in #{region}" do
|
75
|
+
unless %w{deleted failed deleting}.include? vpc_peering_connection.status.code
|
76
76
|
vpc_peering_connection.delete
|
77
77
|
end
|
78
78
|
end
|
@@ -81,7 +81,7 @@ class Chef::Provider::AwsVpcPeeringConnection < Chef::Provisioning::AWSDriver::A
|
|
81
81
|
private
|
82
82
|
|
83
83
|
def accept_connection(vpc_peering_connection, new_resource)
|
84
|
-
if new_resource.peer_owner_id.nil?
|
84
|
+
if new_resource.peer_owner_id.nil? || (new_resource.peer_owner_id == new_resource.driver.account_id)
|
85
85
|
vpc_peering_connection.accept
|
86
86
|
end
|
87
87
|
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "chef/provisioning"
|
2
|
+
require "chef/provisioning/aws_driver/driver"
|
3
3
|
|
4
4
|
require "chef/resource/aws_auto_scaling_group"
|
5
5
|
require "chef/resource/aws_cache_cluster"
|
@@ -45,7 +45,9 @@ module NoResourceCloning
|
|
45
45
|
super
|
46
46
|
end
|
47
47
|
end
|
48
|
+
|
48
49
|
def emit_cloned_resource_warning; end
|
50
|
+
|
49
51
|
def emit_harmless_cloning_debug; end
|
50
52
|
end
|
51
53
|
|
@@ -1,311 +1,304 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require "chef/provider/lwrp_base"
|
2
|
+
require "chef/provisioning/aws_driver/aws_resource"
|
3
|
+
require "chef/provisioning/aws_driver/aws_resource_with_entry"
|
4
|
+
require "chef/provisioning/chef_managed_entry_store"
|
5
|
+
require "chef/provisioning/chef_provider_action_handler"
|
6
6
|
# Enough providers will require this that we put it in here
|
7
|
-
require
|
8
|
-
require
|
7
|
+
require "chef/provisioning/aws_driver/tagging_strategy/ec2"
|
8
|
+
require "retryable"
|
9
9
|
|
10
10
|
module Chef::Provisioning::AWSDriver
|
11
|
-
class AWSProvider < Chef::Provider::LWRPBase
|
12
|
-
|
11
|
+
class AWSProvider < Chef::Provider::LWRPBase
|
12
|
+
use_inline_resources
|
13
13
|
|
14
|
-
|
14
|
+
AWSResource = Chef::Provisioning::AWSDriver::AWSResource
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
class StatusTimeoutError < ::Timeout::Error
|
17
|
+
def initialize(aws_object, initial_status, expected_status)
|
18
|
+
super("timed out waiting for #{aws_object.id} status to change from #{initial_status.inspect} to #{expected_status.inspect}!")
|
19
|
+
end
|
19
20
|
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def action_handler
|
23
|
-
@action_handler ||= Chef::Provisioning::ChefProviderActionHandler.new(self)
|
24
|
-
end
|
25
21
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
22
|
+
def action_handler
|
23
|
+
@action_handler ||= Chef::Provisioning::ChefProviderActionHandler.new(self)
|
24
|
+
end
|
30
25
|
|
31
|
-
|
32
|
-
|
33
|
-
|
26
|
+
# All these need to implement whyrun
|
27
|
+
def whyrun_supported?
|
28
|
+
true
|
29
|
+
end
|
34
30
|
|
35
|
-
|
36
|
-
|
37
|
-
# normally returns.
|
38
|
-
#
|
39
|
-
def converge_by(*args, &block)
|
40
|
-
result = nil
|
41
|
-
super(*args) do
|
42
|
-
result = block.call
|
31
|
+
def region
|
32
|
+
new_resource.driver.aws_config[:region]
|
43
33
|
end
|
44
|
-
result
|
45
|
-
end
|
46
34
|
|
47
|
-
action :create do
|
48
35
|
#
|
49
|
-
#
|
36
|
+
# Return the damned value from the block, not whatever weirdness converge_by
|
37
|
+
# normally returns.
|
50
38
|
#
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
39
|
+
def converge_by(*args)
|
40
|
+
result = nil
|
41
|
+
super(*args) do
|
42
|
+
result = yield
|
43
|
+
end
|
44
|
+
result
|
55
45
|
end
|
56
46
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
if
|
64
|
-
|
47
|
+
action :create do
|
48
|
+
#
|
49
|
+
# If the user specified an ID, get the object for it, and fail if it does not exist.
|
50
|
+
#
|
51
|
+
desired_driver = new_resource.driver
|
52
|
+
desired_id = new_resource.public_send(new_resource.class.aws_id_attribute) if new_resource.class.aws_id_attribute
|
53
|
+
if desired_id
|
54
|
+
aws_object = new_resource.class.get_aws_object(desired_id, resource: new_resource)
|
55
|
+
end
|
56
|
+
|
57
|
+
#
|
58
|
+
# If Chef has already associated the object with an AWS ID, check if it's
|
59
|
+
# the same as the desired AWS ID.
|
60
|
+
#
|
61
|
+
if new_resource.is_a?(AWSResourceWithEntry)
|
62
|
+
entry_driver, entry_id, entry = new_resource.get_id_from_managed_entry
|
63
|
+
if entry_id
|
64
|
+
if desired_id
|
65
|
+
|
66
|
+
#
|
67
|
+
# We have both a desired ID and an entry ID. Find out whether they
|
68
|
+
# match and warn if they don't (because we're going to reassociate and
|
69
|
+
# update the *desired* AWS thing.).
|
70
|
+
#
|
71
|
+
if desired_driver.driver_url == entry_driver.driver_url && desired_id == entry_id
|
72
|
+
Chef::Log.debug "#{new_resource} is already associated with #{entry_id} in #{entry_driver.driver_url}"
|
73
|
+
else
|
74
|
+
Chef::Log.warn "#{new_resource} is currently associated with #{entry_id} in #{entry_driver.driver_url}, but the desired ID is #{desired_id} in #{new_resource.driver.driver_url}! Will associate with new desired ID #{desired_id}."
|
75
|
+
end
|
65
76
|
|
66
|
-
#
|
67
|
-
# We have both a desired ID and an entry ID. Find out whether they
|
68
|
-
# match and warn if they don't (because we're going to reassociate and
|
69
|
-
# update the *desired* AWS thing.).
|
70
|
-
#
|
71
|
-
if desired_driver.driver_url == entry_driver.driver_url && desired_id == entry_id
|
72
|
-
Chef::Log.debug "#{new_resource.to_s} is already associated with #{entry_id} in #{entry_driver.driver_url}"
|
73
77
|
else
|
74
|
-
|
78
|
+
|
79
|
+
#
|
80
|
+
# If we don't have desired (common case), we'll update the existing
|
81
|
+
# resource or create a new one if it's been deleted.
|
82
|
+
#
|
83
|
+
aws_object = new_resource.class.get_aws_object(entry_id, driver: entry_driver, resource: new_resource, required: false)
|
84
|
+
if aws_object
|
85
|
+
Chef::Log.debug "#{new_resource} is currently associated with #{entry_id} in #{entry_driver.driver_url}."
|
86
|
+
else
|
87
|
+
Chef::Log.warn "#{new_resource} is currently associated with #{entry_id} in #{entry_driver.driver_url}, but it does not exist! We will create a new one to replace it."
|
88
|
+
end
|
75
89
|
end
|
76
90
|
|
77
91
|
else
|
78
92
|
|
79
93
|
#
|
80
|
-
# If we don't have
|
81
|
-
#
|
94
|
+
# If we don't currently have an AWS ID associated with this resource, we
|
95
|
+
# will either associate the desired one, or create a new one.
|
82
96
|
#
|
83
|
-
|
84
|
-
|
85
|
-
Chef::Log.debug "#{new_resource.to_s} is currently associated with #{entry_id} in #{entry_driver.driver_url}."
|
97
|
+
if desired_id
|
98
|
+
Chef::Log.debug "#{new_resource} is not yet associated with anything. Associating with desired object #{desired_id} in #{desired_driver.driver_url}."
|
86
99
|
else
|
87
|
-
Chef::Log.
|
100
|
+
Chef::Log.debug "#{new_resource} is not yet associated with anything. Creating a new one in #{desired_driver.driver_url} ..."
|
88
101
|
end
|
89
102
|
end
|
90
103
|
|
91
104
|
else
|
92
105
|
|
93
106
|
#
|
94
|
-
# If
|
95
|
-
#
|
107
|
+
# If it does not support storing IDs in Chef at all, just grab the existing
|
108
|
+
# object and we'll update (or not) based on that.
|
96
109
|
#
|
97
|
-
|
98
|
-
Chef::Log.debug "#{new_resource.to_s} is not yet associated with anything. Associating with desired object #{desired_id} in #{desired_driver.driver_url}."
|
99
|
-
else
|
100
|
-
Chef::Log.debug "#{new_resource.to_s} is not yet associated with anything. Creating a new one in #{desired_driver.driver_url} ..."
|
101
|
-
end
|
102
|
-
end
|
110
|
+
aws_object ||= new_resource.aws_object
|
103
111
|
|
104
|
-
|
112
|
+
end
|
105
113
|
|
106
114
|
#
|
107
|
-
#
|
108
|
-
# object and we'll update (or not) based on that.
|
115
|
+
# Actually update or create the AWS object
|
109
116
|
#
|
110
|
-
|
111
|
-
|
112
|
-
|
117
|
+
if aws_object
|
118
|
+
action, new_obj = update_aws_object(aws_object)
|
119
|
+
aws_object = new_obj if action == :replaced_aws_object
|
120
|
+
else
|
121
|
+
aws_object = create_aws_object
|
122
|
+
end
|
113
123
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
if action == :replaced_aws_object
|
120
|
-
aws_object = new_obj
|
124
|
+
#
|
125
|
+
# Associate the managed entry with the AWS object
|
126
|
+
#
|
127
|
+
if new_resource.is_a?(AWSResourceWithEntry)
|
128
|
+
new_resource.save_managed_entry(aws_object, action_handler, existing_entry: entry)
|
121
129
|
end
|
122
|
-
else
|
123
|
-
aws_object = create_aws_object
|
124
|
-
end
|
125
130
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
if new_resource.is_a?(AWSResourceWithEntry)
|
130
|
-
new_resource.save_managed_entry(aws_object, action_handler, existing_entry: entry)
|
131
|
-
end
|
131
|
+
# This has to be after the managed entry save so the `aws_object` lookup
|
132
|
+
# from the resource succeeds
|
133
|
+
converge_tags if respond_to?(:converge_tags)
|
132
134
|
|
133
|
-
|
134
|
-
# from the resource succeeds
|
135
|
-
if respond_to?(:converge_tags)
|
136
|
-
converge_tags
|
135
|
+
aws_object
|
137
136
|
end
|
138
137
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
ensure
|
148
|
-
@purging = false
|
138
|
+
# TODO: having a @purging flag feels weird
|
139
|
+
action :purge do
|
140
|
+
@purging = true
|
141
|
+
begin
|
142
|
+
action_destroy
|
143
|
+
ensure
|
144
|
+
@purging = false
|
145
|
+
end
|
149
146
|
end
|
150
|
-
end
|
151
147
|
|
152
|
-
|
148
|
+
attr_reader :purging
|
153
149
|
|
154
|
-
|
155
|
-
|
156
|
-
|
150
|
+
action :destroy do
|
151
|
+
desired_driver = new_resource.driver
|
152
|
+
desired_id = new_resource.public_send(new_resource.class.aws_id_attribute) if new_resource.class.aws_id_attribute
|
157
153
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
154
|
+
#
|
155
|
+
# If the user specified an ID, delete THAT; do NOT delete the associated object.
|
156
|
+
#
|
157
|
+
if desired_id
|
158
|
+
aws_object = new_resource.class.get_aws_object(desired_id, resource: new_resource, required: false)
|
159
|
+
if aws_object
|
160
|
+
Chef::Log.debug "#{new_resource} provided #{new_resource.class.aws_id_attribute} #{desired_id} in #{desired_driver.driver_url}. Will delete."
|
161
|
+
end
|
165
162
|
end
|
166
|
-
end
|
167
163
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
164
|
+
#
|
165
|
+
# Managed entries are looked up by ID.
|
166
|
+
#
|
167
|
+
if new_resource.is_a?(AWSResourceWithEntry)
|
168
|
+
entry_driver, entry_id, entry = new_resource.get_id_from_managed_entry
|
169
|
+
if entry_id
|
170
|
+
if desired_id && (desired_id != entry_id || desired_driver.driver_url != entry_driver.driver_url)
|
171
|
+
if new_resource.class.get_aws_object(entry_id, driver: entry_driver, resource: new_resource, required: false)
|
172
|
+
# If the desired ID / driver differs from the entry, don't delete. We
|
173
|
+
# certainly can't delete the AWS object itself, and we don't *want* to
|
174
|
+
# delete the association, because the expectation is that after doing a
|
175
|
+
# delete, you should be able to create a new thing.
|
176
|
+
raise "#{new_resource} provided #{new_resource.class.aws_id_attribute} #{desired_id} in #{desired_driver.driver_url}, but is currently associated with #{entry_id} in #{entry_driver.driver_url}. Cannot delete the entry or the association until this inconsistency is resolved."
|
177
|
+
else
|
178
|
+
Chef::Log.debug "#{new_resource} provided #{new_resource.class.aws_id_attribute} #{desired_id} in #{desired_driver.driver_url}, but is currently associated with #{entry_id} in #{entry_driver.driver_url}, which does not exist. Will delete #{desired_id} and disassociate from #{entry_id}."
|
179
|
+
end
|
181
180
|
else
|
182
|
-
Chef::Log.debug "#{new_resource.to_s} provided #{new_resource.class.aws_id_attribute} #{desired_id} in #{desired_driver.driver_url}, but is currently associated with #{entry_id} in #{entry_driver.driver_url}, which does not exist. Will delete #{desired_id} and disassociate from #{entry_id}."
|
183
|
-
end
|
184
|
-
else
|
185
181
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
182
|
+
# Normal case: entry exists, and is the same as desired (or no desired)
|
183
|
+
aws_object = new_resource.class.get_aws_object(entry_id, driver: entry_driver, resource: new_resource, required: false)
|
184
|
+
if aws_object
|
185
|
+
Chef::Log.debug "#{new_resource} is associated with #{entry_id} in #{entry_driver.driver_url}. Will delete."
|
186
|
+
else
|
187
|
+
Chef::Log.debug "#{new_resource} is associated with #{entry_id} in #{entry_driver.driver_url}, but it does not exist. Will disassociate the entry but not delete."
|
188
|
+
end
|
192
189
|
end
|
193
190
|
end
|
191
|
+
|
192
|
+
#
|
193
|
+
# Non-managed entries all have their own way of looking it up
|
194
|
+
#
|
195
|
+
else
|
196
|
+
aws_object ||= new_resource.aws_object
|
194
197
|
end
|
195
198
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
aws_object ||= new_resource.aws_object
|
201
|
-
end
|
199
|
+
#
|
200
|
+
# Call the delete method
|
201
|
+
#
|
202
|
+
destroy_aws_object(aws_object) if aws_object
|
202
203
|
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
204
|
+
#
|
205
|
+
# Associate the managed entry with the AWS object
|
206
|
+
#
|
207
|
+
if new_resource.is_a?(AWSResourceWithEntry) && entry
|
208
|
+
new_resource.delete_managed_entry(action_handler)
|
209
|
+
end
|
208
210
|
end
|
209
211
|
|
210
|
-
|
211
|
-
# Associate the managed entry with the AWS object
|
212
|
-
#
|
213
|
-
if new_resource.is_a?(AWSResourceWithEntry) && entry
|
214
|
-
new_resource.delete_managed_entry(action_handler)
|
215
|
-
end
|
216
|
-
end
|
212
|
+
protected
|
217
213
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
raise NotImplementedError, :create_aws_object
|
222
|
-
end
|
214
|
+
def create_aws_object
|
215
|
+
raise NotImplementedError, :create_aws_object
|
216
|
+
end
|
223
217
|
|
224
|
-
|
225
|
-
|
226
|
-
|
218
|
+
def update_aws_object(_obj)
|
219
|
+
raise NotImplementedError, :update_aws_object
|
220
|
+
end
|
227
221
|
|
228
|
-
|
229
|
-
|
230
|
-
|
222
|
+
def destroy_aws_object(_obj)
|
223
|
+
raise NotImplementedError, :destroy_aws_object
|
224
|
+
end
|
231
225
|
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
226
|
+
def wait_for_status(aws_object, expected_status, acceptable_errors = [], tries = 60, sleep = 5)
|
227
|
+
wait_for(
|
228
|
+
aws_object: aws_object,
|
229
|
+
query_method: :status,
|
230
|
+
expected_responses: expected_status,
|
231
|
+
acceptable_errors: acceptable_errors,
|
232
|
+
tries: tries,
|
233
|
+
sleep: sleep
|
234
|
+
)
|
235
|
+
end
|
242
236
|
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
237
|
+
def wait_for_state(aws_object, expected_states, acceptable_errors = [], tries = 60, sleep = 5)
|
238
|
+
wait_for(
|
239
|
+
aws_object: aws_object,
|
240
|
+
query_method: :state,
|
241
|
+
expected_responses: expected_states,
|
242
|
+
acceptable_errors: acceptable_errors,
|
243
|
+
tries: tries,
|
244
|
+
sleep: sleep
|
245
|
+
)
|
246
|
+
end
|
253
247
|
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
248
|
+
# Wait until aws_object obtains one of expected_responses
|
249
|
+
#
|
250
|
+
# @param aws_object Aws SDK Object to check state on
|
251
|
+
# @param query_method Method to call on aws_object to get current state
|
252
|
+
# @param expected_responses [Symbol,Array<Symbol>] Final state(s) to look for
|
253
|
+
# @param acceptable_errors [Exception,Array<Exception>] Acceptable errors that are caught and squelched
|
254
|
+
# @param tries [Integer] Number of times to check state, defaults to 60
|
255
|
+
# @param sleep [Integer] Time to wait between checking states, defaults to 5
|
256
|
+
#
|
257
|
+
def wait_for(opts = {})
|
258
|
+
aws_object = opts[:aws_object]
|
259
|
+
query_method = opts[:query_method]
|
260
|
+
expected_responses = [opts[:expected_responses]].flatten
|
261
|
+
acceptable_errors = [opts[:acceptable_errors] || []].flatten
|
262
|
+
tries = opts[:tries] || 60
|
263
|
+
sleep = opts[:sleep] || 5
|
264
|
+
|
265
|
+
Retryable.retryable(tries: tries, sleep: sleep) do |retries, exception|
|
266
|
+
action_handler.report_progress "waited #{retries * sleep}/#{tries * sleep}s for <#{aws_object.class}:#{aws_object.id}>##{query_method} state to change to #{expected_responses.inspect}..."
|
267
|
+
Chef::Log.debug("Current exception in wait_for is #{exception.inspect}") if exception
|
268
|
+
begin
|
269
|
+
yield(aws_object) if block_given?
|
270
|
+
if aws_object.class.to_s.eql?("Aws::EC2::Vpc")
|
271
|
+
vpc = new_resource.driver.ec2.describe_vpcs(vpc_ids: [aws_object.vpc_id]).vpcs
|
272
|
+
current_response = "[:#{vpc[0].state}]"
|
273
|
+
elsif aws_object.class.to_s.eql?("Aws::EC2::NetworkInterface")
|
274
|
+
result = new_resource.driver.ec2_resource.network_interface(aws_object.id)
|
275
|
+
current_response = "[:#{result.status}]"
|
276
|
+
current_response = "[:in_use]" if current_response.eql?("[:in-use]")
|
277
|
+
elsif aws_object.class.to_s.eql?("Aws::EC2::NatGateway")
|
278
|
+
current_response = "[:#{aws_object.state}]"
|
279
|
+
end
|
280
|
+
Chef::Log.debug("Current response in wait_for from [#{query_method}] is #{current_response}")
|
281
|
+
unless expected_responses.to_s.include?(current_response)
|
282
|
+
raise StatusTimeoutError.new(aws_object, current_response, expected_responses)
|
283
|
+
end
|
284
|
+
rescue *acceptable_errors
|
289
285
|
end
|
290
|
-
rescue *acceptable_errors
|
291
286
|
end
|
292
287
|
end
|
293
|
-
end
|
294
288
|
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
289
|
+
# Retry a block with an doubling backoff time (maximum wait of 10 seconds).
|
290
|
+
# @param retry_on [Exception] An exception to retry on, defaults to RuntimeError
|
291
|
+
#
|
292
|
+
def self.retry_with_backoff(*retry_on)
|
293
|
+
retry_on ||= [RuntimeError]
|
294
|
+
Retryable.retryable(tries: 10, sleep: ->(n) { [2**n, 16].min }, on: retry_on) do |_retries, exception|
|
295
|
+
Chef::Log.debug("Current exception in retry_with_backoff is #{exception.inspect}")
|
296
|
+
yield
|
297
|
+
end
|
303
298
|
end
|
304
|
-
end
|
305
299
|
|
306
|
-
|
307
|
-
|
300
|
+
def retry_with_backoff(*retry_on, &block)
|
301
|
+
self.class.retry_with_backoff(*retry_on, &block)
|
302
|
+
end
|
308
303
|
end
|
309
|
-
|
310
|
-
end
|
311
304
|
end
|