Class: MuxTf::Cli::Current::PlanCommand

Inherits:
Object
  • Object
show all
Extended by:
PiotrbCliUtils::Util
Includes:
TerraformHelpers, PiotrbCliUtils::CriCommandSupport
Defined in:
lib/mux_tf/cli/current/plan_command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TerraformHelpers

#tf_apply, #tf_force_unlock, #tf_init, #tf_plan, #tf_show, #tf_stream_helper, #tf_validate

Instance Attribute Details

#last_lock_infoObject (readonly)

Returns the value of attribute last_lock_info.



11
12
13
# File 'lib/mux_tf/cli/current/plan_command.rb', line 11

def last_lock_info
  @last_lock_info
end

Instance Method Details

#plan_cmdObject



13
14
15
16
17
# File 'lib/mux_tf/cli/current/plan_command.rb', line 13

def plan_cmd
  define_cmd("plan", summary: "Re-run plan") do |_opts, _args, _cmd|
    run_validate && run_plan
  end
end

#run_plan(targets: [], level: 1, retry_count: 0) ⇒ Object



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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/mux_tf/cli/current/plan_command.rb', line 29

def run_plan(targets: [], level: 1, retry_count: 0)
  plan_status, = Current.remedy_retry_helper(from: :plan, level: level, attempt: retry_count) {
    @last_lock_info = nil

    plan_filename = PlanFilenameGenerator.for_path

    plan_status, meta = create_plan(plan_filename, targets: targets)

    Current.print_errors_and_warnings(meta)

    remedies = detect_remedies_from_plan(meta)

    if remedies.include?(:unlock)
      @last_lock_info = extract_lock_info(meta)
      throw :abort, [plan_status, meta]
    end

    throw :abort, [plan_status, meta] if remedies.include?(:auth)

    [remedies, plan_status, meta]
  }

  case plan_status
  when :ok
    log "no changes", depth: 1
  when :error
    log "something went wrong", depth: 1
  when :changes
    if ENV["JSON_PLAN"]
      plan_filename = PlanFilenameGenerator.for_path
      plan = PlanSummaryHandler.from_file(plan_filename)

      log plan.plan_text_output

      log ""

      plan.simple_summary do |line|
        log line, depth: 2
      end
    else
      log "Printing Plan Summary ...", depth: 1
      plan_filename = PlanFilenameGenerator.for_path
      plan = PlanSummaryHandler.from_file(plan_filename)
      plan.simple_summary do |line|
        log line, depth: 2
      end
    end
  when :unknown
    # nothing
  end

  plan_status
end

#run_validate(level: 1) ⇒ Object

returns boolean true if succeeded



20
21
22
23
24
25
26
27
# File 'lib/mux_tf/cli/current/plan_command.rb', line 20

def run_validate(level: 1)
  Current.remedy_retry_helper(from: :validate, level: level) do
    validation_info = validate
    PlanFormatter.print_validation_errors(validation_info)
    remedies = PlanFormatter.process_validation(validation_info)
    [remedies, validation_info]
  end
end