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
@@ -15,9 +15,9 @@
15
15
  # limitations under the License.
16
16
  #
17
17
 
18
- require 'chef/provisioning/aws_driver/aws_resource'
19
- require 'chef/resource/aws_route53_record_set'
20
- require 'securerandom'
18
+ require "chef/provisioning/aws_driver/aws_resource"
19
+ require "chef/resource/aws_route53_record_set"
20
+ require "securerandom"
21
21
 
22
22
  # the AWS API doesn't have these objects linked, so give it some help.
23
23
  class Aws::Route53::Types::HostedZone
@@ -25,7 +25,6 @@ class Aws::Route53::Types::HostedZone
25
25
  end
26
26
 
27
27
  class Chef::Resource::AwsRoute53HostedZone < Chef::Provisioning::AWSDriver::AWSResourceWithEntry
28
-
29
28
  aws_sdk_type ::Aws::Route53::Types::HostedZone, load_provider: false
30
29
 
31
30
  resource_name :aws_route53_hosted_zone
@@ -33,7 +32,7 @@ class Chef::Resource::AwsRoute53HostedZone < Chef::Provisioning::AWSDriver::AWSR
33
32
  # name of the domain. AWS will tack on a trailing dot, so we're going to prohibit it here for consistency:
34
33
  # the name is our data bag key, and if a user has "foo.com" in one resource and "foo.com." in another, Route
35
34
  # 53 will happily accept two different domains it calls "foo.com.".
36
- attribute :name, kind_of: String, callbacks: { "domain name cannot end with a dot" => lambda { |n| n !~ /\.$/ } }
35
+ attribute :name, kind_of: String, callbacks: { "domain name cannot end with a dot" => ->(n) { n !~ /\.$/ } }
37
36
 
38
37
  # The comment included in the CreateHostedZoneRequest element. String <= 256 characters.
39
38
  attribute :comment, kind_of: String, default: ""
@@ -42,11 +41,12 @@ class Chef::Resource::AwsRoute53HostedZone < Chef::Provisioning::AWSDriver::AWSR
42
41
  attribute :aws_route53_zone_id, kind_of: String, aws_id_attribute: true,
