chef-provisioning-aws 2.2.2 → 3.0.0.pre.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/chef-provisioning-aws.gemspec +0 -1
  4. data/lib/chef/provider/aws_auto_scaling_group.rb +9 -6
  5. data/lib/chef/provider/aws_dhcp_options.rb +21 -11
  6. data/lib/chef/provider/aws_ebs_volume.rb +26 -24
  7. data/lib/chef/provider/aws_eip_address.rb +11 -12
  8. data/lib/chef/provider/aws_image.rb +1 -1
  9. data/lib/chef/provider/aws_internet_gateway.rb +18 -10
  10. data/lib/chef/provider/aws_key_pair.rb +6 -6
  11. data/lib/chef/provider/aws_launch_configuration.rb +7 -9
  12. data/lib/chef/provider/aws_nat_gateway.rb +2 -2
  13. data/lib/chef/provider/aws_network_acl.rb +11 -8
  14. data/lib/chef/provider/aws_network_interface.rb +34 -29
  15. data/lib/chef/provider/aws_rds_parameter_group.rb +1 -1
  16. data/lib/chef/provider/aws_rds_subnet_group.rb +1 -1
  17. data/lib/chef/provider/aws_route_table.rb +7 -7
  18. data/lib/chef/provider/aws_s3_bucket.rb +24 -12
  19. data/lib/chef/provider/aws_security_group.rb +202 -25
  20. data/lib/chef/provider/aws_server_certificate.rb +3 -4
  21. data/lib/chef/provider/aws_sns_topic.rb +4 -3
  22. data/lib/chef/provider/aws_sqs_queue.rb +7 -3
  23. data/lib/chef/provider/aws_subnet.rb +45 -21
  24. data/lib/chef/provider/aws_vpc.rb +59 -30
  25. data/lib/chef/provisioning/aws_driver/aws_provider.rb +12 -3
  26. data/lib/chef/provisioning/aws_driver/aws_resource.rb +2 -2
  27. data/lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb +1 -1
  28. data/lib/chef/provisioning/aws_driver/aws_tagger.rb +2 -2
  29. data/lib/chef/provisioning/aws_driver/credentials.rb +1 -1
  30. data/lib/chef/provisioning/aws_driver/credentials2.rb +5 -1
  31. data/lib/chef/provisioning/aws_driver/driver.rb +124 -34
  32. data/lib/chef/provisioning/aws_driver/tagging_strategy/rds.rb +4 -4
  33. data/lib/chef/provisioning/aws_driver/tagging_strategy/s3.rb +1 -1
  34. data/lib/chef/provisioning/aws_driver/version.rb +1 -1
  35. data/lib/chef/resource/aws_auto_scaling_group.rb +2 -2
  36. data/lib/chef/resource/aws_cache_cluster.rb +4 -4
  37. data/lib/chef/resource/aws_cache_replication_group.rb +3 -3
  38. data/lib/chef/resource/aws_cache_subnet_group.rb +4 -4
  39. data/lib/chef/resource/aws_cloudsearch_domain.rb +1 -1
  40. data/lib/chef/resource/aws_cloudwatch_alarm.rb +1 -1
  41. data/lib/chef/resource/aws_dhcp_options.rb +10 -3
  42. data/lib/chef/resource/aws_ebs_volume.rb +10 -4
  43. data/lib/chef/resource/aws_eip_address.rb +4 -4
  44. data/lib/chef/resource/aws_elasticsearch_domain.rb +1 -1
  45. data/lib/chef/resource/aws_iam_role.rb +1 -1
  46. data/lib/chef/resource/aws_internet_gateway.rb +11 -4
  47. data/lib/chef/resource/aws_key_pair.rb +4 -3
  48. data/lib/chef/resource/aws_launch_configuration.rb +5 -4
  49. data/lib/chef/resource/aws_load_balancer.rb +14 -3
  50. data/lib/chef/resource/aws_nat_gateway.rb +2 -2
  51. data/lib/chef/resource/aws_network_acl.rb +10 -10
  52. data/lib/chef/resource/aws_network_interface.rb +12 -6
  53. data/lib/chef/resource/aws_rds_parameter_group.rb +6 -6
  54. data/lib/chef/resource/aws_rds_subnet_group.rb +4 -5
  55. data/lib/chef/resource/aws_route53_record_set.rb +1 -1
  56. data/lib/chef/resource/aws_route_table.rb +1 -1
  57. data/lib/chef/resource/aws_s3_bucket.rb +3 -2
  58. data/lib/chef/resource/aws_security_group.rb +6 -6
  59. data/lib/chef/resource/aws_server_certificate.rb +4 -5
  60. data/lib/chef/resource/aws_sns_topic.rb +4 -4
  61. data/lib/chef/resource/aws_sqs_queue.rb +3 -3
  62. data/lib/chef/resource/aws_subnet.rb +5 -5
  63. data/lib/chef/resource/aws_vpc.rb +12 -6
  64. data/lib/chef/resource/aws_vpc_peering_connection.rb +2 -2
  65. data/spec/aws_support.rb +12 -9
  66. data/spec/aws_support/deep_matcher/match_values_failure_messages.rb +15 -5
  67. data/spec/integration/aws_dhcp_options_spec.rb +7 -7
  68. data/spec/integration/aws_ebs_volume_spec.rb +1 -1
  69. data/spec/integration/aws_internet_gateway_spec.rb +19 -18
  70. data/spec/integration/aws_key_pair_spec.rb +1 -1
  71. data/spec/integration/aws_nat_gateway_spec.rb +3 -6
  72. data/spec/integration/aws_network_acl_spec.rb +19 -11
  73. data/spec/integration/aws_network_interface_spec.rb +26 -20
  74. data/spec/integration/aws_rds_instance_spec.rb +6 -7
  75. data/spec/integration/aws_rds_subnet_group_spec.rb +6 -6
  76. data/spec/integration/aws_route53_hosted_zone_spec.rb +1 -1
  77. data/spec/integration/aws_s3_bucket_spec.rb +1 -2
  78. data/spec/integration/aws_security_group_spec.rb +272 -198
  79. data/spec/integration/aws_server_certificate_spec.rb +60 -78
  80. data/spec/integration/aws_subnet_spec.rb +8 -4
  81. data/spec/integration/aws_vpc_spec.rb +29 -23
  82. data/spec/integration/machine_spec.rb +1 -1
  83. data/spec/unit/chef/provisioning/aws_driver/credentials_spec.rb +13 -0
  84. data/spec/unit/chef/provisioning/aws_driver/driver_spec.rb +1 -1
  85. data/spec/unit/chef/provisioning/aws_driver/route53_spec.rb +1 -1
  86. metadata +5 -20
  87. data/spec/persistence_file.txt +0 -220
