terraspace 0.3.2 → 0.4.0
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 +38 -0
- data/README.md +2 -2
- data/lib/templates/base/project/README.md +1 -1
- data/lib/terraspace.rb +2 -0
- data/lib/terraspace/all/preview.rb +1 -1
- data/lib/terraspace/all/runner.rb +1 -0
- data/lib/terraspace/all/summary.rb +29 -2
- data/lib/terraspace/app.rb +9 -5
- data/lib/terraspace/builder.rb +11 -12
- data/lib/terraspace/cli.rb +33 -39
- data/lib/terraspace/cli/all.rb +15 -9
- data/lib/terraspace/cli/bundle.rb +2 -1
- data/lib/terraspace/cli/clean.rb +18 -6
- data/lib/terraspace/cli/clean/all.rb +18 -0
- data/lib/terraspace/cli/clean/base.rb +15 -0
- data/lib/terraspace/cli/clean/cache.rb +25 -0
- data/lib/terraspace/cli/{logs/tasks.rb → clean/logs.rb} +16 -5
- data/lib/terraspace/cli/cloud.rb +3 -9
- data/lib/terraspace/cli/cloud/runs.rb +0 -2
- 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/all.md +10 -0
- data/lib/terraspace/cli/help/clean/cache.md +12 -0
- data/lib/terraspace/cli/help/clean/logs.md +17 -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 +3 -3
- data/lib/terraspace/cli/help/cloud/runs/prune.md +2 -2
- data/lib/terraspace/cli/help/cloud/sync.md +26 -2
- 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/logs.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 +3 -7
- data/lib/terraspace/cli/logs.rb +106 -9
- data/lib/terraspace/cli/{log → logs}/concern.rb +1 -1
- data/lib/terraspace/cli/new.rb +18 -18
- data/lib/terraspace/cli/new/git_hook.rb +4 -1
- data/lib/terraspace/cli/new/helper.rb +9 -2
- data/lib/terraspace/cli/new/project.rb +1 -1
- data/lib/terraspace/cli/summary.rb +2 -2
- data/lib/terraspace/command.rb +1 -1
- data/lib/terraspace/compiler/backend.rb +10 -0
- data/lib/terraspace/compiler/builder.rb +2 -1
- data/lib/terraspace/compiler/commands_concern.rb +18 -0
- data/lib/terraspace/compiler/dependencies/helpers.rb +34 -0
- data/lib/terraspace/compiler/dsl/syntax/helpers/common.rb +0 -26
- data/lib/terraspace/compiler/dsl/syntax/tfvar.rb +1 -0
- data/lib/terraspace/compiler/erb/context.rb +1 -1
- data/lib/terraspace/compiler/erb/helpers.rb +6 -0
- data/lib/terraspace/dependency/graph.rb +2 -1
- data/lib/terraspace/dependency/helper/base.rb +7 -0
- data/lib/terraspace/dependency/helper/depends_on.rb +12 -0
- data/lib/terraspace/dependency/helper/output.rb +11 -0
- data/lib/terraspace/hooks/builder.rb +52 -0
- data/lib/terraspace/hooks/concern.rb +9 -0
- data/lib/terraspace/{terraform/hooks → hooks}/dsl.rb +3 -2
- data/lib/terraspace/hooks/runner.rb +23 -0
- data/lib/terraspace/mod.rb +11 -2
- data/lib/terraspace/plugin/summary/interface.rb +4 -2
- data/lib/terraspace/shell.rb +50 -17
- data/lib/terraspace/terraform/args/custom.rb +1 -1
- data/lib/terraspace/terraform/cloud/runs/lister.rb +0 -2
- data/lib/terraspace/terraform/cloud/syncer.rb +2 -2
- data/lib/terraspace/terraform/cloud/workspace.rb +0 -9
- data/lib/terraspace/terraform/remote_state/fetcher.rb +37 -7
- data/lib/terraspace/terraform/remote_state/marker/output.rb +3 -1
- data/lib/terraspace/terraform/remote_state/output_proxy.rb +18 -14
- data/lib/terraspace/terraform/remote_state/unresolved.rb +40 -0
- data/lib/terraspace/terraform/runner.rb +2 -7
- data/lib/terraspace/version.rb +1 -1
- data/spec/fixtures/dependencies/app/stacks/a1/tfvars/dev.tfvars +1 -0
- data/spec/fixtures/fetcher/c1.json +4 -0
- data/spec/terraspace/all/summary_spec.rb +1 -1
- data/spec/terraspace/compiler/erb/render_spec.rb +15 -0
- data/spec/terraspace/dependency/helper/depends_on_spec.rb +27 -0
- data/spec/terraspace/dependency/helper/output_spec.rb +29 -0
- data/spec/terraspace/{terraform/hooks → hooks}/builder_spec.rb +4 -5
- data/spec/terraspace/terraform/remote_state/fetcher_spec.rb +108 -27
- data/spec/terraspace/terraform/remote_state/marker/output_spec.rb +36 -0
- data/spec/terraspace/terraform/remote_state/output_proxy_spec.rb +69 -0
- data/terraspace.gemspec +1 -1
- metadata +78 -13
- data/lib/terraspace/cli/help/log.md +0 -42
- data/lib/terraspace/cli/help/update.md +0 -5
- data/lib/terraspace/cli/log.rb +0 -112
- data/lib/terraspace/terraform/hooks/builder.rb +0 -40
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
|
@@ -6,10 +6,17 @@ class Terraspace::CLI::New
|
|
6
6
|
def build_gemfile(*list)
|
7
7
|
lines = []
|
8
8
|
list.each do |name|
|
9
|
-
|
10
|
-
lines << line
|
9
|
+
lines << gem_line(name)
|
11
10
|
end
|
12
11
|
lines.join("\n")
|
13
12
|
end
|
13
|
+
|
14
|
+
def gem_line(name)
|
15
|
+
if name == "terraspace"
|
16
|
+
%Q|gem "#{name}", '~> #{Terraspace::VERSION}'|
|
17
|
+
else
|
18
|
+
%Q|gem "#{name}"|
|
19
|
+
end
|
20
|
+
end
|
14
21
|
end
|
15
22
|
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
|
|
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)
|
@@ -9,7 +10,7 @@ module Terraspace::Compiler
|
|
9
10
|
def build
|
10
11
|
build_config
|
11
12
|
build_module if @mod.resolved
|
12
|
-
build_tfvars
|
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
|
@@ -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,34 @@
|
|
1
|
+
module Terraspace::Compiler::Dependencies
|
2
|
+
# This is a separate module specifically because the DSL also has an output method.
|
3
|
+
# The module allows us to include dependency related methods only within tfvars context for the DSL.
|
4
|
+
#
|
5
|
+
# 1. Only include this module to DSL tfvars context.
|
6
|
+
# So the output method works in tfvars .rb files works.
|
7
|
+
# At the same time, the DSL usage of output also works for normal main.tf files.
|
8
|
+
# Passing specs prove this.
|
9
|
+
# 2. For ERB, there's currently only one ERB context. So this module is included in all contexts.
|
10
|
+
# The builder only processes dependencies from tfvars, so these helpers are only respected there.
|
11
|
+
#
|
12
|
+
# Where the module is included in the code:
|
13
|
+
#
|
14
|
+
# 1. lib/terraspace/compiler/dsl/syntax/tfvar.rb
|
15
|
+
# 2. lib/terraspace/compiler/erb/helpers.rb
|
16
|
+
#
|
17
|
+
module Helpers
|
18
|
+
def output(identifier, options={})
|
19
|
+
Terraspace::Dependency::Helper::Output.new(@mod, identifier, options).result
|
20
|
+
end
|
21
|
+
alias_method :terraform_output, :output # backwards compatibility
|
22
|
+
|
23
|
+
def depends_on(*child_names, **options)
|
24
|
+
child_names.flatten!
|
25
|
+
child_names.map do |child_name|
|
26
|
+
each_depends_on(child_name, options)
|
27
|
+
end.join("\n")
|
28
|
+
end
|
29
|
+
|
30
|
+
def each_depends_on(child_name, options={})
|
31
|
+
Terraspace::Dependency::Helper::DependsOn.new(@mod, child_name, options).result
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
module Terraspace::Compiler::Dsl::Syntax::Helpers
|
2
2
|
module Common
|
3
3
|
extend Memoist
|
4
|
-
Fetcher = Terraspace::Terraform::RemoteState::Fetcher
|
5
|
-
Marker = Terraspace::Terraform::RemoteState::Marker
|
6
4
|
Meta = Terraspace::Compiler::Dsl::Meta
|
7
5
|
|
8
6
|
def var
|
@@ -25,29 +23,5 @@ module Terraspace::Compiler::Dsl::Syntax::Helpers
|
|
25
23
|
command = ["terraspace"] + args
|
26
24
|
command.join(separator)
|
27
25
|
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
|
52
26
|
end
|
53
27
|
end
|
@@ -20,8 +20,9 @@ module Terraspace::Dependency
|
|
20
20
|
@batches
|
21
21
|
end
|
22
22
|
|
23
|
+
# Only check when stacks option is pass. Edge case: There can be app/modules but no app/stacks yet
|
23
24
|
def check_empty_nodes!
|
24
|
-
return unless @nodes.empty?
|
25
|
+
return unless @nodes.empty? && @options[:stacks]
|
25
26
|
logger.error "ERROR: No stacks were found that match: #{@options[:stacks].join(' ')}".color(:red)
|
26
27
|
exit 1
|
27
28
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Terraspace::Dependency::Helper
|
2
|
+
class DependsOn < Base
|
3
|
+
def result
|
4
|
+
if @mod.resolved # dependencies have been resolved
|
5
|
+
# Note: A generated line is not really needed. Dependencies are stored in memory. Added to assist users with debugging
|
6
|
+
"# #{@mod.name} depends on #{@identifier}" # raw String value
|
7
|
+
else
|
8
|
+
Terraspace::Terraform::RemoteState::Marker::Output.new(@mod, @identifier, @options).build # Returns OutputProxy which defaults to json
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Terraspace::Dependency::Helper
|
2
|
+
class Output < Base
|
3
|
+
def result
|
4
|
+
if @mod.resolved # dependencies have been resolved
|
5
|
+
Terraspace::Terraform::RemoteState::Fetcher.new(@mod, @identifier, @options).output # Returns OutputProxy which defaults to json
|
6
|
+
else
|
7
|
+
Terraspace::Terraform::RemoteState::Marker::Output.new(@mod, @identifier, @options).build # Returns OutputProxy => Unresolved
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Terraspace::Hooks
|
2
|
+
class Builder
|
3
|
+
extend Memoist
|
4
|
+
include Dsl
|
5
|
+
include DslEvaluator
|
6
|
+
include Terraspace::Util
|
7
|
+
|
8
|
+
# IE: dsl_file: config/hooks/terraform.rb
|
9
|
+
attr_accessor :name
|
10
|
+
def initialize(mod, dsl_file, name)
|
11
|
+
@mod, @dsl_file, @name = mod, dsl_file, name
|
12
|
+
@hooks = {before: {}, after: {}}
|
13
|
+
end
|
14
|
+
|
15
|
+
def build
|
16
|
+
return @hooks unless File.exist?(@dsl_file)
|
17
|
+
evaluate_file(@dsl_file)
|
18
|
+
@hooks.deep_stringify_keys!
|
19
|
+
end
|
20
|
+
memoize :build
|
21
|
+
|
22
|
+
def run_hooks
|
23
|
+
build
|
24
|
+
run_each_hook("before")
|
25
|
+
out = yield if block_given?
|
26
|
+
run_each_hook("after")
|
27
|
+
out
|
28
|
+
end
|
29
|
+
|
30
|
+
def run_each_hook(type)
|
31
|
+
hooks = @hooks.dig(type, @name) || []
|
32
|
+
hooks.each do |hook|
|
33
|
+
run_hook(type, hook)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def run_hook(type, hook)
|
38
|
+
return unless run?(hook)
|
39
|
+
|
40
|
+
command = File.basename(@dsl_file).sub('.rb','') # IE: kubes, kubectl, docker
|
41
|
+
id = "#{command} #{type} #{@name}"
|
42
|
+
label = " label: #{hook["label"]}" if hook["label"]
|
43
|
+
logger.info "Running #{id} hook.#{label}"
|
44
|
+
logger.debug "Hook options: #{hook}"
|
45
|
+
Runner.new(@mod, hook).run
|
46
|
+
end
|
47
|
+
|
48
|
+
def run?(hook)
|
49
|
+
!!hook["execute"]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module Terraspace::
|
1
|
+
module Terraspace::Hooks
|
2
2
|
module Dsl
|
3
3
|
def before(*commands, **props)
|
4
4
|
commands.each do |name|
|
@@ -13,7 +13,8 @@ module Terraspace::Terraform::Hooks
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def each_hook(type, name, props={})
|
16
|
-
@hooks[type][name]
|
16
|
+
@hooks[type][name] ||= []
|
17
|
+
@hooks[type][name] << props
|
17
18
|
end
|
18
19
|
end
|
19
20
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Terraspace::Hooks
|
2
|
+
class Runner
|
3
|
+
include Terraspace::Util
|
4
|
+
|
5
|
+
def initialize(mod, hook)
|
6
|
+
@mod, @hook = mod, hook
|
7
|
+
@execute = @hook["execute"]
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
case @execute
|
12
|
+
when String
|
13
|
+
Terraspace::Shell.new(@mod, @execute, exit_on_fail: @hook["exit_on_fail"]).run
|
14
|
+
when -> (e) { e.respond_to?(:public_instance_methods) && e.public_instance_methods.include?(:call) }
|
15
|
+
@execute.new.call
|
16
|
+
when -> (e) { e.respond_to?(:call) }
|
17
|
+
@execute.call
|
18
|
+
else
|
19
|
+
logger.warn "WARN: execute option not set for hook: #{@hook.inspect}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|