terraspace 2.1.6 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/lib/templates/base/project/config/app.rb +1 -1
- data/lib/terraspace/app.rb +3 -3
- data/lib/terraspace/cli/help/import.md +29 -0
- data/lib/terraspace/cli/import.rb +12 -0
- data/lib/terraspace/cli.rb +6 -0
- data/lib/terraspace/compiler/erb/render.rb +7 -1
- data/lib/terraspace/compiler/erb/rewrite.rb +42 -0
- data/lib/terraspace/compiler/perform.rb +3 -0
- data/lib/terraspace/compiler/strategy/tfvar/layer.rb +4 -3
- data/lib/terraspace/core.rb +1 -1
- data/lib/terraspace/terraform/args/thor.rb +4 -0
- 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 +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9173675976a0e7207ae8ce912195535f2dc43c7bba91c5a90808559ce543df2d
|
4
|
+
data.tar.gz: 6c7b089a9bd1d82873ac5148fc276a0ad3578236f6cf89a3742ea049ef461bbe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72de399e443552b2981df770e22d2a710721f526aacabff3210ee28d85c4c870a2bdf61f02576b4cc1170789229beaa92feb89eba2269a0dbd7f07ccd6e7a152
|
7
|
+
data.tar.gz: eb40bc9c321f6f1fa9f2ba3a4f14f9f831b4aefc23af251655b65dccb58ac838c9493fff8dcde7ec1de007015689627e1ffb4d9049bdd04c871cfb9f4b363bde
|
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.1] - 2022-09-08
|
7
|
+
- [#265](https://github.com/boltops-tools/terraspace/pull/265) import command
|
8
|
+
|
9
|
+
## [2.2.0] - 2022-09-02
|
10
|
+
- [#261](https://github.com/boltops-tools/terraspace/pull/261) extra layer also process env-extra
|
11
|
+
- [#262](https://github.com/boltops-tools/terraspace/pull/262) improve graph dependency processing: replace tfvars so only output and depends_on are evaluated
|
12
|
+
- [#263](https://github.com/boltops-tools/terraspace/pull/263) layering small improvements
|
13
|
+
- layering small improvements: dont use layers that end with - only
|
14
|
+
- rename env var to TS_SHOW_ALL_LAYERS to TS_LAYERING_SHOW
|
15
|
+
|
16
|
+
## [2.1.7] - 2022-08-22
|
17
|
+
- [#259](https://github.com/boltops-tools/terraspace/pull/259) fix TS_PROJECT for ts cloud
|
18
|
+
- builder: skip examples
|
19
|
+
- improve generated config app.rb
|
20
|
+
|
6
21
|
## [2.1.6] - 2022-08-19
|
7
22
|
- [#258](https://github.com/boltops-tools/terraspace/pull/258) Fix terraform apply/destroy missing some passthrough options
|
8
23
|
|
@@ -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
|
data/lib/terraspace/app.rb
CHANGED
@@ -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 =
|
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 =
|
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)
|
@@ -0,0 +1,29 @@
|
|
1
|
+
## Examples
|
2
|
+
|
3
|
+
terraspace import aws_instance.this i-088a0a47e2e852cc8
|
4
|
+
terraspace import module.vpc.aws_vpc.this vpc-000782e4951a734c7
|
5
|
+
terraspace import vpc module.vpc.aws_vpc.this vpc-000782e4951a734c7
|
6
|
+
|
7
|
+
A general workflow is to use terraspace plan, inspect what resources, are missing and and import resources based on that. The `state list` command is also useful.
|
8
|
+
|
9
|
+
terraspace plan vpc
|
10
|
+
terraspace import vpc module.vpc.aws_vpc.this vpc-000782e4951a734c7
|
11
|
+
terraspace plan vpc
|
12
|
+
terraspace import vpc module.vpc.aws_internet_gateway.this[0] igw-0fa4bec3b4b46948a
|
13
|
+
terraspace state list vpc
|
14
|
+
|
15
|
+
Example with output:
|
16
|
+
|
17
|
+
$ terraspace import vpc module.vpc.aws_internet_gateway.this[0] igw-0fa4bec3b4b46948a
|
18
|
+
Building .terraspace-cache/us-west-2/dev/stacks/vpc
|
19
|
+
Current directory: .terraspace-cache/us-west-2/dev/stacks/vpc
|
20
|
+
=> terraform import module.vpc.aws_internet_gateway.this[0] igw-0fa4bec3b4b46948a
|
21
|
+
module.vpc.aws_internet_gateway.this[0]: Importing from ID "igw-0fa4bec3b4b46948a"...
|
22
|
+
module.vpc.aws_internet_gateway.this[0]: Import prepared!
|
23
|
+
Prepared aws_internet_gateway for import
|
24
|
+
module.vpc.aws_internet_gateway.this[0]: Refreshing state... [id=igw-0fa4bec3b4b46948a]
|
25
|
+
|
26
|
+
Import successful!
|
27
|
+
|
28
|
+
The resources that were imported are shown above. These resources are now in
|
29
|
+
your Terraform state and will henceforth be managed by Terraform.
|
data/lib/terraspace/cli.rb
CHANGED
@@ -109,6 +109,12 @@ module Terraspace
|
|
109
109
|
Fmt.new(options.merge(mod: mod)).run
|
110
110
|
end
|
111
111
|
|
112
|
+
desc "import ADDR ID", "Import existing infrastructure into your Terraform state"
|
113
|
+
long_desc Help.text(:import)
|
114
|
+
def import(mod, addr, id)
|
115
|
+
Import.new(options.merge(mod: mod, addr: addr, id: id)).run
|
116
|
+
end
|
117
|
+
|
112
118
|
desc "info STACK", "Get info about stack."
|
113
119
|
long_desc Help.text(:info)
|
114
120
|
instance_option.call
|
@@ -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
|
@@ -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['
|
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/core.rb
CHANGED
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.1
|
4
|
+
version: 2.2.1
|
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-08
|
11
|
+
date: 2022-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -571,6 +571,7 @@ files:
|
|
571
571
|
- lib/terraspace/cli/help/down.md
|
572
572
|
- lib/terraspace/cli/help/fmt.md
|
573
573
|
- lib/terraspace/cli/help/force_unlock.md
|
574
|
+
- lib/terraspace/cli/help/import.md
|
574
575
|
- lib/terraspace/cli/help/info.md
|
575
576
|
- lib/terraspace/cli/help/init.md
|
576
577
|
- lib/terraspace/cli/help/list.md
|
@@ -604,6 +605,7 @@ files:
|
|
604
605
|
- lib/terraspace/cli/help/tfc/sync.md
|
605
606
|
- lib/terraspace/cli/help/up.md
|
606
607
|
- lib/terraspace/cli/help/validate.md
|
608
|
+
- lib/terraspace/cli/import.rb
|
607
609
|
- lib/terraspace/cli/info.rb
|
608
610
|
- lib/terraspace/cli/init.rb
|
609
611
|
- lib/terraspace/cli/list.rb
|
@@ -703,6 +705,7 @@ files:
|
|
703
705
|
- lib/terraspace/compiler/erb/context.rb
|
704
706
|
- lib/terraspace/compiler/erb/helpers.rb
|
705
707
|
- lib/terraspace/compiler/erb/render.rb
|
708
|
+
- lib/terraspace/compiler/erb/rewrite.rb
|
706
709
|
- lib/terraspace/compiler/expander.rb
|
707
710
|
- lib/terraspace/compiler/expander/backend.rb
|
708
711
|
- lib/terraspace/compiler/helper_extender.rb
|
@@ -926,6 +929,7 @@ files:
|
|
926
929
|
- spec/terraspace/compiler/dsl/terraform_spec.rb
|
927
930
|
- spec/terraspace/compiler/dsl/variable_spec.rb
|
928
931
|
- spec/terraspace/compiler/erb/render_spec.rb
|
932
|
+
- spec/terraspace/compiler/erb/rewrite_spec.rb
|
929
933
|
- spec/terraspace/dependency/graph_spec.rb
|
930
934
|
- spec/terraspace/dependency/helper/depends_on_spec.rb
|
931
935
|
- spec/terraspace/dependency/helper/output_spec.rb
|
@@ -961,7 +965,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
961
965
|
- !ruby/object:Gem::Version
|
962
966
|
version: '0'
|
963
967
|
requirements: []
|
964
|
-
rubygems_version: 3.3.
|
968
|
+
rubygems_version: 3.3.21
|
965
969
|
signing_key:
|
966
970
|
specification_version: 4
|
967
971
|
summary: 'Terraspace: The Terraspace Framework'
|
@@ -1083,6 +1087,7 @@ test_files:
|
|
1083
1087
|
- spec/terraspace/compiler/dsl/terraform_spec.rb
|
1084
1088
|
- spec/terraspace/compiler/dsl/variable_spec.rb
|
1085
1089
|
- spec/terraspace/compiler/erb/render_spec.rb
|
1090
|
+
- spec/terraspace/compiler/erb/rewrite_spec.rb
|
1086
1091
|
- spec/terraspace/dependency/graph_spec.rb
|
1087
1092
|
- spec/terraspace/dependency/helper/depends_on_spec.rb
|
1088
1093
|
- spec/terraspace/dependency/helper/output_spec.rb
|