terraspace 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/.cody/aws/bin/build.sh +2 -0
  3. data/.cody/azurerm/bin/build.sh +2 -0
  4. data/.cody/google/bin/build.sh +2 -0
  5. data/CHANGELOG.md +38 -0
  6. data/README.md +2 -2
  7. data/lib/templates/base/project/README.md +1 -1
  8. data/lib/terraspace.rb +2 -0
  9. data/lib/terraspace/all/preview.rb +1 -1
  10. data/lib/terraspace/all/runner.rb +1 -0
  11. data/lib/terraspace/all/summary.rb +29 -2
  12. data/lib/terraspace/app.rb +9 -5
  13. data/lib/terraspace/builder.rb +11 -12
  14. data/lib/terraspace/cli.rb +33 -39
  15. data/lib/terraspace/cli/all.rb +15 -9
  16. data/lib/terraspace/cli/bundle.rb +2 -1
  17. data/lib/terraspace/cli/clean.rb +18 -6
  18. data/lib/terraspace/cli/clean/all.rb +18 -0
  19. data/lib/terraspace/cli/clean/base.rb +15 -0
  20. data/lib/terraspace/cli/clean/cache.rb +25 -0
  21. data/lib/terraspace/cli/{logs/tasks.rb → clean/logs.rb} +16 -5
  22. data/lib/terraspace/cli/cloud.rb +3 -9
  23. data/lib/terraspace/cli/cloud/runs.rb +0 -2
  24. data/lib/terraspace/cli/help/all/down.md +32 -0
  25. data/lib/terraspace/cli/help/all/graph.md +21 -0
  26. data/lib/terraspace/cli/help/all/output.md +22 -0
  27. data/lib/terraspace/cli/help/all/plan.md +25 -0
  28. data/lib/terraspace/cli/help/all/providers.md +21 -0
  29. data/lib/terraspace/cli/help/all/refresh.md +17 -0
  30. data/lib/terraspace/cli/help/all/show.md +21 -0
  31. data/lib/terraspace/cli/help/all/up.md +27 -0
  32. data/lib/terraspace/cli/help/all/validate.md +21 -0
  33. data/lib/terraspace/cli/help/build.md +6 -0
  34. data/lib/terraspace/cli/help/bundle.md +9 -5
  35. data/lib/terraspace/cli/help/check_setup.md +9 -0
  36. data/lib/terraspace/cli/help/clean/all.md +10 -0
  37. data/lib/terraspace/cli/help/clean/cache.md +12 -0
  38. data/lib/terraspace/cli/help/clean/logs.md +17 -0
  39. data/lib/terraspace/cli/help/cloud/destroy.md +16 -0
  40. data/lib/terraspace/cli/help/cloud/list.md +7 -0
  41. data/lib/terraspace/cli/help/cloud/runs/list.md +3 -3
  42. data/lib/terraspace/cli/help/cloud/runs/prune.md +2 -2
  43. data/lib/terraspace/cli/help/cloud/sync.md +26 -2
  44. data/lib/terraspace/cli/help/console.md +8 -0
  45. data/lib/terraspace/cli/help/down.md +26 -0
  46. data/lib/terraspace/cli/help/info.md +43 -0
  47. data/lib/terraspace/cli/help/init.md +37 -0
  48. data/lib/terraspace/cli/help/list.md +20 -0
  49. data/lib/terraspace/cli/help/logs.md +48 -0
  50. data/lib/terraspace/cli/help/logs/remove.md +5 -0
  51. data/lib/terraspace/cli/help/logs/truncate.md +5 -0
  52. data/lib/terraspace/cli/help/new/bootstrap_test.md +8 -0
  53. data/lib/terraspace/cli/help/new/example.md +8 -0
  54. data/lib/terraspace/cli/help/new/git_hook.md +6 -0
  55. data/lib/terraspace/cli/help/new/module.md +9 -0
  56. data/lib/terraspace/cli/help/new/module_test.md +12 -0
  57. data/lib/terraspace/cli/help/new/plugin.md +49 -0
  58. data/lib/terraspace/cli/help/new/project.md +40 -0
  59. data/lib/terraspace/cli/help/new/project_test.md +8 -0
  60. data/lib/terraspace/cli/help/new/shim.md +21 -0
  61. data/lib/terraspace/cli/help/new/stack.md +9 -0
  62. data/lib/terraspace/cli/help/output.md +6 -0
  63. data/lib/terraspace/cli/help/plan.md +29 -0
  64. data/lib/terraspace/cli/help/providers.md +18 -0
  65. data/lib/terraspace/cli/help/refresh.md +11 -0
  66. data/lib/terraspace/cli/help/seed.md +7 -0
  67. data/lib/terraspace/cli/help/show.md +36 -0
  68. data/lib/terraspace/cli/help/summary.md +11 -0
  69. data/lib/terraspace/cli/help/test.md +35 -0
  70. data/lib/terraspace/cli/help/up.md +30 -0
  71. data/lib/terraspace/cli/help/validate.md +9 -0
  72. data/lib/terraspace/cli/info.rb +4 -16
  73. data/lib/terraspace/cli/init.rb +3 -7
  74. data/lib/terraspace/cli/logs.rb +106 -9
  75. data/lib/terraspace/cli/{log → logs}/concern.rb +1 -1
  76. data/lib/terraspace/cli/new.rb +18 -18
  77. data/lib/terraspace/cli/new/git_hook.rb +4 -1
  78. data/lib/terraspace/cli/new/helper.rb +9 -2
  79. data/lib/terraspace/cli/new/project.rb +1 -1
  80. data/lib/terraspace/cli/summary.rb +2 -2
  81. data/lib/terraspace/command.rb +1 -1
  82. data/lib/terraspace/compiler/backend.rb +10 -0
  83. data/lib/terraspace/compiler/builder.rb +2 -1
  84. data/lib/terraspace/compiler/commands_concern.rb +18 -0
  85. data/lib/terraspace/compiler/dependencies/helpers.rb +34 -0
  86. data/lib/terraspace/compiler/dsl/syntax/helpers/common.rb +0 -26
  87. data/lib/terraspace/compiler/dsl/syntax/tfvar.rb +1 -0
  88. data/lib/terraspace/compiler/erb/context.rb +1 -1
  89. data/lib/terraspace/compiler/erb/helpers.rb +6 -0
  90. data/lib/terraspace/dependency/graph.rb +2 -1
  91. data/lib/terraspace/dependency/helper/base.rb +7 -0
  92. data/lib/terraspace/dependency/helper/depends_on.rb +12 -0
  93. data/lib/terraspace/dependency/helper/output.rb +11 -0
  94. data/lib/terraspace/hooks/builder.rb +52 -0
  95. data/lib/terraspace/hooks/concern.rb +9 -0
  96. data/lib/terraspace/{terraform/hooks → hooks}/dsl.rb +3 -2
  97. data/lib/terraspace/hooks/runner.rb +23 -0
  98. data/lib/terraspace/mod.rb +11 -2
  99. data/lib/terraspace/plugin/summary/interface.rb +4 -2
  100. data/lib/terraspace/shell.rb +50 -17
  101. data/lib/terraspace/terraform/args/custom.rb +1 -1
  102. data/lib/terraspace/terraform/cloud/runs/lister.rb +0 -2
  103. data/lib/terraspace/terraform/cloud/syncer.rb +2 -2
  104. data/lib/terraspace/terraform/cloud/workspace.rb +0 -9
  105. data/lib/terraspace/terraform/remote_state/fetcher.rb +37 -7
  106. data/lib/terraspace/terraform/remote_state/marker/output.rb +3 -1
  107. data/lib/terraspace/terraform/remote_state/output_proxy.rb +18 -14
  108. data/lib/terraspace/terraform/remote_state/unresolved.rb +40 -0
  109. data/lib/terraspace/terraform/runner.rb +2 -7
  110. data/lib/terraspace/version.rb +1 -1
  111. data/spec/fixtures/dependencies/app/stacks/a1/tfvars/dev.tfvars +1 -0
  112. data/spec/fixtures/fetcher/c1.json +4 -0
  113. data/spec/terraspace/all/summary_spec.rb +1 -1
  114. data/spec/terraspace/compiler/erb/render_spec.rb +15 -0
  115. data/spec/terraspace/dependency/helper/depends_on_spec.rb +27 -0
  116. data/spec/terraspace/dependency/helper/output_spec.rb +29 -0
  117. data/spec/terraspace/{terraform/hooks → hooks}/builder_spec.rb +4 -5
  118. data/spec/terraspace/terraform/remote_state/fetcher_spec.rb +108 -27
  119. data/spec/terraspace/terraform/remote_state/marker/output_spec.rb +36 -0
  120. data/spec/terraspace/terraform/remote_state/output_proxy_spec.rb +69 -0
  121. data/terraspace.gemspec +1 -1
  122. metadata +78 -13
  123. data/lib/terraspace/cli/help/log.md +0 -42
  124. data/lib/terraspace/cli/help/update.md +0 -5
  125. data/lib/terraspace/cli/log.rb +0 -112
  126. data/lib/terraspace/terraform/hooks/builder.rb +0 -40
