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