Class: Terraspace::Terraform::Tfc::Syncer

Inherits:
CLI::Base
  • Object
show all
Extended by:
Memoist
Includes:
Compiler::DirsConcern, Util::Sure
Defined in:
lib/terraspace/terraform/tfc/syncer.rb

Instance Method Summary collapse

Methods included from Util::Sure

#sure?

Methods included from Compiler::DirsConcern

#cache_dirs, #dirs, #extract_stack_name, #local_paths, #mod_names, #select_stack?, #stack_names, #with_each_mod

Methods inherited from CLI::Base

#initialize

Methods included from Util::Pretty

#pretty_path, #pretty_time

Methods included from Util::Logging

#logger

Constructor Details

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

Instance Method Details

#are_you_sure?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/terraspace/terraform/tfc/syncer.rb', line 28

def are_you_sure?
  message =<<~EOL
    About to sync these project stacks with Terraform Cloud workspaces:

        Stack => Workspace
  EOL

  mods.each do |mod|
    sync = sync(mod)
    message << "    #{mod} => #{sync.workspace_name}\n"
  end
  message << <<~EOL

    A sync does the following for each workspace:

      1. Create or update workspace, including the VCS settings.
      2. Set the working dir.
      3. Set env and terraform variables.

    Are you sure?
  EOL
  sure?(message.chop)
end

#modsObject



14
15
16
17
# File 'lib/terraspace/terraform/tfc/syncer.rb', line 14

def mods
  stacks = @options[:stacks]
  stacks.empty? ? stack_names : stacks
end

#runObject



7
8
9
10
11
12
# File 'lib/terraspace/terraform/tfc/syncer.rb', line 7

def run
  are_you_sure?
  mods.each do |mod|
    run_sync(mod)
  end
end

#run_sync(mod) ⇒ Object



19
20
21
# File 'lib/terraspace/terraform/tfc/syncer.rb', line 19

def run_sync(mod)
  sync(mod).run
end

#sync(mod) ⇒ Object



23
24
25
# File 'lib/terraspace/terraform/tfc/syncer.rb', line 23

def sync(mod)
  Sync.new(@options.merge(mod: mod))
end