terraspace 0.6.11 → 0.6.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -0
- data/lib/terraspace/cli/check_setup.rb +1 -1
- data/lib/terraspace/cli/help/state.md +30 -0
- data/lib/terraspace/cli/init.rb +1 -1
- data/lib/terraspace/cli.rb +3 -3
- data/lib/terraspace/command.rb +9 -1
- data/lib/terraspace/compiler/builder.rb +9 -5
- data/lib/terraspace/compiler/commands_concern.rb +2 -2
- data/lib/terraspace/compiler/dsl/syntax/helpers/common.rb +1 -1
- data/lib/terraspace/core.rb +10 -0
- data/lib/terraspace/logger.rb +6 -2
- data/lib/terraspace/shell.rb +17 -16
- data/lib/terraspace/terraform/args/default.rb +17 -5
- data/lib/terraspace/version.rb +1 -1
- data/terraspace.gemspec +2 -2
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c50b3dfbe37199a7e64fa53fdd2df157d63c045ee0101d25702d52a78b6ff555
|
4
|
+
data.tar.gz: 9731b4341f086406fb11c9436ef434f52261f6161b6c73f00bbefb5d75869944
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 041ffd7c3b81c6160d8332c93583013865cd8c70b7825dd6af570e91a1a59e4c65aa39a9b6745c35b76692b43fb2df89e390dd380ecf3dcb8c78f3bf21a338c0
|
7
|
+
data.tar.gz: bce08f9c7cc634f06d53e9d50255cec2db886c65c2b8e23cbee855fc87080d2ad1a0787ef55c250b93b80e894d1c4d6a72034e5ed33d4ac2beaf1c4a090966f7
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,28 @@
|
|
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.16] - 2021-10-01
|
7
|
+
- [#141](https://github.com/boltops-tools/terraspace/pull/141) terraspace output: remove extra newline at the end
|
8
|
+
|
9
|
+
## [0.6.15] - 2021-10-01
|
10
|
+
- [#140](https://github.com/boltops-tools/terraspace/pull/140) fix terraspace output and Enter a value handling
|
11
|
+
|
12
|
+
## [0.6.14] - 2021-09-30
|
13
|
+
- [#134](https://github.com/boltops-tools/terraspace/pull/134) Use file not plan for the var-files argument
|
14
|
+
- [#139](https://github.com/boltops-tools/terraspace/pull/139) Fix terraspace output to not add extra newlines
|
15
|
+
- terraspace list: change default to show both stacks and modules
|
16
|
+
|
17
|
+
## [0.6.13] - 2021-08-10
|
18
|
+
- use terraspace-bundler 0.4.0
|
19
|
+
|
20
|
+
## [0.6.12] - 2021-07-26
|
21
|
+
- [#128](https://github.com/boltops-tools/terraspace/pull/128) Improve terraspace state comands and Terraspace.argv for internal usage
|
22
|
+
- [#129](https://github.com/boltops-tools/terraspace/pull/129) use Dir.glob(expr, File::FNM_DOTMATCH) so dotfiles are copied, allowing .terraform-version for tfenv
|
23
|
+
- allow -h to help outside terraspace project generally
|
24
|
+
- require rspec-terraspace 0.3.0
|
25
|
+
- state subcommands: straight delegate args
|
26
|
+
- Terraspace.argv for consistency with terraspace test
|
27
|
+
|
6
28
|
## [0.6.11] - 2021-06-22
|
7
29
|
- [#120](https://github.com/boltops-tools/terraspace/pull/120) version check handles a major change
|
8
30
|
|
@@ -0,0 +1,30 @@
|
|
1
|
+
## Examples
|
2
|
+
|
3
|
+
terraspace state list demo
|
4
|
+
terraspace state mv demo
|
5
|
+
terraspace state pull demo
|
6
|
+
terraspace state push demo
|
7
|
+
terraspace state replace demo
|
8
|
+
terraspace state rm demo
|
9
|
+
terraspace state show demo
|
10
|
+
|
11
|
+
## Args Straight Delegation
|
12
|
+
|
13
|
+
The `terraspace state` command delegates to the `terraform state` commands passing the arguments straight through. Refer to the underlying `terraform` command help for arguments. Example:
|
14
|
+
|
15
|
+
terraform state list -h
|
16
|
+
...
|
17
|
+
Options:
|
18
|
+
...
|
19
|
+
-id=ID Filters the results to include only instances whose
|
20
|
+
resource types have an attribute named "id" whose value
|
21
|
+
equals the given id string.
|
22
|
+
|
23
|
+
This means we can use the `-id` or `--id` option and terraspace will pass it straight through. Example:
|
24
|
+
|
25
|
+
terraspace state list demo --id enabled-bull
|
26
|
+
Building .terraspace-cache/us-west-2/dev/stacks/demo
|
27
|
+
Built in .terraspace-cache/us-west-2/dev/stacks/demo
|
28
|
+
Current directory: .terraspace-cache/us-west-2/dev/stacks/demo
|
29
|
+
=> terraform state list --id enabled-bull
|
30
|
+
random_pet.this
|
data/lib/terraspace/cli/init.rb
CHANGED
data/lib/terraspace/cli.rb
CHANGED
@@ -28,7 +28,7 @@ module Terraspace
|
|
28
28
|
option :reconfigure, type: :boolean, desc: "Add terraform -reconfigure option"
|
29
29
|
}
|
30
30
|
type_option = Proc.new {
|
31
|
-
option :type, default: "
|
31
|
+
option :type, default: "all", aliases: %w[t], desc: "Type: stack, module, or all"
|
32
32
|
}
|
33
33
|
|
34
34
|
desc "all SUBCOMMAND", "all subcommands"
|
@@ -189,8 +189,8 @@ module Terraspace
|
|
189
189
|
|
190
190
|
desc "state SUBCOMMAND STACK", "Run state."
|
191
191
|
long_desc Help.text(:state)
|
192
|
-
def state(subcommand, mod)
|
193
|
-
State.new(options.merge(subcommand: subcommand, mod: mod)).run
|
192
|
+
def state(subcommand, mod, *rest)
|
193
|
+
State.new(options.merge(subcommand: subcommand, mod: mod, rest: rest)).run
|
194
194
|
end
|
195
195
|
|
196
196
|
desc "test", "Run test."
|
data/lib/terraspace/command.rb
CHANGED
@@ -30,6 +30,9 @@ module Terraspace
|
|
30
30
|
include Terraspace::Util::Logging
|
31
31
|
|
32
32
|
def dispatch(m, args, options, config)
|
33
|
+
# Terraspace.argv provides consistency when terraspace is being called by rspec-terrspace test harness
|
34
|
+
Terraspace.argv = args.clone # important to clone since Thor removes the first argv
|
35
|
+
|
33
36
|
check_standalone_install!
|
34
37
|
check_project!(args.first)
|
35
38
|
|
@@ -42,7 +45,6 @@ module Terraspace
|
|
42
45
|
# as well thor's normal way:
|
43
46
|
#
|
44
47
|
# terraspace help command
|
45
|
-
help_flags = Thor::HELP_MAPPINGS + ["help"]
|
46
48
|
if args.length > 1 && !(args & help_flags).empty?
|
47
49
|
args -= help_flags
|
48
50
|
args.insert(-2, "help")
|
@@ -59,6 +61,11 @@ module Terraspace
|
|
59
61
|
super
|
60
62
|
end
|
61
63
|
|
64
|
+
def help_flags
|
65
|
+
Thor::HELP_MAPPINGS + ["help"]
|
66
|
+
end
|
67
|
+
private :help_flags
|
68
|
+
|
62
69
|
def check_standalone_install!
|
63
70
|
return unless opt?
|
64
71
|
version_manager = "rvm" if rvm?
|
@@ -94,6 +101,7 @@ module Terraspace
|
|
94
101
|
def check_project!(command_name)
|
95
102
|
return if subcommand?
|
96
103
|
return if command_name.nil?
|
104
|
+
return if help_flags.include?(Terraspace.argv.last) # IE: -h help
|
97
105
|
return if %w[-h -v check_setup completion completion_script help new test version].include?(command_name)
|
98
106
|
return if File.exist?("#{Terraspace.root}/config/app.rb")
|
99
107
|
logger.error "ERROR: It doesnt look like this is a terraspace project. Are you sure you are in a terraspace project?".color(:red)
|
@@ -37,7 +37,7 @@ module Terraspace::Compiler
|
|
37
37
|
|
38
38
|
def build_config_terraform
|
39
39
|
expr = "#{Terraspace.root}/config/terraform/**/*"
|
40
|
-
|
40
|
+
search(expr).each do |path|
|
41
41
|
next unless File.file?(path)
|
42
42
|
next if path.include?('config/terraform/tfvars')
|
43
43
|
build_config_file(basename(path))
|
@@ -45,13 +45,13 @@ module Terraspace::Compiler
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def build_config_file(file)
|
48
|
-
existing =
|
48
|
+
existing = search("#{@mod.root}/#{file}").first
|
49
49
|
return if existing && existing.ends_with?(".tf") # do not overwrite existing backend.tf, provider.tf, etc
|
50
50
|
|
51
51
|
if file.ends_with?(".rb")
|
52
|
-
src_path =
|
52
|
+
src_path = search("#{@mod.root}/#{basename(file)}").first # existing source. IE: backend.rb in module folder
|
53
53
|
end
|
54
|
-
src_path ||=
|
54
|
+
src_path ||= search("#{Terraspace.root}/config/terraform/#{file}").first
|
55
55
|
build_mod_file(src_path) if src_path
|
56
56
|
end
|
57
57
|
|
@@ -65,7 +65,7 @@ module Terraspace::Compiler
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def with_path(path)
|
68
|
-
|
68
|
+
search(path).each do |src_path|
|
69
69
|
next if skip?(src_path)
|
70
70
|
yield(src_path)
|
71
71
|
end
|
@@ -80,5 +80,9 @@ module Terraspace::Compiler
|
|
80
80
|
src_path.include?("#{@mod.root}/test") ||
|
81
81
|
src_path.include?("#{@mod.root}/tfvars")
|
82
82
|
end
|
83
|
+
|
84
|
+
def search(expr)
|
85
|
+
Dir.glob(expr, File::FNM_DOTMATCH)
|
86
|
+
end
|
83
87
|
end
|
84
88
|
end
|
@@ -11,8 +11,8 @@ module Terraspace::Compiler
|
|
11
11
|
def command_is?(*commands)
|
12
12
|
commands.flatten!
|
13
13
|
commands.map!(&:to_s)
|
14
|
-
commands.include?(
|
15
|
-
|
14
|
+
commands.include?(Terraspace.argv[0]) || # IE: terraspace up
|
15
|
+
Terraspace.argv[0] == "all" && commands.include?(Terraspace.argv[1]) # IE: terraspace all up
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -19,7 +19,7 @@ module Terraspace::Compiler::Dsl::Syntax::Helpers
|
|
19
19
|
# terraspace_command('-') => "terraspace-up-demo"
|
20
20
|
#
|
21
21
|
def terraspace_command(separator=' ')
|
22
|
-
args =
|
22
|
+
args = Terraspace.argv[0..1] || []
|
23
23
|
command = ["terraspace"] + args
|
24
24
|
command.join(separator)
|
25
25
|
end
|
data/lib/terraspace/core.rb
CHANGED
@@ -58,5 +58,15 @@ module Terraspace
|
|
58
58
|
i.is_a?(Regexp) ? path =~ i : path.include?(i)
|
59
59
|
end
|
60
60
|
end
|
61
|
+
|
62
|
+
# Terraspace.argv provides consistency when terraspace is being called by rspec-terrspace test harness
|
63
|
+
# So use Terraspace.argv instead of ARGV constant
|
64
|
+
def argv=(argv)
|
65
|
+
@@argv = argv
|
66
|
+
end
|
67
|
+
|
68
|
+
def argv
|
69
|
+
@@argv
|
70
|
+
end
|
61
71
|
end
|
62
72
|
end
|
data/lib/terraspace/logger.rb
CHANGED
@@ -20,8 +20,12 @@ module Terraspace
|
|
20
20
|
# Used to allow terraform output to always go to stdout
|
21
21
|
# Terraspace output goes to stderr by default
|
22
22
|
# See: terraspace/shell.rb
|
23
|
-
def stdout(msg)
|
24
|
-
|
23
|
+
def stdout(msg, newline: true)
|
24
|
+
if newline
|
25
|
+
puts msg
|
26
|
+
else
|
27
|
+
print msg
|
28
|
+
end
|
25
29
|
end
|
26
30
|
end
|
27
31
|
end
|
data/lib/terraspace/shell.rb
CHANGED
@@ -20,13 +20,18 @@ module Terraspace
|
|
20
20
|
def shell
|
21
21
|
env = @options[:env] || {}
|
22
22
|
env.stringify_keys!
|
23
|
-
if
|
23
|
+
if system?
|
24
24
|
system(env, @command, chdir: @mod.cache_dir)
|
25
25
|
else
|
26
26
|
popen3(env)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
def system?
|
31
|
+
@options[:shell] == "system" || # terraspace console
|
32
|
+
ENV['TS_RUNNER_SYSTEM'] # allow manual override
|
33
|
+
end
|
34
|
+
|
30
35
|
def popen3(env)
|
31
36
|
Open3.popen3(env, @command, chdir: @mod.cache_dir) do |stdin, stdout, stderr, wait_thread|
|
32
37
|
handle_streams(stdin, stdout, stderr)
|
@@ -54,7 +59,7 @@ module Terraspace
|
|
54
59
|
lines = buffer.split("\n")
|
55
60
|
lines.each do |line|
|
56
61
|
if f.fileno == stdout.fileno
|
57
|
-
handle_stdout(line)
|
62
|
+
handle_stdout(line, newline: !suppress_newline(line))
|
58
63
|
handle_input(stdin, line)
|
59
64
|
else
|
60
65
|
handle_stderr(line)
|
@@ -65,6 +70,11 @@ module Terraspace
|
|
65
70
|
end
|
66
71
|
end
|
67
72
|
|
73
|
+
def suppress_newline(line)
|
74
|
+
line.size == 8192 && line[-1] != "\n" || # when buffer is very large buffer.split("\n") only gives 8192 chars at a time
|
75
|
+
line.include?("Enter a value:") # prompt
|
76
|
+
end
|
77
|
+
|
68
78
|
def handle_stderr(line)
|
69
79
|
@error ||= Error.new
|
70
80
|
@error.lines << line # aggregate all error lines
|
@@ -81,19 +91,14 @@ module Terraspace
|
|
81
91
|
files.find { |f| !f.eof }.nil?
|
82
92
|
end
|
83
93
|
|
84
|
-
# Terraform doesnt seem to stream the line that prompts with "Enter a value:" when using Open3.popen3
|
85
|
-
# Hack around it by mimicking the "Enter a value:" prompt
|
86
|
-
#
|
87
|
-
# Note: system does stream the prompt but using Open3.popen3 so we can capture output to save to logs.
|
88
94
|
def handle_input(stdin, line)
|
89
|
-
# stdout doesnt seem to flush and show "Enter a value: " look for earlier output
|
90
95
|
patterns = [
|
91
|
-
"
|
96
|
+
"Enter a value:",
|
92
97
|
"\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
|
93
98
|
]
|
94
99
|
if patterns.any? { |pattern| line.include?(pattern) }
|
95
|
-
|
96
|
-
stdin.write_nonblock(
|
100
|
+
answer = $stdin.gets
|
101
|
+
stdin.write_nonblock(answer)
|
97
102
|
end
|
98
103
|
end
|
99
104
|
|
@@ -109,16 +114,12 @@ module Terraspace
|
|
109
114
|
end
|
110
115
|
end
|
111
116
|
|
112
|
-
def handle_stdout(line)
|
113
|
-
prompted = line.include?('Enter a value')
|
114
|
-
@prompt_shown ||= prompted
|
115
|
-
return if @prompt_shown && prompted
|
116
|
-
|
117
|
+
def handle_stdout(line, newline: true)
|
117
118
|
# Terraspace logger has special stdout method so original terraform output
|
118
119
|
# can be piped to jq. IE:
|
119
120
|
# terraspace show demo --json | jq
|
120
121
|
if logger.respond_to?(:stdout) && !@options[:log_to_stderr]
|
121
|
-
logger.stdout(line)
|
122
|
+
logger.stdout(line, newline: newline)
|
122
123
|
else
|
123
124
|
logger.info(line)
|
124
125
|
end
|
@@ -11,12 +11,24 @@ module Terraspace::Terraform::Args
|
|
11
11
|
# https://terraspace.cloud/docs/ci-automation/
|
12
12
|
ENV['TF_IN_AUTOMATION'] = '1' if @options[:auto]
|
13
13
|
|
14
|
-
|
14
|
+
args = []
|
15
|
+
|
16
|
+
if straight_delegate_args?
|
17
|
+
args += @options[:rest]
|
18
|
+
args.flatten!
|
19
|
+
end
|
20
|
+
|
21
|
+
args_meth = "#{@name}_args".gsub(' ', '_') # IE: apply_args, init_args
|
15
22
|
if respond_to?(args_meth)
|
16
|
-
send(args_meth)
|
17
|
-
else
|
18
|
-
[]
|
23
|
+
args += send(args_meth)
|
19
24
|
end
|
25
|
+
|
26
|
+
args
|
27
|
+
end
|
28
|
+
|
29
|
+
# delegate args straight through for special commands, currently state seems to be the only case
|
30
|
+
def straight_delegate_args?
|
31
|
+
@name.include?("state") # IE: "state list", "state pull", "state show"
|
20
32
|
end
|
21
33
|
|
22
34
|
def force_unlock_args
|
@@ -28,7 +40,7 @@ module Terraspace::Terraform::Args
|
|
28
40
|
var_files = @options[:var_files]
|
29
41
|
if var_files
|
30
42
|
var_files.each do |file|
|
31
|
-
copy_to_cache(
|
43
|
+
copy_to_cache(file)
|
32
44
|
end
|
33
45
|
args << var_files.map { |f| "-var-file #{f}" }.join(' ')
|
34
46
|
end
|
data/lib/terraspace/version.rb
CHANGED
data/terraspace.gemspec
CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_dependency "memoist"
|
29
29
|
spec.add_dependency "rainbow"
|
30
30
|
spec.add_dependency "render_me_pretty"
|
31
|
-
spec.add_dependency "terraspace-bundler", "~> 0.
|
31
|
+
spec.add_dependency "terraspace-bundler", "~> 0.4.0"
|
32
32
|
spec.add_dependency "thor"
|
33
33
|
spec.add_dependency "tty-tree"
|
34
34
|
spec.add_dependency "zeitwerk"
|
@@ -37,7 +37,7 @@ Gem::Specification.new do |spec|
|
|
37
37
|
spec.add_dependency "terraspace_plugin_aws", "~> 0.3.0"
|
38
38
|
spec.add_dependency "terraspace_plugin_azurerm", "~> 0.3.0"
|
39
39
|
spec.add_dependency "terraspace_plugin_google", "~> 0.3.0"
|
40
|
-
spec.add_dependency "rspec-terraspace", "~> 0.
|
40
|
+
spec.add_dependency "rspec-terraspace", "~> 0.3.0"
|
41
41
|
|
42
42
|
spec.add_development_dependency "bundler"
|
43
43
|
spec.add_development_dependency "byebug"
|
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.16
|
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-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -156,14 +156,14 @@ dependencies:
|
|
156
156
|
requirements:
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: 0.
|
159
|
+
version: 0.4.0
|
160
160
|
type: :runtime
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: 0.
|
166
|
+
version: 0.4.0
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: thor
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -254,14 +254,14 @@ dependencies:
|
|
254
254
|
requirements:
|
255
255
|
- - "~>"
|
256
256
|
- !ruby/object:Gem::Version
|
257
|
-
version: 0.
|
257
|
+
version: 0.3.0
|
258
258
|
type: :runtime
|
259
259
|
prerelease: false
|
260
260
|
version_requirements: !ruby/object:Gem::Requirement
|
261
261
|
requirements:
|
262
262
|
- - "~>"
|
263
263
|
- !ruby/object:Gem::Version
|
264
|
-
version: 0.
|
264
|
+
version: 0.3.0
|
265
265
|
- !ruby/object:Gem::Dependency
|
266
266
|
name: bundler
|
267
267
|
requirement: !ruby/object:Gem::Requirement
|
@@ -532,6 +532,7 @@ files:
|
|
532
532
|
- lib/terraspace/cli/help/refresh.md
|
533
533
|
- lib/terraspace/cli/help/seed.md
|
534
534
|
- lib/terraspace/cli/help/show.md
|
535
|
+
- lib/terraspace/cli/help/state.md
|
535
536
|
- lib/terraspace/cli/help/summary.md
|
536
537
|
- lib/terraspace/cli/help/test.md
|
537
538
|
- lib/terraspace/cli/help/tfc/destroy.md
|
@@ -848,7 +849,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
848
849
|
- !ruby/object:Gem::Version
|
849
850
|
version: '0'
|
850
851
|
requirements: []
|
851
|
-
rubygems_version: 3.
|
852
|
+
rubygems_version: 3.1.6
|
852
853
|
signing_key:
|
853
854
|
specification_version: 4
|
854
855
|
summary: 'Terraspace: The Terraspace Framework'
|