terraspace 0.2.4 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) 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 +39 -1
  6. data/README.md +14 -1
  7. data/lib/templates/base/git_hook/hook.sh +1 -1
  8. data/lib/templates/base/project/.gitignore +1 -0
  9. data/lib/templates/base/project/README.md +17 -0
  10. data/lib/terraspace.rb +6 -0
  11. data/lib/terraspace/all/base.rb +8 -0
  12. data/lib/terraspace/all/grapher.rb +129 -0
  13. data/lib/terraspace/all/preview.rb +43 -0
  14. data/lib/terraspace/all/runner.rb +169 -0
  15. data/lib/terraspace/all/summary.rb +119 -0
  16. data/lib/terraspace/app.rb +31 -9
  17. data/lib/terraspace/booter.rb +9 -0
  18. data/lib/terraspace/builder.rb +59 -22
  19. data/lib/terraspace/cli.rb +60 -33
  20. data/lib/terraspace/cli/all.rb +63 -0
  21. data/lib/terraspace/cli/build/placeholder.rb +2 -5
  22. data/lib/terraspace/cli/bundle.rb +1 -1
  23. data/lib/terraspace/cli/check_setup.rb +5 -0
  24. data/lib/terraspace/cli/cloud.rb +16 -6
  25. data/lib/terraspace/cli/cloud/runs.rb +22 -0
  26. data/lib/terraspace/cli/commander.rb +1 -8
  27. data/lib/terraspace/cli/down.rb +20 -0
  28. data/lib/terraspace/cli/help/all/down.md +32 -0
  29. data/lib/terraspace/cli/help/all/graph.md +21 -0
  30. data/lib/terraspace/cli/help/all/output.md +22 -0
  31. data/lib/terraspace/cli/help/all/plan.md +25 -0
  32. data/lib/terraspace/cli/help/all/providers.md +21 -0
  33. data/lib/terraspace/cli/help/all/refresh.md +17 -0
  34. data/lib/terraspace/cli/help/all/show.md +21 -0
  35. data/lib/terraspace/cli/help/all/up.md +27 -0
  36. data/lib/terraspace/cli/help/all/validate.md +21 -0
  37. data/lib/terraspace/cli/help/build.md +6 -0
  38. data/lib/terraspace/cli/help/bundle.md +9 -5
  39. data/lib/terraspace/cli/help/check_setup.md +9 -0
  40. data/lib/terraspace/cli/help/clean.md +5 -0
  41. data/lib/terraspace/cli/help/cloud/destroy.md +16 -0
  42. data/lib/terraspace/cli/help/cloud/list.md +7 -0
  43. data/lib/terraspace/cli/help/cloud/runs/list.md +36 -0
  44. data/lib/terraspace/cli/help/cloud/runs/prune.md +25 -0
  45. data/lib/terraspace/cli/help/cloud/sync.md +43 -0
  46. data/lib/terraspace/cli/help/console.md +8 -0
  47. data/lib/terraspace/cli/help/down.md +26 -0
  48. data/lib/terraspace/cli/help/info.md +43 -0
  49. data/lib/terraspace/cli/help/init.md +37 -0
  50. data/lib/terraspace/cli/help/list.md +20 -0
  51. data/lib/terraspace/cli/help/log.md +48 -0
  52. data/lib/terraspace/cli/help/logs/remove.md +5 -0
  53. data/lib/terraspace/cli/help/logs/truncate.md +5 -0
  54. data/lib/terraspace/cli/help/new/bootstrap_test.md +8 -0
  55. data/lib/terraspace/cli/help/new/example.md +8 -0
  56. data/lib/terraspace/cli/help/new/git_hook.md +6 -0
  57. data/lib/terraspace/cli/help/new/module.md +9 -0
  58. data/lib/terraspace/cli/help/new/module_test.md +12 -0
  59. data/lib/terraspace/cli/help/new/plugin.md +49 -0
  60. data/lib/terraspace/cli/help/new/project.md +40 -0
  61. data/lib/terraspace/cli/help/new/project_test.md +8 -0
  62. data/lib/terraspace/cli/help/new/shim.md +21 -0
  63. data/lib/terraspace/cli/help/new/stack.md +9 -0
  64. data/lib/terraspace/cli/help/output.md +6 -0
  65. data/lib/terraspace/cli/help/plan.md +29 -0
  66. data/lib/terraspace/cli/help/providers.md +18 -0
  67. data/lib/terraspace/cli/help/refresh.md +11 -0
  68. data/lib/terraspace/cli/help/seed.md +7 -0
  69. data/lib/terraspace/cli/help/show.md +36 -0
  70. data/lib/terraspace/cli/help/summary.md +11 -0
  71. data/lib/terraspace/cli/help/test.md +35 -0
  72. data/lib/terraspace/cli/help/up.md +30 -0
  73. data/lib/terraspace/cli/help/validate.md +9 -0
  74. data/lib/terraspace/cli/info.rb +4 -16
  75. data/lib/terraspace/cli/init.rb +35 -7
  76. data/lib/terraspace/cli/list.rb +14 -1
  77. data/lib/terraspace/cli/log.rb +112 -0
  78. data/lib/terraspace/cli/log/concern.rb +24 -0
  79. data/lib/terraspace/cli/logs.rb +15 -0
  80. data/lib/terraspace/cli/logs/tasks.rb +32 -0
  81. data/lib/terraspace/cli/new.rb +18 -18
  82. data/lib/terraspace/cli/new/git_hook.rb +5 -2
  83. data/lib/terraspace/cli/new/project.rb +1 -1
  84. data/lib/terraspace/cli/summary.rb +2 -2
  85. data/lib/terraspace/cli/tfc_concern.rb +14 -0
  86. data/lib/terraspace/cli/up.rb +32 -0
  87. data/lib/terraspace/command.rb +1 -1
  88. data/lib/terraspace/compiler/backend.rb +10 -0
  89. data/lib/terraspace/compiler/builder.rb +5 -4
  90. data/lib/terraspace/compiler/cleaner.rb +1 -1
  91. data/lib/terraspace/compiler/cleaner/backend_change.rb +21 -7
  92. data/lib/terraspace/compiler/commands_concern.rb +18 -0
  93. data/lib/terraspace/compiler/dirs_concern.rb +47 -0
  94. data/lib/terraspace/compiler/dsl/syntax/helpers/common.rb +26 -1
  95. data/lib/terraspace/core.rb +11 -2
  96. data/lib/terraspace/dependency/graph.rb +140 -0
  97. data/lib/terraspace/dependency/node.rb +38 -0
  98. data/lib/terraspace/dependency/registry.rb +11 -0
  99. data/lib/terraspace/logger.rb +6 -18
  100. data/lib/terraspace/logger/formatter.rb +13 -0
  101. data/lib/terraspace/mod.rb +7 -1
  102. data/lib/terraspace/plugin/summary/interface.rb +1 -1
  103. data/lib/terraspace/seeder/where.rb +6 -2
  104. data/lib/terraspace/shell.rb +107 -0
  105. data/lib/terraspace/terraform/api.rb +7 -45
  106. data/lib/terraspace/terraform/api/base.rb +7 -0
  107. data/lib/terraspace/terraform/api/client.rb +23 -3
  108. data/lib/terraspace/terraform/api/http.rb +14 -34
  109. data/lib/terraspace/terraform/api/http/concern.rb +10 -0
  110. data/lib/terraspace/terraform/api/runs.rb +28 -0
  111. data/lib/terraspace/terraform/api/token.rb +65 -0
  112. data/lib/terraspace/terraform/api/var.rb +20 -6
  113. data/lib/terraspace/terraform/api/vars.rb +2 -1
  114. data/lib/terraspace/terraform/api/workspace.rb +98 -0
  115. data/lib/terraspace/terraform/args/default.rb +48 -21
  116. data/lib/terraspace/terraform/cloud/runs.rb +13 -0
  117. data/lib/terraspace/terraform/cloud/runs/base.rb +33 -0
  118. data/lib/terraspace/terraform/cloud/runs/item_presenter.rb +37 -0
  119. data/lib/terraspace/terraform/cloud/runs/lister.rb +20 -0
  120. data/lib/terraspace/terraform/cloud/runs/pruner.rb +109 -0
  121. data/lib/terraspace/terraform/cloud/sync.rb +41 -0
  122. data/lib/terraspace/terraform/cloud/syncer.rb +52 -0
  123. data/lib/terraspace/terraform/cloud/workspace.rb +10 -30
  124. data/lib/terraspace/terraform/hooks/builder.rb +1 -1
  125. data/lib/terraspace/terraform/remote_state/fetcher.rb +143 -0
  126. data/lib/terraspace/terraform/remote_state/marker/output.rb +39 -0
  127. data/lib/terraspace/terraform/remote_state/marker/pretty_tracer.rb +37 -0
  128. data/lib/terraspace/terraform/remote_state/output_proxy.rb +29 -0
  129. data/lib/terraspace/terraform/runner.rb +24 -14
  130. data/lib/terraspace/util.rb +1 -5
  131. data/lib/terraspace/util/pretty.rb +18 -0
  132. data/lib/terraspace/version.rb +1 -1
  133. data/spec/fixtures/fetcher/c1.json +37 -0
  134. data/spec/fixtures/parser/cache_dirs/all/01-test.auto.tfvars +5 -0
  135. data/spec/fixtures/parser/cache_dirs/depends_on/01-test.auto.tfvars +2 -0
  136. data/spec/fixtures/parser/cache_dirs/output/01-test.auto.tfvars +2 -0
  137. data/spec/fixtures/summary/down.log +12 -0
  138. data/spec/fixtures/summary/output.log +5 -0
  139. data/spec/fixtures/summary/plan/error.log +20 -0
  140. data/spec/fixtures/summary/plan/success.log +17 -0
  141. data/spec/fixtures/summary/show.log +22 -0
  142. data/spec/fixtures/summary/up/error.log +13 -0
  143. data/spec/fixtures/summary/up/success.log +63 -0
  144. data/spec/fixtures/summary/validate/error.log +13 -0
  145. data/spec/fixtures/summary/validate/success.log +5 -0
  146. data/spec/terraspace/all/grapher_spec.rb +38 -0
  147. data/spec/terraspace/all/runner_spec.rb +48 -0
  148. data/spec/terraspace/all/summary_spec.rb +93 -0
  149. data/spec/terraspace/dependency/graph_spec.rb +162 -0
  150. data/spec/terraspace/seeder_spec.rb +0 -1
  151. data/spec/terraspace/terraform/remote_state/fetcher_spec.rb +52 -0
  152. data/terraspace.gemspec +5 -1
  153. metadata +179 -6
  154. data/lib/terraspace/cli/help/update.md +0 -5
  155. data/lib/terraspace/terraform/cloud.rb +0 -25
  156. data/lib/terraspace/util/sh.rb +0 -19
