terraspace 0.6.10 → 0.6.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8105526fb9629b60b79887ca3208449e24179640bbc03eae6bc11885dc6392cb
4
- data.tar.gz: b387682cd6e5c4111c7a21bbb540793a966476a61e04c719fab3cca71de4a909
3
+ metadata.gz: 9980c8cd350d2b3c724d4dd3ff46a6388ee9c558377315e7320a35617c9810c6
4
+ data.tar.gz: 3bb3f797da63bf403cf8868ddb516cc8411cd3e92d16895876adbf06444dfab4
5
5
  SHA512:
6
- metadata.gz: 1b0cc4aa0d60d7c6cad2785dea6c0300ef9186c6235b67500e3a9eb86cdd419112a0004b4859bb6ba7b398ef9912f1c6e3eb5d21e8cebf00615f45e6f1ac2623
7
- data.tar.gz: a4e99cb75568dcacff91ff641118431f8792fdbd977eb758fc77a5ff751f4d1a274ec5a9586a1c34ac50eb692aa98c155475b1cf539f3ee85697be7a82cd9447
6
+ metadata.gz: 8da2856e9d86af65f0256a90cb4b675b17b48288ed3e752383ece1f0d90e7e1d9c044ecae8727403a698aed1bdac1578a52e25b5f481b63c4057d5e5cf357ac9
7
+ data.tar.gz: 78dd758735d162b8aaacc5d0840853d82a3d08a134e9707bf73cc7cf7918bcb078ea565a0c8ed1893f48699dcfc21c0cf5d7f240f8b6564ba61ab4ffc759831d
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.15] - 2021-10-01
7
+ - [#140](https://github.com/boltops-tools/terraspace/pull/140) fix terraspace output and Enter a value handling
8
+
9
+ ## [0.6.14] - 2021-09-30
10
+ - [#134](https://github.com/boltops-tools/terraspace/pull/134) Use file not plan for the var-files argument
11
+ - [#139](https://github.com/boltops-tools/terraspace/pull/139) Fix terraspace output to not add extra newlines
12
+ - terraspace list: change default to show both stacks and modules
13
+
14
+ ## [0.6.13] - 2021-08-10
15
+ - use terraspace-bundler 0.4.0
16
+
17
+ ## [0.6.12] - 2021-07-26
18
+ - [#128](https://github.com/boltops-tools/terraspace/pull/128) Improve terraspace state comands and Terraspace.argv for internal usage
19
+ - [#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
20
+ - allow -h to help outside terraspace project generally
21
+ - require rspec-terraspace 0.3.0
22
+ - state subcommands: straight delegate args
23
+ - Terraspace.argv for consistency with terraspace test
24
+
25
+ ## [0.6.11] - 2021-06-22
26
+ - [#120](https://github.com/boltops-tools/terraspace/pull/120) version check handles a major change
27
+
6
28
  ## [0.6.10] - 2021-06-01
7
29
  - [#117](https://github.com/boltops-tools/terraspace/pull/117) fix terraspace fmt -t all
8
30
  - clean up IO select call
@@ -35,7 +35,7 @@ class Terraspace::CLI
35
35
  end
36
36
 
37
37
  def check_command?
38
- ARGV[0] == "check_setup"
38
+ Terraspace.argv[0] == "check_setup"
39
39
  end
40
40
 
41
41
  def terraform_is_not_installed
@@ -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
@@ -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
@@ -98,7 +98,7 @@ class Terraspace::CLI
98
98
 
99
99
  # only top level command considered
100
100
  def calling_command
101
- ARGV[0]
101
+ Terraspace.argv[0]
102
102
  end
103
103
  end
104
104
  end
@@ -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: "stack", aliases: %w[t], desc: "Type: stack, module, or all"
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."
@@ -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
- Dir.glob(expr).each do |path|
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 = Dir.glob("#{@mod.root}/#{file}").first
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 = Dir.glob("#{@mod.root}/#{basename(file)}").first # existing source. IE: backend.rb in module folder
52
+ src_path = search("#{@mod.root}/#{basename(file)}").first # existing source. IE: backend.rb in module folder
53
53
  end
54
- src_path ||= Dir.glob("#{Terraspace.root}/config/terraform/#{file}").first
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
- Dir.glob(path).each do |src_path|
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?(ARGV[0]) || # IE: terraspace up
15
- ARGV[0] == "all" && commands.include?(ARGV[1]) # IE: terraspace all up
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 = ARGV[0..1] || []
22
+ args = Terraspace.argv[0..1] || []
23
23
  command = ["terraspace"] + args
24
24
  command.join(separator)
25
25
  end
@@ -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
@@ -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
- puts msg
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
@@ -20,13 +20,18 @@ module Terraspace
20
20
  def shell
21
21
  env = @options[:env] || {}
22
22
  env.stringify_keys!
23
- if @options[:shell] == "system" # terraspace console
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)
@@ -62,9 +67,15 @@ module Terraspace
62
67
  end
63
68
  end
64
69
  end
70
+ handle_stdout("\n") # final newline at the end is exactly system behavior
65
71
  end
66
72
  end
67
73
 
74
+ def suppress_newline(line)
75
+ line.size == 8192 && line[-1] != "\n" || # when buffer is very large buffer.split("\n") only gives 8192 chars at a time
76
+ line.include?("Enter a value:") # prompt
77
+ end
78
+
68
79
  def handle_stderr(line)
69
80
  @error ||= Error.new
70
81
  @error.lines << line # aggregate all error lines
@@ -81,19 +92,14 @@ module Terraspace
81
92
  files.find { |f| !f.eof }.nil?
82
93
  end
83
94
 
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
95
  def handle_input(stdin, line)
89
- # stdout doesnt seem to flush and show "Enter a value: " look for earlier output
90
96
  patterns = [
91
- "Only 'yes' will be accepted", # prompt for apply. can happen on apply
97
+ "Enter a value:",
92
98
  "\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
99
  ]
94
100
  if patterns.any? { |pattern| line.include?(pattern) }
95
- print "\n Enter a value: ".bright
96
- stdin.write_nonblock($stdin.gets)
101
+ answer = $stdin.gets
102
+ stdin.write_nonblock(answer)
97
103
  end
98
104
  end
99
105
 
@@ -109,16 +115,12 @@ module Terraspace
109
115
  end
110
116
  end
111
117
 
112
- def handle_stdout(line)
113
- prompted = line.include?('Enter a value')
114
- @prompt_shown ||= prompted
115
- return if @prompt_shown && prompted
116
-
118
+ def handle_stdout(line, newline: true)
117
119
  # Terraspace logger has special stdout method so original terraform output
118
120
  # can be piped to jq. IE:
119
121
  # terraspace show demo --json | jq
120
122
  if logger.respond_to?(:stdout) && !@options[:log_to_stderr]
121
- logger.stdout(line)
123
+ logger.stdout(line, newline: newline)
122
124
  else
123
125
  logger.info(line)
124
126
  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
- args_meth = "#{@name}_args"
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(plan)
43
+ copy_to_cache(file)
32
44
  end
33
45
  args << var_files.map { |f| "-var-file #{f}" }.join(' ')
34
46
  end
@@ -1,3 +1,3 @@
1
1
  module Terraspace
2
- VERSION = "0.6.10"
2
+ VERSION = "0.6.15"
3
3
  end
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.3.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.2.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.10
4
+ version: 0.6.15
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-06-01 00:00:00.000000000 Z
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.3.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.3.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.2.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.2.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.2.5
852
+ rubygems_version: 3.1.6
852
853
  signing_key:
853
854
  specification_version: 4
854
855
  summary: 'Terraspace: The Terraspace Framework'