43
42
  default: lazy { name =~ /^\/hostedzone\// ? name : nil }
44
43
 
45
- DEFAULTABLE_ATTRS = [:ttl, :type]
44
+ DEFAULTABLE_ATTRS = %i{ttl type}.freeze
46
45
 
47
46
  attribute :defaults, kind_of: Hash,
48
- callbacks: { "'defaults' keys may be any of #{DEFAULTABLE_ATTRS}" => lambda { |dh|
49
- (dh.keys - DEFAULTABLE_ATTRS).size == 0 } }
47
+ callbacks: { "'defaults' keys may be any of #{DEFAULTABLE_ATTRS}" => lambda { |dh|
48
+ (dh.keys - DEFAULTABLE_ATTRS).empty?
49
+ } }
50
50
 
51
51
  def record_sets(&block)
52
52
  if block_given?
@@ -58,31 +58,32 @@ class Chef::Resource::AwsRoute53HostedZone < Chef::Provisioning::AWSDriver::AWSR
58
58
 
59
59
  def aws_object
60
60
  driver, id = get_driver_and_id
61
- result = driver.route53_client.get_hosted_zone(id: id).hosted_zone if id rescue nil
61
+ begin
62
+ result = driver.route53_client.get_hosted_zone(id: id).hosted_zone if id
63
+ rescue StandardError
64
+ nil
65
+ end
62
66
  if result
63
67
  result.resource_record_sets = get_record_sets_from_aws(result.id).resource_record_sets
64
68
  result
65
- else
66
- nil
67
69
  end
68
70
  end
69
71
 
70
72
  # since this is used exactly once, it could plausibly be inlined in #aws_object.
71
- def get_record_sets_from_aws(hosted_zone_id, opts={})
73
+ def get_record_sets_from_aws(hosted_zone_id, opts = {})
72
74
  params = { hosted_zone_id: hosted_zone_id }.merge(opts)
73
75
  driver.route53_client.list_resource_record_sets(params)
74
76
  end
75
77
  end
76
78
 
77
79
  class Chef::Provider::AwsRoute53HostedZone < Chef::Provisioning::AWSDriver::AWSProvider
78
-
79
80
  provides :aws_route53_hosted_zone
80
81
  use_inline_resources
81
82
 
82
- CREATE = "CREATE"
83
- UPDATE = UPSERT = "UPSERT"
84
- DELETE = "DELETE"
85
- RRS_COMMENT = "Managed by chef-provisioning-aws"
83
+ CREATE = "CREATE".freeze
84
+ UPDATE = UPSERT = "UPSERT".freeze
85
+ DELETE = "DELETE".freeze
86
+ RRS_COMMENT = "Managed by chef-provisioning-aws".freeze
86
87
 
87
88
  attr_accessor :record_set_list
88
89
 
@@ -91,9 +92,7 @@ class Chef::Provider::AwsRoute53HostedZone < Chef::Provisioning::AWSDriver::AWSP
91
92
  # add :private_zone here once VPC validation is enabled.
92
93
  [:comment].each do |attr|
93
94
  value = new_resource.send(attr)
94
- if value
95
- config[attr] = value
96
- end
95
+ config[attr] = value if value
97
96
  end
98
97
  config
99
98
  end
@@ -107,14 +106,13 @@ class Chef::Provider::AwsRoute53HostedZone < Chef::Provisioning::AWSDriver::AWSP
107
106
 
108
107
  def create_aws_object
109
108
  converge_by "create new Route 53 zone #{new_resource}" do
110
-
111
109
  # AWS stores some attributes off to the side here.
112
110
  hosted_zone_config = make_hosted_zone_config(new_resource)
113
111
 
114
112
  values = {
115
113
  name: new_resource.name,
116
114
  hosted_zone_config: hosted_zone_config,
117
- caller_reference: "chef-provisioning-aws-#{SecureRandom.uuid.upcase}", # required, unique each call
115
+ caller_reference: "chef-provisioning-aws-#{SecureRandom.uuid.upcase}", # required, unique each call
118
116
  }
119
117
 
120
118
  # this will validate the record_set resources prior to making any AWS calls.
@@ -131,8 +129,8 @@ class Chef::Provider::AwsRoute53HostedZone < Chef::Provisioning::AWSDriver::AWSP
131
129
  new_resource.driver.route53_client.change_resource_record_sets(hosted_zone_id: new_resource.aws_route53_zone_id,
132
130
  change_batch: {
133
131
  comment: RRS_COMMENT,
134
- changes: change_list,
135
- })
132
+ changes: change_list
133
+ })
136
134
  end
137
135
  zone
138
136
  end
@@ -160,15 +158,15 @@ class Chef::Provider::AwsRoute53HostedZone < Chef::Provisioning::AWSDriver::AWSP
160
158
  # so it probably doesn't matter, but bears investigating.
161
159
 
162
160
  # we already checked for duplicate Chef RR resources in #get_record_sets_from_resource.
163
- keyed_chef_resources = record_set_resources.reduce({}) { |coll, rs| (coll[rs.aws_key] ||= []) << rs; coll }
164
- keyed_aws_objects = aws_record_sets.reduce({}) { |coll, rs| coll[rs.aws_key] = rs; coll }
161
+ keyed_chef_resources = record_set_resources.each_with_object({}) { |rs, coll| (coll[rs.aws_key] ||= []) << rs; }
162
+ keyed_aws_objects = aws_record_sets.each_with_object({}) { |rs, coll| coll[rs.aws_key] = rs; }
165
163
 
166
164
  # because DNS is important, we're going to err on the side of caution and only operate on records for
167
165
  # which we have a Chef resource. "total management" might be a nice resource option to have.
168
166
  keyed_chef_resources.each do |key, chef_resource_ary|
169
167
  chef_resource_ary.each do |chef_resource|
170
168
  # RR already exists...
171
- if keyed_aws_objects.has_key?(key)
169
+ if keyed_aws_objects.key?(key)
172
170
  # ... do we want to delete it?
173
171
  if chef_resource.action.first == :destroy
174
172
  change_list << chef_resource.to_aws_change_struct(DELETE)
@@ -185,12 +183,12 @@ class Chef::Provider::AwsRoute53HostedZone < Chef::Provisioning::AWSDriver::AWSP
185
183
  end
186
184
 
187
185
  Chef::Log.debug("RecordSet changes: #{change_list.inspect}")