@@ -0,0 +1,119 @@
1
+ module Terraspace::All
2
+ class Summary
3
+ include Terraspace::CLI::Log::Concern
4
+ include Terraspace::Util::Logging
5
+
6
+ def initialize(data={})
7
+ @data = data
8
+ @command = data[:command]
9
+ @log_path = data[:log_path]
10
+ @terraspace_command = data[:terraspace_command]
11
+ end
12
+
13
+ @@header_shown = false
14
+ def run
15
+ @lines = readlines(@log_path)
16
+ if respond_to?(@command.to_sym)
17
+ send(@command)
18
+ else
19
+ default
20
+ end
21
+ summarize
22
+ end
23
+
24
+ # Examples of "complete" line:
25
+ # [2020-09-06T21:58:25 #11313 terraspace up b1]: Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
26
+ # [2020-09-07T08:28:15 #26093 terraspace down a1]: Destroy complete! Resources: 2 destroyed.
27
+ #
28
+ # handles: up and down
29
+ def default
30
+ @lines.select! do |line|
31
+ line.include?("complete! Resources:") || # success: handles both apply and destroy output
32
+ line.include?("Changes to Outputs") ||
33
+ line.include?("No changes") ||
34
+ line.include?("Error: ") # error
35
+ end
36
+ end
37
+
38
+ # Example 1:
39
+ # [2020-09-07T14:45:14 #23340 terraspace plan b1]: No changes. Infrastructure is up-to-date.
40
+ # Example 2:
41
+ # [2020-09-07T14:46:58 #31974 terraspace plan b1]: Changes to Outputs:
42
+ # [2020-09-07T14:46:58 #31974 terraspace plan b1]: ~ length = 1 -> 2
43
+ def plan
44
+ @lines.select! do |line|
45
+ line.include?("No changes. Infrastructure") ||
46
+ line.include?("Changes to Outputs") ||
47
+ line.include?("Plan:") ||
48
+ line.include?("Changes to ") ||
49
+ line.include?("Error: ") # error
50
+ end
51
+ end
52
+
53
+ def output
54
+ if @lines.grep(/No outputs found/).empty?
55
+ @lines.select! do |line|
56
+ line.include?(" = ") # looks like output
57
+ end
58
+ else
59
+ @lines.select! do |line|
60
+ line.include?("No outputs found")
61
+ end
62
+ end
63
+ end
64
+
65
+ def show
66
+ resources = @lines.grep(/: resource "/).count
67
+ outputs = count_outputs(@lines)
68
+ summary = "Resources: #{resources} Outputs: #{outputs}"
69
+ # get summary line before running select! which will remove lines
70
+ @lines.select! do |line|
71
+ line.include?("Error: ") # error
72
+ end
73
+ @lines.unshift(summary) # add to top
74
+ end
75
+
76
+ # [2020-09-19T19:36:33 #14387 terraspace providers c1]: => terraform providers
77
+ # [2020-09-19T19:36:33 #14387 terraspace providers c1]:
78
+ # [2020-09-19T19:36:33 #14387 terraspace providers c1]: Providers required by configuration:
79
+ # [2020-09-19T19:36:33 #14387 terraspace providers c1]: .
80
+ # [2020-09-19T19:36:33 #14387 terraspace providers c1]: └── provider[registry.terraform.io/hashicorp/random]
81
+ # [2020-09-19T19:36:33 #14387 terraspace providers c1]:
82
+ def providers
83
+ @lines.select! do |line|
84
+ line.include?("provider[")
85
+ end
86
+ end
87
+
88
+ # [2020-09-07T14:53:36 #31106 terraspace show b1]: Outputs:
89
+ # [2020-09-07T14:53:36 #31106 terraspace show b1]:
90
+ # [2020-09-07T14:53:36 #31106 terraspace show b1]: length = 1
91
+ # [2020-09-07T14:53:36 #31106 terraspace show b1]: length2 = 2
92
+ # [2020-09-07T14:53:36 #31106 terraspace show b1]: random_pet_id = "corgi"
93
+ def count_outputs(lines)
94
+ count = 0
95
+ counting = false
96
+ lines.each do |line|
97
+ counting ||= line.include?(": Outputs:")
98
+ count += 1 if counting && line.include?(' = ')
99
+ end
100
+ count
101
+ end
102
+
103
+ # [2020-09-07T13:51:45 #21323 terraspace validate a1]: Success! The configuration is valid.
104
+ def validate
105
+ @lines.select! do |line|
106
+ line.include?("The configuration is") || # success
107
+ line.include?("Error: ") # error
108
+ end
109
+ end
110
+
111
+ private
112
+ def summarize
113
+ @lines.each do |line|
114
+ line.sub!(/.*\]:\s+/, ' ') # remove log info from line
115
+ logger.info("#{@terraspace_command}: #{line}")
116
+ end
117
+ end
118
+ end
119
+ end
@@ -10,18 +10,40 @@ module Terraspace
10
10
 
