Class: StackMaster::Stack
- Inherits:
-
Object
- Object
- StackMaster::Stack
- Defined in:
- lib/stack_master/stack.rb
Constant Summary collapse
- MAX_TEMPLATE_SIZE =
51200
Class Method Summary collapse
Instance Method Summary collapse
- #aws_parameters ⇒ Object
- #aws_tags ⇒ Object
- #maybe_compressed_template_body ⇒ Object
- #parameters_with_defaults ⇒ Object
- #template_default_parameters ⇒ Object
- #template_hash ⇒ Object
- #too_big? ⇒ Boolean
Class Method Details
.find(region, stack_name) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/stack_master/stack.rb', line 43 def self.find(region, stack_name) cf = StackMaster.cloud_formation_driver cf_stack = cf.describe_stacks(stack_name: stack_name).stacks.first return unless cf_stack parameters = cf_stack.parameters.inject({}) do |params_hash, param_struct| params_hash[param_struct.parameter_key] = param_struct.parameter_value params_hash end template_body ||= cf.get_template(stack_name: stack_name).template_body stack_policy_body ||= cf.get_stack_policy(stack_name: stack_name).stack_policy_body outputs = cf_stack.outputs new(region: region, stack_name: stack_name, stack_id: cf_stack.stack_id, parameters: parameters, template_body: template_body, outputs: outputs, notification_arns: cf_stack.notification_arns, stack_policy_body: stack_policy_body, stack_status: cf_stack.stack_status) rescue Aws::CloudFormation::Errors::ValidationError nil end |
.generate(stack_definition, config) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/stack_master/stack.rb', line 68 def self.generate(stack_definition, config) parameter_hash = ParameterLoader.load(stack_definition.parameter_files) template_body = TemplateCompiler.compile(stack_definition.template_file_path) parameters = ParameterResolver.resolve(config, stack_definition, parameter_hash) stack_policy_body = if stack_definition.stack_policy_file_path File.read(stack_definition.stack_policy_file_path) end new(region: stack_definition.region, stack_name: stack_definition.stack_name, tags: stack_definition., parameters: parameters, template_body: template_body, notification_arns: stack_definition.notification_arns, stack_policy_body: stack_policy_body) end |
Instance Method Details
#aws_parameters ⇒ Object
88 89 90 |
# File 'lib/stack_master/stack.rb', line 88 def aws_parameters Utils.hash_to_aws_parameters(parameters) end |
#aws_tags ⇒ Object
92 93 94 |
# File 'lib/stack_master/stack.rb', line 92 def Utils.() end |
#maybe_compressed_template_body ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/stack_master/stack.rb', line 24 def maybe_compressed_template_body if template_body.size > MAX_TEMPLATE_SIZE @compressed_template_body ||= JSON.dump(template_hash) else template_body end end |
#parameters_with_defaults ⇒ Object
39 40 41 |
# File 'lib/stack_master/stack.rb', line 39 def parameters_with_defaults template_default_parameters.merge(parameters) end |
#template_default_parameters ⇒ Object
32 33 34 35 36 37 |
# File 'lib/stack_master/stack.rb', line 32 def template_default_parameters template_hash.fetch('Parameters', {}).inject({}) do |result, (parameter_name, description)| result[parameter_name] = description['Default'] result end end |
#template_hash ⇒ Object
18 19 20 21 22 |
# File 'lib/stack_master/stack.rb', line 18 def template_hash if template_body @template_hash ||= JSON.parse(template_body) end end |
#too_big? ⇒ Boolean
84 85 86 |
# File 'lib/stack_master/stack.rb', line 84 def too_big? maybe_compressed_template_body.size > MAX_TEMPLATE_SIZE end |