lib/cfer/cfn/client.rb in cfer-0.4.1 vs lib/cfer/cfn/client.rb in cfer-0.4.2
- old
+ new
@@ -42,11 +42,12 @@
def method_missing(method, *args, &block)
@cfn.send(method, *args, &block)
end
def estimate(stack, options = {})
- response = validate_template(template_body: stack.to_cfn)
+ estimate_options = upload_or_return_template(stack.to_cfn, options)
+ response = validate_template(estimate_options)
estimate_params = []
response.parameters.each do |tmpl_param|
input_param = stack.input_parameters[tmpl_param.parameter_key]
if input_param
@@ -60,20 +61,22 @@
estimate_params << p
end
end
- estimate_response = estimate_template_cost(template_body: stack.to_cfn, parameters: estimate_params)
+ estimate_response = estimate_template_cost(estimate_options.merge(parameters: estimate_params))
estimate_response.url
end
def converge(stack, options = {})
Preconditions.check(@name).is_not_nil
Preconditions.check(stack) { is_not_nil and has_type(Cfer::Core::Stack) }
- response = validate_template(template_body: stack.to_cfn)
+ template_options = upload_or_return_template(stack.to_cfn, options)
+ response = validate_template(template_options)
+
create_params = []
update_params = []
previous_parameters = fetch_parameters rescue nil
@@ -129,11 +132,11 @@
stack_options[:timeout_in_minutes] = options[:timeout] if options[:timeout]
stack_options.merge! parse_stack_policy(:stack_policy, options[:stack_policy])
stack_options.merge! parse_stack_policy(:stack_policy_during_update, options[:stack_policy_during_update])
- stack_options.merge! upload_or_return_template(stack.to_cfn, options)
+ stack_options.merge! template_options
cfn_stack =
begin
create_stack stack_options.merge parameters: create_params
:created
@@ -266,23 +269,24 @@
end
private
def upload_or_return_template(cfn_hash, options = {})
- if cfn_hash.bytesize <= 51200 && !options[:force_s3]
- { template_body: cfn_hash }
- else
- raise Cfer::Util::CferError, 'Cfer needs to upload the template to S3, but no bucket was specified.' unless options[:s3_path]
+ @template_options ||=
+ if cfn_hash.bytesize <= 51200 && !options[:force_s3]
+ { template_body: cfn_hash }
+ else
+ raise Cfer::Util::CferError, 'Cfer needs to upload the template to S3, but no bucket was specified.' unless options[:s3_path]
- uri = URI(options[:s3_path])
- template = Aws::S3::Object.new bucket_name: uri.host, key: uri.path.reverse.chomp('/').reverse
- template.put body: cfn_hash
+ uri = URI(options[:s3_path])
+ template = Aws::S3::Object.new bucket_name: uri.host, key: uri.path.reverse.chomp('/').reverse
+ template.put body: cfn_hash
- template_url = template.public_url
- template_url = template_url + '?versionId=' + template.version_id if template.version_id
+ template_url = template.public_url
+ template_url = template_url + '?versionId=' + template.version_id if template.version_id
- { template_url: template_url }
- end
+ { template_url: template_url }
+ end
end
def cfn_list_to_hash(attribute, list)
return {} unless list