Module: MuxTf::Cli::Current

Extended by:
TerraformHelpers, PiotrbCliUtils::CmdLoop, PiotrbCliUtils::CriCommandSupport, PiotrbCliUtils::Util
Includes:
MuxTf::Coloring
Defined in:
lib/mux_tf/cli/current.rb

Overview

rubocop:disable Metrics/ModuleLength

Class Method Summary collapse

Methods included from TerraformHelpers

tf_apply, tf_force_unlock, tf_init, tf_plan, tf_show, tf_validate

Methods included from MuxTf::Coloring

included, #pastel

Class Method Details

.plan_filenameObject



63
64
65
# File 'lib/mux_tf/cli/current.rb', line 63

def plan_filename
  PlanFilenameGenerator.for_path
end

.run(args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/mux_tf/cli/current.rb', line 15

def run(args)
  version_check

  if args[0] == "cli"
    cmd_loop
    return
  end

  unless args.empty?
    root_cmd = build_root_cmd
    valid_commands = root_cmd.subcommands.map(&:name)

    if args[0] && valid_commands.include?(args[0])
      stop_reason = catch(:stop) {
        root_cmd.run(args, {}, hard_exit: true)
      }
      log pastel.red("Stopped: #{stop_reason}") if stop_reason
      return
    end
  end

  folder_name = File.basename(Dir.getwd)
  log "Processing #{pastel.cyan(folder_name)} ..."

  ENV["TF_IN_AUTOMATION"] = "1"
  ENV["TF_INPUT"] = "0"

  return launch_cmd_loop(:error) unless run_validate

  if ENV["TF_UPGRADE"]
    upgrade_status, _upgrade_meta = run_upgrade
    return launch_cmd_loop(:error) unless upgrade_status == :ok
  end

  plan_status = run_plan

  case plan_status
  when :ok
    log "exiting", depth: 1
  when :error
    launch_cmd_loop(plan_status)
  when :changes # rubocop:disable Lint/DuplicateBranch
    launch_cmd_loop(plan_status)
  when :unknown # rubocop:disable Lint/DuplicateBranch
    launch_cmd_loop(plan_status)
  end
end