terraspace 0.6.6 → 0.6.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/lib/terraspace/cli/check_setup.rb +1 -0
- data/lib/terraspace/cli/fmt.rb +1 -1
- data/lib/terraspace/cli/help/fmt.md +6 -2
- data/lib/terraspace/hooks/runner.rb +25 -2
- data/lib/terraspace/shell.rb +70 -42
- data/lib/terraspace/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8aff7c57d034f741f93405653b027fa5f6fc7cd149bb705401777c46d9d784ce
|
4
|
+
data.tar.gz: 108a8ba1f3945df8a2aa682df18715952462182fc79a0ee2387c83c969f5d683
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05bfd0234b175533d1f8e477aaa3fffd6c1397d5c3640bde82217f18ec339e02698b37dabcf79e800f57f2c148fc6923f06c697e740fbd58561abaac5bbe903b
|
7
|
+
data.tar.gz: f9c2ff7ae00c5495c30da0b9db1d7f7c6dcc73045dcb6396d8df284e3d79e5c3a6607723629bae7d5d09446e3296ea1e27f9cefdb5cfd6ade419f429bb0ea5da
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,22 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
|
5
5
|
|
6
|
+
## [0.6.11] - 2021-06-22
|
7
|
+
- [#120](https://github.com/boltops-tools/terraspace/pull/120) version check handles a major change
|
8
|
+
|
9
|
+
## [0.6.10] - 2021-06-01
|
10
|
+
- [#117](https://github.com/boltops-tools/terraspace/pull/117) fix terraspace fmt -t all
|
11
|
+
- clean up IO select call
|
12
|
+
|
13
|
+
## [0.6.9] - 2021-05-07
|
14
|
+
- [#112](https://github.com/boltops-tools/terraspace/pull/112) fix smart auto retry
|
15
|
+
|
16
|
+
## [0.6.8] - 2021-05-07
|
17
|
+
- [#110](https://github.com/boltops-tools/terraspace/pull/110) fix popen deadlock with large amounts of output [#97](https://github.com/boltops-tools/terraspace/pull/97) Terraspace hangs when TF_LOG=TRACE environment variable exists #97
|
18
|
+
|
19
|
+
## [0.6.7] - 2021-05-05
|
20
|
+
- [#108](https://github.com/boltops-tools/terraspace/pull/108) provide runner context to terraspace hook
|
21
|
+
|
6
22
|
## [0.6.6] - 2021-04-15
|
7
23
|
- [#101](https://github.com/boltops-tools/terraspace/pull/101) terraspace force-unlock command
|
8
24
|
- [#102](https://github.com/boltops-tools/terraspace/pull/102) fix terraspace all summarized logging
|
@@ -58,6 +58,7 @@ class Terraspace::CLI
|
|
58
58
|
end
|
59
59
|
major, minor, _ = version.split('.')
|
60
60
|
required_major, required_minor = REQUIRED_TERRAFORM_VERSION.split('.')
|
61
|
+
return true if major.to_i > required_major.to_i
|
61
62
|
x = major.to_i >= required_major.to_i
|
62
63
|
y = minor.to_i >= required_minor.to_i
|
63
64
|
x && y
|
data/lib/terraspace/cli/fmt.rb
CHANGED
@@ -14,9 +14,13 @@ Format all source files.
|
|
14
14
|
Format specific module or stack.
|
15
15
|
|
16
16
|
$ terraspace fmt stack1
|
17
|
-
$ terraspace fmt module1
|
17
|
+
$ terraspace fmt module1 -t module
|
18
18
|
|
19
19
|
Format scoping to module or stack types. In case there's a module and stack with the same name.
|
20
20
|
|
21
21
|
$ terraspace fmt example -t module
|
22
|
-
$ terraspace fmt demo -t
|
22
|
+
$ terraspace fmt demo -t stack
|
23
|
+
|
24
|
+
Format all, so both modules and stacks:
|
25
|
+
|
26
|
+
$ terraspace fmt -t all
|
@@ -2,6 +2,17 @@ module Terraspace::Hooks
|
|
2
2
|
class Runner
|
3
3
|
include Terraspace::Util
|
4
4
|
|
5
|
+
# exposing mod and hook so terraspace hooks have access to them via runner context. IE:
|
6
|
+
#
|
7
|
+
# class EnvExporter
|
8
|
+
# def call(runner)
|
9
|
+
# puts "runner.hook #{runner.hook}"
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# Docs: http://terraspace.cloud/docs/config/hooks/ruby/#method-argument
|
14
|
+
#
|
15
|
+
attr_reader :mod, :hook
|
5
16
|
def initialize(mod, hook)
|
6
17
|
@mod, @hook = mod, hook
|
7
18
|
@execute = @hook["execute"]
|
@@ -12,12 +23,24 @@ module Terraspace::Hooks
|
|
12
23
|
when String
|
13
24
|
Terraspace::Shell.new(@mod, @execute, exit_on_fail: @hook["exit_on_fail"]).run
|
14
25
|
when -> (e) { e.respond_to?(:public_instance_methods) && e.public_instance_methods.include?(:call) }
|
15
|
-
@execute.new
|
26
|
+
executor = @execute.new
|
16
27
|
when -> (e) { e.respond_to?(:call) }
|
17
|
-
@execute
|
28
|
+
executor = @execute
|
18
29
|
else
|
19
30
|
logger.warn "WARN: execute option not set for hook: #{@hook.inspect}"
|
20
31
|
end
|
32
|
+
|
33
|
+
return unless executor
|
34
|
+
|
35
|
+
meth = executor.method(:call)
|
36
|
+
case meth.arity
|
37
|
+
when 0
|
38
|
+
executor.call # backwards compatibility
|
39
|
+
when 1
|
40
|
+
executor.call(self)
|
41
|
+
else
|
42
|
+
raise "The #{executor} call method definition has been more than 1 arguments and is not supported"
|
43
|
+
end
|
21
44
|
end
|
22
45
|
end
|
23
46
|
end
|
data/lib/terraspace/shell.rb
CHANGED
@@ -29,70 +29,98 @@ module Terraspace
|
|
29
29
|
|
30
30
|
def popen3(env)
|
31
31
|
Open3.popen3(env, @command, chdir: @mod.cache_dir) do |stdin, stdout, stderr, wait_thread|
|
32
|
-
|
33
|
-
while out = stdout.gets
|
34
|
-
terraform_to_stdout(out)
|
35
|
-
end
|
36
|
-
|
37
|
-
while err = stderr.gets
|
38
|
-
@error ||= Error.new
|
39
|
-
@error.lines << err # aggregate all error lines
|
40
|
-
unless @error.known?
|
41
|
-
# Sometimes may print a "\e[31m\n" which like during dependencies fetcher init
|
42
|
-
# suppress it so dont get a bunch of annoying "newlines"
|
43
|
-
next if err == "\e[31m\n" && @options[:suppress_error_color]
|
44
|
-
logger.error(err)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
32
|
+
handle_streams(stdin, stdout, stderr)
|
48
33
|
status = wait_thread.value.exitstatus
|
49
34
|
exit_status(status)
|
50
35
|
end
|
51
36
|
end
|
52
37
|
|
53
|
-
|
54
|
-
|
38
|
+
BLOCK_SIZE = Integer(ENV['TS_BUFFER_BLOCK_SIZE'] || 102400)
|
39
|
+
BUFFER_TIMEOUT = Integer(ENV['TS_BUFFER_TIMEOUT'] || 3600) # 3600s = 1h
|
40
|
+
def handle_streams(stdin, stdout, stderr)
|
41
|
+
# note: t=0 and t=nil means no timeout. See: https://bit.ly/2PURlCX
|
42
|
+
t = BUFFER_TIMEOUT.to_i unless BUFFER_TIMEOUT.nil?
|
43
|
+
Timeout::timeout(t) do
|
44
|
+
files = [stdout, stderr]
|
45
|
+
until all_eof?(files) do
|
46
|
+
ready = IO.select(files)
|
47
|
+
next unless ready
|
55
48
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
49
|
+
readable = ready[0]
|
50
|
+
readable.each do |f|
|
51
|
+
buffer = f.read_nonblock(BLOCK_SIZE, exception: false)
|
52
|
+
next unless buffer
|
53
|
+
|
54
|
+
lines = buffer.split("\n")
|
55
|
+
lines.each do |line|
|
56
|
+
if f.fileno == stdout.fileno
|
57
|
+
handle_stdout(line)
|
58
|
+
handle_input(stdin, line)
|
59
|
+
else
|
60
|
+
handle_stderr(line)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
62
65
|
end
|
63
66
|
end
|
64
67
|
|
68
|
+
def handle_stderr(line)
|
69
|
+
@error ||= Error.new
|
70
|
+
@error.lines << line # aggregate all error lines
|
71
|
+
|
72
|
+
return if @error.known?
|
73
|
+
# Sometimes may print a "\e[31m\n" which like during dependencies fetcher init
|
74
|
+
# suppress it so dont get a bunch of annoying "newlines"
|
75
|
+
return if line == "\e[31m\n" && @options[:suppress_error_color]
|
76
|
+
|
77
|
+
logger.error(line)
|
78
|
+
end
|
79
|
+
|
80
|
+
def all_eof?(files)
|
81
|
+
files.find { |f| !f.eof }.nil?
|
82
|
+
end
|
83
|
+
|
65
84
|
# Terraform doesnt seem to stream the line that prompts with "Enter a value:" when using Open3.popen3
|
66
85
|
# Hack around it by mimicking the "Enter a value:" prompt
|
67
86
|
#
|
68
87
|
# Note: system does stream the prompt but using Open3.popen3 so we can capture output to save to logs.
|
69
|
-
def
|
70
|
-
|
88
|
+
def handle_input(stdin, line)
|
89
|
+
# stdout doesnt seem to flush and show "Enter a value: " look for earlier output
|
71
90
|
patterns = [
|
72
91
|
"Only 'yes' will be accepted", # prompt for apply. can happen on apply
|
73
92
|
"\e[0m\e[1mvar.", # prompts for variable input. can happen on plan or apply. looking for bold marker also in case "var." shows up somewhere else
|
74
93
|
]
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
94
|
+
if patterns.any? { |pattern| line.include?(pattern) }
|
95
|
+
print "\n Enter a value: ".bright
|
96
|
+
stdin.write_nonblock($stdin.gets)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def exit_status(status)
|
101
|
+
return if status == 0
|
102
|
+
|
103
|
+
exit_on_fail = @options[:exit_on_fail].nil? ? true : @options[:exit_on_fail]
|
104
|
+
if @error && @error.known?
|
105
|
+
raise @error.instance
|
106
|
+
elsif exit_on_fail
|
107
|
+
logger.error "Error running command: #{@command}".color(:red)
|
108
|
+
exit status
|
85
109
|
end
|
86
110
|
end
|
87
111
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
112
|
+
def handle_stdout(line)
|
113
|
+
prompted = line.include?('Enter a value')
|
114
|
+
@prompt_shown ||= prompted
|
115
|
+
return if @prompt_shown && prompted
|
116
|
+
|
117
|
+
# Terraspace logger has special stdout method so original terraform output
|
118
|
+
# can be piped to jq. IE:
|
119
|
+
# terraspace show demo --json | jq
|
92
120
|
if logger.respond_to?(:stdout) && !@options[:log_to_stderr]
|
93
|
-
logger.stdout(
|
121
|
+
logger.stdout(line)
|
94
122
|
else
|
95
|
-
logger.info(
|
123
|
+
logger.info(line)
|
96
124
|
end
|
97
125
|
end
|
98
126
|
end
|
data/lib/terraspace/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: terraspace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tung Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|