@@ -10,12 +10,11 @@ class Chef::Provider::AwsServerCertificate < Chef::Provisioning::AWSDriver::AWSP
10
10
  def create_aws_object
11
11
  converge_by "create server certificate #{new_resource.name}" do
12
12
  opts = {
13
- :name => new_resource.name,
13
+ :server_certificate_name => new_resource.name,
14
14
  :certificate_body => new_resource.certificate_body,
15
- :private_key => new_resource.private_key
16
- }
15
+ :private_key => new_resource.private_key }
17
16
  opts[:certificate_chain] = new_resource.certificate_chain if new_resource.certificate_chain
18
- new_resource.driver.iam.server_certificates.upload(**opts)
17
+ new_resource.driver.iam.upload_server_certificate(**opts)
19
18
  end
20
19
  end
21
20
 
@@ -8,7 +8,7 @@ class Chef::Provider::AwsSnsTopic < Chef::Provisioning::AWSDriver::AWSProvider
8
8
 
9
9
  def create_aws_object
10
10
  converge_by "create SNS topic #{new_resource.name} in #{region}" do
11
- new_resource.driver.sns.topics.create(new_resource.name)
11
+ new_resource.driver.sns.create_topic(name: new_resource.name)
12
12
  end
13
13
  end
14
14
 
@@ -16,8 +16,9 @@ class Chef::Provider::AwsSnsTopic < Chef::Provisioning::AWSDriver::AWSProvider
16
16
  end
17
17
 
18
18
  def destroy_aws_object(topic)
