terraspace 0.6.8 → 0.6.12

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: ac0b4566fae8a6be4cfb7907e60d1d0ec3cdf4f7426989a68e5a7c22c55b4cc5
4
- data.tar.gz: 66bd6807da803a3891ba2d78b5e21e5dcf0af2e8a1ed303ceb8c9e70c6916ea7
3
+ metadata.gz: 381066a03744a48afd9149f20496f9c8179eb7c70e084dd1f70f341c01443c62
4
+ data.tar.gz: 5030206fd23d619433651f7ae266b70ddb88e0123ce56838b448661e35d4f09a
5
5
  SHA512:
6
- metadata.gz: d14b3c79add9cf2075c27682ad466f4afeb474a21943868d3dc1260afd129d127387e0089fa44e08e695bb5c28080b6dcbfdcd6774c3fff244782a50dd8a4f7c
7
- data.tar.gz: c54ed8c38625bccd2ce424a18b70b4ca9198a4921bf10a57e452e0c6d7b1f2ae500f9565ba123cbaa071d7fec9767fa1d263e8a315dc1427ea5d983c8309c790
6
+ metadata.gz: 65ec02586d40a8e5edcd93983d6f7a0a34398d8112c08b8748aa6d877421b6aa1c913ea7765aa15357f9d843170aee35efccca35debfe7137e5087a16507f0a0
7
+ data.tar.gz: 5e7641fbf3d8dd81c5e4da97b7f4689d42dde1ac64fb26de08ac8502cf095ba77b69e665f3eef39ca876e4e2384b82a2a6c72d7faa9e116d9f4dec2016a929e1
data/CHANGELOG.md CHANGED
@@ -3,6 +3,24 @@
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.12] - 2021-07-26
7
+ - [#128](https://github.com/boltops-tools/terraspace/pull/128) Improve terraspace state comands and Terraspace.argv for internal usage
8
+ - [#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
9
+ - allow -h to help outside terraspace project generally
10
+ - require rspec-terraspace 0.3.0
11
+ - state subcommands: straight delegate args
12
+ - Terraspace.argv for consistency with terraspace test
13
+
14
+ ## [0.6.11] - 2021-06-22
15
+ - [#120](https://github.com/boltops-tools/terraspace/pull/120) version check handles a major change
16
+
17
+ ## [0.6.10] - 2021-06-01
18
+ - [#117](https://github.com/boltops-tools/terraspace/pull/117) fix terraspace fmt -t all
19
+ - clean up IO select call
20
+
21
+ ## [0.6.9] - 2021-05-07
22
+ - [#112](https://github.com/boltops-tools/terraspace/pull/112) fix smart auto retry
23
+
6
24
  ## [0.6.8] - 2021-05-07
7
25
  - [#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
8
26
 
@@ -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."
@@ -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
@@ -30,7 +30,7 @@ class Terraspace::CLI
30
30
 
31
31
  def type_dirs
32
32
  type = @options[:type]
33
- if type
33
+ if type && type != "all"
34
34
  app_source_dirs.select { |p| p.include?("/#{type.pluralize}/") }
35
35
  else
36
36
  app_source_dirs
@@ -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 stacke
22
+ $ terraspace fmt demo -t stack
23
+
24
+ Format all, so both modules and stacks:
25
+
26
+ $ terraspace fmt -t all
@@ -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
@@ -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
@@ -38,12 +38,12 @@ module Terraspace
38
38
  BLOCK_SIZE = Integer(ENV['TS_BUFFER_BLOCK_SIZE'] || 102400)
39
39
  BUFFER_TIMEOUT = Integer(ENV['TS_BUFFER_TIMEOUT'] || 3600) # 3600s = 1h
40
40
  def handle_streams(stdin, stdout, stderr)
41
- files = [stdout, stderr]
42
41
  # note: t=0 and t=nil means no timeout. See: https://bit.ly/2PURlCX
43
42
  t = BUFFER_TIMEOUT.to_i unless BUFFER_TIMEOUT.nil?
44
43
  Timeout::timeout(t) do
44
+ files = [stdout, stderr]
45
45
  until all_eof?(files) do
46
- ready = IO.select(files, nil, nil, 0.1)
46
+ ready = IO.select(files)
47
47
  next unless ready
48
48
 
49
49
  readable = ready[0]
@@ -53,14 +53,30 @@ module Terraspace
53
53
 
54
54
  lines = buffer.split("\n")
55
55
  lines.each do |line|
56
- terraform_to_stdout(line)
57
- handle_input(stdin, line)
56
+ if f.fileno == stdout.fileno
57
+ handle_stdout(line)
58
+ handle_input(stdin, line)
59
+ else
60
+ handle_stderr(line)
61
+ end
58
62
  end
59
63
  end
60
64
  end
61
65
  end
62
66
  end
63
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
+
64
80
  def all_eof?(files)
65
81
  files.find { |f| !f.eof }.nil?
66
82
  end
@@ -93,7 +109,7 @@ module Terraspace
93
109
  end
94
110
  end
95
111
 
96
- def terraform_to_stdout(line)
112
+ def handle_stdout(line)
97
113
  prompted = line.include?('Enter a value')
98
114
  @prompt_shown ||= prompted
99
115
  return if @prompt_shown && prompted
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Terraspace
2
- VERSION = "0.6.8"
2
+ VERSION = "0.6.12"
3
3
  end
data/terraspace.gemspec CHANGED
@@ -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.8
4
+ version: 0.6.12
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-05-07 00:00:00.000000000 Z
11
+ date: 2021-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -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