chef-provisioning-aws 2.2.2 → 3.0.0.pre.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/chef-provisioning-aws.gemspec +0 -1
- data/lib/chef/provider/aws_auto_scaling_group.rb +9 -6
- data/lib/chef/provider/aws_dhcp_options.rb +21 -11
- data/lib/chef/provider/aws_ebs_volume.rb +26 -24
- data/lib/chef/provider/aws_eip_address.rb +11 -12
- data/lib/chef/provider/aws_image.rb +1 -1
- data/lib/chef/provider/aws_internet_gateway.rb +18 -10
- data/lib/chef/provider/aws_key_pair.rb +6 -6
- data/lib/chef/provider/aws_launch_configuration.rb +7 -9
- data/lib/chef/provider/aws_nat_gateway.rb +2 -2
- data/lib/chef/provider/aws_network_acl.rb +11 -8
- data/lib/chef/provider/aws_network_interface.rb +34 -29
- data/lib/chef/provider/aws_rds_parameter_group.rb +1 -1
- data/lib/chef/provider/aws_rds_subnet_group.rb +1 -1
- data/lib/chef/provider/aws_route_table.rb +7 -7
- data/lib/chef/provider/aws_s3_bucket.rb +24 -12
- data/lib/chef/provider/aws_security_group.rb +202 -25
- data/lib/chef/provider/aws_server_certificate.rb +3 -4
- data/lib/chef/provider/aws_sns_topic.rb +4 -3
- data/lib/chef/provider/aws_sqs_queue.rb +7 -3
- data/lib/chef/provider/aws_subnet.rb +45 -21
- data/lib/chef/provider/aws_vpc.rb +59 -30
- data/lib/chef/provisioning/aws_driver/aws_provider.rb +12 -3
- data/lib/chef/provisioning/aws_driver/aws_resource.rb +2 -2
- data/lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb +1 -1
- data/lib/chef/provisioning/aws_driver/aws_tagger.rb +2 -2
- data/lib/chef/provisioning/aws_driver/credentials.rb +1 -1
- data/lib/chef/provisioning/aws_driver/credentials2.rb +5 -1
- data/lib/chef/provisioning/aws_driver/driver.rb +124 -34
- data/lib/chef/provisioning/aws_driver/tagging_strategy/rds.rb +4 -4
- data/lib/chef/provisioning/aws_driver/tagging_strategy/s3.rb +1 -1
- data/lib/chef/provisioning/aws_driver/version.rb +1 -1
- data/lib/chef/resource/aws_auto_scaling_group.rb +2 -2
- data/lib/chef/resource/aws_cache_cluster.rb +4 -4
- data/lib/chef/resource/aws_cache_replication_group.rb +3 -3
- data/lib/chef/resource/aws_cache_subnet_group.rb +4 -4
- data/lib/chef/resource/aws_cloudsearch_domain.rb +1 -1
- data/lib/chef/resource/aws_cloudwatch_alarm.rb +1 -1
- data/lib/chef/resource/aws_dhcp_options.rb +10 -3
- data/lib/chef/resource/aws_ebs_volume.rb +10 -4
- data/lib/chef/resource/aws_eip_address.rb +4 -4
- data/lib/chef/resource/aws_elasticsearch_domain.rb +1 -1
- data/lib/chef/resource/aws_iam_role.rb +1 -1
- data/lib/chef/resource/aws_internet_gateway.rb +11 -4
- data/lib/chef/resource/aws_key_pair.rb +4 -3
- data/lib/chef/resource/aws_launch_configuration.rb +5 -4
- data/lib/chef/resource/aws_load_balancer.rb +14 -3
- data/lib/chef/resource/aws_nat_gateway.rb +2 -2
- data/lib/chef/resource/aws_network_acl.rb +10 -10
- data/lib/chef/resource/aws_network_interface.rb +12 -6
- data/lib/chef/resource/aws_rds_parameter_group.rb +6 -6
- data/lib/chef/resource/aws_rds_subnet_group.rb +4 -5
- data/lib/chef/resource/aws_route53_record_set.rb +1 -1
- data/lib/chef/resource/aws_route_table.rb +1 -1
- data/lib/chef/resource/aws_s3_bucket.rb +3 -2
- data/lib/chef/resource/aws_security_group.rb +6 -6
- data/lib/chef/resource/aws_server_certificate.rb +4 -5
- data/lib/chef/resource/aws_sns_topic.rb +4 -4
- data/lib/chef/resource/aws_sqs_queue.rb +3 -3
- data/lib/chef/resource/aws_subnet.rb +5 -5
- data/lib/chef/resource/aws_vpc.rb +12 -6
- data/lib/chef/resource/aws_vpc_peering_connection.rb +2 -2
- data/spec/aws_support.rb +12 -9
- data/spec/aws_support/deep_matcher/match_values_failure_messages.rb +15 -5
- data/spec/integration/aws_dhcp_options_spec.rb +7 -7
- data/spec/integration/aws_ebs_volume_spec.rb +1 -1
- data/spec/integration/aws_internet_gateway_spec.rb +19 -18
- data/spec/integration/aws_key_pair_spec.rb +1 -1
- data/spec/integration/aws_nat_gateway_spec.rb +3 -6
- data/spec/integration/aws_network_acl_spec.rb +19 -11
- data/spec/integration/aws_network_interface_spec.rb +26 -20
- data/spec/integration/aws_rds_instance_spec.rb +6 -7
- data/spec/integration/aws_rds_subnet_group_spec.rb +6 -6
- data/spec/integration/aws_route53_hosted_zone_spec.rb +1 -1
- data/spec/integration/aws_s3_bucket_spec.rb +1 -2
- data/spec/integration/aws_security_group_spec.rb +272 -198
- data/spec/integration/aws_server_certificate_spec.rb +60 -78
- data/spec/integration/aws_subnet_spec.rb +8 -4
- data/spec/integration/aws_vpc_spec.rb +29 -23
- data/spec/integration/machine_spec.rb +1 -1
- data/spec/unit/chef/provisioning/aws_driver/credentials_spec.rb +13 -0
- data/spec/unit/chef/provisioning/aws_driver/driver_spec.rb +1 -1
- data/spec/unit/chef/provisioning/aws_driver/route53_spec.rb +1 -1
- metadata +5 -20
- data/spec/persistence_file.txt +0 -220
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: be58e21bd868bb850a868eb9e28d8cddbd845c7a
|
|
4
|
+
data.tar.gz: a700bfd36411280a8b69193c646ff9d413abe911
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3020304e7089b18d519ea75b9fc537174af9b553733d12d1a572bca11433184851da1e7aa1eda5f5ec2f9e0e4c786a80a1238ee7fd9ea7ab0dab9df0ce5e3be4
|
|
7
|
+
data.tar.gz: a10dac39f023c3fc0bc6ddc5ec7d9c53bc89206d140f44815e86e5853df4f4da8cd819e2a550cd5b0dafe298e851727335505b71bad7d61171c828842f1312ce
|
data/README.md
CHANGED
|
@@ -305,7 +305,7 @@ The `AWSProvider` class will automatically try to call `converge_tags` when runn
|
|
|
305
305
|
def aws_tagger
|
|
306
306
|
@aws_tagger ||= begin
|
|
307
307
|
rds_strategy = Chef::Provisioning::AWSDriver::TaggingStrategy::RDS.new(
|
|
308
|
-
new_resource.driver.rds
|
|
308
|
+
new_resource.driver.rds,
|
|
309
309
|
construct_arn(new_resource),
|
|
310
310
|
new_resource.aws_tags
|
|
311
311
|
)
|
|
@@ -17,7 +17,6 @@ Gem::Specification.new do |s|
|
|
|
17
17
|
|
|
18
18
|
s.add_dependency 'chef-provisioning', '>= 1.0', '< 3.0'
|
|
19
19
|
|
|
20
|
-
s.add_dependency 'aws-sdk-v1', '>= 1.59.0'
|
|
21
20
|
s.add_dependency 'aws-sdk', ['>= 2.2.18', '< 3.0']
|
|
22
21
|
s.add_dependency 'retryable', '~> 2.0', '>= 2.0.1'
|
|
23
22
|
s.add_dependency 'ubuntu_ami', '~> 0.4', '>= 0.4.1'
|
|
@@ -14,16 +14,18 @@ class Chef::Provider::AwsAutoScalingGroup < Chef::Provisioning::AWSDriver::AWSPr
|
|
|
14
14
|
options = desired_options.dup
|
|
15
15
|
options[:min_size] ||= 1
|
|
16
16
|
options[:max_size] ||= 1
|
|
17
|
+
options[:auto_scaling_group_name] = new_resource.name
|
|
18
|
+
options[:launch_configuration_name] = new_resource.launch_configuration if new_resource.launch_configuration
|
|
19
|
+
options[:load_balancer_names] = new_resource.load_balancers if new_resource.load_balancers
|
|
17
20
|
|
|
18
|
-
aws_obj = new_resource.driver.
|
|
19
|
-
new_resource.name, options)
|
|
21
|
+
aws_obj = new_resource.driver.auto_scaling_resource.create_group(options)
|
|
20
22
|
|
|
21
23
|
new_resource.scaling_policies.each do |policy_name, policy|
|
|
22
|
-
aws_obj.
|
|
24
|
+
aws_obj.put_scaling_policy(policy_name: policy_name, adjustment_type: policy[:adjustment_type], scaling_adjustment: policy[:scaling_adjustment])
|
|
23
25
|
end
|
|
24
26
|
|
|
25
27
|
new_resource.notification_configurations.each do |config|
|
|
26
|
-
aws_obj.
|
|
28
|
+
aws_obj.client.put_notification_configuration(auto_scaling_group_name: aws_obj.name, topic_arn: config[:topic], notification_types: config[:types])
|
|
27
29
|
end
|
|
28
30
|
|
|
29
31
|
aws_obj
|
|
@@ -36,14 +38,15 @@ class Chef::Provider::AwsAutoScalingGroup < Chef::Provisioning::AWSDriver::AWSPr
|
|
|
36
38
|
|
|
37
39
|
def destroy_aws_object(group)
|
|
38
40
|
converge_by "delete Auto Scaling group #{new_resource.name} in #{region}" do
|
|
39
|
-
group.delete
|
|
41
|
+
group.delete(force_delete: true)
|
|
42
|
+
group.wait_until_not_exists
|
|
40
43
|
end
|
|
41
44
|
end
|
|
42
45
|
|
|
43
46
|
def desired_options
|
|
44
47
|
@desired_options ||= begin
|
|
45
48
|
options = new_resource.options.dup
|
|
46
|
-
%w(
|
|
49
|
+
%w( min_size max_size availability_zones desired_capacity ).each do |var|
|
|
47
50
|
var = var.to_sym
|
|
48
51
|
value = new_resource.public_send(var)
|
|
49
52
|
options[var] = value if value
|
|
@@ -14,18 +14,24 @@ class Chef::Provider::AwsDhcpOptions < Chef::Provisioning::AWSDriver::AWSProvide
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
converge_by "create DHCP options #{new_resource.name} in #{region}" do
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
create_dhcp_options options
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def create_dhcp_options options
|
|
22
|
+
options = options.map{|k,v| {key: k.to_s.gsub('_', '-'), values: Array(v).map(&:to_s)}}
|
|
23
|
+
ec2_resource = ::Aws::EC2::Resource.new(new_resource.driver.ec2)
|
|
24
|
+
dhcp_options = ec2_resource.create_dhcp_options({dhcp_configurations: options})
|
|
25
|
+
retry_with_backoff(::Aws::EC2::Errors::InvalidDhcpOptionIDNotFound) do
|
|
26
|
+
dhcp_options.create_tags({tags: [{key: "Name", value: new_resource.name}]})
|
|
22
27
|
end
|
|
28
|
+
dhcp_options
|
|
23
29
|
end
|
|
24
30
|
|
|
25
31
|
def update_aws_object(dhcp_options)
|
|
26
32
|
# Verify unmodifiable attributes of existing dhcp_options
|
|
27
|
-
config = dhcp_options.
|
|
28
|
-
differing_options = desired_options.select { |name, value| config[name] != value }
|
|
33
|
+
config = dhcp_options.data.to_h[:dhcp_configurations].map{|a|{a[:key].gsub('-', '_').to_sym => a[:values].map{|k|k[:value]} }}.reduce Hash.new, :merge
|
|
34
|
+
differing_options = desired_options.select { |name, value| config[name] != Array(value).map(&:to_s) }
|
|
29
35
|
if !differing_options.empty?
|
|
30
36
|
old_dhcp_options = dhcp_options
|
|
31
37
|
# Report what we are trying to change ...
|
|
@@ -36,14 +42,18 @@ class Chef::Provider::AwsDhcpOptions < Chef::Provisioning::AWSDriver::AWSProvide
|
|
|
36
42
|
|
|
37
43
|
# create new dhcp_options
|
|
38
44
|
if action_handler.should_perform_actions
|
|
39
|
-
dhcp_options =
|
|
45
|
+
dhcp_options = create_dhcp_options(config.merge(desired_options))
|
|
40
46
|
end
|
|
41
47
|
action_handler.report_progress "create DHCP options #{dhcp_options.id} with new attributes in #{region}"
|
|
42
48
|
|
|
43
49
|
# attach dhcp_options to existing vpcs
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
ec2_resource = ::Aws::EC2::Resource.new(new_resource.driver.ec2)
|
|
51
|
+
ec2_resource.vpcs.each do |vpc|
|
|
52
|
+
if vpc.dhcp_options_id == old_dhcp_options.id
|
|
53
|
+
dhcp_options.associate_with_vpc({
|
|
54
|
+
dry_run: false,
|
|
55
|
+
vpc_id: vpc.id, # required
|
|
56
|
+
})
|
|
47
57
|
end
|
|
48
58
|
end
|
|
49
59
|
|
|
@@ -39,9 +39,9 @@ class Chef::Provider::AwsEbsVolume < Chef::Provisioning::AWSDriver::AWSProvider
|
|
|
39
39
|
def create_aws_object
|
|
40
40
|
volume = nil
|
|
41
41
|
converge_by "create #{new_resource} in #{region}" do
|
|
42
|
-
volume = new_resource.driver.
|
|
43
|
-
retry_with_backoff(
|
|
44
|
-
volume.tags[
|
|
42
|
+
volume = new_resource.driver.ec2_resource.create_volume(initial_options)
|
|
43
|
+
retry_with_backoff(::Aws::EC2::Errors::InvalidVolumeNotFound) do
|
|
44
|
+
new_resource.driver.ec2_resource.create_tags(resources: [volume.volume_id],tags: [{key: "Name", value: new_resource.name}])
|
|
45
45
|
end
|
|
46
46
|
volume
|
|
47
47
|
end
|
|
@@ -54,8 +54,8 @@ class Chef::Provider::AwsEbsVolume < Chef::Provisioning::AWSDriver::AWSProvider
|
|
|
54
54
|
|
|
55
55
|
def update_aws_object(volume)
|
|
56
56
|
if initial_options.has_key?(:availability_zone)
|
|
57
|
-
if availability_zone != volume.
|
|
58
|
-
raise "#{new_resource}.availability_zone is #{availability_zone}, but actual volume has availability_zone_name set to #{volume.
|
|
57
|
+
if availability_zone != volume.availability_zone
|
|
58
|
+
raise "#{new_resource}.availability_zone is #{availability_zone}, but actual volume has availability_zone_name set to #{volume.availability_zone}. Cannot be modified!"
|
|
59
59
|
end
|
|
60
60
|
end
|
|
61
61
|
if initial_options.has_key?(:size)
|
|
@@ -63,9 +63,9 @@ class Chef::Provider::AwsEbsVolume < Chef::Provisioning::AWSDriver::AWSProvider
|
|
|
63
63
|
raise "#{new_resource}.size is #{new_resource.size}, but actual volume has size set to #{volume.size}. Cannot be modified!"
|
|
64
64
|
end
|
|
65
65
|
end
|
|
66
|
-
if initial_options.has_key?(:
|
|
67
|
-
if initial_options[:
|
|
68
|
-
raise "#{new_resource}.snapshot is #{new_resource.snapshot}, but actual volume has snapshot set to #{volume.
|
|
66
|
+
if initial_options.has_key?(:snapshot_id)
|
|
67
|
+
if initial_options[:snapshot_id] != volume.snapshot_id
|
|
68
|
+
raise "#{new_resource}.snapshot is #{new_resource.snapshot}, but actual volume has snapshot set to #{volume.snapshot_id}. Cannot be modified!"
|
|
69
69
|
end
|
|
70
70
|
end
|
|
71
71
|
if initial_options.has_key?(:iops)
|
|
@@ -74,7 +74,7 @@ class Chef::Provider::AwsEbsVolume < Chef::Provisioning::AWSDriver::AWSProvider
|
|
|
74
74
|
end
|
|
75
75
|
end
|
|
76
76
|
if initial_options.has_key?(:volume_type)
|
|
77
|
-
if initial_options[:volume_type] != volume.
|
|
77
|
+
if initial_options[:volume_type] != volume.volume_type
|
|
78
78
|
raise "#{new_resource}.volume_type is #{new_resource.volume_type}, but actual volume has type set to #{volume.type}. Cannot be modified!"
|
|
79
79
|
end
|
|
80
80
|
end
|
|
@@ -86,7 +86,7 @@ class Chef::Provider::AwsEbsVolume < Chef::Provisioning::AWSDriver::AWSProvider
|
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
def destroy_aws_object(volume)
|
|
89
|
-
detach(volume) if volume.
|
|
89
|
+
detach(volume) if volume.state == "in-use"
|
|
90
90
|
delete(volume)
|
|
91
91
|
end
|
|
92
92
|
|
|
@@ -119,20 +119,20 @@ class Chef::Provider::AwsEbsVolume < Chef::Provisioning::AWSDriver::AWSProvider
|
|
|
119
119
|
end
|
|
120
120
|
|
|
121
121
|
def update_attachment(volume)
|
|
122
|
-
status = volume.
|
|
122
|
+
status = new_resource.driver.ec2_resource.volume(volume.id).state
|
|
123
123
|
#
|
|
124
124
|
# If we were told to attach the volume to a machine, do so
|
|
125
125
|
#
|
|
126
|
-
if expected_instance.is_a?(
|
|
126
|
+
if expected_instance.is_a?(::Aws::EC2::Instance) || expected_instance.is_a?(::Aws::EC2::Instance)
|
|
127
127
|
case status
|
|
128
|
-
when
|
|
128
|
+
when "in-use"
|
|
129
129
|
# We don't want to attempt to reattach to the same instance and device
|
|
130
130
|
attachment = current_attachment(volume)
|
|
131
|
-
if attachment.
|
|
131
|
+
if attachment.instance_id != expected_instance.id || attachment.device != new_resource.device
|
|
132
132
|
detach(volume)
|
|
133
133
|
attach(volume)
|
|
134
134
|
end
|
|
135
|
-
when
|
|
135
|
+
when "available"
|
|
136
136
|
attach(volume)
|
|
137
137
|
when nil
|
|
138
138
|
raise VolumeNotFoundError.new(new_resource)
|
|
@@ -147,7 +147,7 @@ class Chef::Provider::AwsEbsVolume < Chef::Provisioning::AWSDriver::AWSProvider
|
|
|
147
147
|
case status
|
|
148
148
|
when nil
|
|
149
149
|
Chef::Log.warn VolumeNotFoundError.new(new_resource)
|
|
150
|
-
when
|
|
150
|
+
when "in-use"
|
|
151
151
|
detach(volume)
|
|
152
152
|
end
|
|
153
153
|
end
|
|
@@ -155,23 +155,24 @@ class Chef::Provider::AwsEbsVolume < Chef::Provisioning::AWSDriver::AWSProvider
|
|
|
155
155
|
end
|
|
156
156
|
|
|
157
157
|
def wait_for_volume_status(volume, expected_status)
|
|
158
|
-
initial_status = volume.status
|
|
159
158
|
log_callback = proc {
|
|
160
159
|
Chef::Log.info("waiting for #{new_resource} status to change to #{expected_status}...")
|
|
161
160
|
}
|
|
162
161
|
|
|
163
|
-
Retryable.retryable(:tries =>
|
|
164
|
-
|
|
162
|
+
Retryable.retryable(:tries => 120, :sleep => 2, :on => VolumeStatusTimeoutError, :ensure => log_callback) do
|
|
163
|
+
status = new_resource.driver.ec2_resource.volume(volume.id).state
|
|
164
|
+
expected_status = "in-use" if expected_status.to_s.eql?("in_use")
|
|
165
|
+
raise VolumeStatusTimeoutError.new(new_resource, status, expected_status) if status != expected_status.to_s
|
|
165
166
|
end
|
|
166
167
|
end
|
|
167
168
|
|
|
168
169
|
def detach(volume)
|
|
169
170
|
attachment = current_attachment(volume)
|
|
170
|
-
instance = attachment.
|
|
171
|
+
instance = attachment.instance_id
|
|
171
172
|
device = attachment.device
|
|
172
173
|
|
|
173
|
-
converge_by "detach #{new_resource} from #{new_resource.machine} (#{instance
|
|
174
|
-
volume.
|
|
174
|
+
converge_by "detach #{new_resource} from #{new_resource.machine} (#{instance})" do
|
|
175
|
+
volume.detach_from_instance(instance_id: instance, device: device)
|
|
175
176
|
end
|
|
176
177
|
|
|
177
178
|
converge_by "wait for #{new_resource} to detach" do
|
|
@@ -182,7 +183,7 @@ class Chef::Provider::AwsEbsVolume < Chef::Provisioning::AWSDriver::AWSProvider
|
|
|
182
183
|
|
|
183
184
|
def attach(volume)
|
|
184
185
|
converge_by "attach #{new_resource} to #{new_resource.machine} (#{expected_instance.instance_id}) to device #{new_resource.device}" do
|
|
185
|
-
volume.
|
|
186
|
+
volume.attach_to_instance(instance_id: expected_instance.id, device: new_resource.device)
|
|
186
187
|
end
|
|
187
188
|
|
|
188
189
|
converge_by "wait for #{new_resource} to attach" do
|
|
@@ -206,7 +207,8 @@ class Chef::Provider::AwsEbsVolume < Chef::Provisioning::AWSDriver::AWSProvider
|
|
|
206
207
|
}
|
|
207
208
|
|
|
208
209
|
Retryable.retryable(:tries => 30, :sleep => 2, :on => VolumeStatusTimeoutError, :ensure => log_callback) do
|
|
209
|
-
|
|
210
|
+
result = new_resource.driver.ec2_resource.volume(volume.id) if volume.id
|
|
211
|
+
raise VolumeStatusTimeoutError.new(new_resource, "exists", "deleted") if new_resource.exists?(result)
|
|
210
212
|
end
|
|
211
213
|
volume
|
|
212
214
|
end
|
|
@@ -20,32 +20,32 @@ class Chef::Provider::AwsEipAddress < Chef::Provisioning::AWSDriver::AWSProvider
|
|
|
20
20
|
converge_by "create Elastic IP address in #{region}" do
|
|
21
21
|
associate_to_vpc = new_resource.associate_to_vpc
|
|
22
22
|
if associate_to_vpc.nil?
|
|
23
|
-
if desired_instance.is_a?(
|
|
23
|
+
if desired_instance.is_a?(::Aws::EC2::Instance) || desired_instance.is_a?(::Aws::EC2::Instance)
|
|
24
24
|
associate_to_vpc = !!desired_instance.vpc_id
|
|
25
25
|
Chef::Log.debug "Since associate_to_vpc is not specified and instance #{new_resource.machine} (#{desired_instance.id}) and #{associate_to_vpc ? "is" : "is not"} in a VPC, setting associate_to_vpc to #{associate_to_vpc}."
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
|
-
new_resource.driver.ec2.
|
|
28
|
+
new_resource.driver.ec2.allocate_address vpc: new_resource.associate_to_vpc
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def update_aws_object(elastic_ip)
|
|
33
33
|
if !new_resource.associate_to_vpc.nil?
|
|
34
|
-
if
|
|
35
|
-
raise "#{new_resource
|
|
34
|
+
if new_resource.associate_to_vpc != (elastic_ip.domain == "vpc")
|
|
35
|
+
raise "#{new_resource}.associate_to_vpc = #{new_resource.associate_to_vpc}, but actual IP address has vpc? set to #{(elastic_ip.domain == 'vpc')}. Cannot be modified!"
|
|
36
36
|
end
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
def destroy_aws_object(elastic_ip)
|
|
41
41
|
#if it's attached to something in a vpc, disassociate first
|
|
42
|
-
if elastic_ip.instance_id
|
|
42
|
+
if !elastic_ip.instance_id.nil? && elastic_ip.domain == "vpc"
|
|
43
43
|
converge_by "dissociate Elastic IP address #{new_resource.name} (#{elastic_ip.public_ip}) from #{elastic_ip.instance_id}" do
|
|
44
|
-
elastic_ip.
|
|
44
|
+
new_resource.driver.ec2.disassociate_address public_ip: elastic_ip.public_ip
|
|
45
45
|
end
|
|
46
46
|
end
|
|
47
47
|
converge_by "delete Elastic IP address #{new_resource.name} (#{elastic_ip.public_ip}) in #{region}" do
|
|
48
|
-
elastic_ip.
|
|
48
|
+
new_resource.driver.ec2.release_address allocation_id: elastic_ip.allocation_id
|
|
49
49
|
end
|
|
50
50
|
end
|
|
51
51
|
|
|
@@ -66,10 +66,10 @@ class Chef::Provider::AwsEipAddress < Chef::Provisioning::AWSDriver::AWSProvider
|
|
|
66
66
|
#
|
|
67
67
|
# If we were told to associate the IP to a machine, do so
|
|
68
68
|
#
|
|
69
|
-
if desired_instance.is_a?(
|
|
69
|
+
if desired_instance.is_a?(::Aws::EC2::Instance) || desired_instance.is_a?(::Aws::EC2::Instance)
|
|
70
70
|
if desired_instance.id != elastic_ip.instance_id
|
|
71
71
|
converge_by "associate Elastic IP address #{new_resource.name} (#{elastic_ip.public_ip}) with #{new_resource.machine} (#{desired_instance.id})" do
|
|
72
|
-
|
|
72
|
+
new_resource.driver.ec2.associate_address instance_id: desired_instance.id, allocation_id: elastic_ip.allocation_id
|
|
73
73
|
end
|
|
74
74
|
end
|
|
75
75
|
|
|
@@ -77,13 +77,12 @@ class Chef::Provider::AwsEipAddress < Chef::Provisioning::AWSDriver::AWSProvider
|
|
|
77
77
|
# If we were told to set the association to false, disassociate it.
|
|
78
78
|
#
|
|
79
79
|
else
|
|
80
|
-
if elastic_ip.
|
|
80
|
+
if !(elastic_ip.association_id.nil?)
|
|
81
81
|
converge_by "disassociate Elastic IP address #{new_resource.name} (#{elastic_ip.public_ip}) from #{elastic_ip.instance_id} in #{region}" do
|
|
82
|
-
|
|
82
|
+
new_resource.driver.ec2.disassociate_address public_ip: elastic_ip.public_ip
|
|
83
83
|
end
|
|
84
84
|
end
|
|
85
85
|
end
|
|
86
|
-
|
|
87
86
|
end
|
|
88
87
|
|
|
89
88
|
end
|
|
@@ -12,7 +12,7 @@ class Chef::Provider::AwsImage < Chef::Provisioning::AWSDriver::AWSProvider
|
|
|
12
12
|
unless instance_id
|
|
13
13
|
# This is an old image and doesn't have the tag added - lets try and find it from the block device mapping
|
|
14
14
|
image.block_device_mappings.map do |dev, opts|
|
|
15
|
-
snapshot = new_resource.driver.
|
|
15
|
+
snapshot = new_resource.driver.ec2_resource.snapshot(opts[:snapshot_id])
|
|
16
16
|
desc = snapshot.description
|
|
17
17
|
m = /CreateImage\(([^\)]+)\)/.match(desc)
|
|
18
18
|
if m
|
|
@@ -17,9 +17,10 @@ class Chef::Provider::AwsInternetGateway < Chef::Provisioning::AWSDriver::AWSPro
|
|
|
17
17
|
desired_vpc = Chef::Resource::AwsVpc.get_aws_object(new_resource.vpc, resource: new_resource) if new_resource.vpc
|
|
18
18
|
|
|
19
19
|
converge_by "create internet gateway #{new_resource.name} in region #{region}" do
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
ec2_resource = ::Aws::EC2::Resource.new(new_resource.driver.ec2)
|
|
21
|
+
internet_gateway = ec2_resource.create_internet_gateway
|
|
22
|
+
retry_with_backoff(::Aws::EC2::Errors::InvalidInternetGatewayIDNotFound) do
|
|
23
|
+
internet_gateway.create_tags({tags: [{key: "Name", value: new_resource.name}]})
|
|
23
24
|
end
|
|
24
25
|
|
|
25
26
|
if desired_vpc
|
|
@@ -31,11 +32,15 @@ class Chef::Provider::AwsInternetGateway < Chef::Provisioning::AWSDriver::AWSPro
|
|
|
31
32
|
end
|
|
32
33
|
|
|
33
34
|
def update_aws_object(internet_gateway)
|
|
34
|
-
|
|
35
|
+
ec2_resource = new_resource.driver.ec2.describe_internet_gateways(:internet_gateway_ids=>[internet_gateway.id])
|
|
36
|
+
current_vpc = ec2_resource.internet_gateways.first.attachments.first
|
|
35
37
|
|
|
36
38
|
if new_resource.vpc
|
|
37
39
|
desired_vpc = Chef::Resource::AwsVpc.get_aws_object(new_resource.vpc, resource: new_resource)
|
|
38
|
-
|
|
40
|
+
current_vpc_id = current_vpc.vpc_id unless current_vpc.nil?
|
|
41
|
+
desired_vpc_id = desired_vpc.vpc_id unless desired_vpc.nil?
|
|
42
|
+
if current_vpc_id != desired_vpc_id
|
|
43
|
+
detach_vpc(internet_gateway)
|
|
39
44
|
attach_vpc(desired_vpc, internet_gateway)
|
|
40
45
|
end
|
|
41
46
|
end
|
|
@@ -51,7 +56,7 @@ class Chef::Provider::AwsInternetGateway < Chef::Provisioning::AWSDriver::AWSPro
|
|
|
51
56
|
private
|
|
52
57
|
|
|
53
58
|
def attach_vpc(vpc, desired_gateway)
|
|
54
|
-
if vpc.
|
|
59
|
+
if vpc.internet_gateways.first && vpc.internet_gateways.first != desired_gateway
|
|
55
60
|
current_driver = self.new_resource.driver
|
|
56
61
|
current_chef_server = self.new_resource.chef_server
|
|
57
62
|
Cheffish.inline_resource(self, action) do
|
|
@@ -64,14 +69,17 @@ class Chef::Provider::AwsInternetGateway < Chef::Provisioning::AWSDriver::AWSPro
|
|
|
64
69
|
end
|
|
65
70
|
end
|
|
66
71
|
converge_by "attach vpc #{vpc.id} to #{desired_gateway.id}" do
|
|
67
|
-
desired_gateway.
|
|
72
|
+
desired_gateway.attach_to_vpc(vpc_id: vpc.id)
|
|
68
73
|
end
|
|
69
74
|
end
|
|
70
75
|
|
|
71
76
|
def detach_vpc(internet_gateway)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
77
|
+
ec2_resource = new_resource.driver.ec2.describe_internet_gateways(:internet_gateway_ids=>[internet_gateway.id])
|
|
78
|
+
vpcid = ec2_resource.internet_gateways.first.attachments.first
|
|
79
|
+
vpc_id = vpcid.vpc_id unless vpcid.nil?
|
|
80
|
+
if vpc_id
|
|
81
|
+
converge_by "detach vpc #{vpc_id} from internet gateway #{internet_gateway.id}" do
|
|
82
|
+
internet_gateway.detach_from_vpc(vpc_id: vpc_id)
|
|
75
83
|
end
|
|
76
84
|
end
|
|
77
85
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require 'chef/provider/lwrp_base'
|
|
2
2
|
require 'chef/provisioning/aws_driver/aws_provider'
|
|
3
|
-
require 'aws-sdk
|
|
3
|
+
require 'aws-sdk'
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
class Chef::Provider::AwsKeyPair < Chef::Provisioning::AWSDriver::AWSProvider
|
|
@@ -13,7 +13,7 @@ class Chef::Provider::AwsKeyPair < Chef::Provisioning::AWSDriver::AWSProvider
|
|
|
13
13
|
action :destroy do
|
|
14
14
|
if current_resource_exists?
|
|
15
15
|
converge_by "delete AWS key pair #{new_resource.name} on region #{region}" do
|
|
16
|
-
driver.ec2.
|
|
16
|
+
driver.ec2.delete_key_pair({key_name:new_resource.name})
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
end
|
|
@@ -75,8 +75,8 @@ class Chef::Provider::AwsKeyPair < Chef::Provisioning::AWSDriver::AWSProvider
|
|
|
75
75
|
if !new_fingerprints.any? { |f| compare_public_key f }
|
|
76
76
|
if new_resource.allow_overwrite
|
|
77
77
|
converge_by "update #{key_description} to match local key at #{new_resource.private_key_path}" do
|
|
78
|
-
driver.ec2.
|
|
79
|
-
driver.ec2.
|
|
78
|
+
driver.ec2.delete_key_pair({key_name:new_resource.name})
|
|
79
|
+
driver.ec2.import_key_pair({key_name: new_resource.name, public_key_material: Cheffish::KeyFormatter.encode(desired_key, :format => :openssh)})
|
|
80
80
|
end
|
|
81
81
|
else
|
|
82
82
|
raise "#{key_description} with fingerprint #{@current_fingerprint} does not match local key fingerprint(s) #{new_fingerprints}, and allow_overwrite is false!"
|
|
@@ -88,7 +88,7 @@ class Chef::Provider::AwsKeyPair < Chef::Provisioning::AWSDriver::AWSProvider
|
|
|
88
88
|
|
|
89
89
|
# Create key
|
|
90
90
|
converge_by "create #{key_description} from local key at #{new_resource.private_key_path}" do
|
|
91
|
-
driver.ec2.
|
|
91
|
+
driver.ec2.import_key_pair({key_name: new_resource.name, public_key_material: Cheffish::KeyFormatter.encode(desired_key, :format => :openssh)})
|
|
92
92
|
end
|
|
93
93
|
end
|
|
94
94
|
end
|
|
@@ -169,7 +169,7 @@ class Chef::Provider::AwsKeyPair < Chef::Provisioning::AWSDriver::AWSProvider
|
|
|
169
169
|
|
|
170
170
|
current_key_pair = new_resource.aws_object
|
|
171
171
|
if current_key_pair
|
|
172
|
-
@current_fingerprint = current_key_pair.
|
|
172
|
+
@current_fingerprint = current_key_pair.key_fingerprint
|
|
173
173
|
else
|
|
174
174
|
current_resource.action [:destroy]
|
|
175
175
|
end
|
|
@@ -10,14 +10,12 @@ class Chef::Provider::AwsLaunchConfiguration < Chef::Provisioning::AWSDriver::AW
|
|
|
10
10
|
image_id = Chef::Resource::AwsImage.get_aws_object_id(new_resource.image, resource: new_resource)
|
|
11
11
|
instance_type = new_resource.instance_type || new_resource.driver.default_instance_type
|
|
12
12
|
options = AWSResource.lookup_options(new_resource.options || options, resource: new_resource)
|
|
13
|
+
options[:launch_configuration_name] = new_resource.name if new_resource.name
|
|
14
|
+
options[:image_id] = image_id
|
|
15
|
+
options[:instance_type] = instance_type
|
|
13
16
|
|
|
14
17
|
converge_by "create launch configuration #{new_resource.name} in #{region}" do
|
|
15
|
-
new_resource.driver.
|
|
16
|
-
new_resource.name,
|
|
17
|
-
image_id,
|
|
18
|
-
instance_type,
|
|
19
|
-
options
|
|
20
|
-
)
|
|
18
|
+
new_resource.driver.auto_scaling_client.create_launch_configuration(options)
|
|
21
19
|
end
|
|
22
20
|
end
|
|
23
21
|
|
|
@@ -25,7 +23,7 @@ class Chef::Provider::AwsLaunchConfiguration < Chef::Provisioning::AWSDriver::AW
|
|
|
25
23
|
if new_resource.image
|
|
26
24
|
image_id = Chef::Resource::AwsImage.get_aws_object_id(new_resource.image, resource: new_resource)
|
|
27
25
|
if image_id != launch_configuration.image_id
|
|
28
|
-
raise "#{new_resource.to_s}.image = #{new_resource.image}
|
|
26
|
+
raise "#{new_resource.to_s}.image = #{new_resource.image}, but actual launch configuration has image set to #{launch_configuration.image_id}. Cannot be modified!"
|
|
29
27
|
end
|
|
30
28
|
end
|
|
31
29
|
if new_resource.instance_type
|
|
@@ -41,8 +39,8 @@ class Chef::Provider::AwsLaunchConfiguration < Chef::Provisioning::AWSDriver::AW
|
|
|
41
39
|
# TODO add a timeout here.
|
|
42
40
|
# TODO is InUse really a status guaranteed to go away??
|
|
43
41
|
begin
|
|
44
|
-
launch_configuration.
|
|
45
|
-
rescue
|
|
42
|
+
new_resource.driver.auto_scaling_client.delete_launch_configuration(launch_configuration_name: launch_configuration.launch_configuration_name)
|
|
43
|
+
rescue ::Aws::AutoScaling::Errors::ResourceInUse
|
|
46
44
|
sleep 5
|
|
47
45
|
retry
|
|
48
46
|
end
|