188
- if change_list.size > 0
186
+ if !change_list.empty?
189
187
  new_resource.driver.route53_client.change_resource_record_sets(hosted_zone_id: new_resource.aws_route53_zone_id,
190
188
  change_batch: {
191
189
  comment: RRS_COMMENT,
192
- changes: change_list,
193
- })
190
+ changes: change_list
191
+ })
194
192
  else
195
193
  Chef::Log.info("All aws_route53_record_set resources up to date (nothing to do).")
196
194
  end
@@ -201,21 +199,21 @@ class Chef::Provider::AwsRoute53HostedZone < Chef::Provisioning::AWSDriver::AWSP
201
199
  converge_by "delete Route53 zone #{new_resource}" do
202
200
  Chef::Log.info("Deleting all non-SOA/NS records for #{hosted_zone.name}")
203
201
 
204
- rr_changes = hosted_zone.resource_record_sets.reject { |aws_rr|
205
- %w{SOA NS}.include?(aws_rr.type)
206
- }.map { |aws_rr|
207
- {
208
- action: DELETE,
209
- resource_record_set: aws_rr.to_change_struct,
210
- }
202
+ rr_changes = hosted_zone.resource_record_sets.reject do |aws_rr|
203
+ %w{SOA NS}.include?(aws_rr.type)
204
+ end.map do |aws_rr|
205
+ {
206
+ action: DELETE,
207
+ resource_record_set: aws_rr.to_change_struct
211
208
  }
209
+ end
212
210
 
213
- if rr_changes.size > 0
211
+ unless rr_changes.empty?
214
212
  aws_struct = {
215
213
  hosted_zone_id: hosted_zone.id,
216
214
  change_batch: {
217
215
  comment: "Purging RRs prior to deleting resource",
218
- changes: rr_changes,
216
+ changes: rr_changes
219
217
  }
220
218
  }
221
219
 
@@ -229,7 +227,6 @@ class Chef::Provider::AwsRoute53HostedZone < Chef::Provisioning::AWSDriver::AWSP
229
227
  # `record_sets` is defined on the `aws_route53_hosted_zone` resource as a block attribute, so compile that,
230
228
  # validate it, and return a list of AWSRoute53RecordSet resource objects.
231
229
  def get_record_sets_from_resource(new_resource)
232
-
233
230
  return nil unless new_resource.record_sets
234
231
  instance_eval(&new_resource.record_sets)
235
232
 
@@ -18,7 +18,7 @@
18
18
  class ::Aws::Route53::Types::ResourceRecordSet
19
19
  # removing AWS's trailing dots may not be the best thing, but otherwise our job gets much harder.
20
20
  def aws_key
21
- "#{name.sub(/\.$/, '')}"
21
+ name.sub(/\.$/, "").to_s
22
22
  end
23
23
 
24
24
  # the API doesn't seem to provide any facility to convert these types into the data structures used by the
@@ -28,13 +28,12 @@ class ::Aws::Route53::Types::ResourceRecordSet
28
28
  name: name,
29
29
  type: type,
30
30
  ttl: ttl,
31
- resource_records: resource_records.map {|r| {:value => r.value}},
31
+ resource_records: resource_records.map { |r| { value: r.value } }
32
32
  }
33
33
  end
34
34
  end
35
35
 
36
36
  class Chef::Resource::AwsRoute53RecordSet < Chef::Provisioning::AWSDriver::SuperLWRP
37
-
38
37
  actions :create, :destroy
39
38
  default_action :create
40
39
 
@@ -43,7 +42,7 @@ class Chef::Resource::AwsRoute53RecordSet < Chef::Provisioning::AWSDriver::Super
43
42
 
44
43
  attribute :rr_name, required: true
45
44
 
46
- attribute :type, equal_to: %w(SOA A TXT NS CNAME MX PTR SRV SPF AAAA), required: true
45
+ attribute :type, equal_to: %w{SOA A TXT NS CNAME MX PTR SRV SPF AAAA}, required: true
47
46
 
48
47
  attribute :ttl, kind_of: Integer, required: true
49
48
 
@@ -51,12 +50,12 @@ class Chef::Resource::AwsRoute53RecordSet < Chef::Provisioning::AWSDriver::Super
51
50
 
52
51
  # this gets set internally and is not intended for DSL use in recipes.
53
52
  attribute :aws_route53_zone_name, kind_of: String, required: true,
