mux_tf 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mux_tf/cli/current.rb +22 -4
- data/lib/mux_tf/plan_formatter.rb +66 -18
- data/lib/mux_tf/terraform_helpers.rb +2 -1
- data/lib/mux_tf/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00bb3571502743499452f7444772ce2eb2b83fec4ed88152f9badde93946bf0c
|
4
|
+
data.tar.gz: 37310310f729f91745266f0a21dd86c0db0af95b04525b1e871746b81479b752
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3363c54464747c089dbdbea6f0fdffa1ba73a83bba8c5af3679206b2e8a4a8e906dc93426a596ca870219750808e4f9c1810826d11539d8aa32e1a0826c2b2db
|
7
|
+
data.tar.gz: 65f7838f5431964c253b59f1d7d3564c5498a43a39deb534797ba1a20ecd3731940956572aa1354171f84d8ccf2eef992c8e59e7b898a85bd55eccdf324e6a21
|
data/lib/mux_tf/cli/current.rb
CHANGED
@@ -80,9 +80,16 @@ module MuxTf
|
|
80
80
|
def process_remedies(remedies)
|
81
81
|
if remedies.delete? :init
|
82
82
|
log "Running terraform init ...", depth: 2
|
83
|
-
|
84
|
-
|
85
|
-
|
83
|
+
remedies = PlanFormatter.init_status_to_remedies(*PlanFormatter.run_tf_init)
|
84
|
+
if process_remedies(remedies)
|
85
|
+
remedies = PlanFormatter.process_validation(validate)
|
86
|
+
return false unless process_remedies(remedies)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
if remedies.delete? :reconfigure
|
90
|
+
log "Running terraform init ...", depth: 2
|
91
|
+
remedies = PlanFormatter.init_status_to_remedies(*PlanFormatter.run_tf_init(reconfigure: true))
|
92
|
+
return false unless process_remedies(remedies)
|
86
93
|
end
|
87
94
|
unless remedies.empty?
|
88
95
|
log "unprocessed remedies: #{remedies.to_a}", depth: 1
|
@@ -154,6 +161,7 @@ module MuxTf
|
|
154
161
|
root_cmd.add_command(shell_cmd)
|
155
162
|
root_cmd.add_command(force_unlock_cmd)
|
156
163
|
root_cmd.add_command(upgrade_cmd)
|
164
|
+
root_cmd.add_command(reconfigure_cmd)
|
157
165
|
root_cmd.add_command(interactive_cmd)
|
158
166
|
|
159
167
|
root_cmd.add_command(exit_cmd)
|
@@ -238,6 +246,16 @@ module MuxTf
|
|
238
246
|
end
|
239
247
|
end
|
240
248
|
|
249
|
+
def reconfigure_cmd
|
250
|
+
define_cmd("reconfigure", summary: "Reconfigure modules/plguins") do |_opts, _args, _cmd|
|
251
|
+
status, meta = PlanFormatter.run_tf_init(reconfigure: true)
|
252
|
+
if status != 0
|
253
|
+
log meta.inspect unless meta.empty?
|
254
|
+
log "Reconfigure Failed!"
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
241
259
|
def interactive_cmd
|
242
260
|
define_cmd("interactive", summary: "Apply interactively") do |_opts, _args, _cmd|
|
243
261
|
plan = PlanSummaryHandler.from_file(PLAN_FILENAME)
|
@@ -274,7 +292,7 @@ module MuxTf
|
|
274
292
|
end
|
275
293
|
|
276
294
|
def run_upgrade
|
277
|
-
exit_code, meta = PlanFormatter.
|
295
|
+
exit_code, meta = PlanFormatter.run_tf_init(upgrade: true)
|
278
296
|
case exit_code
|
279
297
|
when 0
|
280
298
|
[:ok, meta]
|
@@ -6,13 +6,9 @@ module MuxTf
|
|
6
6
|
extend PiotrbCliUtils::Util
|
7
7
|
|
8
8
|
class << self
|
9
|
-
# include CommandHelpers
|
10
|
-
|
11
9
|
def pretty_plan(filename)
|
12
10
|
pastel = Pastel.new
|
13
11
|
|
14
|
-
plan_output = String.new
|
15
|
-
|
16
12
|
phase = :init
|
17
13
|
|
18
14
|
meta = {}
|
@@ -31,7 +27,6 @@ module MuxTf
|
|
31
27
|
parser.state(:plan_error, /^Error: /, %i[refreshing refresh_done])
|
32
28
|
|
33
29
|
status = tf_plan(out: filename, detailed_exitcode: true, compact_warnings: true) { |raw_line|
|
34
|
-
plan_output << raw_line
|
35
30
|
parser.parse(raw_line.rstrip) do |state, line|
|
36
31
|
case state
|
37
32
|
when :none
|
@@ -87,10 +82,21 @@ module MuxTf
|
|
87
82
|
[status.status, meta]
|
88
83
|
end
|
89
84
|
|
90
|
-
def
|
91
|
-
|
85
|
+
def init_status_to_remedies(status, meta)
|
86
|
+
remedies = Set.new
|
87
|
+
if status != 0
|
88
|
+
if meta[:need_reconfigure]
|
89
|
+
remedies << :reconfigure
|
90
|
+
else
|
91
|
+
p [status, meta]
|
92
|
+
remedies << :unknown
|
93
|
+
end
|
94
|
+
end
|
95
|
+
remedies
|
96
|
+
end
|
92
97
|
|
93
|
-
|
98
|
+
def run_tf_init(upgrade: nil, reconfigure: nil)
|
99
|
+
pastel = Pastel.new
|
94
100
|
|
95
101
|
phase = :init
|
96
102
|
|
@@ -98,24 +104,39 @@ module MuxTf
|
|
98
104
|
|
99
105
|
parser = StatefulParser.new(normalizer: pastel.method(:strip))
|
100
106
|
|
101
|
-
parser.state(:
|
102
|
-
parser.state(:
|
107
|
+
parser.state(:modules_init, /^Initializing modules\.\.\./)
|
108
|
+
parser.state(:modules_upgrade, /^Upgrading modules\.\.\./)
|
109
|
+
parser.state(:backend, /^Initializing the backend\.\.\./, [:modules_init, :modules_upgrade])
|
103
110
|
parser.state(:plugins, /^Initializing provider plugins\.\.\./, [:backend])
|
104
111
|
|
105
112
|
parser.state(:plugin_warnings, /^$/, [:plugins])
|
113
|
+
parser.state(:backend_error, /Error:/, [:backend])
|
114
|
+
|
115
|
+
status = tf_init(upgrade: upgrade, reconfigure: reconfigure) { |raw_line|
|
116
|
+
stripped_line = pastel.strip(raw_line.rstrip)
|
106
117
|
|
107
|
-
status = tf_init(upgrade: true, color: false) { |raw_line|
|
108
|
-
plan_output << raw_line
|
109
118
|
parser.parse(raw_line.rstrip) do |state, line|
|
110
119
|
case state
|
111
|
-
when :
|
120
|
+
when :modules_init
|
121
|
+
if phase != state
|
122
|
+
phase = state
|
123
|
+
log "Initializing modules ", depth: 1
|
124
|
+
next
|
125
|
+
end
|
126
|
+
case stripped_line
|
127
|
+
when ""
|
128
|
+
puts
|
129
|
+
else
|
130
|
+
p [state, stripped_line]
|
131
|
+
end
|
132
|
+
when :modules_upgrade
|
112
133
|
if phase != state
|
113
134
|
# first line
|
114
135
|
phase = state
|
115
136
|
log "Upgrding modules ", depth: 1, newline: false
|
116
137
|
next
|
117
138
|
end
|
118
|
-
case
|
139
|
+
case stripped_line
|
119
140
|
when /^- (?<module>[^ ]+) in (?<path>.+)$/
|
120
141
|
# info = $~.named_captures
|
121
142
|
# log "- #{info["module"]}", depth: 2
|
@@ -127,7 +148,7 @@ module MuxTf
|
|
127
148
|
when ""
|
128
149
|
puts
|
129
150
|
else
|
130
|
-
p [state,
|
151
|
+
p [state, stripped_line]
|
131
152
|
end
|
132
153
|
when :backend
|
133
154
|
if phase != state
|
@@ -136,11 +157,20 @@ module MuxTf
|
|
136
157
|
log "Initializing the backend ", depth: 1, newline: false
|
137
158
|
next
|
138
159
|
end
|
139
|
-
case
|
160
|
+
case stripped_line
|
161
|
+
when /^Successfully configured/
|
162
|
+
log line, depth: 2
|
163
|
+
when /unless the backend/
|
164
|
+
log line, depth: 2
|
140
165
|
when ""
|
141
166
|
puts
|
142
167
|
else
|
143
|
-
p [state,
|
168
|
+
p [state, stripped_line]
|
169
|
+
end
|
170
|
+
when :backend_error
|
171
|
+
if raw_line.match "terraform init -reconfigure"
|
172
|
+
meta[:need_reconfigure] = true
|
173
|
+
log Paint["module needs to be reconfigured", :red], depth: 2
|
144
174
|
end
|
145
175
|
when :plugins
|
146
176
|
if phase != state
|
@@ -149,7 +179,25 @@ module MuxTf
|
|
149
179
|
log "Initializing provider plugins ...", depth: 1
|
150
180
|
next
|
151
181
|
end
|
152
|
-
case
|
182
|
+
case stripped_line
|
183
|
+
when /^- (?<module>.+) is built in to Terraform$/
|
184
|
+
info = $LAST_MATCH_INFO.named_captures
|
185
|
+
log "- [BUILTIN] #{info["module"]}", depth: 2
|
186
|
+
when /^- Finding (?<module>[^ ]+) versions matching "(?<version>.+)"\.\.\./
|
187
|
+
info = $LAST_MATCH_INFO.named_captures
|
188
|
+
log "- [FIND] #{info["module"]} matching #{info["version"].inspect}", depth: 2
|
189
|
+
when /^- Finding latest version of (?<module>.+)\.\.\.$/
|
190
|
+
info = $LAST_MATCH_INFO.named_captures
|
191
|
+
log "- [FIND] #{info["module"]}", depth: 2
|
192
|
+
when /^- Installing (?<module>[^ ]+) v(?<version>.+)\.\.\.$/
|
193
|
+
info = $LAST_MATCH_INFO.named_captures
|
194
|
+
log "- [INSTALLING] #{info["module"]} v#{info["version"]}", depth: 2
|
195
|
+
when /^- Installed (?<module>[^ ]+) v(?<version>.+) \(signed by( a)? (?<signed>.+)\)$/
|
196
|
+
info = $LAST_MATCH_INFO.named_captures
|
197
|
+
log "- [INSTALLED] #{info["module"]} v#{info["version"]} (#{info["signed"]})", depth: 2
|
198
|
+
when /^- Using previously-installed (?<module>[^ ]+) v(?<version>.+)$/
|
199
|
+
info = $LAST_MATCH_INFO.named_captures
|
200
|
+
log "- [USING] #{info["module"]} v#{info["version"]}", depth: 2
|
153
201
|
when /^- Downloading plugin for provider "(?<provider>[^"]+)" \((?<provider_path>[^)]+)\) (?<version>.+)\.\.\.$/
|
154
202
|
info = $LAST_MATCH_INFO.named_captures
|
155
203
|
log "- #{info["provider"]} #{info["version"]}", depth: 2
|
@@ -26,10 +26,11 @@ module MuxTf
|
|
26
26
|
capture_terraform(cmd, json: true)
|
27
27
|
end
|
28
28
|
|
29
|
-
def tf_init(input: nil, upgrade: nil, color: true, &block)
|
29
|
+
def tf_init(input: nil, upgrade: nil, reconfigure: nil, color: true, &block)
|
30
30
|
args = []
|
31
31
|
args << "-input=#{input.inspect}" unless input.nil?
|
32
32
|
args << "-upgrade" unless upgrade.nil?
|
33
|
+
args << "-reconfigure" unless reconfigure.nil?
|
33
34
|
args << "-no-color" unless color
|
34
35
|
|
35
36
|
cmd = tf_prepare_command(["init", *args], need_auth: true)
|
data/lib/mux_tf/version.rb
CHANGED