19
- converge_by "delete SNS topic #{topic.name} in #{region}" do
20
- topic.delete
19
+ topic_arn_name = topic.attributes.values_at("TopicArn").first
20
+ converge_by "delete SNS topic_arn #{topic_arn_name} in #{region}" do
21
+ new_resource.driver.sns.delete_topic(topic_arn: topic_arn_name)
21
22
  end
22
23
  end
23
24
 
@@ -4,9 +4,13 @@ class Chef::Provider::AwsSqsQueue < Chef::Provisioning::AWSDriver::AWSProvider
4
4
  provides :aws_sqs_queue
5
5
 
6
6
  def create_aws_object
7
+ options = AWSResource.lookup_options(new_resource.options || {}, resource: new_resource)
8
+ option_sqs = {}
9
+ option_sqs[:queue_name] = new_resource.name if new_resource.name
10
+ option_sqs[:attributes] = options
7
11
  converge_by "create SQS queue #{new_resource.name} in #{region}" do
8
- retry_with_backoff(AWS::SQS::Errors::QueueDeletedRecently) do
9
- new_resource.driver.sqs.queues.create(new_resource.name, new_resource.options || {})
12
+ retry_with_backoff(::Aws::SQS::Errors::QueueDeletedRecently) do
13
+ new_resource.driver.sqs.create_queue(option_sqs)
10
14
  end
11
15
  end
12
16
  end
@@ -16,7 +20,7 @@ class Chef::Provider::AwsSqsQueue < Chef::Provisioning::AWSDriver::AWSProvider
16
20
 
17
21
  def destroy_aws_object(queue)
18
22
  converge_by "delete SQS queue #{new_resource.name} in #{region}" do
19
- queue.delete
23
+ new_resource.driver.sqs.delete_queue(queue_url: queue.queue_url)
20
24
  end
21
25
  end
22
26
  end
@@ -29,15 +29,15 @@ class Chef::Provider::AwsSubnet < Chef::Provisioning::AWSDriver::AWSProvider
29
29
  if !cidr_block
30
30
  cidr_block = Chef::Resource::AwsVpc.get_aws_object(new_resource.vpc, resource: new_resource).cidr_block
31
31
  end
32
- options = { :vpc => new_resource.vpc }
32
+ options = { vpc_id: new_resource.vpc, cidr_block: cidr_block }
33
33
  options[:availability_zone] = new_resource.availability_zone if new_resource.availability_zone
34
34
  options = Chef::Provisioning::AWSDriver::AWSResource.lookup_options(options, resource: new_resource)
35
35
 
36
- converge_by "create subnet #{new_resource.name} with CIDR #{cidr_block} in VPC #{new_resource.vpc} (#{options[:vpc]}) in #{region}" do
37
- subnet = new_resource.driver.ec2.subnets.create(cidr_block, options)
38
- retry_with_backoff(AWS::EC2::Errors::InvalidSubnetID::NotFound) do
39
- subnet.tags['Name'] = new_resource.name
40
- subnet.tags['VPC'] = new_resource.vpc
36
+ converge_by "create subnet #{new_resource.name} with CIDR #{cidr_block} in VPC #{new_resource.vpc} (#{options[:vpc_id]}) in #{region}" do
37
+ subnet = new_resource.driver.ec2_resource.create_subnet(options)
38
+ retry_with_backoff(::Aws::EC2::Errors::InvalidSubnetIDNotFound) do
39
+ new_resource.driver.ec2_resource.create_tags(resources: [subnet.id],tags: [{key: "Name", value: new_resource.name}])
40
+ new_resource.driver.ec2_resource.create_tags(resources: [subnet.id],tags: [{key: "VPC", value: new_resource.vpc}])
41
41
  end
42
42
  subnet
43
43
  end
@@ -49,10 +49,10 @@ class Chef::Provider::AwsSubnet < Chef::Provisioning::AWSDriver::AWSProvider
49
49
  raise "cidr_block for subnet #{new_resource.name} is #{new_resource.cidr_block}, but existing subnet (#{subnet.id})'s cidr_block is #{subnet.cidr_block}. Modification of subnet cidr_block is unsupported!"
