class Terradactyl::ConfigStack

Constants

TERRAFORM_SETTINGS_FILES

Attributes

base_folder[R]
name[R]
path[R]
stack_name[R]
stack_path[R]

Public Class Methods

new(stack_name) click to toggle source
# File lib/terradactyl/config.rb, line 143
def initialize(stack_name)
  @stack_name     = stack_name
  @project_config = ConfigProject.instance
  @base_folder    = @project_config.base_folder
  @stack_path     = "#{@base_folder}/#{@stack_name}"
  @config_file    = "#{@stack_path}/#{ConfigProject::CONFIG_PROJECT_FILE}"
  @defaults       = load_defaults(@project_config.to_h)
  @overlay        = load_overlay(@config_file)
  load_config
end

Public Instance Methods

plan_file() click to toggle source
# File lib/terradactyl/config.rb, line 165
def plan_file
  "#{stack_name}.tfout"
end
plan_path() click to toggle source
# File lib/terradactyl/config.rb, line 169
def plan_path
  "#{stack_path}/#{plan_file}"
end
state_file() click to toggle source
# File lib/terradactyl/config.rb, line 157
def state_file
  'terraform.tfstate'
end
state_path() click to toggle source
# File lib/terradactyl/config.rb, line 161
def state_path
  "#{stack_path}/terraform.tfstate"
end
versions_file() click to toggle source
# File lib/terradactyl/config.rb, line 173
def versions_file
  "#{stack_path}/versions.tf"
end

Private Instance Methods

load_overlay(config_file) click to toggle source
# File lib/terradactyl/config.rb, line 204
def load_overlay(config_file)
  overlay = super(config_file)

  unless overlay_specifies_version?(overlay)
    overlay.merge!(terraform_required_version)
  end

  overlay
end
overlay_specifies_version?(overlay) click to toggle source
# File lib/terradactyl/config.rb, line 214
def overlay_specifies_version?(overlay)
  overlay['terradactyl']&.fetch('terraform', {})&.fetch('version', nil)
end
terraform_required_version() click to toggle source
# File lib/terradactyl/config.rb, line 179
def terraform_required_version
  matches = TERRAFORM_SETTINGS_FILES.each_with_object([]) do |file, memo|
    path = File.join(stack_path, file)
    next unless File.exist?(path)

    File.readlines(path).each do |line|
      next if line =~ /(?:\s*#\s*)/

      if (match = line.match(Common.required_versions_re))
        memo << match
      end
    end
  end

  return {} unless matches.any?

  {
    'terradactyl' => {
      'terraform' => {
        'version' => matches.last[:value].delete('"')
      }
    }
  }
end