mux_tf 0.15.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/mux_tf/cli/current/plan_command.rb +131 -0
- data/lib/mux_tf/cli/current.rb +172 -206
- data/lib/mux_tf/cli/mux.rb +168 -5
- data/lib/mux_tf/cli/plan_summary.rb +12 -21
- data/lib/mux_tf/error_handling_methods.rb +79 -0
- data/lib/mux_tf/formatter_common.rb +257 -0
- data/lib/mux_tf/handlers/plan_handler.rb +8 -0
- data/lib/mux_tf/handlers.rb +6 -0
- data/lib/mux_tf/init_formatter.rb +306 -0
- data/lib/mux_tf/plan_formatter.rb +285 -602
- data/lib/mux_tf/plan_summary_handler.rb +52 -31
- data/lib/mux_tf/plan_utils.rb +215 -56
- data/lib/mux_tf/resource_tokenizer.rb +1 -1
- data/lib/mux_tf/stderr_line_handler.rb +145 -0
- data/lib/mux_tf/terraform_helpers.rb +46 -7
- data/lib/mux_tf/tmux.rb +55 -6
- data/lib/mux_tf/version.rb +1 -1
- data/lib/mux_tf/yaml_cache.rb +51 -34
- data/lib/mux_tf.rb +6 -12
- data/mux_tf.gemspec +12 -1
- metadata +110 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba26f39729fa94e469929d34bbbddfe76015515a25080f0e33f9052db4d3770f
|
4
|
+
data.tar.gz: 0b458886281f0c795982faf52b0fd91ee42831839c2158f32994cbecd66bf354
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd0c0487a164a98beef1eaa088cdbd46692fc8ad827b6e1388e6258ed8bc880c86330e39bdb083c639038aeb24dab345cbdc69dca06997a70a30506c8397e010
|
7
|
+
data.tar.gz: 56e4b5582a7680fec00b36caa6e2c7752317d87a9e661140c266dded106284765cd554d6908c030fb858a490e2523e272fb6247108407e7a430b5fec6ce0bde6
|
@@ -0,0 +1,131 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MuxTf
|
4
|
+
module Cli
|
5
|
+
module Current
|
6
|
+
class PlanCommand
|
7
|
+
include TerraformHelpers
|
8
|
+
include PiotrbCliUtils::CriCommandSupport
|
9
|
+
extend PiotrbCliUtils::Util
|
10
|
+
|
11
|
+
attr_reader :last_lock_info
|
12
|
+
|
13
|
+
def plan_cmd
|
14
|
+
define_cmd("plan", summary: "Re-run plan") do |_opts, _args, _cmd|
|
15
|
+
run_validate && run_plan
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# returns boolean true if succeeded
|
20
|
+
def run_validate(level: 1)
|
21
|
+
Current.remedy_retry_helper(from: :validate, level: level) do
|
22
|
+
validation_info = validate
|
23
|
+
PlanFormatter.print_validation_errors(validation_info)
|
24
|
+
remedies = PlanFormatter.process_validation(validation_info)
|
25
|
+
[remedies, validation_info]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def run_plan(targets: [], level: 1, retry_count: 0)
|
30
|
+
plan_status, = Current.remedy_retry_helper(from: :plan, level: level, attempt: retry_count) {
|
31
|
+
@last_lock_info = nil
|
32
|
+
|
33
|
+
plan_filename = PlanFilenameGenerator.for_path
|
34
|
+
|
35
|
+
plan_status, meta = create_plan(plan_filename, targets: targets)
|
36
|
+
|
37
|
+
Current.print_errors_and_warnings(meta)
|
38
|
+
|
39
|
+
remedies = detect_remedies_from_plan(meta)
|
40
|
+
|
41
|
+
if remedies.include?(:unlock)
|
42
|
+
@last_lock_info = extract_lock_info(meta)
|
43
|
+
throw :abort, [plan_status, meta]
|
44
|
+
end
|
45
|
+
|
46
|
+
throw :abort, [plan_status, meta] if remedies.include?(:auth)
|
47
|
+
|
48
|
+
[remedies, plan_status, meta]
|
49
|
+
}
|
50
|
+
|
51
|
+
case plan_status
|
52
|
+
when :ok
|
53
|
+
log "no changes", depth: 1
|
54
|
+
when :error
|
55
|
+
log "something went wrong", depth: 1
|
56
|
+
when :changes
|
57
|
+
if ENV["JSON_PLAN"]
|
58
|
+
plan_filename = PlanFilenameGenerator.for_path
|
59
|
+
plan = PlanSummaryHandler.from_file(plan_filename)
|
60
|
+
|
61
|
+
log plan.plan_text_output
|
62
|
+
|
63
|
+
log ""
|
64
|
+
|
65
|
+
plan.simple_summary do |line|
|
66
|
+
log line, depth: 2
|
67
|
+
end
|
68
|
+
else
|
69
|
+
log "Printing Plan Summary ...", depth: 1
|
70
|
+
plan_filename = PlanFilenameGenerator.for_path
|
71
|
+
plan = PlanSummaryHandler.from_file(plan_filename)
|
72
|
+
plan.simple_summary do |line|
|
73
|
+
log line, depth: 2
|
74
|
+
end
|
75
|
+
end
|
76
|
+
when :unknown
|
77
|
+
# nothing
|
78
|
+
end
|
79
|
+
|
80
|
+
plan_status
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def validate
|
86
|
+
log "Validating module ...", depth: 1
|
87
|
+
tf_validate # from Terraform Helpers
|
88
|
+
end
|
89
|
+
|
90
|
+
def create_plan(filename, targets: [])
|
91
|
+
log "Preparing Plan ...", depth: 1
|
92
|
+
exit_code, meta = PlanFormatter.pretty_plan(filename, targets: targets)
|
93
|
+
case exit_code
|
94
|
+
when 0
|
95
|
+
[:ok, meta]
|
96
|
+
when 1
|
97
|
+
[:error, meta]
|
98
|
+
when 2
|
99
|
+
[:changes, meta]
|
100
|
+
else
|
101
|
+
log pastel.yellow("terraform plan exited with an unknown exit code: #{exit_code}")
|
102
|
+
[:unknown, meta]
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def detect_remedies_from_plan(meta)
|
107
|
+
remedies = Set.new
|
108
|
+
meta[:errors]&.each do |error|
|
109
|
+
remedies << :plan if error[:message].include?("timeout while waiting for plugin to start")
|
110
|
+
end
|
111
|
+
remedies << :unlock if lock_error?(meta)
|
112
|
+
remedies << :auth if meta[:need_auth]
|
113
|
+
remedies
|
114
|
+
end
|
115
|
+
|
116
|
+
def lock_error?(meta)
|
117
|
+
meta && meta["error"] == "lock"
|
118
|
+
end
|
119
|
+
|
120
|
+
def extract_lock_info(meta)
|
121
|
+
{
|
122
|
+
lock_id: meta["ID"],
|
123
|
+
operation: meta["Operation"],
|
124
|
+
who: meta["Who"],
|
125
|
+
created: meta["Created"]
|
126
|
+
}
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|