11
11
  def defaults
12
12
  config = ActiveSupport::OrderedOptions.new
13
- config.test_framework = "rspec"
14
- config.logger = Logger.new($stdout)
15
- config.logger.level = :info
16
- config.hooks = Hooks.new
17
- config.cloud = ActiveSupport::OrderedOptions.new
18
- config.cloud.overwrite = true
19
- config.cloud.overwrite_sensitive = true
20
- config.cloud.relative_root = nil
13
+ config.all = ActiveSupport::OrderedOptions.new
14
+ config.all.concurrency = 5
15
+ config.all.exit_on_fail = ActiveSupport::OrderedOptions.new
16
+ config.all.exit_on_fail.down = true
17
+ config.all.exit_on_fail.up = true
18
+ config.all.ignore_stacks = []
19
+ config.auto_create_backend = true
21
20
  config.build = ActiveSupport::OrderedOptions.new
22
- config.build.cache_root = nil # defaults to /full/path/to/.terraspace-cache
23
21
  config.build.cache_dir = ":CACHE_ROOT/:REGION/:ENV/:BUILD_DIR"
22
+ config.build.cache_root = nil # defaults to /full/path/to/.terraspace-cache
24
23
  config.build.clean_cache = nil # defaults to /full/path/to/.terraspace-cache
