Sha256: b918b6f8d7946437cb7f2058e59c2fa01c98543725911c9ddfe85d673bc6555e

Contents?: true

Size: 1.49 KB

Versions: 48

Compression:

Stored size: 1.49 KB

Contents

class Terraspace::Terraform::Runner
  class Backend
    extend Memoist
    include Terraspace::Compiler::CommandsConcern

    def initialize(mod)
      @mod = mod
    end

    @@created = {}
    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

    def cache_key
      @mod.build_dir
    end

    def backend_name
      backend.keys.first # IE: s3, gcs, etc
    end

    def backend_info
      backend.values.first # structure within the s3 or gcs key
    end

    def backend
      Parser.new(@mod).result
    end
    memoize :backend

    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

    def requires_backend?
      command_is?(requires_backend_commands)
    end

    def requires_backend_commands
      %w[down init output plan providers refresh show up validate]
    end
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
terraspace-2.2.17 lib/terraspace/terraform/runner/backend.rb
terraspace-2.2.16 lib/terraspace/terraform/runner/backend.rb
terraspace-2.2.15 lib/terraspace/terraform/runner/backend.rb
terraspace-2.2.14 lib/terraspace/terraform/runner/backend.rb
terraspace-2.2.13 lib/terraspace/terraform/runner/backend.rb
terraspace-2.2.12 lib/terraspace/terraform/runner/backend.rb
terraspace-2.2.11 lib/terraspace/terraform/runner/backend.rb
terraspace-2.2.10 lib/terraspace/terraform/runner/backend.rb
terraspace-2.2.9 lib/terraspace/terraform/runner/backend.rb
terraspace-2.2.8 lib/terraspace/terraform/runner/backend.rb
terraspace-2.2.7 lib/terraspace/terraform/runner/backend.rb
terraspace-2.2.6 lib/terraspace/terraform/runner/backend.rb
terraspace-2.2.5 lib/terraspace/terraform/runner/backend.rb
terraspace-2.2.4 lib/terraspace/terraform/runner/backend.rb
terraspace-2.2.3 lib/terraspace/terraform/runner/backend.rb
terraspace-2.2.2 lib/terraspace/terraform/runner/backend.rb
terraspace-2.2.1 lib/terraspace/terraform/runner/backend.rb
terraspace-2.2.0 lib/terraspace/terraform/runner/backend.rb
terraspace-2.1.7 lib/terraspace/terraform/runner/backend.rb
terraspace-2.1.6 lib/terraspace/terraform/runner/backend.rb