Class: Terraspace::Compiler::Strategy::Mod

Inherits:
AbstractBase show all
Includes:
Util::Logging
Defined in:
lib/terraspace/compiler/strategy/mod.rb,
lib/terraspace/compiler/strategy/mod/rb.rb,
lib/terraspace/compiler/strategy/mod/tf.rb,
lib/terraspace/compiler/strategy/mod/base.rb,
lib/terraspace/compiler/strategy/mod/pass.rb,
lib/terraspace/compiler/strategy/mod/tfvars.rb,
lib/terraspace/compiler/strategy/mod/text_file.rb

Defined Under Namespace

Classes: Base, Pass, Rb, TextFile, Tf, Tfvars

Constant Summary collapse

@@copy_modules_warned =
false

Instance Method Summary collapse

Methods included from Util::Logging

#logger

Methods inherited from AbstractBase

#initialize

Constructor Details

This class inherits a constructor from Terraspace::Compiler::Strategy::AbstractBase

Instance Method Details

#copy_modules?(path) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/terraspace/compiler/strategy/mod.rb', line 23

def copy_modules?(path)
  return false if path.include?("/modules/") && path.ends_with?(".rb") # For DSL
  return false unless @options[:type_dir] == "modules"

  copy_modules = Terraspace.config.build.copy_modules
  if copy_modules.nil? && @@copy_modules_warned == false
    logger.info "WARN: config.build.copy_modules is not set. Defaulting to true.".color(:yellow)
    logger.info <<~EOL
    The terraspace building behavior is to copy modules from
    the app/modules folder to the .terraspace-cache for speed.
    Most do not need app/modules to be compiled.
    Other files like app/stacks and tfvars files are still compiled.
    This is a change from previous versions of Terraspace, where
    all files were compiled.

    You can turn this warning off by setting:

    .terraspace/config.rb

        Terraspace.configure do |config|
          config.build.copy_modules = true
        end

    In future Terraspace versions, the default will be true.
    There will be no warning message, but it will still be configurable.
    EOL
    copy_modules = true
    @@copy_modules_warned = true
  end

  copy_modules
end

#runObject



5
6
7
8
9
# File 'lib/terraspace/compiler/strategy/mod.rb', line 5

def run
  klass = strategy_class(@src_path)
  strategy = klass.new(@mod, @src_path) # IE: Terraspace::Compiler::Strategy::Mod::Rb.new
  strategy.run
end

#strategy_class(path) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/terraspace/compiler/strategy/mod.rb', line 11

def strategy_class(path)
  # Significant speed improvement
  return Mod::Pass if copy_modules?(path)

  ext = File.extname(path).sub('.','')
  return Mod::Pass if ext.empty? # infinite loop without this
  return Mod::Pass if Terraspace.pass_file?(path) or !text_file?(path)
  # Fallback to Mod::Tf for all other files. ERB useful for terraform.tfvars
  "Terraspace::Compiler::Strategy::Mod::#{ext.camelize}".constantize rescue Mod::Pass
end