terraspace 0.6.17 → 0.6.21

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: 9681902927e9231899ed1d67ff66a4b50ac46bb2411fa271431f4cbf80cd87c7
4
- data.tar.gz: c67623a069d74c5b722a37e852888949fcfd0302acb0a9db88805f7141927426
3
+ metadata.gz: e846de537f7e1a415fa06437138b66342b39742d637843e0dd2ab0f8f308d884
4
+ data.tar.gz: e3cac1d61f893d8864496f5a1b8af43e0b5ac142111a2869b077e92a6dd1802e
5
5
  SHA512:
6
- metadata.gz: d3e4dc815c6a64cec67b2c87ab10f3be92f0ab661f11b757aefa5140c9a105e7769b48e50aa81f3b67118bd3076c2d7840a4c0f9c91f880272731b298c068d47
7
- data.tar.gz: 12f5a76c19760c1fe049f38fe55148000d5305b7f3e407b27bd5ee779a7eb10ac8ea4fd2dfcb7474b5fbfecb93339171c6b117d706d2e45e2825aac41d0f4e1f
6
+ metadata.gz: bd9fed4ac9bb408d6284bc473966320700e076c3ed0e06461b93c612361527f629e19e88e13c54aba306af6cfe846d8e9aa2f7a408840216583364b5950ebb38
7
+ data.tar.gz: 8a3672f6d5cf32f4e4ac44cfa28d4e0577a66e7c5982e66f2a0f2eab94ecdfdf6fda649714e8545353ad65f47c9eebc212a25ae36fa6b8753d11a0244f626964
data/CHANGELOG.md CHANGED
@@ -3,6 +3,26 @@
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.21] - 2021-12-16
7
+ - [#164](https://github.com/boltops-tools/terraspace/pull/164) Use Activesupport All
8
+
9
+ ## [0.6.20] - 2021-12-14
10
+ - [#162](https://github.com/boltops-tools/terraspace/pull/162) expand_string? interface method so plugins can decide whether or not to expand the string
11
+ - improve seed generator column spacing
12
+
13
+ ## [0.6.19] - 2021-11-24
14
+ - [#149](https://github.com/boltops-tools/terraspace/pull/149) change default fallback mod strategy to Mod::Tf instead of Mod::Pass for ERB support
15
+ - [#152](https://github.com/boltops-tools/terraspace/pull/152) fix naming typo in cli help
16
+ - [#153](https://github.com/boltops-tools/terraspace/pull/153) only remove and create log dir if it exists
17
+ - [#155](https://github.com/boltops-tools/terraspace/pull/155) add terraspace bundle example cli help
18
+ - [#157](https://github.com/boltops-tools/terraspace/pull/157) handle edge case: Enter a value chopped off
19
+ - [#158](https://github.com/boltops-tools/terraspace/pull/158) use pass strategy for binary files
20
+ - [#159](https://github.com/boltops-tools/terraspace/pull/159) process terraform.tfvars file with erb, change default processing strategy back to pass
21
+
22
+ ## [0.6.18] - 2021-10-28
23
+ - [#147](https://github.com/boltops-tools/terraspace/pull/147) improve error message output
24
+ - [#148](https://github.com/boltops-tools/terraspace/pull/148) Improve shim wrapper generator
25
+
6
26
  ## [0.6.17] - 2021-10-02
7
27
  - [#142](https://github.com/boltops-tools/terraspace/pull/142) improve builder skip check: check if its a dir
8
28
 
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,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
@@ -34,6 +34,7 @@ module Terraspace::Plugin::Expander
34
34
  #
35
35
  def expansion(string)
36
36
  return string unless string.is_a?(String) # in case of nil
37
+ return string unless expand_string?(string)
37
38
 
38
39
  string = string.dup
39
40
  vars = string.scan(/:\w+/) # => [":ENV", ":BUILD_DIR"]
@@ -43,6 +44,11 @@ module Terraspace::Plugin::Expander
43
44
  strip(string)
44
45
  end
45
46
 
47
+ # interface method
48
+ def expand_string?(string)
49
+ true
50
+ end
51
+
46
52
  # remove leading and trailing common separators.
47
53
  #
48
54
  # This is useful for when INSTANCE is not set.
@@ -49,7 +49,7 @@ class Terraspace::Seeder
49
49
  end
50
50
 
51
51
  def rpad
52
- all_vars.keys.map(&:size).max
52
+ all_vars.keys.map(&:size).max + 2
53
53
  end
54
54
  memoize :rpad
55
55
 
@@ -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?
@@ -71,8 +71,49 @@ module Terraspace
71
71
  end
72
72
 
73
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
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
76
117
  end
77
118
 
78
119
  def handle_stderr(line)
@@ -91,17 +132,6 @@ module Terraspace
91
132
  files.find { |f| !f.eof }.nil?
92
133
  end
93
134
 
94
- def handle_input(stdin, line)
95
- patterns = [
96
- "Enter a value:",
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
98
- ]
99
- if patterns.any? { |pattern| line.include?(pattern) }
100
- answer = $stdin.gets
101
- stdin.write_nonblock(answer)
102
- end
103
- end
104
-
105
135
  def exit_status(status)
106
136
  return if status == 0
107
137
 
@@ -113,16 +143,5 @@ module Terraspace
113
143
  exit status
114
144
  end
115
145
  end
116
-
117
- def handle_stdout(line, newline: true)
118
- # Terraspace logger has special stdout method so original terraform output
119
- # can be piped to jq. IE:
120
- # terraspace show demo --json | jq
121
- if logger.respond_to?(:stdout) && !@options[:log_to_stderr]
122
- logger.stdout(line, newline: newline)
123
- else
124
- logger.info(line)
125
- end
126
- end
127
146
  end
128
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.17"
2
+ VERSION = "0.6.21"
3
3
  end
data/lib/terraspace.rb CHANGED
@@ -5,11 +5,7 @@ $:.unshift(File.expand_path("../", __FILE__))
5
5
  require "terraspace/autoloader"
6
6
  Terraspace::Autoloader.setup
7
7
 
8
- require "active_support/concern"
9
- require "active_support/core_ext/class"
10
- require "active_support/core_ext/hash"
11
- require "active_support/core_ext/string"
12
- require "active_support/ordered_options"
8
+ require "active_support/all"
13
9
  require "cli-format"
14
10
  require "deep_merge/rails_compat"
15
11
  require "dsl_evaluator"
@@ -37,8 +37,8 @@ describe Terraspace::Seeder::Content do
37
37
  result = content.build
38
38
  expected =<<~EOL
39
39
  # Required variables:
40
- name = "string"
41
- azs = [...] # list(string)
40
+ name = "string"
41
+ azs = [...] # list(string)
42
42
 
43
43
  # Optional variables:
44
44
  # project = "project-name"
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.17
4
+ version: 0.6.21
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-02 00:00:00.000000000 Z
11
+ date: 2021-12-16 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
@@ -614,6 +615,7 @@ files:
614
615
  - lib/terraspace/compiler/strategy/mod/pass.rb
615
616
  - lib/terraspace/compiler/strategy/mod/rb.rb
616
617
  - lib/terraspace/compiler/strategy/mod/tf.rb
618
+ - lib/terraspace/compiler/strategy/mod/tfvars.rb
617
619
  - lib/terraspace/compiler/strategy/tfvar.rb
618
620
  - lib/terraspace/compiler/strategy/tfvar/base.rb
619
621
  - lib/terraspace/compiler/strategy/tfvar/layer.rb
@@ -850,7 +852,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
850
852
  - !ruby/object:Gem::Version
851
853
  version: '0'
852
854
  requirements: []
853
- rubygems_version: 3.1.6
855
+ rubygems_version: 3.2.32
854
856
  signing_key:
855
857
  specification_version: 4
856
858
  summary: 'Terraspace: The Terraspace Framework'