50
50
  end
51
51
  vpc = Chef::Resource::AwsVpc.get_aws_object(new_resource.vpc, resource: new_resource)
52
- if vpc && subnet.vpc != vpc
52
+ if vpc && subnet.vpc.id != vpc.id
53
53
  raise "VPC for subnet #{new_resource.name} is #{new_resource.vpc} (#{vpc.id}), but existing subnet (#{subnet.id})'s vpc is #{subnet.vpc.id}. Modification of subnet VPC is unsupported!"
54
54
  end
55
- if new_resource.availability_zone && subnet.availability_zone_name != new_resource.availability_zone
55
+ if new_resource.availability_zone && subnet.availability_zone != new_resource.availability_zone
56
56
  raise "availability_zone for subnet #{new_resource.name} is #{new_resource.availability_zone}, but existing subnet (#{subnet.id})'s availability_zone is #{subnet.availability_zone}. Modification of subnet availability_zone is unsupported!"
57
57
  end
58
58
  end
@@ -76,7 +76,7 @@ class Chef::Provider::AwsSubnet < Chef::Provisioning::AWSDriver::AWSProvider
76
76
  # It is common during subnet purging for the instance to be terminated but
77
77
  # temporarily hanging around - this causes a `The network interface at device index 0 cannot be detached`
78
78
  # error to be raised when trying to detach
79
- retry_with_backoff(AWS::EC2::Errors::OperationNotPermitted) do
79
+ retry_with_backoff(::Aws::EC2::Errors::OperationNotPermitted) do
80
80
  Cheffish.inline_resource(self, action) do
81
81
  aws_network_interface network do
82
82
  action :purge
@@ -91,7 +91,7 @@ class Chef::Provider::AwsSubnet < Chef::Provisioning::AWSDriver::AWSProvider
91
91
  # If the subnet doesn't exist we can't check state on it - state can only be :pending or :available
92
92
  begin
93
93
  subnet.delete
94
- rescue AWS::EC2::Errors::InvalidSubnetID::NotFound
94
+ rescue ::Aws::EC2::Errors::InvalidSubnetIDNotFound
95
95
  end
96
96
  end
97
97
  end
@@ -100,7 +100,7 @@ class Chef::Provider::AwsSubnet < Chef::Provisioning::AWSDriver::AWSProvider
100
100
 
101
101
  def update_map_public_ip_on_launch(subnet)
102
102
  if !new_resource.map_public_ip_on_launch.nil?
103
- subnet_desc = subnet.client.describe_subnets(subnet_ids: [ subnet.id ])[:subnet_set].first
103
+ subnet_desc = subnet.client.describe_subnets(subnet_ids: [ subnet.id ])[:subnets].first
104
104
  if new_resource.map_public_ip_on_launch
105
105
  if !subnet_desc[:map_public_ip_on_launch]
106
106
  converge_by "turn on automatic public IPs for subnet #{subnet.id}" do
@@ -118,26 +118,46 @@ class Chef::Provider::AwsSubnet < Chef::Provisioning::AWSDriver::AWSProvider
118
118
  end
119
119
 
120
120
  def update_route_table(subnet)
121
+ current_route_table_association = subnet.client.describe_route_tables(filters: [{name: "vpc-id", values: [subnet.vpc.id]}]).route_tables
122
+ route_table_entry = nil
123
+ do_break = false
124
+ # Below snippet gives the entry of route_table who is associated with current subnet either by matching its
125
+ # subnet_id or with a default subnet (i.e by checking association.main == true & in that case
126
+ # association.subnet_id is nil)
127
+ current_route_table_association.each do |route_tbl|
128
+ if !route_tbl.associations.empty?
129
+ route_tbl.associations.each do |r|
130
+ if r.subnet_id == subnet.id
131
+ route_table_entry = r
132
+ do_break = true
133
+ break
134
+ elsif r.subnet_id.nil? && r.main == true
135
+ route_table_entry = r
136
+ end
137
+ end
138
+ break if do_break
139
+ end
140
+ end
121
141
  if new_resource.route_table == :default_to_main
