Class: Terraspace::Builder
Defined Under Namespace
Classes: Allow, Children
Instance Method Summary
collapse
#run_hooks
#cache_dirs, #dirs, #extract_stack_name, #local_paths, #mod_names, #select_stack?, #stack_names, #with_each_mod
#command_is?
#pretty_path, #pretty_time
Methods included from Util::Sure
#sure?
#logger
Constructor Details
#initialize(options = {}) ⇒ Builder
terraspace all:
none: dont build any stacks at all. used by `terraspace all up`
root_only: only build root stack. used by `terraspace all up`
root_with_children: build all children stacks as well as the root stack. normal `terraspace all down`
terraspace up:
root_with_children: build all children stacks as well as the root stack. normal `terraspace up`
19
20
21
22
|
# File 'lib/terraspace/builder.rb', line 19
def initialize(options={})
super
@include_stacks = @options[:include_stacks] || :root_with_children
end
|
Instance Method Details
#build(modules: true) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/terraspace/builder.rb', line 39
def build(modules: true)
build_dir = Util.pretty_path(@mod.cache_dir)
placeholder_stack_message
logger.info "Building #{build_dir}" unless @options[:quiet] FileUtils.mkdir_p(@mod.cache_dir) run_hooks("terraspace.rb", "build") do
build_dir("modules") if modules
build_stacks
logger.debug "Built in #{build_dir}"
end
end
|
#build_children_stacks ⇒ Object
Build stacks that are part of the dependency graph. Because .terraspace-cache folders need to exist so ‘terraform state pull` works to get the state info.
63
64
65
66
|
# File 'lib/terraspace/builder.rb', line 63
def build_children_stacks
children = Children.new(@mod, @options)
children.build
end
|
#build_dir(type_dir) ⇒ Object
68
69
70
71
72
73
74
|
# File 'lib/terraspace/builder.rb', line 68
def build_dir(type_dir)
with_each_mod(type_dir) do |mod|
is_root_module = mod.cache_dir == @mod.cache_dir
next if is_root_module Compiler::Perform.new(mod, type_dir: type_dir).compile
end
end
|
#build_stacks ⇒ Object
55
56
57
58
59
|
# File 'lib/terraspace/builder.rb', line 55
def build_stacks
return if @include_stacks == :none
build_children_stacks if @include_stacks == :root_with_children
Compiler::Perform.new(@mod).compile end
|
#check_allow! ⇒ Object
51
52
53
|
# File 'lib/terraspace/builder.rb', line 51
def check_allow!
Allow.new(@mod).check!
end
|
#clean ⇒ Object
76
77
78
|
# File 'lib/terraspace/builder.rb', line 76
def clean
Compiler::Cleaner.new(@mod, @options).clean if clean?
end
|
#clean? ⇒ Boolean
80
81
82
83
84
85
86
87
|
# File 'lib/terraspace/builder.rb', line 80
def clean?
if @options[:clean].nil?
clean_cache = Terraspace.config.build.clean_cache
clean_cache.nil? ? true : clean_cache
else
@options[:clean]
end
end
|
#placeholder_stack_message ⇒ Object
89
90
91
92
93
|
# File 'lib/terraspace/builder.rb', line 89
def placeholder_stack_message
return if @options[:quiet]
return unless @options[:mod] == "placeholder"
logger.info "Building one stack to build all stacks"
end
|
#resolve_dependencies ⇒ Object
34
35
36
37
|
# File 'lib/terraspace/builder.rb', line 34
def resolve_dependencies
resolver = Terraspace::Dependency::Resolver.new(@options.merge(quiet: true))
resolver.resolve end
|
#run ⇒ Object
24
25
26
27
28
29
30
31
32
|
# File 'lib/terraspace/builder.rb', line 24
def run
return if @options[:build] == false
Terraspace::Check.check!
check_allow!
@mod.root_module = true
clean
resolve_dependencies if @include_stacks == :root_with_children
build
end
|