class Terraspace::Compiler::Builder
Public Class Methods
new(mod)
click to toggle source
# File lib/terraspace/compiler/builder.rb, line 6 def initialize(mod) @mod = mod end
Public Instance Methods
build()
click to toggle source
# File lib/terraspace/compiler/builder.rb, line 10 def build build_config build_module if @mod.resolved build_tfvars unless command_is?(:seed) # avoid dependencies being built and erroring when backend bucket doesnt exist end
build_config()
click to toggle source
build common config files: provider and backend for the root module
# File lib/terraspace/compiler/builder.rb, line 17 def build_config return unless build? build_config_terraform end
build_module()
click to toggle source
# File lib/terraspace/compiler/builder.rb, line 22 def build_module with_mod_file do |src_path| build_mod_file(src_path) end end
build_tfvars()
click to toggle source
# File lib/terraspace/compiler/builder.rb, line 28 def build_tfvars return unless build? Strategy::Tfvar.new(@mod).run # writer within Strategy to control file ordering end
Private Instance Methods
build?()
click to toggle source
# File lib/terraspace/compiler/builder.rb, line 34 def build? @mod.type == "stack" || @mod.root_module? end
build_config_file(file)
click to toggle source
# File lib/terraspace/compiler/builder.rb, line 47 def build_config_file(file) existing = search("#{@mod.root}/#{file}").first return if existing && existing.ends_with?(".tf") # do not overwrite existing backend.tf, provider.tf, etc if file.ends_with?(".rb") src_path = search("#{@mod.root}/#{basename(file)}").first # existing source. IE: backend.rb in module folder end src_path ||= search("#{Terraspace.root}/config/terraform/#{file}").first build_mod_file(src_path) if src_path end
build_config_terraform()
click to toggle source
# File lib/terraspace/compiler/builder.rb, line 38 def build_config_terraform expr = "#{Terraspace.root}/config/terraform/**/*" search(expr).each do |path| next unless File.file?(path) next if path.include?('config/terraform/tfvars') build_config_file(basename(path)) end end
build_mod_file(src_path)
click to toggle source
# File lib/terraspace/compiler/builder.rb, line 58 def build_mod_file(src_path) content = Strategy::Mod.new(@mod, src_path).run Writer.new(@mod, src_path: src_path).write(content) end
search(expr)
click to toggle source
# File lib/terraspace/compiler/builder.rb, line 84 def search(expr) Dir.glob(expr, File::FNM_DOTMATCH) end
skip?(src_path)
click to toggle source
# File lib/terraspace/compiler/builder.rb, line 74 def skip?(src_path) return true unless File.file?(src_path) # certain folders will be skipped src_path.include?("#{@mod.root}/config/args") || src_path.include?("#{@mod.root}/config/helpers") || src_path.include?("#{@mod.root}/config/hooks") || src_path.include?("#{@mod.root}/test") || src_path.include?("#{@mod.root}/tfvars") end
with_mod_file(&block)
click to toggle source
# File lib/terraspace/compiler/builder.rb, line 63 def with_mod_file(&block) with_path("#{@mod.root}/**/*", &block) # Only all files end
with_path(path) { |src_path| ... }
click to toggle source
# File lib/terraspace/compiler/builder.rb, line 67 def with_path(path) search(path).each do |src_path| next if skip?(src_path) yield(src_path) end end