122
- if !subnet.route_table_association.main?
142
+ if !route_table_entry.main
123
143
  converge_by "reset route table of subnet #{new_resource.name} to the VPC default" do
124
- subnet.route_table = nil
144
+ subnet.client.disassociate_route_table(association_id: route_table_entry.route_table_association_id)
125
145
  end
126
146
  end
127
147
  else
128
148
  route_table = Chef::Resource::AwsRouteTable.get_aws_object(new_resource.route_table, resource: new_resource)
129
- current_route_table_association = subnet.route_table_association
130
- if current_route_table_association.main?
149
+ if route_table_entry.main && route_table_entry.subnet_id.nil?
131
150
  # Even if the user sets the route table explicitly to the main route table,
132
151
  # we have work to do here: we need to make the relationship explicit so that
133
152
  # it won't be changed when the main route table of the VPC changes.
134
153
  converge_by "set route table of subnet #{new_resource.name} to #{new_resource.route_table}" do
135
- subnet.route_table = route_table.id
154
+ subnet.client.associate_route_table(route_table_id: route_table.id, subnet_id: subnet.id)
136
155
  end
137
- elsif current_route_table_association.route_table.id != route_table.id
156
+ elsif route_table_entry.route_table_id != route_table.id
138
157
  # The route table is different now. Change it.
139
- converge_by "change route table of subnet #{new_resource.name} to #{new_resource.route_table} (was #{current_route_table_association.route_table.id})" do
140
- subnet.route_table = route_table.id
158
+ converge_by "change route table of subnet #{new_resource.name} to #{new_resource.route_table} (was #{route_table_entry.route_table_id})" do
159
+ subnet.client.disassociate_route_table(association_id: route_table_entry.route_table_association_id) if route_table_entry.main == false
160
+ subnet.client.associate_route_table(route_table_id: route_table.id, subnet_id: subnet.id)
141
161
  end
142
162
  end
143
163
  end
@@ -147,9 +167,13 @@ class Chef::Provider::AwsSubnet < Chef::Provisioning::AWSDriver::AWSProvider
147
167
  if new_resource.network_acl
148
168
  network_acl_id =
149
169
  AWSResource.lookup_options({ network_acl: new_resource.network_acl }, resource: new_resource)[:network_acl]
150
- if subnet.network_acl.id != network_acl_id
170
+ # Below snippet gives the entry of network_acl who is associated with current subnet by matching its subnet_id
171
+ network_acl_association = subnet.client.describe_network_acls(filters: [{name: "vpc-id", values: [subnet.vpc.id]}, {name: "association.subnet-id", values: [subnet.id]}]).network_acls.first.associations
172
+ current_network_acl_association = network_acl_association.find { |r| r.subnet_id == subnet.id } unless network_acl_association.empty?
173
+
174
+ if current_network_acl_association.network_acl_id != network_acl_id && !current_network_acl_association.nil?
151
175
  converge_by "update network ACL of subnet #{new_resource.name} to #{new_resource.network_acl}" do
152
- subnet.network_acl = network_acl_id
176
+ subnet.client.replace_network_acl_association(association_id: current_network_acl_association.network_acl_association_id, network_acl_id: network_acl_id)
153
177
  end
154
178
  end
155
179
  end
@@ -42,21 +42,23 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
42
42
  protected
43
43
 
44
44
  def create_aws_object
45
- options = { }
45
+ options = {}
46
46
  options[:instance_tenancy] = new_resource.instance_tenancy if new_resource.instance_tenancy
47
+ options[:cidr_block] = new_resource.cidr_block
47
48
 
48
49
  converge_by "create VPC #{new_resource.name} in #{region}" do
49
- vpc = new_resource.driver.ec2.vpcs.create(new_resource.cidr_block, options)
50
+ ec2_resource = ::Aws::EC2::Resource.new(new_resource.driver.ec2)
51
+ vpc = ec2_resource.create_vpc({ cidr_block: new_resource.cidr_block, instance_tenancy: options[:instance_tenancy] })
50
52
  wait_for_state(vpc, [:available])
