class Terradactyl::Stack
Attributes
stack_config[R]
Public Class Methods
load(stack_name)
click to toggle source
# File lib/terradactyl/stack.rb, line 9 def self.load(stack_name) new(stack_name) end
new(stack_name)
click to toggle source
# File lib/terradactyl/stack.rb, line 13 def initialize(stack_name) @stack_name = validate_stack_name(stack_name) @stack_config = ConfigStack.new(@stack_name) @tf_version = tf_version Commands.extend_by_revision(@tf_version, self) print_message "Terraform version: #{@tf_version}" inject_env_vars rescue NameError print_crit "Unsupported Terraform version: #{@tf_version}" Stacks.error!(stack_name) throw :error end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/terradactyl/stack.rb, line 30 def <=>(other) name <=> other.name end
config()
click to toggle source
Calls superclass method
Terradactyl::Common#config
# File lib/terradactyl/stack.rb, line 26 def config stack_config || super end
plan_file_obj()
click to toggle source
# File lib/terradactyl/stack.rb, line 55 def plan_file_obj @plan_file_obj ||= load_plan_file end
planned?()
click to toggle source
# File lib/terradactyl/stack.rb, line 38 def planned? File.exist?(plan_path) end
print_error()
click to toggle source
# File lib/terradactyl/stack.rb, line 51 def print_error print_content(plan_file_obj.error_output) end
print_plan()
click to toggle source
# File lib/terradactyl/stack.rb, line 47 def print_plan print_content(plan_file_obj.plan_output) end
remove_plan_file()
click to toggle source
# File lib/terradactyl/stack.rb, line 42 def remove_plan_file print_dot("Removing Plan File: #{plan_file}", :light_yellow) FileUtils.rm_rf(plan_path) end
to_s()
click to toggle source
# File lib/terradactyl/stack.rb, line 34 def to_s "<name: #{name}, path: #{path}>" end
Private Instance Methods
autoinstall?()
click to toggle source
# File lib/terradactyl/stack.rb, line 61 def autoinstall? config.terraform.autoinstall end
command_options()
click to toggle source
rubocop:disable Metrics/AbcSize
# File lib/terradactyl/stack.rb, line 99 def command_options subcmd = caller_locations(1, 1)[0].label.to_sym Terraform::Commands::Options.new do |dat| dat.environment = config.environment dat.echo = config.terraform.echo dat.quiet = config.terraform.quiet config.terraform.send(subcmd)&.each_pair do |key, value| dat.send("#{key}=".to_sym, value) end end end
inject_env_vars()
click to toggle source
# File lib/terradactyl/stack.rb, line 90 def inject_env_vars return unless config.misc.disable_color args = ENV['TF_CLI_ARGS'].to_s.split(',') args << '-no-color' ENV['TF_CLI_ARGS'] = args.compact.flatten.uniq.join(',') end
method_missing(sym, *args, &block)
click to toggle source
Calls superclass method
# File lib/terradactyl/stack.rb, line 121 def method_missing(sym, *args, &block) config.send(sym.to_sym, *args, &block) rescue NameError super end
popd()
click to toggle source
# File lib/terradactyl/stack.rb, line 117 def popd Dir.chdir(@working_dir_last) end
pushd(path)
click to toggle source
rubocop:enable Metrics/AbcSize
# File lib/terradactyl/stack.rb, line 112 def pushd(path) @working_dir_last = Dir.pwd Dir.chdir(path) end
respond_to_missing?(sym, *args)
click to toggle source
Calls superclass method
# File lib/terradactyl/stack.rb, line 127 def respond_to_missing?(sym, *args) config.respond_to?(sym) || super end
setup_terraform()
click to toggle source
# File lib/terradactyl/stack.rb, line 71 def setup_terraform %i[install_dir downloads_url releases_url].each do |opt| Terraform::VersionManager.send("#{opt}=".to_sym, config.terraform.send(opt)) end Terraform::VersionManager.version = @tf_version Terraform::VersionManager.install if autoinstall? end
tf_version()
click to toggle source
# File lib/terradactyl/stack.rb, line 65 def tf_version Terraform::VersionManager.resolve(config.terraform.version) rescue Terraform::VersionManager::VersionManagerError Terraform::VersionManager.latest end
validate_stack_name(stack_name)
click to toggle source
# File lib/terradactyl/stack.rb, line 81 def validate_stack_name(stack_name) klass = self.class.to_s.split('::').last unless (valid_name = Stacks.validate(stack_name)) print_crit("#{klass} not found: #{File.basename(stack_name)}") abort end valid_name end