Class: Kitchen::Driver::Aws::StackGenerator

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/kitchen/driver/aws/stack_generator.rb

Overview

A class for encapsulating the stack payload logic

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, cf) ⇒ StackGenerator

Returns a new instance of StackGenerator.



29
30
31
32
# File 'lib/kitchen/driver/aws/stack_generator.rb', line 29

def initialize(config, cf)
  @config = config
  @cf = cf
end

Instance Attribute Details

#cfObject (readonly)

Returns the value of attribute cf.



27
28
29
# File 'lib/kitchen/driver/aws/stack_generator.rb', line 27

def cf
  @cf
end

#configObject (readonly)

Returns the value of attribute config.



27
28
29
# File 'lib/kitchen/driver/aws/stack_generator.rb', line 27

def config
  @config
end

Instance Method Details

#cf_stack_dataObject

Transform the provided config into the hash to send to AWS. Some fields can be passed in null, others need to be ommitted if they are null



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/kitchen/driver/aws/stack_generator.rb', line 36

def cf_stack_data
  s = { stack_name: config[:stack_name] }
  s[:template_url] = config[:template_url] if config[:template_file]
  if config[:template_file]
    s[:template_body] = File.open(config[:template_file], 'rb') { |file| file.read }
  end
  s[:capabilities] = config[:capabilities] if !config[:capabilities].nil? && (config[:capabilities].is_a? Array)
  s[:timeout_in_minutes] = config[:timeout_in_minutes] if !config[:timeout_in_minutes].nil? && config[:timeout_in_minutes] > 0
  s[:disable_rollback] = config[:disable_rollback]     if !config[:disable_rollback].nil? && config[:disable_rollback] == true || config[:disable_rollback] == false
  s[:parameters] = []
  config[:parameters].each do |k, v|
    s[:parameters].push(parameter_key: k.to_s, parameter_value: v.to_s)
  end
  s
end