51
- retry_with_backoff(AWS::EC2::Errors::InvalidVpcID::NotFound) do
52
- vpc.tags['Name'] = new_resource.name
53
+ retry_with_backoff(::Aws::EC2::Errors::InvalidVpcIDNotFound) do
54
+ ec2_resource.create_tags(resources: [vpc.vpc_id], tags: [{ key: "Name", value: new_resource.name }])
53
55
  end
54
56
  vpc
55
57
  end
56
58
  end
57
59
 
58
60
  def update_aws_object(vpc)
59
- if new_resource.instance_tenancy && new_resource.instance_tenancy != vpc.instance_tenancy
61
+ if new_resource.instance_tenancy && new_resource.instance_tenancy.to_s != vpc.instance_tenancy
60
62
  raise "Tenancy of VPC #{new_resource.name} is #{vpc.instance_tenancy}, but desired tenancy is #{new_resource.instance_tenancy}. Instance tenancy of VPCs cannot be changed!"
61
63
  end
62
64
  if new_resource.cidr_block && new_resource.cidr_block != vpc.cidr_block
@@ -71,8 +73,8 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
71
73
  #SDK V2
72
74
  nat_gateways = new_resource.driver.ec2_client.describe_nat_gateways({
73
75
  :filter => [
74
- { name: 'vpc-id', values: [vpc.id] },
75
- { name: 'state', values: ['available', 'pending'] }
76
+ { name: "vpc-id", values: [vpc.id] },
77
+ { name: "state", values: ["available", "pending"] },
76
78
  ]
77
79
  }).nat_gateways
78
80
 
@@ -100,7 +102,7 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
100
102
  # If any of the below resources start needing complicated delete logic (dependent resources needing to
101
103
  # be deleted) move that logic into `delete_aws_resource` and add the purging logic to the resource
102
104
  vpc.network_acls.each do |na|
103
- next if na.default?
105
+ next if na.is_default
104
106
  Cheffish.inline_resource(self, action) do
105
107
  aws_network_acl na do
106
108
  action :purge
@@ -118,8 +120,9 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
118
120
  end
119
121
  end
120
122
  end
123
+
121
124
  vpc.security_groups.each do |sg|
122
- next if sg.name == 'default'
125
+ next if sg.group_name == "default"
123
126
  Cheffish.inline_resource(self, action) do
124
127
  aws_security_group sg do
125
128
  action :purge
@@ -151,9 +154,9 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
151
154
  :filters => [
152
155
  {
153
156
  :name => filter,
154
- :values => [vpc.id]
155
- }
156
- ]
157
+ :values => [vpc.id],
158
+ },
159
+ ],
157
160
  }).vpc_peering_connections
158
161
  end
159
162
 
@@ -170,11 +173,13 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
170
173
  end
171
174
 
172
175
  # Detach or destroy the internet gateway
173
- ig = vpc.internet_gateway
176
+ ig = vpc.internet_gateways.first
174
177
  if ig
175
178
  Cheffish.inline_resource(self, action) do
176
179
  aws_internet_gateway ig do
177
- if ig.tags['OwnedByVPC'] == vpc.id
180
+ ig_tag = ig.tags.find { |i| i.key == "OwnedByVPC" }
181
+ ig_vpc = ig_tag.value unless ig_tag.nil?
182
+ if ig_vpc == vpc.id
178
183
  action :purge
179
184
  else
180
185
  action :detach
@@ -218,11 +223,11 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
218
223
  end
219
224
 
220
225
  def update_internet_gateway(vpc)
221
- current_ig = vpc.internet_gateway
226
+ current_ig = vpc.internet_gateways.first
222
227
  current_driver = self.new_resource.driver
223
228
  current_chef_server = self.new_resource.chef_server
224
229
  case new_resource.internet_gateway
225
- when String, Chef::Resource::AwsInternetGateway, AWS::EC2::InternetGateway
230
+ when String, Chef::Resource::AwsInternetGateway, ::Aws::EC2::InternetGateway
226
231
  new_ig = Chef::Resource::AwsInternetGateway.get_aws_object(new_resource.internet_gateway, resource: new_resource)
227
232
  if !current_ig
228
233
  Cheffish.inline_resource(self, action) do
@@ -239,7 +244,9 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
239
244
  elsif current_ig != new_ig
240
245
  Cheffish.inline_resource(self, action) do
