terraspace 2.1.7 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/terraspace/app.rb +2 -2
- data/lib/terraspace/compiler/erb/render.rb +7 -1
- data/lib/terraspace/compiler/erb/rewrite.rb +42 -0
- data/lib/terraspace/compiler/strategy/tfvar/layer.rb +4 -3
- data/lib/terraspace/version.rb +1 -1
- data/spec/terraspace/compiler/erb/render_spec.rb +1 -1
- data/spec/terraspace/compiler/erb/rewrite_spec.rb +30 -0
- metadata +6 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 672cf9e56e84babb2bc53f8e076a13cb51aa9741416fcd6128e66b3774d335fb
|
|
4
|
+
data.tar.gz: 10417698653e7ae38863e1c9d3a1fafebb2ea937693e8c5c0f65cb14e81b1f0b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fbb895751949a30c32caaadad94a7d24c711313ca3675bb849f8ec9ab04b21e00901051ba5914d2c6a9317cabd91345cf8efe2ed053b90f61bb56228117b2249
|
|
7
|
+
data.tar.gz: d2fcb5d16322d8a2c7bdf15be9d8108aefaee66505deb4c54acaad2339958d4a9cf4def684e4a08a44ff467f2ce9e7269a9d38924bf668634bdd93e3cd55d69d
|
data/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,13 @@
|
|
|
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
|
+
|
|
6
13
|
## [2.1.7] - 2022-08-22
|
|
7
14
|
- [#259](https://github.com/boltops-tools/terraspace/pull/259) fix TS_PROJECT for ts cloud
|
|
8
15
|
- builder: skip examples
|
data/lib/terraspace/app.rb
CHANGED
|
@@ -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 =
|
|
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
|
-
|
|
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
|
|
@@ -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['
|
|
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['
|
|
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
|
data/lib/terraspace/version.rb
CHANGED
|
@@ -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
|
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.
|
|
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-
|
|
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.
|
|
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
|