Class: StackMaster::Stack
- Inherits:
-
Object
- Object
- StackMaster::Stack
- Includes:
- Utils::Initializable
- Defined in:
- lib/stack_master/stack.rb
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#notification_arns ⇒ Object
readonly
Returns the value of attribute notification_arns.
-
#outputs ⇒ Object
readonly
Returns the value of attribute outputs.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
-
#role_arn ⇒ Object
readonly
Returns the value of attribute role_arn.
-
#stack_id ⇒ Object
readonly
Returns the value of attribute stack_id.
-
#stack_name ⇒ Object
readonly
Returns the value of attribute stack_name.
-
#stack_policy_body ⇒ Object
readonly
Returns the value of attribute stack_policy_body.
-
#stack_status ⇒ Object
readonly
Returns the value of attribute stack_status.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#template_body ⇒ Object
readonly
Returns the value of attribute template_body.
-
#template_format ⇒ Object
readonly
Returns the value of attribute template_format.
Class Method Summary collapse
- .find(region, stack_name) ⇒ Object
- .generate(stack_definition, config) ⇒ Object
- .generate_without_parameters(stack_definition, config) ⇒ Object
Instance Method Summary collapse
- #aws_parameters ⇒ Object
- #aws_tags ⇒ Object
- #max_template_size(use_s3) ⇒ Object
- #parameters_with_defaults ⇒ Object
- #template ⇒ Object
- #template_default_parameters ⇒ Object
- #too_big?(use_s3 = false) ⇒ Boolean
Methods included from Utils::Initializable
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
3 4 5 |
# File 'lib/stack_master/stack.rb', line 3 def files @files end |
#notification_arns ⇒ Object (readonly)
Returns the value of attribute notification_arns.
3 4 5 |
# File 'lib/stack_master/stack.rb', line 3 def notification_arns @notification_arns end |
#outputs ⇒ Object (readonly)
Returns the value of attribute outputs.
3 4 5 |
# File 'lib/stack_master/stack.rb', line 3 def outputs @outputs end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
3 4 5 |
# File 'lib/stack_master/stack.rb', line 3 def parameters @parameters end |
#region ⇒ Object (readonly)
Returns the value of attribute region.
3 4 5 |
# File 'lib/stack_master/stack.rb', line 3 def region @region end |
#role_arn ⇒ Object (readonly)
Returns the value of attribute role_arn.
3 4 5 |
# File 'lib/stack_master/stack.rb', line 3 def role_arn @role_arn end |
#stack_id ⇒ Object (readonly)
Returns the value of attribute stack_id.
3 4 5 |
# File 'lib/stack_master/stack.rb', line 3 def stack_id @stack_id end |
#stack_name ⇒ Object (readonly)
Returns the value of attribute stack_name.
3 4 5 |
# File 'lib/stack_master/stack.rb', line 3 def stack_name @stack_name end |
#stack_policy_body ⇒ Object (readonly)
Returns the value of attribute stack_policy_body.
3 4 5 |
# File 'lib/stack_master/stack.rb', line 3 def stack_policy_body @stack_policy_body end |
#stack_status ⇒ Object (readonly)
Returns the value of attribute stack_status.
3 4 5 |
# File 'lib/stack_master/stack.rb', line 3 def stack_status @stack_status end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
3 4 5 |
# File 'lib/stack_master/stack.rb', line 3 def @tags end |
#template_body ⇒ Object (readonly)
Returns the value of attribute template_body.
3 4 5 |
# File 'lib/stack_master/stack.rb', line 3 def template_body @template_body end |
#template_format ⇒ Object (readonly)
Returns the value of attribute template_format.
3 4 5 |
# File 'lib/stack_master/stack.rb', line 3 def template_format @template_format end |
Class Method Details
.find(region, stack_name) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/stack_master/stack.rb', line 30 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_stage: 'Original').template_body template_format = TemplateUtils.identify_template_format(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, template_format: template_format, outputs: outputs, role_arn: cf_stack.role_arn, 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
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/stack_master/stack.rb', line 58 def self.generate(stack_definition, config) parameter_hash = ParameterLoader.load(parameter_files: stack_definition.all_parameter_files, parameters: stack_definition.parameters) template_parameters = ParameterResolver.resolve(config, stack_definition, parameter_hash[:template_parameters]) compile_time_parameters = ParameterResolver.resolve(config, stack_definition, parameter_hash[:compile_time_parameters]) template_body = TemplateCompiler.compile(config, stack_definition.compiler, stack_definition.template_dir, stack_definition.template, compile_time_parameters, stack_definition.) template_format = TemplateUtils.identify_template_format(template_body) 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: template_parameters, template_body: template_body, template_format: template_format, role_arn: stack_definition.role_arn, notification_arns: stack_definition.notification_arns, stack_policy_body: stack_policy_body) end |
.generate_without_parameters(stack_definition, config) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/stack_master/stack.rb', line 78 def self.generate_without_parameters(stack_definition, config) parameter_hash = ParameterLoader.load(parameter_files: stack_definition.all_parameter_files, parameters: stack_definition.parameters) compile_time_parameters = ParameterResolver.resolve(config, stack_definition, parameter_hash[:compile_time_parameters]) template_body = TemplateCompiler.compile(config, stack_definition.compiler, stack_definition.template_dir, stack_definition.template, compile_time_parameters, stack_definition.) template_format = TemplateUtils.identify_template_format(template_body) 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: {}, template_body: template_body, template_format: template_format, role_arn: stack_definition.role_arn, notification_arns: stack_definition.notification_arns, stack_policy_body: stack_policy_body) end |
Instance Method Details
#aws_parameters ⇒ Object
106 107 108 |
# File 'lib/stack_master/stack.rb', line 106 def aws_parameters Utils.hash_to_aws_parameters(parameters) end |
#aws_tags ⇒ Object
110 111 112 |
# File 'lib/stack_master/stack.rb', line 110 def Utils.() end |
#max_template_size(use_s3) ⇒ Object
97 98 99 100 |
# File 'lib/stack_master/stack.rb', line 97 def max_template_size(use_s3) return TemplateUtils::MAX_S3_TEMPLATE_SIZE if use_s3 TemplateUtils::MAX_TEMPLATE_SIZE end |
#parameters_with_defaults ⇒ Object
26 27 28 |
# File 'lib/stack_master/stack.rb', line 26 def parameters_with_defaults template_default_parameters.merge(parameters) end |
#template ⇒ Object
114 115 116 |
# File 'lib/stack_master/stack.rb', line 114 def template @template ||= TemplateUtils.maybe_compressed_template_body(template_body) end |
#template_default_parameters ⇒ Object
19 20 21 22 23 24 |
# File 'lib/stack_master/stack.rb', line 19 def template_default_parameters TemplateUtils.template_hash(template).fetch('Parameters', {}).inject({}) do |result, (parameter_name, description)| result[parameter_name] = description['Default'] result end end |
#too_big?(use_s3 = false) ⇒ Boolean
102 103 104 |
# File 'lib/stack_master/stack.rb', line 102 def too_big?(use_s3 = false) template.size > max_template_size(use_s3) end |