241
246
  aws_internet_gateway current_ig do
242
- if current_ig.tags['OwnedByVPC'] == vpc.id
247
+ ig_tag = current_ig.tags.find { |i| i.key == "OwnedByVPC" }
248
+ ig_vpc = ig_tag.value unless ig_tag.nil?
249
+ if ig_vpc == vpc.id
243
250
  action :destroy
244
251
  else
245
252
  action :detach
@@ -268,8 +275,10 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
268
275
  when false
269
276
  if current_ig
270
277
  Cheffish.inline_resource(self, action) do
271
- aws_internet_gateway current_ig.id do
272
- if current_ig.tags['OwnedByVPC'] == vpc.id
278
+ aws_internet_gateway current_ig do
279
+ ig_tag = current_ig.tags.find { |i| i.key == "OwnedByVPC" }
280
+ ig_vpc = ig_tag.value unless ig_tag.nil?
281
+ if ig_vpc == vpc.id
273
282
  action :destroy
274
283
  else
275
284
  action :detach
@@ -284,15 +293,28 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
284
293
 
285
294
  def update_main_route_table(vpc)
286
295
  desired_route_table = Chef::Resource::AwsRouteTable.get_aws_object(new_resource.main_route_table, resource: new_resource)
287
- current_route_table = vpc.route_tables.main_route_table
288
- if current_route_table.id != desired_route_table.id
289
- main_association = current_route_table.associations.select { |a| a.main? }.first
290
- if !main_association
291
- raise "No main route table association found for #{new_resource.to_s} current main route table #{current_route_table.id}: error! Probably a race condition."
296
+ main_route_table = nil
297
+ current_route_table = nil
298
+ # Below snippet gives the entry of main_route_table and current_route_table entry who is associated with current vpc.It is an replacement of "vpc.route_tables.main_route_table"
299
+ vpc.route_tables.entries.each do |entry|
300
+ if !entry.associations.empty?
301
+ entry.associations.each do |r|
302
+ if r.main == true
303
+ main_route_table = r
304
+ elsif r.main == false
305
+ current_route_table = r
306
+ end
307
+ end
292
308
  end
293
- converge_by "change main route table for #{new_resource.to_s} to #{desired_route_table.id} (was #{current_route_table.id})" do
309
+ end
310
+ current_route_table ||= main_route_table
311
+ if current_route_table.route_table_id != desired_route_table.id
312
+ if main_route_table.nil?
313
+ raise "No main route table association found for #{new_resource.to_s} current main route table. error! Probably a race condition."
314
+ end
315
+ converge_by "change main route table for #{new_resource.to_s} to #{desired_route_table.id} (was #{current_route_table.route_table_id})" do
294
316
  vpc.client.replace_route_table_association(
295
- association_id: main_association.id,
317
+ association_id: main_route_table.id,
296
318
  route_table_id: desired_route_table.id
297
319
  )
298
320
  end
@@ -304,12 +326,16 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
304
326
  # If no route table is provided and we fetch the current main one from AWS,
305
327
  # there is no guarantee that is the 'default' route table created when
306
328
  # creating the VPC
307
- main_route_table ||= vpc.route_tables.main_route_table
329
+ main_route_table = nil
330
+ # Below snippet gives the entry of main_route_table entry who is associated with current vpc.It is an replacement of "vpc.route_tables.main_route_table"
331
+ vpc.route_tables.entries.each do |entry|
332
+ main_route_table = entry.associations.find { |r| r.main == true } unless entry.associations.empty?
333
+ end
308
334
  main_routes = new_resource.main_routes
309
335
  current_driver = self.new_resource.driver
310
336
  current_chef_server = self.new_resource.chef_server
311
337
  Cheffish.inline_resource(self, action) do
312
- aws_route_table main_route_table.id do
338
+ aws_route_table main_route_table.route_table_id do
313
339
  vpc vpc
314
340
  routes main_routes
315
341
  driver current_driver
@@ -322,9 +348,12 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
322
348
  def update_dhcp_options(vpc)
323
349
  dhcp_options = vpc.dhcp_options