24
+ config.cloud = ActiveSupport::OrderedOptions.new
25
+ config.cloud.auto_sync = true
26
+ config.cloud.working_dir_prefix = nil
27
+ config.cloud.hostname = nil
28
+ config.cloud.vars = ActiveSupport::OrderedOptions.new
29
+ config.cloud.vars.overwrite = true
30
+ config.cloud.vars.overwrite_sensitive = true
31
+ config.cloud.vars.show_message = "create"
32
+ config.cloud.workspace = ActiveSupport::OrderedOptions.new
33
+ config.cloud.workspace.attrs = ActiveSupport::OrderedOptions.new
34
+ config.hooks = Hooks.new
35
+ config.init = ActiveSupport::OrderedOptions.new
36
+ config.init.mode = "auto" # auto, never, always
37
+ config.log = ActiveSupport::OrderedOptions.new
38
+ config.log.root = Terraspace.log_root
39
+ config.logger = Logger.new(ENV['TS_LOG_PATH'] || $stderr)
40
+ config.logger.level = ENV['TS_LOG_LEVEL'] || :info
41
+ config.logger.formatter = Logger::Formatter.new
42
+ config.test_framework = "rspec"
43
+ config.terraform = ActiveSupport::OrderedOptions.new
44
+ config.terraform.plugin_cache = ActiveSupport::OrderedOptions.new
45
+ config.terraform.plugin_cache.enabled = true
46
+ config.terraform.plugin_cache.dir = ENV['TF_PLUGIN_CACHE_DIR'] || "#{Terraspace.tmp_root}/plugin_cache"
25
47
  config
