Sha256: 2317bdf7eed5e08ed29fbe9e80b6e90d232bdb3d6946206b928a073df07557f0

Contents?: true

Size: 1.3 KB

Versions: 48

Compression:

Stored size: 1.3 KB

Contents

module Terraspace::Terraform::Tfc
  class Sync < Terraspace::CLI::Base
    extend Memoist
    include Terraspace::Terraform::Api::Client

    # Note about why workspace.create is called:
    #
    # CLI::Init#run
    #   init => runs `terraform init`
    #   build_remote_dependencies
    #   sync_cloud => leads to create_workspace
    #
    # The `terraform init` will auto-create the TFC workspace
    # If there is a .terraform folder the config.init.mode == "auto" though,
    # then the workspace won't be created.
    # So we check and create the workspace if necessary.
    def run
      # Note: workspace still gets created by `terraform init` However, variables wont be sync if returns early
      return unless Terraspace.config.tfc.auto_sync || @options[:override_auto_sync]
      return unless workspaces_backend?
      logger.info "Syncing to Terraform Cloud: #{@mod.name} => #{workspace_name}"
      @api = Terraspace::Terraform::Api.new(@mod, remote)
      workspace.create_or_update
      workspace.set_working_dir
      workspace.set_env_vars
    end

    def workspace
      @api.workspace
    end

    def workspaces_backend?
      remote && remote['workspaces']
    end

    # already memoized in Api::Client
    def backend
      Terraspace::Terraform::Runner::Backend::Parser.new(@mod).result
    end
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

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