324
350
  desired_dhcp_options = Chef::Resource::AwsDhcpOptions.get_aws_object(new_resource.dhcp_options, resource: new_resource)
325
- if dhcp_options != desired_dhcp_options
351
+ if dhcp_options.id != desired_dhcp_options.id
326
352
  converge_by "change DHCP options for #{new_resource.to_s} to #{new_resource.dhcp_options} (#{desired_dhcp_options.id}) - was #{dhcp_options.id}" do
327
- vpc.dhcp_options = desired_dhcp_options
353
+ vpc.associate_dhcp_options({
354
+ dhcp_options_id: desired_dhcp_options.id, # required
355
+ dry_run: false,
356
+ })
328
357
  end
329
358
  end
330
359
  end
@@ -29,7 +29,7 @@ class AWSProvider < Chef::Provider::LWRPBase
29
29
  end
30
30
 
31
31
  def region
32
- new_resource.driver.region
32
+ new_resource.driver.aws_config[:region]
33
33
  end
34
34
 
35
35
  #
@@ -273,9 +273,18 @@ class AWSProvider < Chef::Provider::LWRPBase
273
273
  Chef::Log.debug("Current exception in wait_for is #{exception.inspect}") if exception
274
274
  begin
275
275
  yield(aws_object) if block_given?
276
- current_response = aws_object.send(query_method)
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
277
286
  Chef::Log.debug("Current response in wait_for from [#{query_method}] is #{current_response}")
278
- unless expected_responses.include?(current_response)
287
+ unless expected_responses.to_s.include?(current_response)
279
288
  raise StatusTimeoutError.new(aws_object, current_response, expected_responses)
280
289
  end
281
290
  rescue *acceptable_errors
@@ -1,4 +1,4 @@
1
- require 'aws'
1
+ require 'aws-sdk'
2
2
  require 'chef/provisioning/aws_driver/super_lwrp'
3
3
  require 'chef/provisioning/chef_managed_entry_store'
4
4
  # Enough resources will eventually require this that we put 1 require in here
@@ -87,7 +87,7 @@ module AWSDriver
87
87
  # `AWSResource.lookup_options` will translate each ID with
88
88
  # `AwsSubnet.get_aws_object('subnet1')`, which supports Chef names
89
89
  # (`mysubnet`) as well as AWS subnet Ids (`subnet-1234abcd`) or AWS objects
90
- # (`AWS::EC2::Subnet`).
90
+ # (`::Aws::EC2::Subnet`).
91
91
  #
92
92
  # Keys that represent non-AWS-objects (such as `timeout`) are left alone.
93
93
  #
@@ -20,7 +20,7 @@ class Chef::Provisioning::AWSDriver::AWSResourceWithEntry < Chef::Provisioning::
20
20
  #
21
21
  # Save the ID of this object to Chef.
22
22
  #
23
- # @param aws_object [AWS::EC2::Core] The AWS object containing the ID.
23
+ # @param aws_object [::Aws::EC2::Core] The AWS object containing the ID.
24
24
  # @param action_handler [Chef::Provisioning::ActionHandler] The action handler,
25
25
  # which handles progress reporting, update reporting ("little green text")
26
26
  # and dry run.
@@ -16,7 +16,7 @@ class AWSTagger
16
16
  def_delegators :@tagging_strategy, :desired_tags, :current_tags, :set_tags, :delete_tags
17
17
 
18
18
  def converge_tags
19
- if desired_tags.nil?
19
+ if desired_tags.nil? || desired_tags.empty?
20
20
  Chef::Log.debug "aws_tags not provided, nothing to converge"
21
21
  return
22
22
  end
@@ -37,7 +37,7 @@ class AWSTagger
37
37
  Retryable.retryable(
38
38
  :tries => 20,
39
39
  :sleep => lambda { |n| [2**n, 10].min },
40
- :on => [AWS::Errors::Base, Aws::Errors::ServiceError,]
40
+ :on => [::Aws::EC2::Errors, Aws::S3::Errors, ::Aws::S3::Errors::ServiceError,]
41
41
  ) do |retries, exception|
42
42
  if retries > 0
43
43
  Chef::Log.info "Retrying the tagging, previous try failed with #{exception.inspect}"