54
- is: lambda { |zone_name| validate_zone_name!(rr_name, zone_name) }
53
+ is: ->(zone_name) { validate_zone_name!(rr_name, zone_name) }
55
54
 
56
55
  attribute :aws_route53_hosted_zone, required: true
57
56
 
58
57
  def initialize(name, *args)
59
- self.rr_name(name) unless @rr_name
58
+ rr_name(name) unless @rr_name
60
59
  super(name, *args)
61
60
  end
62
61
 
@@ -65,31 +64,30 @@ class Chef::Resource::AwsRoute53RecordSet < Chef::Provisioning::AWSDriver::Super
65
64
  # we'll check for integers, but leave the user responsible for valid DNS names.
66
65
  when "A"
67
66
  rr_list.all? { |v| v =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/ } ||
68
- raise(::Chef::Exceptions::ValidationFailed,
69
- "A records are of the form '141.2.25.3'")
67
+ raise(::Chef::Exceptions::ValidationFailed,
68
+ "A records are of the form '141.2.25.3'")
70
69
  when "MX"
71
- rr_list.all? { |v| v =~ /^\d+\s+[^ ]+/} ||
72
- raise(::Chef::Exceptions::ValidationFailed,
73
- "MX records must have a priority and mail server, of the form '15 mail.example.com.'")
70
+ rr_list.all? { |v| v =~ /^\d+\s+[^ ]+/ } ||
71
+ raise(::Chef::Exceptions::ValidationFailed,
72
+ "MX records must have a priority and mail server, of the form '15 mail.example.com.'")
74
73
  when "SRV"
75
74
  rr_list.all? { |v| v =~ /^\d+\s+\d+\s+\d+\s+[^ ]+$/ } ||
76
- raise(::Chef::Exceptions::ValidationFailed,
77
- "SRV records must have a priority, weight, port, and hostname, of the form '15 10 25 service.example.com.'")
75
+ raise(::Chef::Exceptions::ValidationFailed,
76
+ "SRV records must have a priority, weight, port, and hostname, of the form '15 10 25 service.example.com.'")
78
77
  when "CNAME"
79
78
  rr_list.size == 1 ||
80
- raise(::Chef::Exceptions::ValidationFailed,
81
- "CNAME records may only have a single value (a hostname).")
82
-
79
+ raise(::Chef::Exceptions::ValidationFailed,
80
+ "CNAME records may only have a single value (a hostname).")
83
81
 
84
82
  when "SOA", "NS", "TXT", "PTR", "AAAA", "SPF"
85
83
  true
86
84
  else
87
- raise ArgumentError, "Argument '#{type}' must be one of #{%w(SOA NS A MX SRV CNAME TXT PTR AAAA SPF)}"
85
+ raise ArgumentError, "Argument '#{type}' must be one of %w(SOA NS A MX SRV CNAME TXT PTR AAAA SPF)"
88
86
  end
89
87
  end
90
88
 
91
89
  def validate_zone_name!(rr_name, zone_name)
92
- if rr_name.end_with?('.') && rr_name !~ /#{zone_name}\.$/
90
+ if rr_name.end_with?(".") && rr_name !~ /#{zone_name}\.$/
93
91
  raise(::Chef::Exceptions::ValidationFailed, "RecordSet name #{rr_name} does not match parent HostedZone name #{zone_name}.")
94
92
  end
95
93
  true
@@ -97,14 +95,14 @@ class Chef::Resource::AwsRoute53RecordSet < Chef::Provisioning::AWSDriver::Super
97
95
 
98
96
  # because these resources can't actually converge themselves, we have to trigger the validations.
99
97
  def validate!
100
- [:rr_name, :type, :ttl, :resource_records, :aws_route53_zone_name].each { |f| self.send(f) }
98
+ %i{rr_name type ttl resource_records aws_route53_zone_name}.each { |f| send(f) }
101
99
 
102
100
  # this was in an :is validator, but didn't play well with inheriting default values.
103
101
  validate_rr_type!(type, resource_records)
104
102
  end
105
103
 
106
104
  def aws_key
107
- "#{fqdn}"
105
+ fqdn.to_s
108
106
  end
109
107
 
110
108
  def fqdn
@@ -120,7 +118,7 @@ class Chef::Resource::AwsRoute53RecordSet < Chef::Provisioning::AWSDriver::Super
120
118
  name: fqdn,
121
119
  type: type,
122
120
  ttl: ttl,
