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,11 +1,9 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "aws_resource"
|
2
2
|
|
3
3
|
module Chef::Provisioning::AWSDriver
|
4
|
-
class AWSRDSResource < AWSResource
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
class AWSRDSResource < AWSResource
|
5
|
+
def rds_tagging_type
|
6
|
+
raise "You must add the RDS resource type lookup from http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_Tagging.html#USER_Tagging.ARN"
|
7
|
+
end
|
8
8
|
end
|
9
|
-
|
10
|
-
end
|
11
9
|
end
|
@@ -1,212 +1,209 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "aws-sdk"
|
2
|
+
require "chef/provisioning/aws_driver/super_lwrp"
|
3
|
+
require "chef/provisioning/chef_managed_entry_store"
|
4
4
|
# Enough resources will eventually require this that we put 1 require in here
|
5
|
-
require
|
5
|
+
require "chef/provisioning/aws_driver/aws_taggable"
|
6
6
|
|
7
7
|
# Common AWS resource - contains metadata that all AWS resources will need
|
8
8
|
class Chef
|
9
|
-
module Provisioning
|
10
|
-
module AWSDriver
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
# Backwards compatibility for action :destroy
|
25
|
-
def action(*args)
|
26
|
-
if args == [ :delete ]
|
27
|
-
super(:destroy)
|
28
|
-
else
|
29
|
-
super
|
30
|
-
end
|
31
|
-
end
|
9
|
+
module Provisioning
|
10
|
+
module AWSDriver
|
11
|
+
class AWSResource < Chef::Provisioning::AWSDriver::SuperLWRP
|
12
|
+
actions :create, :destroy, :purge, :nothing
|
13
|
+
default_action :create
|
14
|
+
|
15
|
+
def initialize(name, run_context = nil)
|
16
|
+
name = name.public_send(self.class.aws_sdk_class_id) if name.is_a?(self.class.aws_sdk_class)
|
17
|
+
super
|
18
|
+
if run_context
|
19
|
+
driver run_context.chef_provisioning.current_driver
|
20
|
+
chef_server run_context.cheffish.current_chef_server
|
21
|
+
end
|
22
|
+
end
|
32
23
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
24
|
+
# Backwards compatibility for action :destroy
|
25
|
+
def action(*args)
|
26
|
+
if args == [:delete]
|
27
|
+
super(:destroy)
|
28
|
+
else
|
29
|
+
super
|
30
|
+
end
|
31
|
+
end
|
40
32
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
value
|
49
|
-
else
|
50
|
-
run_context.chef_provisioning.driver_for(value)
|
51
|
-
end
|
52
|
-
end)
|
53
|
-
|
54
|
-
#
|
55
|
-
# The Chef server on which any IDs should be looked up.
|
56
|
-
#
|
57
|
-
attribute :chef_server, kind_of: Hash
|
58
|
-
|
59
|
-
#
|
60
|
-
# The managed entry store.
|
61
|
-
#
|
62
|
-
attribute :managed_entry_store, kind_of: Chef::Provisioning::ManagedEntryStore,
|
63
|
-
default: lazy { Chef::Provisioning::ChefManagedEntryStore.new(chef_server) }
|
64
|
-
|
65
|
-
#
|
66
|
-
# Get the current AWS object. This should return the aws_object even if it has
|
67
|
-
# a status like 'deleted' or 'inactive'. If there is an aws_object, we return it.
|
68
|
-
# Callers will need to check the status if they care.
|
69
|
-
#
|
70
|
-
def aws_object
|
71
|
-
raise NotImplementedError, :aws_object
|
72
|
-
end
|
33
|
+
# In Chef < 12.4 we need to define this method. In > 12.4 this method is
|
34
|
+
# already defined for us so we don't need to overwrite it.
|
35
|
+
unless defined?(:action=)
|
36
|
+
def action=(value)
|
37
|
+
action(value)
|
38
|
+
end
|
39
|
+
end
|
73
40
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
41
|
+
#
|
42
|
+
# The desired driver.
|
43
|
+
#
|
44
|
+
attribute :driver, kind_of: Chef::Provisioning::Driver,
|
45
|
+
coerce: (proc do |value|
|
46
|
+
case value
|
47
|
+
when nil, Chef::Provisioning::Driver
|
48
|
+
value
|
49
|
+
else
|
50
|
+
run_context.chef_provisioning.driver_for(value)
|
51
|
+
end
|
52
|
+
end)
|
53
|
+
|
54
|
+
#
|
55
|
+
# The Chef server on which any IDs should be looked up.
|
56
|
+
#
|
57
|
+
attribute :chef_server, kind_of: Hash
|
58
|
+
|
59
|
+
#
|
60
|
+
# The managed entry store.
|
61
|
+
#
|
62
|
+
attribute :managed_entry_store, kind_of: Chef::Provisioning::ManagedEntryStore,
|
63
|
+
default: lazy { Chef::Provisioning::ChefManagedEntryStore.new(chef_server) }
|
64
|
+
|
65
|
+
#
|
66
|
+
# Get the current AWS object. This should return the aws_object even if it has
|
67
|
+
# a status like 'deleted' or 'inactive'. If there is an aws_object, we return it.
|
68
|
+
# Callers will need to check the status if they care.
|
69
|
+
#
|
70
|
+
def aws_object
|
71
|
+
raise NotImplementedError, :aws_object
|
72
|
+
end
|
80
73
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
# For example, `load_balancer_options` is passed into `lookup_options`, and if
|
86
|
-
# it looks like this: `{ subnets: `[ 'subnet1', 'subnet2' ] }`, then
|
87
|
-
# `AWSResource.lookup_options` will translate each ID with
|
88
|
-
# `AwsSubnet.get_aws_object('subnet1')`, which supports Chef names
|
89
|
-
# (`mysubnet`) as well as AWS subnet Ids (`subnet-1234abcd`) or AWS objects
|
90
|
-
# (`::Aws::EC2::Subnet`).
|
91
|
-
#
|
92
|
-
# Keys that represent non-AWS-objects (such as `timeout`) are left alone.
|
93
|
-
#
|
94
|
-
def self.lookup_options(options = Hash.new, **handler_options)
|
95
|
-
options = options.dup
|
96
|
-
options.each do |name, value|
|
97
|
-
if name.to_s.end_with?('s')
|
98
|
-
handler_name = :"#{name[0..-2]}"
|
99
|
-
if aws_option_handlers[handler_name]
|
100
|
-
options[name] = [options[name]].flatten.map { |value| aws_option_handlers[handler_name].get_aws_object_id(value, **handler_options) }
|
74
|
+
def aws_object_id
|
75
|
+
@aws_object_id ||= begin
|
76
|
+
o = aws_object
|
77
|
+
o.public_send(self.class.aws_sdk_class_id) if o
|
101
78
|
end
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
79
|
+
end
|
80
|
+
|
81
|
+
#
|
82
|
+
# Look up an AWS options list, translating standard names using the appropriate
|
83
|
+
# classes.
|
84
|
+
#
|
85
|
+
# For example, `load_balancer_options` is passed into `lookup_options`, and if
|
86
|
+
# it looks like this: `{ subnets: `[ 'subnet1', 'subnet2' ] }`, then
|
87
|
+
# `AWSResource.lookup_options` will translate each ID with
|
88
|
+
# `AwsSubnet.get_aws_object('subnet1')`, which supports Chef names
|
89
|
+
# (`mysubnet`) as well as AWS subnet Ids (`subnet-1234abcd`) or AWS objects
|
90
|
+
# (`::Aws::EC2::Subnet`).
|
91
|
+
#
|
92
|
+
# Keys that represent non-AWS-objects (such as `timeout`) are left alone.
|
93
|
+
#
|
94
|
+
def self.lookup_options(options = {}, **handler_options)
|
95
|
+
options = options.dup
|
96
|
+
options.each do |name, value|
|
97
|
+
if name.to_s.end_with?("s")
|
98
|
+
handler_name = :"#{name[0..-2]}"
|
99
|
+
if aws_option_handlers[handler_name]
|
100
|
+
options[name] = [options[name]].flatten.map { |value| aws_option_handlers[handler_name].get_aws_object_id(value, **handler_options) }
|
101
|
+
end
|
102
|
+
else
|
103
|
+
handler_name = name.to_sym
|
104
|
+
if aws_option_handlers[handler_name]
|
105
|
+
options[handler_name] = aws_option_handlers[handler_name].get_aws_object_id(value, **handler_options)
|
106
|
+
end
|
107
|
+
end
|
106
108
|
end
|
109
|
+
options
|
107
110
|
end
|
108
|
-
end
|
109
|
-
options
|
110
|
-
end
|
111
111
|
|
112
|
-
|
113
|
-
|
112
|
+
def self.get_aws_object(value, resource: nil, run_context: nil, driver: nil, managed_entry_store: nil, required: true)
|
113
|
+
return nil if value.nil?
|
114
114
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
115
|
+
if resource
|
116
|
+
run_context ||= resource.run_context
|
117
|
+
driver ||= resource.driver
|
118
|
+
managed_entry_store ||= resource.managed_entry_store
|
119
|
+
end
|
120
|
+
if value.is_a?(self)
|
121
|
+
resource = value
|
122
|
+
else
|
123
|
+
resource = new(value, run_context)
|
124
|
+
resource.driver driver if driver
|
125
|
+
resource.managed_entry_store managed_entry_store if managed_entry_store
|
126
|
+
end
|
127
127
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
result
|
133
|
-
end
|
128
|
+
result = resource.aws_object
|
129
|
+
raise "#{self}[#{value}] does not exist!" if required && result.nil?
|
130
|
+
result
|
131
|
+
end
|
134
132
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
133
|
+
def self.get_aws_object_id(value, **options)
|
134
|
+
aws_object = get_aws_object(value, **options)
|
135
|
+
aws_object.public_send(aws_sdk_class_id) if aws_object
|
136
|
+
end
|
139
137
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
138
|
+
protected
|
139
|
+
|
140
|
+
# This supports the introduction of the NOT_PASSED chef constant
|
141
|
+
# in chef 12.5
|
142
|
+
# TODO remove when we make 12.5 and higher a dependency
|
143
|
+
NOT_PASSED = Object.new unless defined?(NOT_PASSED)
|
144
|
+
|
145
|
+
def self.aws_sdk_type(sdk_class,
|
146
|
+
option_names: nil,
|
147
|
+
option_name: NOT_PASSED,
|
148
|
+
load_provider: true,
|
149
|
+
id: :name,
|
150
|
+
aws_id_prefix: nil)
|
151
|
+
self.resource_name = convert_to_snake_case(name.split("::")[-1])
|
152
|
+
@aws_sdk_class = sdk_class
|
153
|
+
@aws_sdk_class_id = id
|
154
|
+
@aws_id_prefix = aws_id_prefix
|
155
|
+
|
156
|
+
# Go ahead and require the provider since we're here anyway ...
|
157
|
+
require "chef/provider/#{resource_name}" if load_provider
|
158
|
+
|
159
|
+
option_name = :"#{resource_name[4..-1]}" if option_name == NOT_PASSED
|
160
|
+
@aws_sdk_option_name = option_name
|
161
|
+
|
162
|
+
option_names ||= begin
|
163
|
+
option_names = []
|
164
|
+
option_names << aws_sdk_option_name
|
165
|
+
option_names << :"#{option_name}_#{aws_sdk_class_id}" if aws_sdk_class_id
|
166
|
+
option_names
|
167
|
+
end
|
168
|
+
option_names.each do |option_name|
|
169
|
+
aws_option_handlers[option_name] = self
|
170
|
+
end
|
173
171
|
|
174
|
-
|
175
|
-
|
176
|
-
|
172
|
+
name = self.name.split("::")[-1]
|
173
|
+
eval("Chef::Provisioning::AWSDriver::Resources::#{name} = self", binding, __FILE__, __LINE__)
|
174
|
+
end
|
177
175
|
|
178
|
-
|
179
|
-
|
180
|
-
|
176
|
+
class << self
|
177
|
+
attr_reader :aws_sdk_class
|
178
|
+
end
|
181
179
|
|
182
|
-
|
183
|
-
|
184
|
-
|
180
|
+
class << self
|
181
|
+
attr_reader :aws_sdk_class_id
|
182
|
+
end
|
185
183
|
|
186
|
-
|
187
|
-
|
188
|
-
|
184
|
+
class << self
|
185
|
+
attr_reader :aws_id_prefix
|
186
|
+
end
|
189
187
|
|
190
|
-
|
191
|
-
|
192
|
-
|
188
|
+
class << self
|
189
|
+
attr_reader :aws_sdk_option_name
|
190
|
+
end
|
193
191
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
192
|
+
@@aws_option_handlers = {}
|
193
|
+
def self.aws_option_handlers
|
194
|
+
@@aws_option_handlers
|
195
|
+
end
|
198
196
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
197
|
+
# Add support for aws_id_attribute: true
|
198
|
+
def self.attribute(name, aws_id_attribute: false, **validation_opts)
|
199
|
+
@aws_id_attribute = name if aws_id_attribute
|
200
|
+
super(name, validation_opts)
|
201
|
+
end
|
204
202
|
|
205
|
-
|
206
|
-
|
203
|
+
class << self
|
204
|
+
attr_reader :aws_id_attribute
|
205
|
+
end
|
206
|
+
end
|
207
207
|
end
|
208
208
|
end
|
209
|
-
|
210
|
-
end
|
211
|
-
end
|
212
209
|
end
|
@@ -1,9 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "chef/provisioning/aws_driver/aws_resource"
|
2
|
+
require "chef/provisioning/aws_driver/resources"
|
3
3
|
|
4
4
|
# Common AWS resource - contains metadata that all AWS resources will need
|
5
5
|
class Chef::Provisioning::AWSDriver::AWSResourceWithEntry < Chef::Provisioning::AWSDriver::AWSResource
|
6
|
-
|
7
6
|
#
|
8
7
|
# Dissociate the ID of this object from Chef.
|
9
8
|
#
|
@@ -31,11 +30,9 @@ class Chef::Provisioning::AWSDriver::AWSResourceWithEntry < Chef::Provisioning::
|
|
31
30
|
def save_managed_entry(aws_object, action_handler, existing_entry: nil)
|
32
31
|
if should_have_managed_entry?
|
33
32
|
managed_entry = existing_entry ||
|
34
|
-
|
33
|
+
managed_entry_store.new_entry(self.class.managed_entry_type, name)
|
35
34
|
updated = update_managed_entry(aws_object, managed_entry)
|
36
|
-
if updated || !existing_entry
|
37
|
-
managed_entry.save(action_handler)
|
38
|
-
end
|
35
|
+
managed_entry.save(action_handler) if updated || !existing_entry
|
39
36
|
end
|
40
37
|
end
|
41
38
|
|
@@ -45,11 +42,11 @@ class Chef::Provisioning::AWSDriver::AWSResourceWithEntry < Chef::Provisioning::
|
|
45
42
|
if entry
|
46
43
|
driver = self.driver
|
47
44
|
if entry.driver_url != driver.driver_url
|
48
|
-
# TODO some people don't send us run_context (like Drivers). We might need
|
45
|
+
# TODO: some people don't send us run_context (like Drivers). We might need
|
49
46
|
# to exit early here if the driver_url doesn't match the provided driver.
|
50
47
|
driver = run_context.chef_provisioning.driver_for(entry.driver_url)
|
51
48
|
end
|
52
|
-
[
|
49
|
+
[driver, entry.reference[self.class.managed_entry_id_name], entry]
|
53
50
|
end
|
54
51
|
end
|
55
52
|
end
|
@@ -57,7 +54,7 @@ class Chef::Provisioning::AWSDriver::AWSResourceWithEntry < Chef::Provisioning::
|
|
57
54
|
# Formatted output for logging statements - contains resource type, resource name and aws object id (if available)
|
58
55
|
def to_s
|
59
56
|
id = get_driver_and_id[1]
|
60
|
-
"#{declared_type}[#{@name}] (#{
|
57
|
+
"#{declared_type}[#{@name}] (#{id || 'no AWS object id'})"
|
61
58
|
end
|
62
59
|
|
63
60
|
protected
|
@@ -83,14 +80,17 @@ class Chef::Provisioning::AWSDriver::AWSResourceWithEntry < Chef::Provisioning::
|
|
83
80
|
def get_driver_and_id
|
84
81
|
driver, id, entry = get_id_from_managed_entry
|
85
82
|
# If the value isn't already stored, look up the user-specified public_ip
|
86
|
-
|
87
|
-
|
83
|
+
unless id
|
84
|
+
driver = self.driver
|
85
|
+
id = public_send(self.class.aws_id_attribute)
|
86
|
+
end
|
87
|
+
[driver, id]
|
88
88
|
end
|
89
89
|
|
90
90
|
def self.aws_sdk_type(sdk_class,
|
91
91
|
id: :id,
|
92
92
|
managed_entry_type: nil,
|
93
|
-
managed_entry_id_name:
|
93
|
+
managed_entry_id_name: "id",
|
94
94
|
backcompat_data_bag_name: nil,
|
95
95
|
**options)
|
96
96
|
super(sdk_class, id: id, **options)
|
@@ -101,12 +101,12 @@ class Chef::Provisioning::AWSDriver::AWSResourceWithEntry < Chef::Provisioning::
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
-
|
105
|
-
|
104
|
+
class << self
|
105
|
+
attr_reader :managed_entry_type
|
106
106
|
end
|
107
107
|
|
108
|
-
|
109
|
-
|
108
|
+
class << self
|
109
|
+
attr_reader :managed_entry_id_name
|
110
110
|
end
|
111
111
|
|
112
112
|
def should_have_managed_entry?
|