Class: Terraspace::Terraform::Runner::Backend
- Inherits:
-
Object
- Object
- Terraspace::Terraform::Runner::Backend
- Extended by:
- Memoist
- Includes:
- Compiler::CommandsConcern
- Defined in:
- lib/terraspace/terraform/runner/backend.rb,
lib/terraspace/terraform/runner/backend/parser.rb
Defined Under Namespace
Classes: Parser
Constant Summary collapse
- @@created =
{}
Instance Method Summary collapse
- #backend ⇒ Object
- #backend_info ⇒ Object
- #backend_interface(name) ⇒ Object
- #backend_name ⇒ Object
- #cache_key ⇒ Object
- #create ⇒ Object
-
#initialize(mod) ⇒ Backend
constructor
A new instance of Backend.
- #requires_backend? ⇒ Boolean
- #requires_backend_commands ⇒ Object
Methods included from Compiler::CommandsConcern
Constructor Details
#initialize(mod) ⇒ Backend
Returns a new instance of Backend.
6 7 8 |
# File 'lib/terraspace/terraform/runner/backend.rb', line 6 def initialize(mod) @mod = mod end |
Instance Method Details
#backend ⇒ Object
40 41 42 |
# File 'lib/terraspace/terraform/runner/backend.rb', line 40 def backend Parser.new(@mod).result end |
#backend_info ⇒ Object
36 37 38 |
# File 'lib/terraspace/terraform/runner/backend.rb', line 36 def backend_info backend.values.first # structure within the s3 or gcs key end |
#backend_interface(name) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/terraspace/terraform/runner/backend.rb', line 45 def backend_interface(name) return unless name # IE: TerraspacePluginAws::Interfaces::Backend klass_name = Terraspace::Plugin.klass("Backend", backend: name) klass_name.constantize if klass_name rescue NameError end |
#backend_name ⇒ Object
32 33 34 |
# File 'lib/terraspace/terraform/runner/backend.rb', line 32 def backend_name backend.keys.first # IE: s3, gcs, etc end |
#cache_key ⇒ Object
28 29 30 |
# File 'lib/terraspace/terraform/runner/backend.rb', line 28 def cache_key @mod.build_dir end |
#create ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/terraspace/terraform/runner/backend.rb', line 11 def create return if @@created[cache_key] return if Terraspace.config.auto_create_backend == false return unless requires_backend? # set immediately, since local storage wont reach bottom. # if fail for other backends, there will be an exception anyway @@created[cache_key] = true klass = backend_interface(backend_name) return unless klass # in case auto-creation is not supported for specific backend # IE: TerraspacePluginAws::Interfaces::Backend.new interface = klass.new(backend_info) interface.call end |
#requires_backend? ⇒ Boolean
53 54 55 |
# File 'lib/terraspace/terraform/runner/backend.rb', line 53 def requires_backend? command_is?(requires_backend_commands) end |
#requires_backend_commands ⇒ Object
57 58 59 |
# File 'lib/terraspace/terraform/runner/backend.rb', line 57 def requires_backend_commands %w[down init output plan providers refresh show up validate] end |