26
48
  end
27
49
 
@@ -5,6 +5,7 @@ module Terraspace
5
5
  load_plugin_default_configs
6
6
  Terraspace.config # load project config
7
7
  Terraspace::App::Hooks.run_hook(:on_boot)
8
+ set_plugin_cache!
8
9
  end
9
10
 
10
11
  def load_plugin_default_configs
@@ -14,6 +15,14 @@ module Terraspace
14
15
  end
15
16
  end
16
17
 
18
+ def set_plugin_cache!
19
+ plugin_cache = Terraspace.config.terraform.plugin_cache
20
+ return unless plugin_cache.enabled
21
+ dir = ENV['TF_PLUGIN_CACHE_DIR'] ||= plugin_cache.dir
22
+ FileUtils.mkdir_p(dir)
23
+ dir
24
+ end
25
+
17
26
  extend self
18
27
  end
19
28
  end
@@ -1,48 +1,85 @@
1
1
  module Terraspace
2
2
  class Builder < Terraspace::CLI::Base
3
+ include Compiler::DirsConcern
4
+ include Compiler::CommandsConcern
5
+
6
+ attr_reader :graph
7
+
3
8
  def run
9
+ return if @options[:build] == false
4
10
  Terraspace::CLI::CheckSetup.check!
5
11
  @mod.root_module = true
6
- Compiler::Cleaner.new(@mod, @options).clean if clean?
12
+ clean
7
13
  build_dir = Util.pretty_path(@mod.cache_dir)
8
- logger.info "Building #{build_dir}"
14
+ placeholder_stack_message
15
+ logger.info "Building #{build_dir}" unless @options[:quiet] # from terraspace all
16
+
17
+ build_unresolved
18
+ auto_create_backend
19
+ batches = build_batches
20
+ build_all
21
+ logger.info "Built in #{build_dir}" unless @options[:quiet] # from terraspace all
22
+ batches
23
+ end
24
+
25
+ # Builds dependency graph and returns the batches to run
26
+ def build_batches
27
+ dependencies = Terraspace::Dependency::Registry.data # populated after build_unresolved
28
+ @graph = Terraspace::Dependency::Graph.new(stack_names, dependencies, @options)
29
+ @graph.build
30
+ end
9
31
 
