Class: Terraspace::Terraform::Tfc::Sync

Inherits:
CLI::Base
  • Object
show all
Extended by:
Memoist
Includes:
Api::Client
Defined in:
lib/terraspace/terraform/tfc/sync.rb

Instance Method Summary collapse

Methods included from Api::Client

#api, #build, #remote, #workspace_name

Methods inherited from CLI::Base

#initialize

Methods included from Util::Pretty

#pretty_path, #pretty_time

Methods included from Util::Sure

#sure?

Methods included from Util::Logging

#logger

Constructor Details

This class inherits a constructor from Terraspace::CLI::Base

Instance Method Details

#backendObject

already memoized in Api::Client



37
38
39
# File 'lib/terraspace/terraform/tfc/sync.rb', line 37

def backend
  Terraspace::Terraform::Runner::Backend::Parser.new(@mod).result
end

#runObject

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.



17
18
19
20
21
22
23
24
25
26
# File 'lib/terraspace/terraform/tfc/sync.rb', line 17

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

#workspaceObject



28
29
30
# File 'lib/terraspace/terraform/tfc/sync.rb', line 28

def workspace
  @api.workspace
end

#workspaces_backend?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/terraspace/terraform/tfc/sync.rb', line 32

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