123
- resource_records: resource_records.map { |rr| { value: rr } },
121
+ resource_records: resource_records.map { |rr| { value: rr } }
124
122
  }
125
123
  end
126
124
 
@@ -129,7 +127,7 @@ class Chef::Resource::AwsRoute53RecordSet < Chef::Provisioning::AWSDriver::Super
129
127
  # http://redirx.me/?t3zo
130
128
  {
131
129
  action: aws_action,
132
- resource_record_set: self.to_aws_struct
130
+ resource_record_set: to_aws_struct
133
131
  }
134
132
  end
135
133
 
@@ -138,8 +136,8 @@ class Chef::Resource::AwsRoute53RecordSet < Chef::Provisioning::AWSDriver::Super
138
136
 
139
137
  record_sets.each do |rs|
140
138
  key = rs.aws_key
141
- if seen.has_key?(key)
142
- raise Chef::Exceptions::ValidationFailed.new("Duplicate RecordSet found in resource: [#{key}]")
139
+ if seen.key?(key)
140
+ raise Chef::Exceptions::ValidationFailed, "Duplicate RecordSet found in resource: [#{key}]"
143
141
  else
144
142
  seen[key] = 1
145
143
  end
@@ -1,4 +1,4 @@
1
- require 'chef/provisioning/aws_driver/aws_resource_with_entry'
1
+ require "chef/provisioning/aws_driver/aws_resource_with_entry"
2
2
 
3
3
  #
4
4
  # An AWS route table, specifying where to route traffic destined for particular
@@ -16,7 +16,7 @@ class Chef::Resource::AwsRouteTable < Chef::Provisioning::AWSDriver::AWSResource
16
16
  include Chef::Provisioning::AWSDriver::AWSTaggable
17
17
  aws_sdk_type ::Aws::EC2::RouteTable
18
18
 
19
- require 'chef/resource/aws_vpc'
19
+ require "chef/resource/aws_vpc"
20
20
 
21
21
  #
22
22
  # The name of this route table.
@@ -33,7 +33,7 @@ class Chef::Resource::AwsRouteTable < Chef::Provisioning::AWSDriver::AWSResource
33
33
  #
34
34
  # This is required for new route tables.
35
35
  #
36
- attribute :vpc, kind_of: [ String, AwsVpc, ::Aws::EC2::Vpc ], required: true
36
+ attribute :vpc, kind_of: [String, AwsVpc, ::Aws::EC2::Vpc], required: true
37
37
 
38
38
  #
39
39
  # Enable route propagation from one or more virtual private gateways
@@ -43,8 +43,8 @@ class Chef::Resource::AwsRouteTable < Chef::Provisioning::AWSDriver::AWSResource
43
43
  # virtual_private_gateways ['vgw-abcd1234', 'vgw-abcd5678']
44
44
  # ```
45
45
  #
46
- attribute :virtual_private_gateways, kind_of: [ String, Array ],
47
- coerce: proc { |v| [v].flatten }
46
+ attribute :virtual_private_gateways, kind_of: [String, Array],
47
+ coerce: proc { |v| [v].flatten }
48
48
 
49
49
  #
50
50
  # The routes for this route table.
@@ -89,8 +89,8 @@ class Chef::Resource::AwsRouteTable < Chef::Provisioning::AWSDriver::AWSResource
89
89
  # ```ruby
90
90
  # ignore_route_targets ['^eni-']
91
91
  # ```
92
- attribute :ignore_route_targets, kind_of: [ String, Array ], default: [],
93
- coerce: proc { |v| [v].flatten }
92
+ attribute :ignore_route_targets, kind_of: [String, Array], default: [],
93
+ coerce: proc { |v| [v].flatten }
94
94
 