10
- build_all("modules") # build all modules and stacks as dependencies
11
- build_all("stacks")
32
+ def build_all
33
+ # At this point dependencies have been resolved.
34
+ Terraspace::Terraform::RemoteState::Fetcher.flush!
35
+ @resolved = true
36
+ build_unresolved
37
+ end
38
+
39
+ def build_unresolved
40
+ build_dir("modules")
41
+ build_dir("stacks")
12
42
  build_root_module
13
- logger.info "Built in #{build_dir}"
14
43
  end
15
44
 
16
45
  def build_root_module
46
+ @mod.resolved = @resolved
17
47
  Compiler::Builder.new(@mod).build
18
48
  end
19
49
 
20
- def build_all(type_dir)
21
- built = []
22
- local_paths(type_dir).each do |path|
23
- next unless File.directory?(path)
24
- mod_name = File.basename(path)
25
- next if built.include?(mod_name) # ensures modules in app folder take higher precedence than vendor folder
26
-
27
- consider_stacks = type_dir == "stacks"
28
- mod = Mod.new(mod_name, consider_stacks: consider_stacks)
29
-
50
+ def build_dir(type_dir)
51
+ with_each_mod(type_dir) do |mod|
52
+ mod.resolved = @resolved
53
+ is_root_module = mod.cache_dir == @mod.cache_dir
54
+ next if is_root_module # handled by build_root_module
30
55
  Compiler::Builder.new(mod).build
31
- built << mod_name
32
56
  end
33
57
  end
34
58
 
35
- def local_paths(type_dir)
36
- dirs("app/#{type_dir}/*") + dirs("vendor/#{type_dir}/*")
59
+ # Auto create after build_unresolved since will need to run state pull for dependencies
60
+ def auto_create_backend
61
+ return if Terraspace.config.auto_create_backend == false
62
+ return unless requires_backend?
63
+ Terraspace::Compiler::Backend.new(@mod).create
37
64
  end
38
65
 
39
- def dirs(path)
40
- Dir.glob("#{Terraspace.root}/#{path}")
66
+ def clean
67
+ Compiler::Cleaner.new(@mod, @options).clean if clean?
41
68
  end
42
69
 
43
70
  def clean?
44
- clean_cache = Terraspace.config.build.clean_cache
45
- clean_cache.nil? ? true : clean_cache
71
+ if @options[:clean].nil?
72
+ clean_cache = Terraspace.config.build.clean_cache
73
+ clean_cache.nil? ? true : clean_cache
74
+ else
75
+ @options[:clean]
76
+ end
77
+ end
78
+
79
+ def placeholder_stack_message
80
+ return if @options[:quiet]
81
+ return unless @options[:mod] == "placeholder"
82
+ logger.info "Building one stack to build all stacks"
46
83
  end
47
84
  end
48
85
  end
@@ -28,74 +28,99 @@ module Terraspace
28
28
  option :reconfigure, type: :boolean, desc: "Add terraform -reconfigure option"
29
29
  }
30
30
 
31
- desc "new SUBCOMMAND", "new subcommands"
32
- long_desc Help.text(:new)
33
- subcommand "new", New
31
+ desc "all SUBCOMMAND", "all subcommands"
32
+ long_desc Help.text(:all)
33
+ subcommand "all", All
34
34
 
35
35
  desc "cloud SUBCOMMAND", "cloud subcommands"
36
36
  long_desc Help.text(:cloud)
37
37
  subcommand "cloud", Cloud
38
38
 
39
- desc "build STACK", "build"
39
+ desc "logs SUBCOMMAND", "logs management subcommands"
40
+ long_desc Help.text(:logs)
41
+ subcommand "logs", Logs
42
+
43
+ desc "new SUBCOMMAND", "new subcommands"
44
+ long_desc Help.text(:new)
45
+ subcommand "new", New
46
+
47
+ desc "build [STACK]", "Build project."
40
48
  long_desc Help.text(:build)
41
- option :quiet, type: :boolean, default: true, desc: "quiet output"
49
+ option :quiet, type: :boolean, desc: "quiet output"
42
50
  instance_option.call
43
51
  yes_option.call
