terraspace 0.6.15 → 0.6.19

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: 9980c8cd350d2b3c724d4dd3ff46a6388ee9c558377315e7320a35617c9810c6
4
- data.tar.gz: 3bb3f797da63bf403cf8868ddb516cc8411cd3e92d16895876adbf06444dfab4
3
+ metadata.gz: 2fc510d1165404c449bcc9e3fe0af371d979aa5babc28e8531097f3ccd50c6eb
4
+ data.tar.gz: 95a69d72a293c58ff9435a162dbb20383dc8ee6dea8e681a5b8ab672cf90bbd2
5
5
  SHA512:
6
- metadata.gz: 8da2856e9d86af65f0256a90cb4b675b17b48288ed3e752383ece1f0d90e7e1d9c044ecae8727403a698aed1bdac1578a52e25b5f481b63c4057d5e5cf357ac9
7
- data.tar.gz: 78dd758735d162b8aaacc5d0840853d82a3d08a134e9707bf73cc7cf7918bcb078ea565a0c8ed1893f48699dcfc21c0cf5d7f240f8b6564ba61ab4ffc759831d
6
+ metadata.gz: c143d467df63cffe80862bec7ed0d06bc6edec50485b8a885d04a19f9f8d5a7a699dd494ff4daf074e303b50a1fc0f788340e6cd00bb42c875c834a05262b864
7
+ data.tar.gz: 90e43491736d1f3e43081d51bd9b0100a1641a3aaed71bac5eff71492a19298d0e56da762f79c07ff679e420509ce37e638974a643cc0633cde581c860e051fb
data/CHANGELOG.md CHANGED
@@ -3,6 +3,25 @@
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.19] - 2021-11-24
7
+ - [#149](https://github.com/boltops-tools/terraspace/pull/149) change default fallback mod strategy to Mod::Tf instead of Mod::Pass for ERB support
8
+ - [#152](https://github.com/boltops-tools/terraspace/pull/152) fix naming typo in cli help
9
+ - [#153](https://github.com/boltops-tools/terraspace/pull/153) only remove and create log dir if it exists
10
+ - [#155](https://github.com/boltops-tools/terraspace/pull/155) add terraspace bundle example cli help
11
+ - [#157](https://github.com/boltops-tools/terraspace/pull/157) handle edge case: Enter a value chopped off
12
+ - [#158](https://github.com/boltops-tools/terraspace/pull/158) use pass strategy for binary files
13
+ - [#159](https://github.com/boltops-tools/terraspace/pull/159) process terraform.tfvars file with erb, change default processing strategy back to pass
14
+
15
+ ## [0.6.18] - 2021-10-28
16
+ - [#147](https://github.com/boltops-tools/terraspace/pull/147) improve error message output
17
+ - [#148](https://github.com/boltops-tools/terraspace/pull/148) Improve shim wrapper generator
18
+
19
+ ## [0.6.17] - 2021-10-02
20
+ - [#142](https://github.com/boltops-tools/terraspace/pull/142) improve builder skip check: check if its a dir
21
+
22
+ ## [0.6.16] - 2021-10-01
23
+ - [#141](https://github.com/boltops-tools/terraspace/pull/141) terraspace output: remove extra newline at the end
24
+
6
25
  ## [0.6.15] - 2021-10-01
7
26
  - [#140](https://github.com/boltops-tools/terraspace/pull/140) fix terraspace output and Enter a value handling
8
27
 
data/SECURITY.md ADDED
@@ -0,0 +1,3 @@
1
+ # Security Policy
2
+
3
+ Refer to: https://terraspace.cloud/docs/policies/security/
@@ -4,7 +4,6 @@ class Terraspace::CLI::Clean
4
4
  action = @options[:truncate] ? "truncate" : "remove"
5
5
  are_you_sure?(action)
6
6
  @options[:truncate] ? truncate : remove
7
- logger.info "Logs #{action}d" # IE: Logs truncated or Logs removed
8
7
  end
9
8
 
10
9
  def truncate
@@ -14,6 +13,7 @@ class Terraspace::CLI::Clean
14
13
  end
15
14
 
16
15
  def remove
16
+ return unless File.exist?(log_root)
17
17
  puts "Removing all files in #{pretty_log_root}/" unless @options[:mute]
18
18
  FileUtils.rm_rf(log_root)
19
19
  FileUtils.mkdir_p(log_root)
@@ -16,3 +16,9 @@
16
16
  ## Info on a module
17
17
 
18
18
  terraspace bundle info MODULE
19
+
20
+ ## Import Example As Stack
21
+
22
+ You can import a module's example as a stack.
23
+
24
+ terraspace bundle example MODULE EXAMPLE
@@ -1,4 +1,4 @@
1
- Typically, Terrasapce auto init should handle initialization. You can run init if you need to though.
1
+ Typically, Terraspace auto init should handle initialization. You can run init if you need to though.
2
2
 
3
3
  ## Example
4
4
 
@@ -18,7 +18,6 @@ class Terraspace::CLI::New
18
18
  end
19
19
 
20
20
  def create
21
- return unless File.exist?(".git")
22
21
  dest = @path
23
22
  template "terraspace", dest
24
23
  chmod dest, 0755
@@ -44,6 +43,8 @@ class Terraspace::CLI::New
44
43
 
45
44
  export PATH=#{dir}:/$PATH
46
45
 
46
+ Also note, the shim wrapper contains starter code. Though it should generally work for most systems,
47
+ it might require adjustments depending on your system.
47
48
  EOL
48
49
  end
49
50
 
@@ -0,0 +1,28 @@
1
+ class Terraspace::Compiler::Builder
2
+ class Skip
3
+ def initialize(mod, src_path)
4
+ @mod, @src_path = mod, src_path
5
+ end
6
+
7
+ def check?
8
+ return true unless File.file?(@src_path)
9
+
10
+ # skip certain folders
11
+ check_dirs?(
12
+ "config/args",
13
+ "config/helpers",
14
+ "config/hooks",
15
+ "test",
16
+ "tfvars",
17
+ )
18
+ end
19
+
20
+ def check_dirs?(*names)
21
+ names.flatten.detect { |name| check_dir?(name) }
22
+ end
23
+
24
+ def check_dir?(name)
25
+ @src_path.include?("#{@mod.root}/#{name}/")
26
+ end
27
+ end
28
+ end
@@ -72,13 +72,7 @@ module Terraspace::Compiler
72
72
  end
73
73
 
74
74
  def skip?(src_path)
75
- return true unless File.file?(src_path)
76
- # certain folders will be skipped
77
- src_path.include?("#{@mod.root}/config/args") ||
78
- src_path.include?("#{@mod.root}/config/helpers") ||
79
- src_path.include?("#{@mod.root}/config/hooks") ||
80
- src_path.include?("#{@mod.root}/test") ||
81
- src_path.include?("#{@mod.root}/tfvars")
75
+ Skip.new(@mod, src_path).check?
82
76
  end
83
77
 
84
78
  def search(expr)
@@ -0,0 +1,4 @@
1
+ class Terraspace::Compiler::Strategy::Mod
2
+ class Tfvars < Tf
3
+ end
4
+ end
@@ -1,3 +1,5 @@
1
+ require "open3"
2
+
1
3
  module Terraspace::Compiler::Strategy
2
4
  class Mod < AbstractBase
3
5
  def run
@@ -9,8 +11,15 @@ module Terraspace::Compiler::Strategy
9
11
  def strategy_class(path)
10
12
  ext = File.extname(path).sub('.','')
11
13
  return Mod::Pass if ext.empty? # infinite loop without this
12
- return Mod::Pass if Terraspace.pass_file?(path)
14
+ return Mod::Pass if Terraspace.pass_file?(path) or !text_file?(path)
15
+ # Fallback to Mod::Tf for all other files. ERB useful for terraform.tfvars
13
16
  "Terraspace::Compiler::Strategy::Mod::#{ext.camelize}".constantize rescue Mod::Pass
14
17
  end
18
+
19
+ # Thanks: https://stackoverflow.com/questions/2355866/ruby-how-to-determine-if-file-being-read-is-binary-or-text
20
+ def text_file?(filename)
21
+ file_type, status = Open3.capture2e("file", filename)
22
+ status.success? && file_type.include?("text")
23
+ end
15
24
  end
16
25
  end
@@ -2,7 +2,7 @@ class Terraspace::Shell
2
2
  class Error
3
3
  attr_accessor :lines
4
4
  def initialize
5
- @lines = '' # holds aggregation of all error lines
5
+ @lines = [] # holds aggregation of all error lines
6
6
  end
7
7
 
8
8
  def known?
@@ -11,11 +11,11 @@ class Terraspace::Shell
11
11
 
12
12
  def instance
13
13
  if reinit_required?
14
- Terraspace::InitRequiredError.new(@lines)
14
+ Terraspace::InitRequiredError.new(message)
15
15
  elsif bucket_not_found?
16
- Terraspace::BucketNotFoundError.new(@lines)
16
+ Terraspace::BucketNotFoundError.new(message)
17
17
  elsif shared_cache_error?
18
- Terraspace::SharedCacheError.new(@lines)
18
+ Terraspace::SharedCacheError.new(message)
19
19
  end
20
20
  end
21
21
 
@@ -34,7 +34,8 @@ class Terraspace::Shell
34
34
  end
35
35
 
36
36
  def message
37
- @lines.gsub("\n", ' ').squeeze(' ') # remove double whitespaces and newlines
37
+ # For error messages, terraform lines from buffer do not contain newlines. So join with newline
38
+ @lines.join("\n")
38
39
  end
39
40
 
40
41
  def shared_cache_error?
@@ -67,13 +67,53 @@ module Terraspace
67
67
  end
68
68
  end
69
69
  end
70
- handle_stdout("\n") # final newline at the end is exactly system behavior
71
70
  end
72
71
  end
73
72
 
74
73
  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
74
+ # Regular prompt
75
+ line.include?("Enter a value:") ||
76
+ # Edge case: When buffer is very large buffer.split("\n") only gives 8192 chars at a time
77
+ line.size == 8192 && line[-1] != "\n" ||
78
+ # Edge case: "value:" chopped off "Enter a" and "value" prompt
79
+ # Very hard to reproduce. Happens 1/5 times on terraspace up autoscaling example.
80
+ # Sometimes lines come in as:
81
+ # [...," Only 'yes' will be accepted to approve.", "", " \e[1mEnter a"]
82
+ # [" value:\e[0m \e[0m"]
83
+ line.match(/Enter a$/) || line.match(/^ value:/) # chopped off prompt
84
+ # line.include?(" value:") && lines.last.match(/Enter a$/) # chopped off prompt
85
+ end
86
+
87
+ def handle_stdout(line, newline: true)
88
+ # Terraspace logger has special stdout method so original terraform output
89
+ # can be piped to jq. IE:
90
+ # terraspace show demo --json | jq
91
+ if logger.respond_to?(:stdout) && !@options[:log_to_stderr]
92
+ logger.stdout(line, newline: newline)
93
+ else
94
+ logger.info(line)
95
+ end
96
+ end
97
+
98
+ def handle_input(stdin, line)
99
+ # Edge case: "value:" chopped off "Enter a" and "value" prompt
100
+ # This means "Enter a value:" is not needed but leaving it for now
101
+ patterns = [
102
+ /^ value:/,
103
+ "Enter a value:",
104
+ "\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
105
+ ]
106
+ matched = patterns.any? do |pattern|
107
+ if pattern.is_a?(String)
108
+ line.include?(pattern)
109
+ else # Regexp
110
+ line.match(pattern)
111
+ end
112
+ end
113
+ if matched
114
+ answer = $stdin.gets
115
+ stdin.write_nonblock(answer)
116
+ end
77
117
  end
78
118
 
79
119
  def handle_stderr(line)
@@ -92,17 +132,6 @@ module Terraspace
92
132
  files.find { |f| !f.eof }.nil?
93
133
  end
94
134
 
95
- def handle_input(stdin, line)
96
- patterns = [
97
- "Enter a value:",
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
99
- ]
100
- if patterns.any? { |pattern| line.include?(pattern) }
101
- answer = $stdin.gets
102
- stdin.write_nonblock(answer)
103
- end
104
- end
105
-
106
135
  def exit_status(status)
107
136
  return if status == 0
108
137
 
@@ -114,16 +143,5 @@ module Terraspace
114
143
  exit status
115
144
  end
116
145
  end
117
-
118
- def handle_stdout(line, newline: true)
119
- # Terraspace logger has special stdout method so original terraform output
120
- # can be piped to jq. IE:
121
- # terraspace show demo --json | jq
122
- if logger.respond_to?(:stdout) && !@options[:log_to_stderr]
123
- logger.stdout(line, newline: newline)
124
- else
125
- logger.info(line)
126
- end
127
- end
128
146
  end
129
147
  end
@@ -9,10 +9,11 @@ class Terraspace::Terraform::Runner
9
9
  end
10
10
 
11
11
  def retry?
12
- if @retries <= 3 && !@stop_retrying
12
+ max_retries = ENV['TS_MAX_RETRIES'] ? ENV['TS_MAX_RETRIES'].to_i : 3
13
+ if @retries <= max_retries && !@stop_retrying
13
14
  true # will retry
14
15
  else
15
- logger.info "ERROR: #{@exception.message}"
16
+ logger.info "ERROR after max retries #{max_retries}: #{@exception.message}"
16
17
  false # will not retry
17
18
  end
18
19
  end
@@ -1,3 +1,3 @@
1
1
  module Terraspace
2
- VERSION = "0.6.15"
2
+ VERSION = "0.6.19"
3
3
  end
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.15
4
+ version: 0.6.19
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-10-01 00:00:00.000000000 Z
11
+ date: 2021-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -384,6 +384,7 @@ files:
384
384
  - LICENSE.txt
385
385
  - README.md
386
386
  - Rakefile
387
+ - SECURITY.md
387
388
  - exe/terraspace
388
389
  - lib/templates/base/arg/terraform.rb.tt
389
390
  - lib/templates/base/git_hook/hook.sh
@@ -578,6 +579,7 @@ files:
578
579
  - lib/terraspace/compiler/backend/parser.rb
579
580
  - lib/terraspace/compiler/basename.rb
580
581
  - lib/terraspace/compiler/builder.rb
582
+ - lib/terraspace/compiler/builder/skip.rb
581
583
  - lib/terraspace/compiler/cleaner.rb
582
584
  - lib/terraspace/compiler/cleaner/backend_change.rb
583
585
  - lib/terraspace/compiler/commands_concern.rb
@@ -613,6 +615,7 @@ files:
613
615
  - lib/terraspace/compiler/strategy/mod/pass.rb
614
616
  - lib/terraspace/compiler/strategy/mod/rb.rb
615
617
  - lib/terraspace/compiler/strategy/mod/tf.rb
618
+ - lib/terraspace/compiler/strategy/mod/tfvars.rb
616
619
  - lib/terraspace/compiler/strategy/tfvar.rb
617
620
  - lib/terraspace/compiler/strategy/tfvar/base.rb
618
621
  - lib/terraspace/compiler/strategy/tfvar/layer.rb