95
95
  attribute :route_table_id, kind_of: String, aws_id_attribute: true, default: lazy {
96
96
  name =~ /^rtb-[a-f0-9]+$/ ? name : nil
@@ -1,19 +1,19 @@
1
- require 'chef/provisioning/aws_driver/aws_resource'
1
+ require "chef/provisioning/aws_driver/aws_resource"
2
2
 
3
3
  class Chef::Resource::AwsS3Bucket < Chef::Provisioning::AWSDriver::AWSResource
4
4
  include Chef::Provisioning::AWSDriver::AWSTaggable
5
5
 
6
6
  aws_sdk_type ::Aws::S3::Bucket, id: :name
7
7
 
8
- attribute :name, :kind_of => String, :name_attribute => true
9
- attribute :options, :kind_of => Hash, :default => {}
10
- attribute :enable_website_hosting, :kind_of => [TrueClass, FalseClass], :default => false
11
- attribute :website_options, :kind_of => Hash, :default => {}
12
- attribute :recursive_delete, :kind_of => [TrueClass, FalseClass], :default => false
8
+ attribute :name, kind_of: String, name_attribute: true
9
+ attribute :options, kind_of: Hash, default: {}
10
+ attribute :enable_website_hosting, kind_of: [TrueClass, FalseClass], default: false
11
+ attribute :website_options, kind_of: Hash, default: {}
12
+ attribute :recursive_delete, kind_of: [TrueClass, FalseClass], default: false
13
13
 
14
14
  def aws_object
15
15
  resource = ::Aws::S3::Resource.new(driver.s3_client)
16
- result = resource.buckets.find{|b| b.name==name}
16
+ result = resource.buckets.find { |b| b.name == name }
17
17
  result && result.exists? ? result : nil
18
18
  end
19
19
  end
@@ -1,16 +1,16 @@
1
- require 'chef/provisioning/aws_driver/aws_resource'
2
- require 'chef/resource/aws_vpc'
3
- require 'chef/provisioning/aws_driver/exceptions'
1
+ require "chef/provisioning/aws_driver/aws_resource"
2
+ require "chef/resource/aws_vpc"
3
+ require "chef/provisioning/aws_driver/exceptions"
4
4
 
5
5
  class Chef::Resource::AwsSecurityGroup < Chef::Provisioning::AWSDriver::AWSResource
6
6
  include Chef::Provisioning::AWSDriver::AWSTaggable
7
7
 
8
8
  aws_sdk_type ::Aws::EC2::SecurityGroup,
9
9
  id: :id,
10
- option_names: [:security_group, :security_group_id, :security_group_name]
10
+ option_names: %i{security_group security_group_id security_group_name}
11
11
 
12
12
  attribute :name, kind_of: String, name_attribute: true
13
- attribute :vpc, kind_of: [ String, AwsVpc, ::Aws::EC2::Vpc ]
13
+ attribute :vpc, kind_of: [String, AwsVpc, ::Aws::EC2::Vpc]
14
14
  attribute :description, kind_of: String
15
15
 
16
16
  #
@@ -46,8 +46,8 @@ class Chef::Resource::AwsSecurityGroup < Chef::Provisioning::AWSDriver::AWSResou
46
46
  # - `inbound_rules load_balancer('myloadbalancer') => 80`
47
47
  # - `inbound_rules AWS.ec2.security_groups.first => 80`
48
48
  #
49
- attribute :inbound_rules, kind_of: [ Array, Hash ]
50
- attribute :outbound_rules, kind_of: [ Array, Hash ]
49
+ attribute :inbound_rules, kind_of: [Array, Hash]
50
+ attribute :outbound_rules, kind_of: [Array, Hash]
51
51
 
52
52
  attribute :security_group_id, kind_of: String, aws_id_attribute: true, default: lazy {
53
53
  name =~ /^sg-[a-f0-9]+$/ ? name : nil
@@ -61,15 +61,15 @@ class Chef::Resource::AwsSecurityGroup < Chef::Provisioning::AWSDriver::AWSResou
61
61
  # provided
62
62
  if vpc
63
63
  vpc_object = Chef::Resource::AwsVpc.get_aws_object(vpc, resource: self)
64
- results=vpc_object.security_groups.to_a.select { |s| s.group_name == name or s.id == name }
64
+ results = vpc_object.security_groups.to_a.select { |s| (s.group_name == name) || (s.id == name) }
65
65
  else
66
- results=driver.ec2_resource.security_groups.to_a.select { |s| s.group_name == name or s.id == name }
66
+ results = driver.ec2_resource.security_groups.to_a.select { |s| (s.group_name == name) || (s.id == name) }
67
67
  end
68
68
  if results.size >= 2
69
69
  raise ::Chef::Provisioning::AWSDriver::Exceptions::MultipleSecurityGroupError.new(name, results)
70
70
  end
71
71
  result = results.first
72
72
  end
73
- result ? result : nil
73
+ result || nil
74
74
  end
75
75
  end