@@ -1,4 +1,4 @@
1
- class Terraspace::CLI::Log
1
+ class Terraspace::CLI::Logs
2
2
  module Concern
3
3
  # Filters for lines that belong to the last ran process pid
4
4
  def readlines(path)
@@ -1,40 +1,40 @@
1
1
  class Terraspace::CLI
2
2
  class New < Terraspace::Command
3
- long_desc Help.text(:git_hook)
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(:shim)
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(:module)
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(:stack)
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(:project)
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(:project_test)
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(:module_test)
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(:bootstrap_test)
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(:plugin)
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
- return unless File.exist?(".git")
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
- line = %Q|gem "#{name}"|
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
@@ -54,7 +54,7 @@ class Terraspace::CLI::New
54
54
  end
55
55
 
56
56
  def create_test
57
- return if @options[:test_structure] == false
57
+ return unless @options[:test_structure]
58
58
  Test::Bootstrap.start(["--dir", name])
59
59
  end
60
60
 
@@ -12,7 +12,7 @@ class Terraspace::CLI
12
12
 
13
13
  def run
14
14
  Terraspace.check_project!
15
- build
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 build
25
+ def build_placeholder
26
26
  Build::Placeholder.new(@options).build
27
27
  end
28
28
 
@@ -86,7 +86,7 @@ module Terraspace
86
86
 
