terraspace 0.2.4 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.cody/aws/bin/build.sh +2 -0
- data/.cody/azurerm/bin/build.sh +2 -0
- data/.cody/google/bin/build.sh +2 -0
- data/CHANGELOG.md +39 -1
- data/README.md +14 -1
- data/lib/templates/base/git_hook/hook.sh +1 -1
- data/lib/templates/base/project/.gitignore +1 -0
- data/lib/templates/base/project/README.md +17 -0
- data/lib/terraspace.rb +6 -0
- data/lib/terraspace/all/base.rb +8 -0
- data/lib/terraspace/all/grapher.rb +129 -0
- data/lib/terraspace/all/preview.rb +43 -0
- data/lib/terraspace/all/runner.rb +169 -0
- data/lib/terraspace/all/summary.rb +119 -0
- data/lib/terraspace/app.rb +31 -9
- data/lib/terraspace/booter.rb +9 -0
- data/lib/terraspace/builder.rb +59 -22
- data/lib/terraspace/cli.rb +60 -33
- data/lib/terraspace/cli/all.rb +63 -0
- data/lib/terraspace/cli/build/placeholder.rb +2 -5
- data/lib/terraspace/cli/bundle.rb +1 -1
- data/lib/terraspace/cli/check_setup.rb +5 -0
- data/lib/terraspace/cli/cloud.rb +16 -6
- data/lib/terraspace/cli/cloud/runs.rb +22 -0
- data/lib/terraspace/cli/commander.rb +1 -8
- data/lib/terraspace/cli/down.rb +20 -0
- data/lib/terraspace/cli/help/all/down.md +32 -0
- data/lib/terraspace/cli/help/all/graph.md +21 -0
- data/lib/terraspace/cli/help/all/output.md +22 -0
- data/lib/terraspace/cli/help/all/plan.md +25 -0
- data/lib/terraspace/cli/help/all/providers.md +21 -0
- data/lib/terraspace/cli/help/all/refresh.md +17 -0
- data/lib/terraspace/cli/help/all/show.md +21 -0
- data/lib/terraspace/cli/help/all/up.md +27 -0
- data/lib/terraspace/cli/help/all/validate.md +21 -0
- data/lib/terraspace/cli/help/build.md +6 -0
- data/lib/terraspace/cli/help/bundle.md +9 -5
- data/lib/terraspace/cli/help/check_setup.md +9 -0
- data/lib/terraspace/cli/help/clean.md +5 -0
- data/lib/terraspace/cli/help/cloud/destroy.md +16 -0
- data/lib/terraspace/cli/help/cloud/list.md +7 -0
- data/lib/terraspace/cli/help/cloud/runs/list.md +36 -0
- data/lib/terraspace/cli/help/cloud/runs/prune.md +25 -0
- data/lib/terraspace/cli/help/cloud/sync.md +43 -0
- data/lib/terraspace/cli/help/console.md +8 -0
- data/lib/terraspace/cli/help/down.md +26 -0
- data/lib/terraspace/cli/help/info.md +43 -0
- data/lib/terraspace/cli/help/init.md +37 -0
- data/lib/terraspace/cli/help/list.md +20 -0
- data/lib/terraspace/cli/help/log.md +48 -0
- data/lib/terraspace/cli/help/logs/remove.md +5 -0
- data/lib/terraspace/cli/help/logs/truncate.md +5 -0
- data/lib/terraspace/cli/help/new/bootstrap_test.md +8 -0
- data/lib/terraspace/cli/help/new/example.md +8 -0
- data/lib/terraspace/cli/help/new/git_hook.md +6 -0
- data/lib/terraspace/cli/help/new/module.md +9 -0
- data/lib/terraspace/cli/help/new/module_test.md +12 -0
- data/lib/terraspace/cli/help/new/plugin.md +49 -0
- data/lib/terraspace/cli/help/new/project.md +40 -0
- data/lib/terraspace/cli/help/new/project_test.md +8 -0
- data/lib/terraspace/cli/help/new/shim.md +21 -0
- data/lib/terraspace/cli/help/new/stack.md +9 -0
- data/lib/terraspace/cli/help/output.md +6 -0
- data/lib/terraspace/cli/help/plan.md +29 -0
- data/lib/terraspace/cli/help/providers.md +18 -0
- data/lib/terraspace/cli/help/refresh.md +11 -0
- data/lib/terraspace/cli/help/seed.md +7 -0
- data/lib/terraspace/cli/help/show.md +36 -0
- data/lib/terraspace/cli/help/summary.md +11 -0
- data/lib/terraspace/cli/help/test.md +35 -0
- data/lib/terraspace/cli/help/up.md +30 -0
- data/lib/terraspace/cli/help/validate.md +9 -0
- data/lib/terraspace/cli/info.rb +4 -16
- data/lib/terraspace/cli/init.rb +35 -7
- data/lib/terraspace/cli/list.rb +14 -1
- data/lib/terraspace/cli/log.rb +112 -0
- data/lib/terraspace/cli/log/concern.rb +24 -0
- data/lib/terraspace/cli/logs.rb +15 -0
- data/lib/terraspace/cli/logs/tasks.rb +32 -0
- data/lib/terraspace/cli/new.rb +18 -18
- data/lib/terraspace/cli/new/git_hook.rb +5 -2
- data/lib/terraspace/cli/new/project.rb +1 -1
- data/lib/terraspace/cli/summary.rb +2 -2
- data/lib/terraspace/cli/tfc_concern.rb +14 -0
- data/lib/terraspace/cli/up.rb +32 -0
- data/lib/terraspace/command.rb +1 -1
- data/lib/terraspace/compiler/backend.rb +10 -0
- data/lib/terraspace/compiler/builder.rb +5 -4
- data/lib/terraspace/compiler/cleaner.rb +1 -1
- data/lib/terraspace/compiler/cleaner/backend_change.rb +21 -7
- data/lib/terraspace/compiler/commands_concern.rb +18 -0
- data/lib/terraspace/compiler/dirs_concern.rb +47 -0
- data/lib/terraspace/compiler/dsl/syntax/helpers/common.rb +26 -1
- data/lib/terraspace/core.rb +11 -2
- data/lib/terraspace/dependency/graph.rb +140 -0
- data/lib/terraspace/dependency/node.rb +38 -0
- data/lib/terraspace/dependency/registry.rb +11 -0
- data/lib/terraspace/logger.rb +6 -18
- data/lib/terraspace/logger/formatter.rb +13 -0
- data/lib/terraspace/mod.rb +7 -1
- data/lib/terraspace/plugin/summary/interface.rb +1 -1
- data/lib/terraspace/seeder/where.rb +6 -2
- data/lib/terraspace/shell.rb +107 -0
- data/lib/terraspace/terraform/api.rb +7 -45
- data/lib/terraspace/terraform/api/base.rb +7 -0
- data/lib/terraspace/terraform/api/client.rb +23 -3
- data/lib/terraspace/terraform/api/http.rb +14 -34
- data/lib/terraspace/terraform/api/http/concern.rb +10 -0
- data/lib/terraspace/terraform/api/runs.rb +28 -0
- data/lib/terraspace/terraform/api/token.rb +65 -0
- data/lib/terraspace/terraform/api/var.rb +20 -6
- data/lib/terraspace/terraform/api/vars.rb +2 -1
- data/lib/terraspace/terraform/api/workspace.rb +98 -0
- data/lib/terraspace/terraform/args/default.rb +48 -21
- data/lib/terraspace/terraform/cloud/runs.rb +13 -0
- data/lib/terraspace/terraform/cloud/runs/base.rb +33 -0
- data/lib/terraspace/terraform/cloud/runs/item_presenter.rb +37 -0
- data/lib/terraspace/terraform/cloud/runs/lister.rb +20 -0
- data/lib/terraspace/terraform/cloud/runs/pruner.rb +109 -0
- data/lib/terraspace/terraform/cloud/sync.rb +41 -0
- data/lib/terraspace/terraform/cloud/syncer.rb +52 -0
- data/lib/terraspace/terraform/cloud/workspace.rb +10 -30
- data/lib/terraspace/terraform/hooks/builder.rb +1 -1
- data/lib/terraspace/terraform/remote_state/fetcher.rb +143 -0
- data/lib/terraspace/terraform/remote_state/marker/output.rb +39 -0
- data/lib/terraspace/terraform/remote_state/marker/pretty_tracer.rb +37 -0
- data/lib/terraspace/terraform/remote_state/output_proxy.rb +29 -0
- data/lib/terraspace/terraform/runner.rb +24 -14
- data/lib/terraspace/util.rb +1 -5
- data/lib/terraspace/util/pretty.rb +18 -0
- data/lib/terraspace/version.rb +1 -1
- data/spec/fixtures/fetcher/c1.json +37 -0
- data/spec/fixtures/parser/cache_dirs/all/01-test.auto.tfvars +5 -0
- data/spec/fixtures/parser/cache_dirs/depends_on/01-test.auto.tfvars +2 -0
- data/spec/fixtures/parser/cache_dirs/output/01-test.auto.tfvars +2 -0
- data/spec/fixtures/summary/down.log +12 -0
- data/spec/fixtures/summary/output.log +5 -0
- data/spec/fixtures/summary/plan/error.log +20 -0
- data/spec/fixtures/summary/plan/success.log +17 -0
- data/spec/fixtures/summary/show.log +22 -0
- data/spec/fixtures/summary/up/error.log +13 -0
- data/spec/fixtures/summary/up/success.log +63 -0
- data/spec/fixtures/summary/validate/error.log +13 -0
- data/spec/fixtures/summary/validate/success.log +5 -0
- data/spec/terraspace/all/grapher_spec.rb +38 -0
- data/spec/terraspace/all/runner_spec.rb +48 -0
- data/spec/terraspace/all/summary_spec.rb +93 -0
- data/spec/terraspace/dependency/graph_spec.rb +162 -0
- data/spec/terraspace/seeder_spec.rb +0 -1
- data/spec/terraspace/terraform/remote_state/fetcher_spec.rb +52 -0
- data/terraspace.gemspec +5 -1
- metadata +179 -6
- data/lib/terraspace/cli/help/update.md +0 -5
- data/lib/terraspace/terraform/cloud.rb +0 -25
- data/lib/terraspace/util/sh.rb +0 -19
@@ -0,0 +1,24 @@
|
|
1
|
+
class Terraspace::CLI::Log
|
2
|
+
module Concern
|
3
|
+
# Filters for lines that belong to the last ran process pid
|
4
|
+
def readlines(path)
|
5
|
+
lines = IO.readlines(path)
|
6
|
+
found = lines.reverse.find do |line|
|
7
|
+
pid(line) # search in reverse order for lines with interesting info
|
8
|
+
end
|
9
|
+
unless found
|
10
|
+
puts "WARN: Could not find the pid in the logfile #{Terraspace::Util.pretty_path(path)}".color(:yellow)
|
11
|
+
return []
|
12
|
+
end
|
13
|
+
|
14
|
+
pid = pid(found)
|
15
|
+
lines.select {|l| l.include?(" ##{pid} ") }
|
16
|
+
end
|
17
|
+
|
18
|
+
# [2020-09-06T21:58:25 #11313 terraspace up b1]:
|
19
|
+
def pid(line)
|
20
|
+
md = line.match(/:\d{2} #(\d+) /)
|
21
|
+
md[1] if md
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Terraspace::CLI
|
2
|
+
class Logs < Terraspace::Command
|
3
|
+
desc "truncate", "Truncates logs. IE: Keeps the files but removes contents and zero bytes the files."
|
4
|
+
long_desc Help.text("logs/truncate")
|
5
|
+
def truncate
|
6
|
+
Tasks.new(options).truncate
|
7
|
+
end
|
8
|
+
|
9
|
+
desc "remove", "Removes logs"
|
10
|
+
long_desc Help.text("logs/remove")
|
11
|
+
def remove
|
12
|
+
Tasks.new(options).remove
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class Terraspace::CLI::Logs
|
2
|
+
class Tasks
|
3
|
+
def initialize(options={})
|
4
|
+
@options = options
|
5
|
+
end
|
6
|
+
|
7
|
+
def truncate
|
8
|
+
puts "Truncating log files in #{pretty_log_root}/" unless @options[:mute]
|
9
|
+
log_files.each do |path|
|
10
|
+
File.open(path, "w").close # truncates files
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def remove
|
15
|
+
puts "Removing all files in #{pretty_log_root}/" unless @options[:mute]
|
16
|
+
FileUtils.rm_rf(log_root)
|
17
|
+
FileUtils.mkdir_p(log_root)
|
18
|
+
end
|
19
|
+
|
20
|
+
def log_files
|
21
|
+
Dir.glob("#{log_root}/**/*.log")
|
22
|
+
end
|
23
|
+
|
24
|
+
def pretty_log_root
|
25
|
+
Terraspace::Util.pretty_path(log_root)
|
26
|
+
end
|
27
|
+
|
28
|
+
def log_root
|
29
|
+
Terraspace.config.log.root
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/terraspace/cli/new.rb
CHANGED
@@ -1,40 +1,40 @@
|
|
1
1
|
class Terraspace::CLI
|
2
2
|
class New < Terraspace::Command
|
3
|
-
long_desc Help.text(
|
3
|
+
long_desc Help.text("new/git_hook")
|
4
4
|
GitHook.cli_options.each { |args| option(*args) }
|
5
|
-
register(GitHook, "git_hook", "git_hook", "Generates new git hook")
|
5
|
+
register(GitHook, "git_hook", "git_hook", "Generates new git hook.")
|
6
6
|
|
7
|
-
long_desc Help.text(
|
7
|
+
long_desc Help.text("new/shim")
|
8
8
|
Shim.cli_options.each { |args| option(*args) }
|
9
|
-
register(Shim, "shim", "shim", "Generates terraspace shim")
|
9
|
+
register(Shim, "shim", "shim", "Generates terraspace shim.")
|
10
10
|
|
11
|
-
long_desc Help.text(
|
11
|
+
long_desc Help.text("new/module")
|
12
12
|
Module.base_options.each { |args| option(*args) }
|
13
13
|
Module.component_options.each { |args| option(*args) }
|
14
|
-
register(Module, "module", "module NAME", "Generates new module")
|
14
|
+
register(Module, "module", "module NAME", "Generates new module.")
|
15
15
|
|
16
|
-
long_desc Help.text(
|
16
|
+
long_desc Help.text("new/stack")
|
17
17
|
Stack.base_options.each { |args| option(*args) }
|
18
18
|
Stack.component_options.each { |args| option(*args) }
|
19
|
-
register(Stack, "stack", "stack NAME", "Generates new stack")
|
19
|
+
register(Stack, "stack", "stack NAME", "Generates new stack.")
|
20
20
|
|
21
|
-
long_desc Help.text(
|
21
|
+
long_desc Help.text("new/project")
|
22
22
|
Project.base_options.each { |args| option(*args) }
|
23
23
|
Project.project_options.each { |args| option(*args) }
|
24
|
-
register(Project, "project", "project NAME", "Generates new project")
|
24
|
+
register(Project, "project", "project NAME", "Generates new project.")
|
25
25
|
|
26
|
-
long_desc Help.text(
|
27
|
-
register(Test::Project, "project_test", "project_test NAME", "Generates new project test")
|
26
|
+
long_desc Help.text("new/project_test")
|
27
|
+
register(Test::Project, "project_test", "project_test NAME", "Generates new project test.")
|
28
28
|
|
29
|
-
long_desc Help.text(
|
30
|
-
register(Test::Module, "module_test", "module_test NAME", "Generates new module test")
|
29
|
+
long_desc Help.text("new/module_test")
|
30
|
+
register(Test::Module, "module_test", "module_test NAME", "Generates new module test.")
|
31
31
|
|
32
|
-
long_desc Help.text(
|
32
|
+
long_desc Help.text("new/bootstrap_test")
|
33
33
|
Test::Bootstrap.options.each { |args| option(*args) }
|
34
|
-
register(Test::Bootstrap, "bootstrap_test", "bootstrap_test", "Generates bootstrap test setup")
|
34
|
+
register(Test::Bootstrap, "bootstrap_test", "bootstrap_test", "Generates bootstrap test setup.")
|
35
35
|
|
36
|
-
long_desc Help.text(
|
36
|
+
long_desc Help.text("new/plugin")
|
37
37
|
Plugin.options.each { |args| option(*args) }
|
38
|
-
register(Plugin, "plugin", "plugin", "Generates plugin")
|
38
|
+
register(Plugin, "plugin", "plugin", "Generates plugin.")
|
39
39
|
end
|
40
40
|
end
|
@@ -15,7 +15,10 @@ class Terraspace::CLI::New
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def create
|
18
|
-
|
18
|
+
unless File.exist?(".git")
|
19
|
+
puts "No .git folder found. Not creating git hook."
|
20
|
+
return
|
21
|
+
end
|
19
22
|
dest = ".git/hooks/#{options[:type]}"
|
20
23
|
template "hook.sh", dest
|
21
24
|
chmod dest, 0755
|
@@ -25,7 +28,7 @@ class Terraspace::CLI::New
|
|
25
28
|
def terraspace_build_commands
|
26
29
|
code = []
|
27
30
|
@options[:envs].each do |env|
|
28
|
-
code << %Q|TS_ENV=#{env} terraspace build
|
31
|
+
code << %Q|TS_ENV=#{env} terraspace build|
|
29
32
|
end
|
30
33
|
code.join("\n")
|
31
34
|
end
|
@@ -12,7 +12,7 @@ class Terraspace::CLI
|
|
12
12
|
|
13
13
|
def run
|
14
14
|
Terraspace.check_project!
|
15
|
-
|
15
|
+
build_placeholder
|
16
16
|
puts "Summary of resources based on backend storage statefiles"
|
17
17
|
backend_expr = '.terraspace-cache/**/backend.*'
|
18
18
|
# Currently summary assumes backend are within the same bucket and key prefix
|
@@ -22,7 +22,7 @@ class Terraspace::CLI
|
|
22
22
|
|
23
23
|
# Grab the last module and build that.
|
24
24
|
# Assume the backend key has the same prefix
|
25
|
-
def
|
25
|
+
def build_placeholder
|
26
26
|
Build::Placeholder.new(@options).build
|
27
27
|
end
|
28
28
|
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class Terraspace::CLI
|
2
|
+
class Up < Base
|
3
|
+
include TfcConcern
|
4
|
+
|
5
|
+
def run
|
6
|
+
build
|
7
|
+
if @options[:yes] && !tfc?
|
8
|
+
plan
|
9
|
+
Commander.new("apply", @options.merge(plan: plan_path)).run
|
10
|
+
else
|
11
|
+
Commander.new("apply", @options).run
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
# must build to compute tfc?
|
17
|
+
def build
|
18
|
+
Terraspace::Builder.new(@options).run
|
19
|
+
@options[:build] = false
|
20
|
+
end
|
21
|
+
|
22
|
+
def plan
|
23
|
+
FileUtils.mkdir_p(File.dirname(plan_path))
|
24
|
+
Commander.new("plan", @options.merge(out: plan_path)).run
|
25
|
+
end
|
26
|
+
|
27
|
+
def plan_path
|
28
|
+
@@timestamp ||= Time.now.utc.strftime("%Y%m%d%H%M%S")
|
29
|
+
"#{Terraspace.tmp_root}/plans/#{@mod.name}-#{@@timestamp}.plan"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/terraspace/command.rb
CHANGED
@@ -6,7 +6,13 @@ module Terraspace::Compiler
|
|
6
6
|
@mod = mod
|
7
7
|
end
|
8
8
|
|
9
|
+
@@created = {}
|
9
10
|
def create
|
11
|
+
return if @@created[cache_key]
|
12
|
+
# set immediately, since local storage wont reach bottom.
|
13
|
+
# if fail for other backends, there will be an exception anyway
|
14
|
+
@@created[cache_key] = true
|
15
|
+
|
10
16
|
klass = backend_interface(backend_name)
|
11
17
|
return unless klass # in case auto-creation is not supported for specific backend
|
12
18
|
|
@@ -14,6 +20,10 @@ module Terraspace::Compiler
|
|
14
20
|
interface.call
|
15
21
|
end
|
16
22
|
|
23
|
+
def cache_key
|
24
|
+
@mod.build_dir
|
25
|
+
end
|
26
|
+
|
17
27
|
def backend_name
|
18
28
|
backend.keys.first # IE: s3, gcs, etc
|
19
29
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module Terraspace::Compiler
|
2
2
|
class Builder
|
3
|
+
include CommandsConcern
|
3
4
|
include Basename
|
4
5
|
|
5
6
|
def initialize(mod)
|
@@ -8,14 +9,14 @@ module Terraspace::Compiler
|
|
8
9
|
|
9
10
|
def build
|
10
11
|
build_config
|
11
|
-
build_module
|
12
|
-
build_tfvars
|
12
|
+
build_module if @mod.resolved
|
13
|
+
build_tfvars unless command_is?(:seed) # avoid dependencies being built and erroring when backend bucket doesnt exist
|
13
14
|
end
|
14
15
|
|
15
16
|
# build common config files: provider and backend for the root module
|
16
17
|
def build_config
|
17
18
|
return unless build?
|
18
|
-
|
19
|
+
build_config_terraform
|
19
20
|
end
|
20
21
|
|
21
22
|
def build_module
|
@@ -34,7 +35,7 @@ module Terraspace::Compiler
|
|
34
35
|
@mod.type == "stack" || @mod.root_module?
|
35
36
|
end
|
36
37
|
|
37
|
-
def
|
38
|
+
def build_config_terraform
|
38
39
|
expr = "#{Terraspace.root}/config/terraform/**/*"
|
39
40
|
Dir.glob(expr).each do |path|
|
40
41
|
next unless File.file?(path)
|
@@ -9,14 +9,9 @@ class Terraspace::Compiler::Cleaner
|
|
9
9
|
def purge
|
10
10
|
return unless purge?
|
11
11
|
|
12
|
+
are_you_sure? if local_statefile_exist?
|
12
13
|
cache_root = Terraspace::Util.pretty_path(Terraspace.cache_root)
|
13
|
-
|
14
|
-
Backend change detected. Will remove #{cache_root} for complete reinitialization
|
15
|
-
WARN: If you are using local storage for state, this will remove it.
|
16
|
-
Will remove #{cache_root}
|
17
|
-
EOL
|
18
|
-
sure?(message.strip)
|
19
|
-
logger.info "Backend change detected. Removing #{cache_root} for complete reinitialization"
|
14
|
+
logger.debug "Backend change detected. Removing #{cache_root} for complete reinitialization"
|
20
15
|
FileUtils.rm_rf(Terraspace.cache_root)
|
21
16
|
end
|
22
17
|
|
@@ -26,6 +21,15 @@ class Terraspace::Compiler::Cleaner
|
|
26
21
|
current_backend != fresh_backend
|
27
22
|
end
|
28
23
|
|
24
|
+
def local_statefile_exist?
|
25
|
+
# Note: Will not go into .terraform folders. No need to for terraform.tfstate
|
26
|
+
Dir.glob("#{Terraspace.cache_root}/**/*").each do |path|
|
27
|
+
basename = File.basename(path)
|
28
|
+
return true if basename == 'terraform.tfstate'
|
29
|
+
end
|
30
|
+
false
|
31
|
+
end
|
32
|
+
|
29
33
|
def current_backend
|
30
34
|
materialized_path = find_src_path("#{@mod.cache_dir}/backend*")
|
31
35
|
IO.read(materialized_path) if materialized_path
|
@@ -37,6 +41,16 @@ class Terraspace::Compiler::Cleaner
|
|
37
41
|
end
|
38
42
|
|
39
43
|
private
|
44
|
+
def are_you_sure?
|
45
|
+
cache_root = Terraspace::Util.pretty_path(Terraspace.cache_root)
|
46
|
+
message =<<~EOL
|
47
|
+
Backend change detected. Will remove #{cache_root} for complete reinitialization
|
48
|
+
#{"WARN: You are using local storage for state, this will remove it.".color(:yellow)}
|
49
|
+
Will remove #{cache_root} and all terraform.tfstate files
|
50
|
+
EOL
|
51
|
+
sure?(message.strip) # from Util
|
52
|
+
end
|
53
|
+
|
40
54
|
def find_src_path(expr)
|
41
55
|
path = Dir.glob(expr).first
|
42
56
|
path if path && File.exist?(path)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Terraspace::Compiler
|
2
|
+
module CommandsConcern
|
3
|
+
def requires_backend?
|
4
|
+
command_is?(requires_backend_commands)
|
5
|
+
end
|
6
|
+
|
7
|
+
def requires_backend_commands
|
8
|
+
%w[down init output plan providers refresh show up validate]
|
9
|
+
end
|
10
|
+
|
11
|
+
def command_is?(*commands)
|
12
|
+
commands.flatten!
|
13
|
+
commands.map!(&:to_s)
|
14
|
+
commands.include?(ARGV[0]) || # IE: terraspace up
|
15
|
+
ARGV[0] == "all" && commands.include?(ARGV[1]) # IE: terraspace all up
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Terraspace::Compiler
|
2
|
+
module DirsConcern
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
extend Memoist
|
5
|
+
|
6
|
+
def cache_dirs
|
7
|
+
cache_dirs = []
|
8
|
+
with_each_mod("stacks") do |mod|
|
9
|
+
cache_dirs << mod.cache_dir
|
10
|
+
end
|
11
|
+
cache_dirs
|
12
|
+
end
|
13
|
+
|
14
|
+
def with_each_mod(type_dir)
|
15
|
+
mod_names(type_dir).each do |mod_name|
|
16
|
+
consider_stacks = type_dir == "stacks"
|
17
|
+
mod = Terraspace::Mod.new(mod_name, @options.merge(consider_stacks: consider_stacks))
|
18
|
+
yield(mod)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def mod_names(type_dir)
|
23
|
+
names, built = [], []
|
24
|
+
local_paths(type_dir).each do |path|
|
25
|
+
next unless File.directory?(path)
|
26
|
+
mod_name = File.basename(path)
|
27
|
+
next if built.include?(mod_name) # ensures modules in app folder take higher precedence than vendor folder
|
28
|
+
names << mod_name
|
29
|
+
end
|
30
|
+
names
|
31
|
+
end
|
32
|
+
memoize :mod_names
|
33
|
+
|
34
|
+
def local_paths(type_dir)
|
35
|
+
dirs("app/#{type_dir}/*") + dirs("vendor/#{type_dir}/*")
|
36
|
+
end
|
37
|
+
|
38
|
+
def dirs(path)
|
39
|
+
Dir.glob("#{Terraspace.root}/#{path}")
|
40
|
+
end
|
41
|
+
|
42
|
+
def stack_names
|
43
|
+
mod_names("stacks") - Terraspace.config.all.ignore_stacks
|
44
|
+
end
|
45
|
+
memoize :stack_names
|
46
|
+
end
|
47
|
+
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module Terraspace::Compiler::Dsl::Syntax::Helpers
|
2
2
|
module Common
|
3
3
|
extend Memoist
|
4
|
-
|
4
|
+
Fetcher = Terraspace::Terraform::RemoteState::Fetcher
|
5
|
+
Marker = Terraspace::Terraform::RemoteState::Marker
|
5
6
|
Meta = Terraspace::Compiler::Dsl::Meta
|
6
7
|
|
7
8
|
def var
|
@@ -24,5 +25,29 @@ module Terraspace::Compiler::Dsl::Syntax::Helpers
|
|
24
25
|
command = ["terraspace"] + args
|
25
26
|
command.join(separator)
|
26
27
|
end
|
28
|
+
|
29
|
+
def terraform_output(identifier, options={})
|
30
|
+
if @mod.resolved # dependencies have been resolved
|
31
|
+
Fetcher.new(@mod, identifier, options).output
|
32
|
+
else
|
33
|
+
Marker::Output.new(@mod, identifier, options).build
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def depends_on(*child_names, **options)
|
38
|
+
child_names.flatten!
|
39
|
+
child_names.map do |child_name|
|
40
|
+
each_depends_on(child_name, options)
|
41
|
+
end.join("\n")
|
42
|
+
end
|
43
|
+
|
44
|
+
def each_depends_on(child_name, options={})
|
45
|
+
if @mod.resolved # dependencies have been resolved
|
46
|
+
# Note: A generated line is not really needed. Dependencies are stored in memory. Added to assist users with debugging
|
47
|
+
"# #{@mod.name} depends on #{child_name}"
|
48
|
+
else
|
49
|
+
Marker::Output.new(@mod, child_name, options).build
|
50
|
+
end
|
51
|
+
end
|
27
52
|
end
|
28
53
|
end
|