44
- def build(mod)
45
- Terraspace::Builder.new(@options.merge(mod: mod)).run
52
+ def build(mod="placeholder")
53
+ Terraspace::Builder.new(options.merge(mod: mod)).run # building any stack builds them all
46
54
  end
47
55
 
48
- desc "bundle", "bundle"
56
+ desc "bundle", "Bundle with Terrafile."
49
57
  long_desc Help.text(:bundle)
50
58
  def bundle(*args)
51
59
  Bundle.new(options.merge(args: args)).run
52
60
  end
53
61
 
54
- desc "check_setup", "check_setup"
62
+ desc "check_setup", "Check setup."
55
63
  long_desc Help.text(:check_setup)
56
64
  def check_setup
57
65
  CheckSetup.new(options).run
58
66
  end
59
67
 
60
- desc "clean", "clean .terraspace-cache dir"
68
+ desc "clean", "Removes .terraspace-cache dir."
61
69
  long_desc Help.text(:clean)
62
70
  def clean
63
71
  Clean.new(options).run
64
72
  end
65
73
 
66
- desc "console STACK", "console .terraspace-cache dir"
74
+ desc "console STACK", "Run console in built terraform project."
67
75
  long_desc Help.text(:console)
68
76
  instance_option.call
69
77
  def console(mod)
70
- Commander.new("console", options.merge(mod: mod)).run
78
+ Commander.new("console", options.merge(mod: mod, shell: "system")).run
71
79
  end
72
80
 
73
- desc "down STACK", "down"
81
+ desc "down STACK", "Destroy infrastructure stack."
74
82
  long_desc Help.text(:down)
75
83
  instance_option.call
76
84
  yes_option.call
77
85
  reconfigure_option.call
78
86
  option :destroy_workspace, type: :boolean, desc: "Also destroy the Cloud workspace. Only applies when using Terraform Cloud remote backend."
79
87
  def down(mod)
80
- Commander.new("destroy", options.merge(mod: mod, command: "down")).run
81
- Terraspace::Terraform::Cloud::Workspace.new(options.merge(mod: mod)).destroy if @options[:destroy_workspace]
88
+ Down.new(options.merge(mod: mod)).run
82
89
  end
83
90
 
84
- desc "info STACK", "info"
91
+ desc "info STACK", "Get info about stack."
85
92
  long_desc Help.text(:info)
86
- format_option.call
87
93
  instance_option.call
94
+ option :format, desc: "Output formats: #{CliFormat.formats.join(', ')}"
88
95
  def info(mod)
89
96
  Info.new(options.merge(mod: mod)).run
90
97
  end
91
98
 
92
- desc "list", "list stacks and modules"
99
+ desc "init STACK", "Run init in built terraform project."
100
+ long_desc Help.text(:init)
101
+ instance_option.call
102
+ def init(mod)
103
+ Commander.new("init", options.merge(mod: mod, quiet: false)).run
104
+ end
105
+
106
+ desc "list", "List stacks and modules."
93
107
  long_desc Help.text(:list)
108
+ option :type, aliases: %w[t], desc: "Type: stack or module. Default all"
94
109
  def list
95
110
  List.new(options).run
96
111
  end
97
112
 
98
- desc "plan STACK", "plan stack"
113
+ desc "log [ACTION] [STACK]", "View and tail logs."
114
+ long_desc Help.text("log")
115
+ option :timestamps, aliases: %w[t], type: :boolean, desc: "Whether or not to show the leading timestamp. Defaults to timestamps for multiple logs, and no timestamp if a single log is specified. Note: In follow mode, timestamp always shown"
116
+ option :follow, aliases: %w[f], type: :boolean, desc: "Follow the log in live tail fashion. Must specify a stack if using this option."
117
+ option :limit, aliases: %w[n], default: 10, type: :numeric, desc: "Number of lines to limit showing. Only applies in no-follow mode."
118
+ option :all, aliases: %w[a], type: :boolean, desc: "All mode turns off the limit. Defaults to all if a single log is specified. Only applies in no-follow mode."
119
+ def log(action=nil, stack=nil)
120
+ Log.new(@options.merge(action: action, stack: stack)).run
121
+ end
122
+
123
+ desc "plan STACK", "Plan stack."
99
124
  long_desc Help.text(:plan)