87
87
  # meant to be overriden
88
88
  def website
89
- ""
89
+ "https://terraspace.cloud"
90
90
  end
91
91
 
92
92
  # https://github.com/erikhuda/thor/issues/244
@@ -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
@@ -1,5 +1,6 @@
1
1
  module Terraspace::Compiler::Dsl::Syntax
2
2
  module Tfvar
3
3
  include_dir("tfvar")
4
+ include Terraspace::Compiler::Dependencies::Helpers
4
5
  end
5
6
  end
@@ -1,6 +1,6 @@
1
1
  module Terraspace::Compiler::Erb
2
2
  class Context
3
- include Terraspace::Compiler::Dsl::Syntax::Mod
3
+ include Helpers
4
4
 
5
5
  attr_reader :mod, :options
6
6
  def initialize(mod)
@@ -0,0 +1,6 @@
1
+ module Terraspace::Compiler::Erb
2
+ module Helpers
3
+ include Terraspace::Compiler::Dsl::Syntax::Mod
4
+ include Terraspace::Compiler::Dependencies::Helpers
5
+ end
6
+ 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,7 @@
1
+ module Terraspace::Dependency::Helper
2
+ class Base
3
+ def initialize(mod, identifier, options)
4
+ @mod, @identifier, @options = mod, identifier, options
5
+ end
6
+ end
7
+ 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
@@ -0,0 +1,9 @@
1
+ module Terraspace::Hooks
2
+ module Concern
3
+ def run_hooks(dsl_file, name, &block)
4
+ hooks = Builder.new(@mod, "#{Terraspace.root}/config/hooks/#{dsl_file}", name)
5
+ hooks.build # build hooks
6
+ hooks.run_hooks(&block)
7
+ end
8
+ end
9
+ end
@@ -1,4 +1,4 @@
1
- module Terraspace::Terraform::Hooks
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] = props
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