Class: Terraspace::CLI::Build::Placeholder

Inherits:
Object
  • Object
show all
Includes:
Terraspace::Compiler::DirsConcern, Util::Logging
Defined in:
lib/terraspace/cli/build/placeholder.rb

Instance Method Summary collapse

Methods included from Util::Logging

#logger

Methods included from Terraspace::Compiler::DirsConcern

#cache_dirs, #dirs, #extract_stack_name, #local_paths, #mod_names, #select_stack?, #stack_names, #with_each_mod

Constructor Details

#initialize(options = {}) ⇒ Placeholder

Returns a new instance of Placeholder.



9
10
11
# File 'lib/terraspace/cli/build/placeholder.rb', line 9

def initialize(options={})
  @options = options
end

Instance Method Details

#buildObject

Grab the last module and build that. Assume the backend key has the same prefix Note: Tried building a empty “null” stack but with TFC a null space workspace is created, which is undesired.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/terraspace/cli/build/placeholder.rb', line 16

def build
  return if ENV['TS_SUMMARY_BUILD'] == '0'

  mod = @options[:mod]
  if !mod or %w[placeholder].include?(mod)
    logger.info "Building one of the modules to get backend.tf info"
    mod = find_stack
  end
  Terraspace::Builder.new(@options.merge(mod: mod, init: false)).run # generate and init
  Terraspace::Mod.new(mod, @options) # mod metadata
end

#find_stackObject

Used by: terraspace build placeholder



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/terraspace/cli/build/placeholder.rb', line 29

def find_stack
  stack_paths = Dir.glob("{app,vendor}/stacks/*")
  stack_paths.select! do |path|
    stack_name = extract_stack_name(path)
    select = Terraspace::Compiler::Select.new(stack_name)
    select.selected?
  end
  mod_path = stack_paths.last
  unless mod_path
    logger.info "No stacks found."
    exit 0
  end
  File.basename(mod_path) # mod name
end