Class: Terraspace::Compiler::Expander
- Inherits:
-
Object
- Object
- Terraspace::Compiler::Expander
- Extended by:
- Memoist
- Defined in:
- lib/terraspace/compiler/expander/backend.rb,
lib/terraspace/compiler/expander.rb
Overview
Simpler than Terraspace::Terraform::Runner::Backend::Parser because Terraspace::Compiler::Expander autodetect backend super early on. It’s so early that don’t want helper methods like <%= expansion(…) %> to be called. Calling the expansion helper itself results in Terraspace autodetecting a concrete Terraspace Plugin Expander, which creates an infinite loop. This simple detection class avoids calling ERB and avoids the infinite loop.
Defined Under Namespace
Classes: Backend
Class Method Summary collapse
Instance Method Summary collapse
- #expander ⇒ Object
-
#expander_class ⇒ Object
IE: TerraspacePluginAws::Interfaces::Expander.
- #expander_class_name ⇒ Object
-
#initialize(mod, backend = nil) ⇒ Expander
constructor
A new instance of Expander.
-
#parse_backend ⇒ Object
autodetect by parsing backend.tf or backend.rb.
-
#plugin_backend ⇒ Object
autodetect by looking up loaded plugins.
Constructor Details
#initialize(mod, backend = nil) ⇒ Expander
Returns a new instance of Expander.
6 7 8 |
# File 'lib/terraspace/compiler/expander.rb', line 6 def initialize(mod, backend=nil) @mod, @backend = mod, backend end |
Class Method Details
.autodetect(mod, opts = {}) ⇒ Object
56 57 58 |
# File 'lib/terraspace/compiler/expander.rb', line 56 def autodetect(mod, opts={}) new(mod, opts) end |
Instance Method Details
#expander ⇒ Object
10 11 12 |
# File 'lib/terraspace/compiler/expander.rb', line 10 def .new(@mod) end |
#expander_class ⇒ Object
IE: TerraspacePluginAws::Interfaces::Expander
16 17 18 19 20 21 22 |
# File 'lib/terraspace/compiler/expander.rb', line 16 def class_name = class_name ? class_name.constantize : Terraspace::Plugin::Expander::Generic rescue NameError => e logger.debug "#{e.class}: #{e.}" Terraspace::Plugin::Expander::Generic end |
#expander_class_name ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/terraspace/compiler/expander.rb', line 24 def plugin = Terraspace.config.autodetect. # contains plugin name. IE: aws, azurerm, google if plugin # early return for user override of autodetection return Terraspace::Plugin.klass("Expander", plugin: plugin) # can return nil end backend = @backend || parse_backend class_name = Terraspace::Plugin.klass("Expander", backend: backend) # can return nil unless class_name backend = plugin_backend class_name = Terraspace::Plugin.klass("Expander", backend: backend) # can return nil end class_name end |
#parse_backend ⇒ Object
autodetect by parsing backend.tf or backend.rb
41 42 43 |
# File 'lib/terraspace/compiler/expander.rb', line 41 def parse_backend Backend.new(@mod).detect end |
#plugin_backend ⇒ Object
autodetect by looking up loaded plugins
46 47 48 49 50 51 52 |
# File 'lib/terraspace/compiler/expander.rb', line 46 def plugin_backend plugin = Terraspace::Plugin.autodetect if plugin data = Terraspace::Plugin.[plugin] data[:backend] # IE: s3, azurerm, gcs end end |