class Terraform::Stacks
Singleton to keep track of stack templates
Attributes
stacks[R]
Public Class Methods
base_config()
click to toggle source
# File lib/terraform_dsl/stacks.rb, line 37 def base_config { 'common' => {}, 'stacks' => [ base_stack_config ], } end
base_stack_config()
click to toggle source
# File lib/terraform_dsl/stacks.rb, line 44 def base_stack_config { 'name' => 'SET_NAME', 'uuid' => uuid, 'description' => 'SET_A_DESCRIPTION', 'root' => 'SET_A_TEMPLATE', 'variables' => {}, } end
dir()
click to toggle source
# File lib/terraform_dsl/stacks.rb, line 58 def dir File.expand_path(File.join(ENV['TERRAFORM_DATA_DIR'] || 'data', 'stacks')) end
init()
click to toggle source
# File lib/terraform_dsl/stacks.rb, line 25 def init config = ENV['STACK_CONFIG'] || 'stacks.yml' fail "stacks.yaml already exists at #{File.expand_path(config)}" if File.exist?(config) File.open(config,'w') do |f| f.write(YAML.dump(base_config)) end end
load()
click to toggle source
# File lib/terraform_dsl/stacks.rb, line 13 def load config = ENV['STACK_CONFIG'] || 'stacks.yml' fail 'stacks.yml must exist in root directory, or specify STACK_CONFIG pointing to stacks.yml' unless File.exist?(config) stack_specs = YAML.load(File.read(config)) fail MalformedConfig, 'Stacks must be an array' unless stack_specs.key?('stacks') && stack_specs['stacks'].is_a?(Array) common = stack_specs['common'] || {} stack_specs['stacks'].each do |stack_spec| stack = Stack.load(stack_spec.merge(common)) @stacks[stack.name] = stack end end
reset!()
click to toggle source
# File lib/terraform_dsl/stacks.rb, line 54 def reset! @stacks ||= {} end
uuid()
click to toggle source
# File lib/terraform_dsl/stacks.rb, line 33 def uuid "#{Time.now.utc.to_i}_#{SecureRandom.urlsafe_base64(6)}" end