100
125
  auto_option.call
101
126
  input_option.call
@@ -106,21 +131,21 @@ module Terraspace
106
131
  Commander.new("plan", options.merge(mod: mod)).run
107
132
  end
108
133
 
109
- desc "providers STACK", "providers"
134
+ desc "providers STACK", "Show providers."
110
135
  long_desc Help.text(:providers)
111
136
  instance_option.call
112
137
  def providers(mod)
113
138
  Commander.new("providers", options.merge(mod: mod)).run
114
139
  end
115
140
 
116
- desc "refresh STACK", "refresh"
141
+ desc "refresh STACK", "Run refresh."
117
142
  long_desc Help.text(:refresh)
118
143
  instance_option.call
119
144
  def refresh(mod)
120
145
  Commander.new("refresh", options.merge(mod: mod)).run
121
146
  end
122
147
 
123
- desc "seed STACK", "seed"
148
+ desc "seed STACK", "Build starer seed tfvars file."
124
149
  long_desc Help.text(:seed)
125
150
  option :yes, aliases: :y, type: :boolean, desc: "bypass prompts and force overwrite files"
126
151
  option :where, desc: "where to create file. either under app or seed folder structure. values: app or stack"
@@ -130,8 +155,8 @@ module Terraspace
130
155
  Seed.new(options.merge(mod: mod)).run
131
156
  end
132
157
 
133
- desc "summary", "Summary of resources"
134
- long_desc Help.text(:clean)
158
+ desc "summary", "Summarize resources."
159
+ long_desc Help.text(:summary)
135
160
  option :mod, desc: "Module to build to generate a backend file for discovery. By default the last module is used. Usually, it wont matter."
136
161
  init_option.call
137
162
  option :short, aliases: %w[s], type: :boolean, desc: "Only show statefiles"
@@ -139,20 +164,22 @@ module Terraspace
139
164
  Summary.new(options).run
140
165
  end
141
166
 
142
- desc "show STACK", "show"
167
+ desc "show STACK", "Run show."
143
168
  long_desc Help.text(:show)
144
169
  instance_option.call
170
+ option :plan, desc: "path to created.plan"
171
+ option :json, type: :boolean, desc: "show plan in json format"
145
172
  def show(mod)
146
173
  Commander.new("show", options.merge(mod: mod)).run
147
174
  end
148
175
 
149
- desc "test", "test"
176
+ desc "test", "Run test."
150
177
  long_desc Help.text(:test)
151
178
  def test
152
179
  Test.new(options).run
153
180
  end
154
181
 
155
- desc "output STACK", "output"
182
+ desc "output STACK", "Run output."
156
183
  long_desc Help.text(:output)
157
184
  format_option.call
158
185
  instance_option.call
@@ -161,8 +188,8 @@ module Terraspace
161
188
  Commander.new("output", options.merge(mod: mod)).run
162
189
  end
163
190
 
164
- desc "update STACK", "Update infrasturcture. IE: apply plan"
165
- long_desc Help.text(:update)
191
+ desc "up STACK", "Deploy infrastructure stack."
192
+ long_desc Help.text(:up)
166
193
  auto_option.call
167
194
  init_option.call
168
195
  input_option.call
@@ -171,11 +198,11 @@ module Terraspace
171
198
  reconfigure_option.call
172
199
  option :plan, desc: "Execution plan that can be used to only execute a pre-determined set of actions."
173
200
  option :var_files, type: :array, desc: "list of var files"
174
- def update(mod)
175
- Commander.new("apply", options.merge(mod: mod)).run
201
+ def up(mod)
202
+ Up.new(options.merge(mod: mod)).run
176
203
  end
177
204
 
178
- desc "validate STACK", "validate"
205
+ desc "validate STACK", "Validate stack."
179
206
  long_desc Help.text(:validate)
180
207
  instance_option.call
181
208
  def validate(mod)
@@ -194,7 +221,7 @@ module Terraspace
194
221
  Completer::Script.generate
195
222
  end
196
223
 
197
- desc "version", "prints version"
224
+ desc "version", "Prints version."
198
225
  def version
199
226
  puts VERSION
200
227
  end