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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 471e59d4e8478c78dd4de1190397e89548e68646fa6fcec02748442ecf9b282e
4
- data.tar.gz: 65250fbef38cef2731688e9c75877747a2a567ecd0d9ba40ce30b2c86c5c73e6
3
+ metadata.gz: 6b99a86e9b9b829fa0ac1b04a6774b02a43e67642219ea3f22aeb663869bfec6
4
+ data.tar.gz: f2b265d5e13a86949ddb753e991fc8784c77361909162123dfd7d06d0c1c3555
5
5
  SHA512:
6
- metadata.gz: 400b78be5d433399119713533a7b56fd7b143b253cae7e96d344273d74784ba9fe877a2a92293f237cec9f0642694256bd04c0b0ad0bef73050d205603884f92
7
- data.tar.gz: eac5b2042f655964d08454d7b5ea3ba40012145fed1c560bf116757c91857479ef7430cd1b7a2be661e828dbaf12a7cd0323014fb847a13299ef8fdc01cc8125
6
+ metadata.gz: 7fd4d65aac675d439e5e23089db75f937e3f50c72158099d1088112db67ed97c93afef6c47e0555cdde5a6dfe3e175ede017fc9e509c5419128c53ee114de91d
7
+ data.tar.gz: 4ef8b0354c0e8dd14ccd074bc6ecd2cda96f80c846bfd3dc790dce4cf20f36efbe236020eff587555032ec1dd869ec405cde649a348e232e747ba7900ad79393
@@ -10,4 +10,6 @@ export PATH=~/bin:$PATH # ~/bin/terraspace wrapper
10
10
  set -x
11
11
  terraspace new project infra --examples
12
12
  cd infra
13
+ terraspace new bootstrap_test
14
+ terraspace new project_test demo --examples
13
15
  terraspace test
@@ -17,4 +17,6 @@ export ARM_TENANT_ID=$(cat ~/.azure/app-client.json | jq -r '.tenant_id')
17
17
  set -x
18
18
  terraspace new project infra --examples --plugin azurerm
19
19
  cd infra
20
+ terraspace new bootstrap_test
21
+ terraspace new project_test demo --examples --plugin azurerm
20
22
  terraspace test
