mux_tf 0.3.3 → 0.4.5
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.rb +25 -5
- data/lib/mux_tf/plan_formatter.rb +66 -18
- data/lib/mux_tf/plan_summary_handler.rb +2 -0
- data/lib/mux_tf/terraform_helpers.rb +2 -1
- data/lib/mux_tf/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bd3960b0080f99acf0d83a006d8a49fff87e31c93fc4fe2b86524abb3b98357
|
4
|
+
data.tar.gz: b03d2cf165991634502a75e624c69f22dd5adce5eb0ad9565368a667248b45a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d27554cd534c7c75ee592213863989e35a3f6ce1e6bd466103ea35cbe483193d7ab7746b251b3bd085e2242015ae5f2aad3c7d5d06c59eff198f7b917d6cdf2
|
7
|
+
data.tar.gz: c1de1a658d5dffb6bf63be73260c90a358d5d8fe8b52669683c73ad72502bb679b72f94e6cd08c6f53b7ddc23beaf5060ed505d33dec82df4b709b6e0c3836dc
|
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)
|
@@ -170,7 +178,8 @@ module MuxTf
|
|
170
178
|
define_cmd("apply", summary: "Apply the current plan") do |_opts, _args, _cmd|
|
171
179
|
status = tf_apply(filename: PLAN_FILENAME)
|
172
180
|
if status.success?
|
173
|
-
|
181
|
+
plan_status = run_plan
|
182
|
+
throw :stop, :done if plan_status == :ok
|
174
183
|
else
|
175
184
|
log "Apply Failed!"
|
176
185
|
end
|
@@ -238,6 +247,16 @@ module MuxTf
|
|
238
247
|
end
|
239
248
|
end
|
240
249
|
|
250
|
+
def reconfigure_cmd
|
251
|
+
define_cmd("reconfigure", summary: "Reconfigure modules/plguins") do |_opts, _args, _cmd|
|
252
|
+
status, meta = PlanFormatter.run_tf_init(reconfigure: true)
|
253
|
+
if status != 0
|
254
|
+
log meta.inspect unless meta.empty?
|
255
|
+
log "Reconfigure Failed!"
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
241
260
|
def interactive_cmd
|
242
261
|
define_cmd("interactive", summary: "Apply interactively") do |_opts, _args, _cmd|
|
243
262
|
plan = PlanSummaryHandler.from_file(PLAN_FILENAME)
|
@@ -271,10 +290,11 @@ module MuxTf
|
|
271
290
|
when :unknown
|
272
291
|
# nothing
|
273
292
|
end
|
293
|
+
plan_status
|
274
294
|
end
|
275
295
|
|
276
296
|
def run_upgrade
|
277
|
-
exit_code, meta = PlanFormatter.
|
297
|
+
exit_code, meta = PlanFormatter.run_tf_init(upgrade: true)
|
278
298
|
case exit_code
|
279
299
|
when 0
|
280
300
|
[: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
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mux_tf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Banasik
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -122,7 +122,7 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
-
description:
|
125
|
+
description:
|
126
126
|
email:
|
127
127
|
- piotr@jane.app
|
128
128
|
executables:
|
@@ -155,7 +155,7 @@ licenses:
|
|
155
155
|
metadata:
|
156
156
|
homepage_uri: https://github.com/piotrb/mux_tf
|
157
157
|
source_code_uri: https://github.com/piotrb/mux_tf
|
158
|
-
post_install_message:
|
158
|
+
post_install_message:
|
159
159
|
rdoc_options: []
|
160
160
|
require_paths:
|
161
161
|
- lib
|
@@ -170,8 +170,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
170
170
|
- !ruby/object:Gem::Version
|
171
171
|
version: '0'
|
172
172
|
requirements: []
|
173
|
-
rubygems_version: 3.
|
174
|
-
signing_key:
|
173
|
+
rubygems_version: 3.0.3
|
174
|
+
signing_key:
|
175
175
|
specification_version: 4
|
176
176
|
summary: Terraform Multiplexing Scripts
|
177
177
|
test_files: []
|