terraspace 2.1.5 → 2.2.0

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: 786aaa7595dab99d8ffb03635a1bbdac8ac8f05f9bf8d54ac233df032e2656e8
4
- data.tar.gz: bdc2ac26c76de54170a7627b9437e4a08535de61a81d868e0b29c8606db80c7a
3
+ metadata.gz: 672cf9e56e84babb2bc53f8e076a13cb51aa9741416fcd6128e66b3774d335fb
4
+ data.tar.gz: 10417698653e7ae38863e1c9d3a1fafebb2ea937693e8c5c0f65cb14e81b1f0b
5
5
  SHA512:
6
- metadata.gz: 2f57094e1b29721f0948e1e94ac264cafa2b57dde3c55e4d5c5807cfff5c4ebf5ef044f8ca8a2b1132be13294c03f5a350ccc70db6fc4642226445fc4346c9c1
7
- data.tar.gz: 8b700ec6b2543b0388d6be8989cee3bdeb14e814b927c93b6aa6855a00e31cf6117587d8300cf875b44771bd24e4d5a6aa0d260456f453a8ee73625cefa32a91
6
+ metadata.gz: fbb895751949a30c32caaadad94a7d24c711313ca3675bb849f8ec9ab04b21e00901051ba5914d2c6a9317cabd91345cf8efe2ed053b90f61bb56228117b2249
7
+ data.tar.gz: d2fcb5d16322d8a2c7bdf15be9d8108aefaee66505deb4c54acaad2339958d4a9cf4def684e4a08a44ff467f2ce9e7269a9d38924bf668634bdd93e3cd55d69d
data/CHANGELOG.md CHANGED
@@ -3,6 +3,21 @@
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
+ ## [2.2.0] - 2022-09-02
7
+ - [#261](https://github.com/boltops-tools/terraspace/pull/261) extra layer also process env-extra
8
+ - [#262](https://github.com/boltops-tools/terraspace/pull/262) improve graph dependency processing: replace tfvars so only output and depends_on are evaluated
9
+ - [#263](https://github.com/boltops-tools/terraspace/pull/263) layering small improvements
10
+ - layering small improvements: dont use layers that end with - only
11
+ - rename env var to TS_SHOW_ALL_LAYERS to TS_LAYERING_SHOW
12
+
13
+ ## [2.1.7] - 2022-08-22
14
+ - [#259](https://github.com/boltops-tools/terraspace/pull/259) fix TS_PROJECT for ts cloud
15
+ - builder: skip examples
16
+ - improve generated config app.rb
17
+
18
+ ## [2.1.6] - 2022-08-19
19
+ - [#258](https://github.com/boltops-tools/terraspace/pull/258) Fix terraform apply/destroy missing some passthrough options
20
+
6
21
  ## [2.1.5] - 2022-07-21
7
22
  - [#255](https://github.com/boltops-tools/terraspace/pull/255) dont compute git info when not cloud not enabled and warn message improvement
8
23
  - pin terraspace to major version in initially generated Gemfile
@@ -1,6 +1,6 @@
1
1
  # Docs: https://terraspace.cloud/docs/config/reference/
2
2
  Terraspace.configure do |config|
3
- config.logger.level = :info
3
+ # config.logger.level = :info
4
4
 
5
5
  # To enable Terraspace Cloud set config.cloud.org
6
6
  # config.cloud.org = "ORG" # required: replace with your org. only letters, numbers, underscore and dashes allowed
@@ -47,7 +47,7 @@ module Terraspace
47
47
  config.bundle.logger = ts_logger
48
48
 
49
49
  config.cloud = ActiveSupport::OrderedOptions.new
50
- config.cloud.project = "main"
50
+ config.cloud.project = Terraspace.project
51
51
  config.cloud.org = ENV['TS_ORG'] # required for Terraspace cloud
52
52
  config.cloud.record = "changes" # IE: changes or all
53
53
  config.cloud.stack = ":APP-:ROLE-:MOD_NAME-:ENV-:EXTRA-:REGION"
@@ -72,7 +72,7 @@ module Terraspace
72
72
  config.layering.enable_names = ActiveSupport::OrderedOptions.new
73
73
  config.layering.enable_names.expansion = true
74
74
  config.layering.names = {}
75
- config.layering.show = false
75
+ config.layering.show = cast_boolean(ENV['TS_LAYERING_SHOW'])
76
76
  config.layering.mode = ENV['TS_LAYERING_MODE'] || "simple" # simple, namespace, provider
77
77
 
78
78
  config.summary = ActiveSupport::OrderedOptions.new
@@ -104,7 +104,7 @@ module Terraspace
104
104
  # so dont have to add activemodel as a dependency just for this method
105
105
  FALSE_VALUES = [nil, false, 0, "0", "f", "F", "false", "FALSE", "off", "OFF"].to_set
106
106
  def cast_boolean(value)
107
- if value == ""
107
+ if value.nil? || value == ""
108
108
  nil
109
109
  else
110
110
  !FALSE_VALUES.include?(value)
@@ -6,7 +6,13 @@ module Terraspace::Compiler::Erb
6
6
 
7
7
  def build
8
8
  context = Context.new(@mod)
9
- RenderMePretty.result(@src_path, context: context)
9
+ if @mod.resolved
10
+ RenderMePretty.result(@src_path, context: context)
11
+ else
12
+ # Replace contents so only the `output` and `depends_on` are evaluated
13
+ temp_path = Rewrite.new(@src_path).rewrite
14
+ RenderMePretty.result(temp_path, context: context)
15
+ end
10
16
  end
11
17
  end
12
18
  end
@@ -0,0 +1,42 @@
1
+ module Terraspace::Compiler::Erb
2
+ class Rewrite
3
+ def initialize(src_path)
4
+ @src_path = src_path
5
+ end
6
+
7
+ def rewrite
8
+ input = IO.read(@src_path)
9
+ output = replace(input)
10
+ tfvar_path = @src_path.sub(Terraspace.root,'')
11
+ temp_path = "/tmp/terraspace/rewrite#{tfvar_path}"
12
+ FileUtils.mkdir_p(File.dirname(temp_path))
13
+ IO.write(temp_path, output)
14
+ temp_path
15
+ end
16
+
17
+ # Replace contents so only the `output` and `depends_on` are evaluated
18
+ def replace(input)
19
+ lines = input.split("\n").map {|l| l+"\n"} # mimic IO.readlines
20
+ new_lines = lines.map do |line|
21
+ new_line(line)
22
+ end
23
+ new_lines.join('')
24
+ end
25
+
26
+ def new_line(line)
27
+ md = line.match(/.*(<% |<%=)/) || line.match(/.*<%$/)
28
+ if md
29
+ words = %w[output depends_on] # TODO: consider allowing user customizations
30
+ # IE: <%= output or <% depends_on
31
+ regexp = Regexp.new(".*<%.*#{words.join('|')}.*")
32
+ if line.match(regexp)
33
+ line # passthrough
34
+ else
35
+ line.sub('<%', '<%#') # replace with ERB opening comment
36
+ end
37
+ else
38
+ line # passthrough
39
+ end
40
+ end
41
+ end
42
+ end
@@ -21,6 +21,9 @@ module Terraspace::Compiler
21
21
 
22
22
  def compile_module
23
23
  with_mod_file do |src_path|
24
+ # Skip examples. Dont want to process tfvars <%= output(...) %> which triggers dependency graph
25
+ # Also a speed improvement.
26
+ next if src_path.include?("#{@mod.root}/examples/")
24
27
  compile_mod_file(src_path)
25
28
  end
26
29
  end
@@ -70,6 +70,7 @@ class Terraspace::Compiler::Strategy::Tfvar
70
70
  sum += layer_levels(layer) unless layer.nil?
71
71
  sum
72
72
  end
73
+ all = all.reject { |layer| layer.ends_with?('-') }
73
74
  all.map! do |layer|
74
75
  layer = layer.blank? ? layer : "/#{layer}"
75
76
  [
@@ -92,7 +93,7 @@ class Terraspace::Compiler::Strategy::Tfvar
92
93
  logger.info "See: http://terraspace.test/docs/layering/instance-option/"
93
94
  end
94
95
  extra = Terraspace.extra || @mod.instance
95
- levels = ["base", Terraspace.env, extra].reject(&:blank?) # layer levels. @mod.instance can be nil
96
+ levels = ["base", Terraspace.env, extra, "#{Terraspace.env}-#{extra}"].reject(&:blank?) # layer levels. @mod.instance can be nil
96
97
  levels.map! do |i|
97
98
  # base layer has prefix of '', reject with blank so it doesnt produce '//'
98
99
  [prefix, i].reject(&:blank?).join('/')
@@ -158,11 +159,11 @@ class Terraspace::Compiler::Strategy::Tfvar
158
159
  return unless @mod.resolved
159
160
  return if @@shown_layers[@mod.name]
160
161
  logger.debug "Layers for #{@mod.name}:"
161
- show = Terraspace.config.layering.show || ENV['TS_SHOW_ALL_LAYERS']
162
+ show = Terraspace.config.layering.show || ENV['TS_LAYERING_SHOW_ALL']
162
163
  paths.each do |path|
163
164
  next if ARGV[0] == "all" # dont show layers with all command since fork happens after build
164
165
  next unless path.include?('.tfvars')
165
- if ENV['TS_SHOW_ALL_LAYERS']
166
+ if ENV['TS_LAYERING_SHOW_ALL']
166
167
  message = " #{pretty_path(path)}"
167
168
  message = "#{message} (found)".color(:yellow) if File.exist?(path)
168
169
  logger.info message
@@ -20,7 +20,7 @@ module Terraspace
20
20
 
21
21
  def project
22
22
  if ENV['TS_PROJECT'].blank?
23
- config.cloud.project
23
+ "main"
24
24
  else
25
25
  ENV['TS_PROJECT']
26
26
  end
@@ -60,6 +60,17 @@ module Terraspace::Terraform::Args
60
60
  result
61
61
  end
62
62
 
63
+ def terraform_arg_types
64
+ arg_types = terraform_arg_types_for_command(@name)
65
+ # "terraspace apply/destroy" support the same options as "plan", but they don't document
66
+ # them directly in their "-help" option, so we need to add them.
67
+ if ["apply", "destroy"].include? @name
68
+ arg_types.merge! terraform_arg_types_for_command("plan")
69
+ end
70
+
71
+ arg_types
72
+ end
73
+
63
74
  # Parses terraform COMMAND -help output for arg types.
64
75
  # Return Example:
65
76
  #
@@ -69,8 +80,8 @@ module Terraspace::Terraform::Args
69
80
  # var: :hash,
70
81
  # }
71
82
  #
72
- def terraform_arg_types
73
- out = terraform_help(@name)
83
+ def terraform_arg_types_for_command(name)
84
+ out = terraform_help(name)
74
85
  lines = out.split("\n")
75
86
  lines.select! do |line|
76
87
  line =~ /^ -/
@@ -1,3 +1,3 @@
1
1
  module Terraspace
2
- VERSION = "2.1.5"
2
+ VERSION = "2.2.0"
3
3
  end
@@ -13,7 +13,7 @@ describe Terraspace::Compiler::Erb::Render do
13
13
  it "build" do
14
14
  allow(Terraspace::Terraform::RemoteState::Marker::Output).to receive(:stack_names).and_return("b1")
15
15
  result = render.build
16
- expect(result).to eq "length = (unresolved)"
16
+ expect(result).to eq "length = (unresolved)\n"
17
17
  end
18
18
  end
19
19
  end
@@ -0,0 +1,30 @@
1
+ describe Terraspace::Compiler::Erb::Rewrite do
2
+ let(:rewrite) { described_class.new(src_path) }
3
+
4
+ context "has output" do
5
+ let(:src_path) { fixture("rewrite/dev.tfvars") }
6
+ it "replace" do
7
+ input =<<~EOL
8
+ length = <%= output('b1.length') %>
9
+ foo = <%= foo %>
10
+ <% depends_on "b1" %>
11
+ <%
12
+ 3.times do |i|
13
+ puts i
14
+ end
15
+ %>
16
+ EOL
17
+ text = rewrite.replace(input)
18
+ expect(text).to eq <<~EOL
19
+ length = <%= output('b1.length') %>
20
+ foo = <%#= foo %>
21
+ <% depends_on "b1" %>
22
+ <%#
23
+ 3.times do |i|
24
+ puts i
25
+ end
26
+ %>
27
+ EOL
28
+ end
29
+ end
30
+ end
@@ -51,6 +51,19 @@ describe Terraspace::Terraform::Args::Pass do
51
51
  end
52
52
  end
53
53
 
54
+ context "indirectly documented args" do
55
+ # "terraform apply -help" doesn't document "-target" directly, but refers to
56
+ # "terraform plan -help" documentation.
57
+ context "-target=resource" do
58
+ let(:args) { ["-target=foo.bar"] }
59
+ let(:name) { "apply" }
60
+ it "pass through args" do
61
+ args = pass.args
62
+ expect(args).to eq ["-target=foo.bar"]
63
+ end
64
+ end
65
+ end
66
+
54
67
  context "hash arg" do
55
68
  context "-var 'foo=bar'" do
56
69
  let(:args) { ["-var 'foo=bar'"] }
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: 2.1.5
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-21 00:00:00.000000000 Z
11
+ date: 2022-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -703,6 +703,7 @@ files:
703
703
  - lib/terraspace/compiler/erb/context.rb
704
704
  - lib/terraspace/compiler/erb/helpers.rb
705
705
  - lib/terraspace/compiler/erb/render.rb
706
+ - lib/terraspace/compiler/erb/rewrite.rb
706
707
  - lib/terraspace/compiler/expander.rb
707
708
  - lib/terraspace/compiler/expander/backend.rb
708
709
  - lib/terraspace/compiler/helper_extender.rb
@@ -926,6 +927,7 @@ files:
926
927
  - spec/terraspace/compiler/dsl/terraform_spec.rb
927
928
  - spec/terraspace/compiler/dsl/variable_spec.rb
928
929
  - spec/terraspace/compiler/erb/render_spec.rb
930
+ - spec/terraspace/compiler/erb/rewrite_spec.rb
929
931
  - spec/terraspace/dependency/graph_spec.rb
930
932
  - spec/terraspace/dependency/helper/depends_on_spec.rb
931
933
  - spec/terraspace/dependency/helper/output_spec.rb
@@ -961,7 +963,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
961
963
  - !ruby/object:Gem::Version
962
964
  version: '0'
963
965
  requirements: []
964
- rubygems_version: 3.3.12
966
+ rubygems_version: 3.3.21
965
967
  signing_key:
966
968
  specification_version: 4
967
969
  summary: 'Terraspace: The Terraspace Framework'
@@ -1083,6 +1085,7 @@ test_files:
1083
1085
  - spec/terraspace/compiler/dsl/terraform_spec.rb
1084
1086
  - spec/terraspace/compiler/dsl/variable_spec.rb
1085
1087
  - spec/terraspace/compiler/erb/render_spec.rb
1088
+ - spec/terraspace/compiler/erb/rewrite_spec.rb
1086
1089
  - spec/terraspace/dependency/graph_spec.rb
1087
1090
  - spec/terraspace/dependency/helper/depends_on_spec.rb
1088
1091
  - spec/terraspace/dependency/helper/output_spec.rb