@@ -14,4 +14,6 @@ export GOOGLE_PROJECT=$(cat $GOOGLE_APPLICATION_CREDENTIALS | jq -r '.project_id
14
14
  set -x
15
15
  terraspace new project infra --examples --plugin google
16
16
  cd infra
17
+ terraspace new bootstrap_test
18
+ terraspace new project_test demo --examples --plugin google
17
19
  terraspace test
@@ -3,6 +3,44 @@
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
+ ## [0.4.0]
7
+ * improve hooks: allow multiple hooks of same type, change path hooks/terraform.rb
8
+ * improve hooks: introduce terraspace-level as well as terraform-level hooks
9
+ * improve hooks: can take Ruby block or shell script
10
+ * improve auto init: reinit when module source changed, improve auto init: generalize retry check
11
+ * fix already_init? detection for case when stack does use module
12
+ * terraspace bundler options: can set any option now
13
+ * add `terraspace all init` command
14
+ * improve terraspace clean, prompt user and add `-y` option
15
+ * bundle: check if in terraspace project
16
+ * Rename NullObject to Unresolved
17
+ * improve error message when stacks not found. give `terraspace list` hint
18
+ * terraspace list. change default to `--type stack`
19
+ * change summary option to --details
20
+ * include terraspace version in generated Gemfile
21
+ * logs command to handle viewing, and clean logs to clean
22
+
23
+ ## [0.3.6]
24
+ * #44 improve logs management commands: `terraspace logs remove` and `terraspace logs truncate`
25
+
26
+ ## [0.3.5]
27
+ * #43 rename `terraform_output` helper to `output`. Keep `terraform_output` for backwards compatibility
28
+ * to_ruby natural interface to access output with full power of Ruby
29
+ * output formatters removed in favor for `.to_ruby` method.
30
+
31
+ ## [0.3.4]
32
+ * #42 update cli docs and bug fixes
33
+ * fix console by using system instead of popen3
34
+ * fix build for edge case when app/modules exist but app/stacks do not
35
+ * terraspace new project: do not generate spec folder by default
36
+ * improve all output summary
37
+ * remove redundant `terraspace cloud setup`, instead use: `terraspace cloud sync`
38
+ * improve terraspace info output
39
+ * fix integration test pipeline
40
+
41
+ ## [0.3.3]
42
+ * #41 fix `terraspace build` and `terraspace seed` when bucket doesnt exist yet and there are dependenices defined.
43
+
6
44
  ## [0.3.2]
7
45
  * #40 fix backend auto creation
8
46
 
data/README.md CHANGED
@@ -81,14 +81,14 @@ To choose multiple stacks to deploy
81
81
 
82
82
  terraspace all up instance vpc
83
83
 
84
- When you use the all command, the dependency graph is calculated and the stacks are deployed in the right order. To learn more: [Deploy Multiple Stacks](https://terraspace.cloud/docs/dependencies/deploy-all/).
84
+ When you use the all command, the dependency graph is calculated and the stacks are deployed in the right order. To learn more: [Deploy Multiple Stacks](https://terraspace.cloud/docs/intro/deploy-all/).
85
85
 
86
86
  ## Features
87
87
 
88
88
  * [Config Structure](https://terraspace.cloud/docs/config/): A common config structure that gets materializes with the deployed module. Configs can be dynamically controlled to keep your code DRY. You can override the settings if needed, like for using existing backends. See: [Existing Backends](https://terraspace.cloud/docs/state/existing/).
89
89
  * [Generators](https://terraspace.cloud/docs/generators/): Built-in generators to quickly create the starter module. Focus on code instead of boilerplate structure.
90
90
  * [Tfvars](https://terraspace.cloud/docs/tfvars/) & [Layering](https://terraspace.cloud/docs/tfvars/layering/): Use the same code with different tfvars to create multiple environments. Terraspace conventionally loads tfvars from the `tfvars` folder. Rich layering support allows you to build different environments like dev and prod with the same code. Examples are in [Full Layering](https://terraspace.cloud/docs/tfvars/full-layering/).
91
- * [Deploy Multiple Stacks](https://terraspace.cloud/docs/dependencies/deploy-all/): The ability to deploy multiple stacks with a single command. Terraspace calculates the [dependency graph](https://terraspace.cloud/docs/dependencies/) and deploys stacks in the right order. You can also target specific stacks and deploy [subgraphs](https://terraspace.cloud/docs/dependencies/subgraphs/).
91
+ * [Deploy Multiple Stacks](https://terraspace.cloud/docs/intro/deploy-all/): The ability to deploy multiple stacks with a single command. Terraspace calculates the [dependency graph](https://terraspace.cloud/docs/dependencies/) and deploys stacks in the right order. You can also target specific stacks and deploy [subgraphs](https://terraspace.cloud/docs/dependencies/subgraphs/).
92
92
  * [Configurable CLI](https://terraspace.cloud/docs/cli/): Configurable [CLI Hooks](https://terraspace.cloud/docs/cli/hooks/) and [CLI Args](https://terraspace.cloud/docs/cli/args/) allow you to adjust the underlying terraform command.
93
93
  * [Testing](https://terraspace.cloud/docs/testing/): A testing framework that allows you to create test harnesses, deploy real-resources, and have higher confidence that your code works.
94
94
  * [Terraform Cloud and Terraform Enterprise Support](https://terraspace.cloud/docs/cloud/): TFC and TFE are both supported. Terraspace adds additional conveniences to make working with Terraform Cloud Workspaces easier.
@@ -14,4 +14,4 @@ To deploy individual stacks:
14
14
 
15
15
  ## Terrafile
16
16
 
17
- To add more modules for use, you can add them to the [Terrafile](https://terraspace.cloud/docs/terrafile/).
17
+ To use more modules, add them to the [Terrafile](https://terraspace.cloud/docs/terrafile/).
@@ -6,6 +6,7 @@ require "active_support/core_ext/class"
6
6
  require "active_support/core_ext/hash"
7
7
  require "active_support/core_ext/string"
8
8
  require "active_support/ordered_options"
9
+ require "cli-format"
9
10
  require "deep_merge/rails_compat"
10
11
  require "dsl_evaluator"
11
12
  require "fileutils"
@@ -26,6 +27,7 @@ module Terraspace
26
27
  extend Core # for Terraspace.root
27
28
  class Error < StandardError; end
28
29
  class InitRequiredError < Error; end
30
+ class BucketNotFoundError < Error; end
29
31
  end
30
32
 
31
33
  Terraspace::Booter.boot
@@ -22,7 +22,7 @@ module Terraspace::All
22
22
  @batches.map do |batch|
23
23
  i += 1
24
24
  batch.map do |stack|
25
- command = " terraspace #{@command}"
25
+ command = " terraspace #{@command}"
26
26
  ljust = command.size + max_name_size + 1
27
27
  command = "#{command} #{stack.name}"
28
28
  command.ljust(ljust, ' ') + " # batch #{i}"
@@ -105,6 +105,7 @@ module Terraspace::All
105
105
  set_log_path!(mod_name)
106
106
  name = command_map(@command)
107
107
  o = @options.merge(mod: mod_name, yes: true, build: false, input: false)
108
+ o.merge!(quiet: false) if @command == "init" # noisy so can filter and summarize output
108
109
  case @command
109
110
  when "up"
110
111
  Terraspace::CLI::Up.new(o).run
@@ -1,6 +1,6 @@
1
1
  module Terraspace::All
2
2
  class Summary
3
- include Terraspace::CLI::Log::Concern
3
+ include Terraspace::CLI::Logs::Concern
4
4
  include Terraspace::Util::Logging
5
5
 
6
6
  def initialize(data={})
@@ -35,6 +35,13 @@ module Terraspace::All
35
35
  end
36
36
  end
37
37
 
38
+ def init
39
+ @lines.select! do |line|
40
+ line.include?("successfully initialized") || # success
41
+ line.include?("Error: ") # error
42
+ end
43
+ end
44
+
38
45
  # Example 1:
39
46
  # [2020-09-07T14:45:14 #23340 terraspace plan b1]: No changes. Infrastructure is up-to-date.
40
47
  # Example 2:
@@ -51,7 +58,15 @@ module Terraspace::All
51
58
  end
52
59
 
53
60
  def output
54
- @lines # pass through all output info
61
+ if @lines.grep(/No outputs found/).empty?
62
+ @lines.select! do |line|
63
+ line.include?(" = ") # looks like output
64
+ end
65
+ else
66
+ @lines.select! do |line|
67
+ line.include?("No outputs found")
68
+ end
69
+ end
55
70
  end
56
71
 
57
72
  def show
@@ -65,6 +80,18 @@ module Terraspace::All
65
80
  @lines.unshift(summary) # add to top
66
81
  end
67
82
 
83
+ # [2020-09-19T19:36:33 #14387 terraspace providers c1]: => terraform providers
84
+ # [2020-09-19T19:36:33 #14387 terraspace providers c1]:
85
+ # [2020-09-19T19:36:33 #14387 terraspace providers c1]: Providers required by configuration:
86
+ # [2020-09-19T19:36:33 #14387 terraspace providers c1]: .
87
+ # [2020-09-19T19:36:33 #14387 terraspace providers c1]: └── provider[registry.terraform.io/hashicorp/random]
88
+ # [2020-09-19T19:36:33 #14387 terraspace providers c1]:
89
+ def providers
90
+ @lines.select! do |line|
91
+ line.include?("provider[")
92
+ end
93
+ end
94
+
68
95
  # [2020-09-07T14:53:36 #31106 terraspace show b1]: Outputs:
69
96
  # [2020-09-07T14:53:36 #31106 terraspace show b1]:
70
97
  # [2020-09-07T14:53:36 #31106 terraspace show b1]: length = 1
@@ -9,6 +9,8 @@ module Terraspace
9
9
  end
10
10
 
11
11
  def defaults
12
+ ts_logger = Logger.new(ENV['TS_LOG_PATH'] || $stderr)
13
+
12
14
  config = ActiveSupport::OrderedOptions.new
13
15
  config.all = ActiveSupport::OrderedOptions.new
14
16
  config.all.concurrency = 5
@@ -21,14 +23,16 @@ module Terraspace
21
23
  config.build.cache_dir = ":CACHE_ROOT/:REGION/:ENV/:BUILD_DIR"
22
24
  config.build.cache_root = nil # defaults to /full/path/to/.terraspace-cache
23
25
  config.build.clean_cache = nil # defaults to /full/path/to/.terraspace-cache
26
+ config.bundle = ActiveSupport::OrderedOptions.new
27
+ config.bundle.logger = ts_logger
24
28
  config.cloud = ActiveSupport::OrderedOptions.new
25
29
  config.cloud.auto_sync = true
26
- config.cloud.working_dir_prefix = nil
27
30
  config.cloud.hostname = nil
28
31
  config.cloud.vars = ActiveSupport::OrderedOptions.new
29
32
  config.cloud.vars.overwrite = true
30
33
  config.cloud.vars.overwrite_sensitive = true
31
34
  config.cloud.vars.show_message = "create"
35
+ config.cloud.working_dir_prefix = nil
32
36
  config.cloud.workspace = ActiveSupport::OrderedOptions.new
33
37
  config.cloud.workspace.attrs = ActiveSupport::OrderedOptions.new
34
38
  config.hooks = Hooks.new
@@ -36,14 +40,14 @@ module Terraspace
36
40
  config.init.mode = "auto" # auto, never, always
37
41
  config.log = ActiveSupport::OrderedOptions.new
38
42
  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
43
+ config.logger = ts_logger
41
44
  config.logger.formatter = Logger::Formatter.new
42
- config.test_framework = "rspec"
45
+ config.logger.level = ENV['TS_LOG_LEVEL'] || :info
43
46
  config.terraform = ActiveSupport::OrderedOptions.new
44
47
  config.terraform.plugin_cache = ActiveSupport::OrderedOptions.new
45
- config.terraform.plugin_cache.enabled = true
46
48
  config.terraform.plugin_cache.dir = ENV['TF_PLUGIN_CACHE_DIR'] || "#{Terraspace.tmp_root}/plugin_cache"
49
+ config.terraform.plugin_cache.enabled = true
50
+ config.test_framework = "rspec"
47
51
  config
48
52
  end
49
53
 
@@ -1,6 +1,8 @@
1
1
  module Terraspace
2
2
  class Builder < Terraspace::CLI::Base
3
+ include Compiler::CommandsConcern
3
4
  include Compiler::DirsConcern
5
+ include Hooks::Concern
4
6
 
5
7
  attr_reader :graph
6
8
 
@@ -13,11 +15,14 @@ module Terraspace
13
15
  placeholder_stack_message
14
16
  logger.info "Building #{build_dir}" unless @options[:quiet] # from terraspace all
15
17
 
16
- build_unresolved
17
- auto_create_backend
18
- batches = build_batches
19
- build_all
20
- logger.info "Built in #{build_dir}" unless @options[:quiet] # from terraspace all
18
+ batches = nil
19
+ run_hooks("terraspace.rb", "build") do
20
+ build_unresolved
21
+ auto_create_backend
22
+ batches = build_batches
23
+ build_all
24
+ logger.info "Built in #{build_dir}" unless @options[:quiet] # from terraspace all
25
+ end
21
26
  batches
22
27
  end
23
28
 
@@ -58,16 +63,10 @@ module Terraspace
58
63
  # Auto create after build_unresolved since will need to run state pull for dependencies
59
64
  def auto_create_backend
60
65
  return if Terraspace.config.auto_create_backend == false
61
- return unless create_backend?
66
+ return unless requires_backend?
62
67
  Terraspace::Compiler::Backend.new(@mod).create
63
68
  end
64
69
 
65
- def create_backend?
66
- commands = %w[down init output plan providers refresh show up validate]
67
- commands.include?(ARGV[0]) || # IE: terraspace up
68
- ARGV[0] == "all" && commands.include?(ARGV[1]) # IE: terraspace all up
69
- end
70
-
71
70
  def clean
72
71
  Compiler::Cleaner.new(@mod, @options).clean if clean?
73
72
  end
@@ -32,19 +32,19 @@ module Terraspace
32
32
  long_desc Help.text(:all)
33
33
  subcommand "all", All
34
34
 
35
+ desc "clean SUBCOMMAND", "clean subcommands"
36
+ long_desc Help.text(:clean)
37
+ subcommand "clean", Clean
38
+
35
39
  desc "cloud SUBCOMMAND", "cloud subcommands"
36
40
  long_desc Help.text(:cloud)
37
41
  subcommand "cloud", Cloud
38
42
 
39
- desc "logs SUBCOMMAND", "logs management subcommands"
40
- long_desc Help.text(:logs)
41
- subcommand "logs", Logs
42
-
43
43
  desc "new SUBCOMMAND", "new subcommands"
44
44
  long_desc Help.text(:new)
45
45
  subcommand "new", New
46
46
 
47
- desc "build [STACK]", "build"
47
+ desc "build [STACK]", "Build project."
48
48
  long_desc Help.text(:build)
49
49
  option :quiet, type: :boolean, desc: "quiet output"
50
50
  instance_option.call
@@ -53,32 +53,26 @@ module Terraspace
53
53
  Terraspace::Builder.new(options.merge(mod: mod)).run # building any stack builds them all
54
54
  end
55
55
 
56
- desc "bundle", "bundle"
56
+ desc "bundle", "Bundle with Terrafile."
57
57
  long_desc Help.text(:bundle)
58
58
  def bundle(*args)
59
59
  Bundle.new(options.merge(args: args)).run
60
60
  end
61
61
 
62
- desc "check_setup", "check_setup"
62
+ desc "check_setup", "Check setup."
63
63
  long_desc Help.text(:check_setup)
64
64
  def check_setup
65
65
  CheckSetup.new(options).run
66
66
  end
67
67
 
68
- desc "clean", "clean .terraspace-cache dir"
69
- long_desc Help.text(:clean)
70
- def clean
71
- Clean.new(options).run
72
- end
73
-
74
- desc "console STACK", "console .terraspace-cache dir"
68
+ desc "console STACK", "Run console in built terraform project."
75
69
  long_desc Help.text(:console)
76
70
  instance_option.call
77
71
  def console(mod)
78
- Commander.new("console", options.merge(mod: mod)).run
72
+ Commander.new("console", options.merge(mod: mod, shell: "system")).run
79
73
  end
80
74
 
81
- desc "down STACK", "down"
75
+ desc "down STACK", "Destroy infrastructure stack."
82
76
  long_desc Help.text(:down)
83
77
  instance_option.call
84
78
  yes_option.call
@@ -88,39 +82,39 @@ module Terraspace
88
82
  Down.new(options.merge(mod: mod)).run
89
83
  end
90
84
 
91
- desc "info STACK", "info"
85
+ desc "info STACK", "Get info about stack."
92
86
  long_desc Help.text(:info)
93
- format_option.call
94
87
  instance_option.call
88
+ option :format, desc: "Output formats: #{CliFormat.formats.join(', ')}"
95
89
  def info(mod)
96
90
  Info.new(options.merge(mod: mod)).run
97
91
  end
98
92
 
99
- desc "init STACK", "init"
93
+ desc "init STACK", "Run init in built terraform project."
100
94
  long_desc Help.text(:init)
101
95
  instance_option.call
102
96
  def init(mod)
103
97
  Commander.new("init", options.merge(mod: mod, quiet: false)).run
104
98
  end
105
99
 
106
- desc "list", "list stacks and modules"
100
+ desc "list", "List stacks and modules."
107
101
  long_desc Help.text(:list)
108
- option :type, aliases: %w[t], desc: "Type: stack or module. Default all"
102
+ option :type, default: "stack", aliases: %w[t], desc: "Type: stack, module, or all"
109
103
  def list
110
104
  List.new(options).run
111
105
  end
112
106
 
113
- desc "log [ACTION] [STACK]", "The all log command allows you to view multiple logs."
114
- long_desc Help.text("log")
107
+ desc "logs [ACTION] [STACK]", "View and tail logs."
108
+ long_desc Help.text("logs")
115
109
  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
110
  option :follow, aliases: %w[f], type: :boolean, desc: "Follow the log in live tail fashion. Must specify a stack if using this option."
117
111
  option :limit, aliases: %w[n], default: 10, type: :numeric, desc: "Number of lines to limit showing. Only applies in no-follow mode."
118
112
  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
113
+ def logs(action=nil, stack=nil)
114
+ Logs.new(@options.merge(action: action, stack: stack)).run
121
115
  end
122
116
 
123
- desc "plan STACK", "plan stack"
117
+ desc "plan STACK", "Plan stack."
124
118
  long_desc Help.text(:plan)
125
119
  auto_option.call
126
120
  input_option.call
@@ -131,21 +125,21 @@ module Terraspace
131
125
  Commander.new("plan", options.merge(mod: mod)).run
132
126
  end
133
127
 
134
- desc "providers STACK", "providers"
128
+ desc "providers STACK", "Show providers."
135
129
  long_desc Help.text(:providers)
136
130
  instance_option.call
137
131
  def providers(mod)
138
132
  Commander.new("providers", options.merge(mod: mod)).run
139
133
  end
140
134
 
141
- desc "refresh STACK", "refresh"
135
+ desc "refresh STACK", "Run refresh."
142
136
  long_desc Help.text(:refresh)
143
137
  instance_option.call
144
138
  def refresh(mod)
145
139
  Commander.new("refresh", options.merge(mod: mod)).run
146
140
  end
147
141
 
148
- desc "seed STACK", "seed"
142
+ desc "seed STACK", "Build starer seed tfvars file."
149
143
  long_desc Help.text(:seed)
150
144
  option :yes, aliases: :y, type: :boolean, desc: "bypass prompts and force overwrite files"
151
145
  option :where, desc: "where to create file. either under app or seed folder structure. values: app or stack"
@@ -155,16 +149,16 @@ module Terraspace
155
149
  Seed.new(options.merge(mod: mod)).run
156
150
  end
157
151
 
158
- desc "summary", "Summary of resources"
159
- long_desc Help.text(:clean)
152
+ desc "summary", "Summarize resources."
153
+ long_desc Help.text(:summary)
160
154
  option :mod, desc: "Module to build to generate a backend file for discovery. By default the last module is used. Usually, it wont matter."
161
155
  init_option.call
162
- option :short, aliases: %w[s], type: :boolean, desc: "Only show statefiles"
156
+ option :details, type: :boolean, desc: "Show details of the listed resources"
163
157
  def summary
164
158
  Summary.new(options).run
165
159
  end
166
160
 
167
- desc "show STACK", "show"
161
+ desc "show STACK", "Run show."
168
162
  long_desc Help.text(:show)
169
163
  instance_option.call
170
164
  option :plan, desc: "path to created.plan"
@@ -173,13 +167,13 @@ module Terraspace
173
167
  Commander.new("show", options.merge(mod: mod)).run
174
168
  end
175
169
 
176
- desc "test", "test"
170
+ desc "test", "Run test."
177
171
  long_desc Help.text(:test)
178
172
  def test
179
173
  Test.new(options).run
180
174
  end
181
175
 
182
- desc "output STACK", "output"
176
+ desc "output STACK", "Run output."
183
177
  long_desc Help.text(:output)
184
178
  format_option.call
185
179
  instance_option.call
@@ -188,8 +182,8 @@ module Terraspace
188
182
  Commander.new("output", options.merge(mod: mod)).run
189
183
  end
190
184
 
191
- desc "up STACK", "Deploy infrastructure. IE: terraform apply"
192
- long_desc Help.text(:update)
185
+ desc "up STACK", "Deploy infrastructure stack."
186
+ long_desc Help.text(:up)
193
187
  auto_option.call
194
188
  init_option.call
195
189
  input_option.call
@@ -202,7 +196,7 @@ module Terraspace
202
196
  Up.new(options.merge(mod: mod)).run
203
197
  end
204
198
 
205
- desc "validate STACK", "validate"
199
+ desc "validate STACK", "Validate stack."
206
200
  long_desc Help.text(:validate)
207
201
  instance_option.call
208
202
  def validate(mod)
@@ -221,7 +215,7 @@ module Terraspace
221
215
  Completer::Script.generate
222
216
  end
223
217
 
224
- desc "version", "prints version"
218
+ desc "version", "Prints version."
225
219
  def version
226
220
  puts VERSION
227
221
  end