chef-provisioning-aws 3.0.4 → 3.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +16 -5
- data/Rakefile +15 -6
- data/chef-provisioning-aws.gemspec +17 -17
- data/lib/chef/provider/aws_auto_scaling_group.rb +5 -6
- data/lib/chef/provider/aws_cache_cluster.rb +21 -15
- data/lib/chef/provider/aws_cache_replication_group.rb +12 -8
- data/lib/chef/provider/aws_cache_subnet_group.rb +3 -3
- data/lib/chef/provider/aws_cloudsearch_domain.rb +9 -13
- data/lib/chef/provider/aws_cloudwatch_alarm.rb +10 -12
- data/lib/chef/provider/aws_dhcp_options.rb +18 -21
- data/lib/chef/provider/aws_ebs_volume.rb +24 -26
- data/lib/chef/provider/aws_eip_address.rb +10 -13
- data/lib/chef/provider/aws_elasticsearch_domain.rb +19 -18
- data/lib/chef/provider/aws_iam_instance_profile.rb +5 -7
- data/lib/chef/provider/aws_iam_role.rb +14 -17
- data/lib/chef/provider/aws_image.rb +6 -6
- data/lib/chef/provider/aws_instance.rb +5 -5
- data/lib/chef/provider/aws_internet_gateway.rb +8 -11
- data/lib/chef/provider/aws_key_pair.rb +15 -17
- data/lib/chef/provider/aws_launch_configuration.rb +11 -14
- data/lib/chef/provider/aws_load_balancer.rb +1 -2
- data/lib/chef/provider/aws_nat_gateway.rb +6 -7
- data/lib/chef/provider/aws_network_acl.rb +28 -29
- data/lib/chef/provider/aws_network_interface.rb +25 -27
- data/lib/chef/provider/aws_rds_instance.rb +12 -13
- data/lib/chef/provider/aws_rds_parameter_group.rb +8 -8
- data/lib/chef/provider/aws_rds_subnet_group.rb +8 -9
- data/lib/chef/provider/aws_route_table.rb +19 -20
- data/lib/chef/provider/aws_s3_bucket.rb +22 -25
- data/lib/chef/provider/aws_security_group.rb +268 -285
- data/lib/chef/provider/aws_server_certificate.rb +6 -5
- data/lib/chef/provider/aws_sns_topic.rb +4 -6
- data/lib/chef/provider/aws_sqs_queue.rb +3 -4
- data/lib/chef/provider/aws_subnet.rb +29 -34
- data/lib/chef/provider/aws_vpc.rb +108 -116
- data/lib/chef/provider/aws_vpc_peering_connection.rb +11 -11
- data/lib/chef/provisioning/aws_driver.rb +4 -2
- data/lib/chef/provisioning/aws_driver/aws_provider.rb +234 -241
- data/lib/chef/provisioning/aws_driver/aws_rds_resource.rb +5 -7
- data/lib/chef/provisioning/aws_driver/aws_resource.rb +182 -185
- data/lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb +17 -17
- data/lib/chef/provisioning/aws_driver/aws_taggable.rb +13 -15
- data/lib/chef/provisioning/aws_driver/aws_tagger.rb +47 -48
- data/lib/chef/provisioning/aws_driver/credentials.rb +96 -100
- data/lib/chef/provisioning/aws_driver/credentials2.rb +42 -45
- data/lib/chef/provisioning/aws_driver/driver.rb +1349 -1362
- data/lib/chef/provisioning/aws_driver/exceptions.rb +10 -12
- data/lib/chef/provisioning/aws_driver/super_lwrp.rb +60 -60
- data/lib/chef/provisioning/aws_driver/tagging_strategy/auto_scaling.rb +49 -50
- data/lib/chef/provisioning/aws_driver/tagging_strategy/ec2.rb +37 -38
- data/lib/chef/provisioning/aws_driver/tagging_strategy/elasticsearch.rb +14 -15
- data/lib/chef/provisioning/aws_driver/tagging_strategy/elb.rb +29 -31
- data/lib/chef/provisioning/aws_driver/tagging_strategy/rds.rb +39 -40
- data/lib/chef/provisioning/aws_driver/tagging_strategy/s3.rb +41 -43
- data/lib/chef/provisioning/aws_driver/version.rb +5 -5
- data/lib/chef/provisioning/driver_init/aws.rb +2 -2
- data/lib/chef/resource/aws_auto_scaling_group.rb +1 -1
- data/lib/chef/resource/aws_cache_cluster.rb +9 -12
- data/lib/chef/resource/aws_cache_replication_group.rb +9 -11
- data/lib/chef/resource/aws_cache_subnet_group.rb +8 -10
- data/lib/chef/resource/aws_cloudsearch_domain.rb +4 -5
- data/lib/chef/resource/aws_cloudwatch_alarm.rb +17 -18
- data/lib/chef/resource/aws_dhcp_options.rb +2 -2
- data/lib/chef/resource/aws_ebs_volume.rb +10 -10
- data/lib/chef/resource/aws_eip_address.rb +5 -5
- data/lib/chef/resource/aws_elasticsearch_domain.rb +4 -4
- data/lib/chef/resource/aws_iam_instance_profile.rb +4 -5
- data/lib/chef/resource/aws_iam_role.rb +2 -3
- data/lib/chef/resource/aws_image.rb +3 -3
- data/lib/chef/resource/aws_instance.rb +4 -4
- data/lib/chef/resource/aws_internet_gateway.rb +3 -3
- data/lib/chef/resource/aws_key_pair.rb +7 -7
- data/lib/chef/resource/aws_launch_configuration.rb +4 -4
- data/lib/chef/resource/aws_load_balancer.rb +7 -7
- data/lib/chef/resource/aws_nat_gateway.rb +11 -11
- data/lib/chef/resource/aws_network_acl.rb +7 -8
- data/lib/chef/resource/aws_network_interface.rb +9 -9
- data/lib/chef/resource/aws_rds_instance.rb +4 -4
- data/lib/chef/resource/aws_rds_parameter_group.rb +3 -3
- data/lib/chef/resource/aws_rds_subnet_group.rb +4 -4
- data/lib/chef/resource/aws_route53_hosted_zone.rb +37 -40
- data/lib/chef/resource/aws_route53_record_set.rb +22 -24
- data/lib/chef/resource/aws_route_table.rb +7 -7
- data/lib/chef/resource/aws_s3_bucket.rb +7 -7
- data/lib/chef/resource/aws_security_group.rb +10 -10
- data/lib/chef/resource/aws_server_certificate.rb +6 -8
- data/lib/chef/resource/aws_sns_topic.rb +2 -2
- data/lib/chef/resource/aws_sqs_queue.rb +5 -7
- data/lib/chef/resource/aws_subnet.rb +9 -9
- data/lib/chef/resource/aws_vpc.rb +11 -11
- data/lib/chef/resource/aws_vpc_peering_connection.rb +4 -4
- data/spec/aws_support.rb +44 -45
- data/spec/aws_support/aws_resource_run_wrapper.rb +2 -2
- data/spec/aws_support/deep_matcher.rb +2 -3
- data/spec/aws_support/deep_matcher/fuzzy_match_objects.rb +6 -9
- data/spec/aws_support/deep_matcher/match_values_failure_messages.rb +30 -37
- data/spec/aws_support/deep_matcher/matchable_array.rb +0 -1
- data/spec/aws_support/deep_matcher/matchable_object.rb +1 -2
- data/spec/aws_support/deep_matcher/rspec_monkeypatches.rb +4 -4
- data/spec/aws_support/delayed_stream.rb +2 -2
- data/spec/aws_support/matchers/create_an_aws_object.rb +6 -6
- data/spec/aws_support/matchers/destroy_an_aws_object.rb +6 -6
- data/spec/aws_support/matchers/have_aws_object_tags.rb +4 -5
- data/spec/aws_support/matchers/match_an_aws_object.rb +5 -6
- data/spec/aws_support/matchers/update_an_aws_object.rb +6 -7
- data/spec/integration/aws_auto_scaling_group_spec.rb +56 -64
- data/spec/integration/aws_cache_cluster_spec.rb +70 -71
- data/spec/integration/aws_cache_subnet_group_spec.rb +13 -14
- data/spec/integration/aws_cloudsearch_domain_spec.rb +6 -8
- data/spec/integration/aws_cloudwatch_alarm_spec.rb +200 -208
- data/spec/integration/aws_dhcp_options_spec.rb +32 -43
- data/spec/integration/aws_ebs_volume_spec.rb +52 -73
- data/spec/integration/aws_eip_address_spec.rb +24 -31
- data/spec/integration/aws_elasticsearch_domain_spec.rb +31 -33
- data/spec/integration/aws_iam_instance_profile_spec.rb +36 -45
- data/spec/integration/aws_iam_role_spec.rb +39 -46
- data/spec/integration/aws_internet_gateway_spec.rb +64 -75
- data/spec/integration/aws_key_pair_spec.rb +6 -6
- data/spec/integration/aws_launch_configuration_spec.rb +17 -18
- data/spec/integration/aws_nat_gateway_spec.rb +21 -24
- data/spec/integration/aws_network_acl_spec.rb +81 -95
- data/spec/integration/aws_network_interface_spec.rb +28 -43
- data/spec/integration/aws_rds_instance_spec.rb +29 -40
- data/spec/integration/aws_rds_parameter_group_spec.rb +32 -35
- data/spec/integration/aws_rds_subnet_group_spec.rb +30 -40
- data/spec/integration/aws_route53_hosted_zone_spec.rb +205 -205
- data/spec/integration/aws_route_table_spec.rb +118 -136
- data/spec/integration/aws_s3_bucket_spec.rb +19 -27
- data/spec/integration/aws_security_group_spec.rb +369 -388
- data/spec/integration/aws_server_certificate_spec.rb +16 -18
- data/spec/integration/aws_subnet_spec.rb +44 -58
- data/spec/integration/aws_vpc_peering_connection_spec.rb +43 -50
- data/spec/integration/aws_vpc_spec.rb +99 -115
- data/spec/integration/load_balancer_spec.rb +169 -183
- data/spec/integration/machine_batch_spec.rb +24 -31
- data/spec/integration/machine_image_spec.rb +54 -66
- data/spec/integration/machine_spec.rb +216 -237
- data/spec/persistence_file.txt +219 -0
- data/spec/spec_helper.rb +16 -17
- data/spec/unit/chef/provisioning/aws_driver/credentials_spec.rb +67 -74
- data/spec/unit/chef/provisioning/aws_driver/driver_spec.rb +29 -29
- data/spec/unit/chef/provisioning/aws_driver/route53_spec.rb +13 -15
- metadata +4 -3
@@ -1,18 +1,19 @@
|
|
1
|
-
require
|
1
|
+
require "chef/provisioning/aws_driver/aws_provider"
|
2
2
|
|
3
3
|
class Chef::Provider::AwsServerCertificate < Chef::Provisioning::AWSDriver::AWSProvider
|
4
4
|
provides :aws_server_certificate
|
5
5
|
|
6
|
-
def update_aws_object(
|
6
|
+
def update_aws_object(_certificate)
|
7
7
|
Chef::Log.warn("aws_server_certificate does not support modifying an existing certificate")
|
8
8
|
end
|
9
9
|
|
10
10
|
def create_aws_object
|
11
11
|
converge_by "create server certificate #{new_resource.name}" do
|
12
12
|
opts = {
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
13
|
+
server_certificate_name: new_resource.name,
|
14
|
+
certificate_body: new_resource.certificate_body,
|
15
|
+
private_key: new_resource.private_key
|
16
|
+
}
|
16
17
|
opts[:certificate_chain] = new_resource.certificate_chain if new_resource.certificate_chain
|
17
18
|
new_resource.driver.iam.upload_server_certificate(**opts)
|
18
19
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "chef/provisioning/aws_driver/aws_provider"
|
2
|
+
require "date"
|
3
3
|
|
4
4
|
class Chef::Provider::AwsSnsTopic < Chef::Provisioning::AWSDriver::AWSProvider
|
5
5
|
provides :aws_sns_topic
|
6
|
-
|
6
|
+
|
7
7
|
protected
|
8
8
|
|
9
9
|
def create_aws_object
|
@@ -12,8 +12,7 @@ class Chef::Provider::AwsSnsTopic < Chef::Provisioning::AWSDriver::AWSProvider
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
def update_aws_object(topic)
|
16
|
-
end
|
15
|
+
def update_aws_object(topic); end
|
17
16
|
|
18
17
|
def destroy_aws_object(topic)
|
19
18
|
topic_arn_name = topic.attributes.values_at("TopicArn").first
|
@@ -21,5 +20,4 @@ class Chef::Provider::AwsSnsTopic < Chef::Provisioning::AWSDriver::AWSProvider
|
|
21
20
|
new_resource.driver.sns.delete_topic(topic_arn: topic_arn_name)
|
22
21
|
end
|
23
22
|
end
|
24
|
-
|
25
23
|
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
1
|
+
require "chef/provisioning/aws_driver/aws_provider"
|
2
2
|
|
3
3
|
class Chef::Provider::AwsSqsQueue < Chef::Provisioning::AWSDriver::AWSProvider
|
4
4
|
provides :aws_sqs_queue
|
5
|
-
|
5
|
+
|
6
6
|
def create_aws_object
|
7
7
|
options = AWSResource.lookup_options(new_resource.options || {}, resource: new_resource)
|
8
8
|
option_sqs = {}
|
@@ -15,8 +15,7 @@ class Chef::Provider::AwsSqsQueue < Chef::Provisioning::AWSDriver::AWSProvider
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
def update_aws_object(queue)
|
19
|
-
end
|
18
|
+
def update_aws_object(queue); end
|
20
19
|
|
21
20
|
def destroy_aws_object(queue)
|
22
21
|
converge_by "delete SQS queue #{new_resource.name} in #{region}" do
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "chef/provisioning/aws_driver/aws_provider"
|
2
|
+
require "chef/provisioning/aws_driver/aws_resource"
|
3
|
+
require "date"
|
4
|
+
require "chef/resource/aws_vpc"
|
5
5
|
|
6
6
|
class Chef::Provider::AwsSubnet < Chef::Provisioning::AWSDriver::AWSProvider
|
7
7
|
include Chef::Provisioning::AWSDriver::TaggingStrategy::EC2ConvergeTags
|
@@ -11,13 +11,11 @@ class Chef::Provider::AwsSubnet < Chef::Provisioning::AWSDriver::AWSProvider
|
|
11
11
|
def action_create
|
12
12
|
subnet = super
|
13
13
|
|
14
|
-
|
14
|
+
unless new_resource.map_public_ip_on_launch.nil?
|
15
15
|
update_map_public_ip_on_launch(subnet)
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
update_route_table(subnet)
|
20
|
-
end
|
18
|
+
update_route_table(subnet) unless new_resource.route_table.nil?
|
21
19
|
|
22
20
|
update_network_acl(subnet)
|
23
21
|
end
|
@@ -26,9 +24,7 @@ class Chef::Provider::AwsSubnet < Chef::Provisioning::AWSDriver::AWSProvider
|
|
26
24
|
|
27
25
|
def create_aws_object
|
28
26
|
cidr_block = new_resource.cidr_block
|
29
|
-
|
30
|
-
cidr_block = Chef::Resource::AwsVpc.get_aws_object(new_resource.vpc, resource: new_resource).cidr_block
|
31
|
-
end
|
27
|
+
cidr_block ||= Chef::Resource::AwsVpc.get_aws_object(new_resource.vpc, resource: new_resource).cidr_block
|
32
28
|
options = { vpc_id: new_resource.vpc, cidr_block: cidr_block }
|
33
29
|
options[:availability_zone] = new_resource.availability_zone if new_resource.availability_zone
|
34
30
|
options = Chef::Provisioning::AWSDriver::AWSResource.lookup_options(options, resource: new_resource)
|
@@ -36,8 +32,8 @@ class Chef::Provider::AwsSubnet < Chef::Provisioning::AWSDriver::AWSProvider
|
|
36
32
|
converge_by "create subnet #{new_resource.name} with CIDR #{cidr_block} in VPC #{new_resource.vpc} (#{options[:vpc_id]}) in #{region}" do
|
37
33
|
subnet = new_resource.driver.ec2_resource.create_subnet(options)
|
38
34
|
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}])
|
35
|
+
new_resource.driver.ec2_resource.create_tags(resources: [subnet.id], tags: [{ key: "Name", value: new_resource.name }])
|
36
|
+
new_resource.driver.ec2_resource.create_tags(resources: [subnet.id], tags: [{ key: "VPC", value: new_resource.vpc }])
|
41
37
|
end
|
42
38
|
subnet
|
43
39
|
end
|
@@ -59,10 +55,10 @@ class Chef::Provider::AwsSubnet < Chef::Provisioning::AWSDriver::AWSProvider
|
|
59
55
|
|
60
56
|
def destroy_aws_object(subnet)
|
61
57
|
if purging
|
62
|
-
# TODO possibly convert to http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/EC2/Client.html#terminate_instances-instance_method
|
58
|
+
# TODO: possibly convert to http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/EC2/Client.html#terminate_instances-instance_method
|
63
59
|
p = Chef::ChefFS::Parallelizer.new(5)
|
64
|
-
current_driver =
|
65
|
-
current_chef_server =
|
60
|
+
current_driver = new_resource.driver
|
61
|
+
current_chef_server = new_resource.chef_server
|
66
62
|
p.parallel_do(subnet.instances.to_a) do |instance|
|
67
63
|
Cheffish.inline_resource(self, action) do
|
68
64
|
aws_instance instance.id do
|
@@ -87,7 +83,7 @@ class Chef::Provider::AwsSubnet < Chef::Provisioning::AWSDriver::AWSProvider
|
|
87
83
|
end
|
88
84
|
end
|
89
85
|
end
|
90
|
-
converge_by "delete #{new_resource
|
86
|
+
converge_by "delete #{new_resource} in VPC #{new_resource.vpc} in #{region}" do
|
91
87
|
# If the subnet doesn't exist we can't check state on it - state can only be :pending or :available
|
92
88
|
begin
|
93
89
|
subnet.delete
|
@@ -99,10 +95,10 @@ class Chef::Provider::AwsSubnet < Chef::Provisioning::AWSDriver::AWSProvider
|
|
99
95
|
private
|
100
96
|
|
101
97
|
def update_map_public_ip_on_launch(subnet)
|
102
|
-
|
103
|
-
subnet_desc = subnet.client.describe_subnets(subnet_ids: [
|
98
|
+
unless new_resource.map_public_ip_on_launch.nil?
|
99
|
+
subnet_desc = subnet.client.describe_subnets(subnet_ids: [subnet.id])[:subnets].first
|
104
100
|
if new_resource.map_public_ip_on_launch
|
105
|
-
|
101
|
+
unless subnet_desc[:map_public_ip_on_launch]
|
106
102
|
converge_by "turn on automatic public IPs for subnet #{subnet.id}" do
|
107
103
|
subnet.client.modify_subnet_attribute(subnet_id: subnet.id, map_public_ip_on_launch: { value: true })
|
108
104
|
end
|
@@ -118,28 +114,27 @@ class Chef::Provider::AwsSubnet < Chef::Provisioning::AWSDriver::AWSProvider
|
|
118
114
|
end
|
119
115
|
|
120
116
|
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
|
117
|
+
current_route_table_association = subnet.client.describe_route_tables(filters: [{ name: "vpc-id", values: [subnet.vpc.id] }]).route_tables
|
122
118
|
route_table_entry = nil
|
123
119
|
do_break = false
|
124
|
-
# Below snippet gives the entry of route_table who is associated with current subnet either by matching its
|
120
|
+
# Below snippet gives the entry of route_table who is associated with current subnet either by matching its
|
125
121
|
# subnet_id or with a default subnet (i.e by checking association.main == true & in that case
|
126
122
|
# association.subnet_id is nil)
|
127
123
|
current_route_table_association.each do |route_tbl|
|
128
|
-
if
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
end
|
124
|
+
next if route_tbl.associations.empty?
|
125
|
+
route_tbl.associations.each do |r|
|
126
|
+
if r.subnet_id == subnet.id
|
127
|
+
route_table_entry = r
|
128
|
+
do_break = true
|
129
|
+
break
|
130
|
+
elsif r.subnet_id.nil? && r.main == true
|
131
|
+
route_table_entry = r
|
137
132
|
end
|
138
|
-
break if do_break
|
139
133
|
end
|
134
|
+
break if do_break
|
140
135
|
end
|
141
136
|
if new_resource.route_table == :default_to_main
|
142
|
-
|
137
|
+
unless route_table_entry.main
|
143
138
|
converge_by "reset route table of subnet #{new_resource.name} to the VPC default" do
|
144
139
|
subnet.client.disassociate_route_table(association_id: route_table_entry.route_table_association_id)
|
145
140
|
end
|
@@ -168,7 +163,7 @@ class Chef::Provider::AwsSubnet < Chef::Provisioning::AWSDriver::AWSProvider
|
|
168
163
|
network_acl_id =
|
169
164
|
AWSResource.lookup_options({ network_acl: new_resource.network_acl }, resource: new_resource)[:network_acl]
|
170
165
|
# 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
|
166
|
+
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
167
|
current_network_acl_association = network_acl_association.find { |r| r.subnet_id == subnet.id } unless network_acl_association.empty?
|
173
168
|
|
174
169
|
if current_network_acl_association.network_acl_id != network_acl_id && !current_network_acl_association.nil?
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "chef/provisioning/aws_driver/aws_provider"
|
2
|
+
require "date"
|
3
|
+
require "chef/provisioning"
|
4
|
+
require "retryable"
|
5
5
|
|
6
6
|
class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
|
7
7
|
include Chef::Provisioning::AWSDriver::TaggingStrategy::EC2ConvergeTags
|
@@ -19,24 +19,18 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
|
|
19
19
|
#
|
20
20
|
# Attach/detach internet gateway
|
21
21
|
#
|
22
|
-
|
23
|
-
update_internet_gateway(vpc)
|
24
|
-
end
|
22
|
+
update_internet_gateway(vpc) unless new_resource.internet_gateway.nil?
|
25
23
|
|
26
24
|
# Replace the main route table for the VPC
|
27
|
-
|
28
|
-
update_main_route_table(vpc)
|
29
|
-
end
|
25
|
+
update_main_route_table(vpc) unless new_resource.main_route_table.nil?
|
30
26
|
|
31
27
|
# Update the main route table
|
32
|
-
|
28
|
+
unless new_resource.main_routes.nil?
|
33
29
|
update_main_routes(vpc, new_resource.main_route_table)
|
34
30
|
end
|
35
31
|
|
36
32
|
# Update DHCP options
|
37
|
-
|
38
|
-
update_dhcp_options(vpc)
|
39
|
-
end
|
33
|
+
update_dhcp_options(vpc) unless new_resource.dhcp_options.nil?
|
40
34
|
end
|
41
35
|
|
42
36
|
protected
|
@@ -48,7 +42,7 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
|
|
48
42
|
|
49
43
|
converge_by "create VPC #{new_resource.name} in #{region}" do
|
50
44
|
ec2_resource = ::Aws::EC2::Resource.new(new_resource.driver.ec2)
|
51
|
-
vpc = ec2_resource.create_vpc(
|
45
|
+
vpc = ec2_resource.create_vpc(cidr_block: new_resource.cidr_block, instance_tenancy: options[:instance_tenancy])
|
52
46
|
wait_for_state(vpc, [:available])
|
53
47
|
retry_with_backoff(::Aws::EC2::Errors::InvalidVpcIDNotFound) do
|
54
48
|
ec2_resource.create_tags(resources: [vpc.vpc_id], tags: [{ key: "Name", value: new_resource.name }])
|
@@ -67,16 +61,16 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
|
|
67
61
|
end
|
68
62
|
|
69
63
|
def destroy_aws_object(vpc)
|
70
|
-
current_driver =
|
71
|
-
current_chef_server =
|
64
|
+
current_driver = new_resource.driver
|
65
|
+
current_chef_server = new_resource.chef_server
|
72
66
|
if purging
|
73
|
-
#SDK V2
|
74
|
-
nat_gateways = new_resource.driver.ec2_client.describe_nat_gateways(
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
67
|
+
# SDK V2
|
68
|
+
nat_gateways = new_resource.driver.ec2_client.describe_nat_gateways(
|
69
|
+
filter: [
|
70
|
+
{ name: "vpc-id", values: [vpc.id] },
|
71
|
+
{ name: "state", values: %w{available pending} }
|
72
|
+
]
|
73
|
+
).nat_gateways
|
80
74
|
|
81
75
|
nat_gateways.each do |nat_gw|
|
82
76
|
nat_gw_resource = new_resource.driver.ec2_resource.nat_gateway(nat_gw.nat_gateway_id)
|
@@ -89,7 +83,7 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
|
|
89
83
|
end
|
90
84
|
end
|
91
85
|
|
92
|
-
#SDK V1
|
86
|
+
# SDK V1
|
93
87
|
vpc.subnets.each do |s|
|
94
88
|
Cheffish.inline_resource(self, action) do
|
95
89
|
aws_subnet s do
|
@@ -132,10 +126,10 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
|
|
132
126
|
end
|
133
127
|
end
|
134
128
|
|
135
|
-
#SDK V2
|
129
|
+
# SDK V2
|
136
130
|
vpc_new_sdk = new_resource.driver.ec2_resource.vpc(vpc.id)
|
137
131
|
vpc_new_sdk.route_tables.each do |rt|
|
138
|
-
next if rt.associations.any?
|
132
|
+
next if rt.associations.any?(&:main)
|
139
133
|
Cheffish.inline_resource(self, action) do
|
140
134
|
aws_route_table rt do
|
141
135
|
action :purge
|
@@ -146,18 +140,18 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
|
|
146
140
|
end
|
147
141
|
|
148
142
|
vpc_peering_connections = []
|
149
|
-
%w
|
143
|
+
%w{
|
150
144
|
requester-vpc-info.vpc-id
|
151
145
|
accepter-vpc-info.vpc-id
|
152
|
-
|
153
|
-
vpc_peering_connections += new_resource.driver.ec2_client.describe_vpc_peering_connections(
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
146
|
+
}.each do |filter|
|
147
|
+
vpc_peering_connections += new_resource.driver.ec2_client.describe_vpc_peering_connections(
|
148
|
+
filters: [
|
149
|
+
{
|
150
|
+
name: filter,
|
151
|
+
values: [vpc.id]
|
152
|
+
}
|
153
|
+
]
|
154
|
+
).vpc_peering_connections
|
161
155
|
end
|
162
156
|
|
163
157
|
vpc_peering_connections.each do |pc_type|
|
@@ -192,7 +186,7 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
|
|
192
186
|
|
193
187
|
# We cannot delete the main route table, and it will be deleted when the VPC is deleted anyways
|
194
188
|
|
195
|
-
converge_by "delete #{new_resource
|
189
|
+
converge_by "delete #{new_resource} in #{region}" do
|
196
190
|
vpc.delete
|
197
191
|
end
|
198
192
|
end
|
@@ -202,16 +196,15 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
|
|
202
196
|
def update_vpc_attributes(vpc)
|
203
197
|
# Figure out what (if anything) we need to update
|
204
198
|
update_attributes = {}
|
205
|
-
%w
|
199
|
+
%w{enable_dns_support enable_dns_hostnames}.each do |name|
|
206
200
|
desired_value = new_resource.public_send(name)
|
207
|
-
if
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
end
|
201
|
+
next if desired_value.nil?
|
202
|
+
# enable_dns_support -> enableDnsSupport
|
203
|
+
aws_attr_name = name.gsub(/_./) { |v| v[1..1].upcase }
|
204
|
+
name = name.to_sym
|
205
|
+
actual_value = vpc.client.describe_vpc_attribute(vpc_id: vpc.id, attribute: aws_attr_name)
|
206
|
+
if actual_value[name][:value] != desired_value
|
207
|
+
update_attributes[name] = { old_value: actual_value[name][:value], value: desired_value }
|
215
208
|
end
|
216
209
|
end
|
217
210
|
|
@@ -224,70 +217,70 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
|
|
224
217
|
|
225
218
|
def update_internet_gateway(vpc)
|
226
219
|
current_ig = vpc.internet_gateways.first
|
227
|
-
current_driver =
|
228
|
-
current_chef_server =
|
220
|
+
current_driver = new_resource.driver
|
221
|
+
current_chef_server = new_resource.chef_server
|
229
222
|
case new_resource.internet_gateway
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
end
|
223
|
+
when String, Chef::Resource::AwsInternetGateway, ::Aws::EC2::InternetGateway
|
224
|
+
new_ig = Chef::Resource::AwsInternetGateway.get_aws_object(new_resource.internet_gateway, resource: new_resource)
|
225
|
+
if !current_ig
|
226
|
+
Cheffish.inline_resource(self, action) do
|
227
|
+
aws_internet_gateway new_ig do
|
228
|
+
vpc vpc.id
|
229
|
+
# We have to set the driver & chef server on all resources because
|
230
|
+
# `with_chef_driver(...) do` gets evaluated at compile-time and these
|
231
|
+
# resources aren't constructed until converge-time. So the driver has
|
232
|
+
# been reset at this point
|
233
|
+
driver current_driver
|
234
|
+
chef_server current_chef_server
|
243
235
|
end
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
driver current_driver
|
255
|
-
chef_server current_chef_server
|
256
|
-
end
|
257
|
-
aws_internet_gateway new_ig do
|
258
|
-
vpc vpc.id
|
259
|
-
driver current_driver
|
260
|
-
chef_server current_chef_server
|
236
|
+
end
|
237
|
+
elsif current_ig != new_ig
|
238
|
+
Cheffish.inline_resource(self, action) do
|
239
|
+
aws_internet_gateway current_ig do
|
240
|
+
ig_tag = current_ig.tags.find { |i| i.key == "OwnedByVPC" }
|
241
|
+
ig_vpc = ig_tag.value unless ig_tag.nil?
|
242
|
+
if ig_vpc == vpc.id
|
243
|
+
action :destroy
|
244
|
+
else
|
245
|
+
action :detach
|
261
246
|
end
|
247
|
+
driver current_driver
|
248
|
+
chef_server current_chef_server
|
249
|
+
end
|
250
|
+
aws_internet_gateway new_ig do
|
251
|
+
vpc vpc.id
|
252
|
+
driver current_driver
|
253
|
+
chef_server current_chef_server
|
262
254
|
end
|
263
255
|
end
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
256
|
+
end
|
257
|
+
when true
|
258
|
+
unless current_ig
|
259
|
+
Cheffish.inline_resource(self, action) do
|
260
|
+
aws_internet_gateway "igw-managed-by-#{vpc.id}" do
|
261
|
+
vpc vpc.id
|
262
|
+
aws_tags "OwnedByVPC" => vpc.id
|
263
|
+
driver current_driver
|
264
|
+
chef_server current_chef_server
|
273
265
|
end
|
274
266
|
end
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
driver current_driver
|
287
|
-
chef_server current_chef_server
|
267
|
+
end
|
268
|
+
when false
|
269
|
+
if current_ig
|
270
|
+
Cheffish.inline_resource(self, action) do
|
271
|
+
aws_internet_gateway current_ig do
|
272
|
+
ig_tag = current_ig.tags.find { |i| i.key == "OwnedByVPC" }
|
273
|
+
ig_vpc = ig_tag.value unless ig_tag.nil?
|
274
|
+
if ig_vpc == vpc.id
|
275
|
+
action :destroy
|
276
|
+
else
|
277
|
+
action :detach
|
288
278
|
end
|
279
|
+
driver current_driver
|
280
|
+
chef_server current_chef_server
|
289
281
|
end
|
290
282
|
end
|
283
|
+
end
|
291
284
|
end
|
292
285
|
end
|
293
286
|
|
@@ -297,22 +290,21 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
|
|
297
290
|
current_route_table = nil
|
298
291
|
# 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
292
|
vpc.route_tables.entries.each do |entry|
|
300
|
-
if
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
end
|
293
|
+
next if entry.associations.empty?
|
294
|
+
entry.associations.each do |r|
|
295
|
+
if r.main == true
|
296
|
+
main_route_table = r
|
297
|
+
elsif r.main == false
|
298
|
+
current_route_table = r
|
307
299
|
end
|
308
300
|
end
|
309
301
|
end
|
310
302
|
current_route_table ||= main_route_table
|
311
303
|
if current_route_table.route_table_id != desired_route_table.id
|
312
304
|
if main_route_table.nil?
|
313
|
-
raise "No main route table association found for #{new_resource
|
305
|
+
raise "No main route table association found for #{new_resource} current main route table. error! Probably a race condition."
|
314
306
|
end
|
315
|
-
converge_by "change main route table for #{new_resource
|
307
|
+
converge_by "change main route table for #{new_resource} to #{desired_route_table.id} (was #{current_route_table.route_table_id})" do
|
316
308
|
vpc.client.replace_route_table_association(
|
317
309
|
association_id: main_route_table.id,
|
318
310
|
route_table_id: desired_route_table.id
|
@@ -332,8 +324,8 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
|
|
332
324
|
main_route_table = entry.associations.find { |r| r.main == true } unless entry.associations.empty?
|
333
325
|
end
|
334
326
|
main_routes = new_resource.main_routes
|
335
|
-
current_driver =
|
336
|
-
current_chef_server =
|
327
|
+
current_driver = new_resource.driver
|
328
|
+
current_chef_server = new_resource.chef_server
|
337
329
|
Cheffish.inline_resource(self, action) do
|
338
330
|
aws_route_table main_route_table.route_table_id do
|
339
331
|
vpc vpc
|
@@ -349,11 +341,11 @@ class Chef::Provider::AwsVpc < Chef::Provisioning::AWSDriver::AWSProvider
|
|
349
341
|
dhcp_options = vpc.dhcp_options
|
350
342
|
desired_dhcp_options = Chef::Resource::AwsDhcpOptions.get_aws_object(new_resource.dhcp_options, resource: new_resource)
|
351
343
|
if dhcp_options.id != desired_dhcp_options.id
|
352
|
-
converge_by "change DHCP options for #{new_resource
|
353
|
-
vpc.associate_dhcp_options(
|
344
|
+
converge_by "change DHCP options for #{new_resource} to #{new_resource.dhcp_options} (#{desired_dhcp_options.id}) - was #{dhcp_options.id}" do
|
345
|
+
vpc.associate_dhcp_options(
|
354
346
|
dhcp_options_id: desired_dhcp_options.id, # required
|
355
|
-
dry_run: false
|
356
|
-
|
347
|
+
dry_run: false
|
348
|
+
)
|
357
349
|
end
|
358
350
|
end
|
359
351
|
end
|