Sha256: 92f7923e109aa5e0e025603e48e20f1f72c93de50ddc430127ebc24bbd0a5ec9

Contents?: true

Size: 1.58 KB

Versions: 1

Compression:

Stored size: 1.58 KB

Contents

require 'bora/stack'
require 'deep_merge'

class Bora
  class Template
    # These are properties that you can define on the template, but which can also be defined and overriden in the stack

    INHERITABLE_PROPERTIES = %w(capabilities default_region tags on_failure disable_rollback).freeze

    # These are properties that can be passed in from the command line to override what's defined inthe stack
    OVERRIDABLE_PROPERTIES = %w(cfn_stack_name).freeze

    def initialize(template_name, template_config, override_config = {})
      @template_name = template_name
      @template_config = template_config
      @stacks = {}
      template_config['stacks'].each do |stack_name, stack_config|
        stack_name = "#{template_name}-#{stack_name}"
        resolved_config = resolve_stack_config(template_config, stack_config, override_config)
        @stacks[stack_name] = Stack.new(stack_name, template_config['template_file'], resolved_config)
      end
    end

    def stack(name)
      @stacks[name]
    end

    def stacks
      @stacks.values
    end

    def rake_tasks
      @stacks.each { |_, s| s.rake_tasks }
    end

    private

    def resolve_stack_config(template_config, stack_config, override_config)
      inheritable_properties(template_config).deep_merge!(stack_config).merge(overridable_properties(override_config))
    end

    def inheritable_properties(config)
      config.select { |k| INHERITABLE_PROPERTIES.include?(k) }
    end

    def overridable_properties(config)
      config.select { |k| INHERITABLE_PROPERTIES.include?(k) || OVERRIDABLE_PROPERTIES.include?(k) }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bora-1.7.1 lib/bora/template.rb