terraspace 0.5.11 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -7
  3. data/README.md +2 -0
  4. data/lib/terraspace/app.rb +37 -16
  5. data/lib/terraspace/app/inits.rb +13 -0
  6. data/lib/terraspace/booter.rb +19 -2
  7. data/lib/terraspace/cli.rb +13 -6
  8. data/lib/terraspace/cli/build/placeholder.rb +6 -1
  9. data/lib/terraspace/cli/commander.rb +1 -1
  10. data/lib/terraspace/cli/down.rb +1 -1
  11. data/lib/terraspace/cli/help/{cloud → tfc}/destroy.md +1 -1
  12. data/lib/terraspace/cli/help/{cloud → tfc}/list.md +1 -1
  13. data/lib/terraspace/cli/help/{cloud → tfc}/runs/list.md +3 -3
  14. data/lib/terraspace/cli/help/{cloud → tfc}/runs/prune.md +3 -3
  15. data/lib/terraspace/cli/help/{cloud → tfc}/sync.md +3 -3
  16. data/lib/terraspace/cli/init.rb +21 -8
  17. data/lib/terraspace/cli/new/helper.rb +2 -2
  18. data/lib/terraspace/cli/state.rb +10 -0
  19. data/lib/terraspace/cli/{cloud.rb → tfc.rb} +3 -3
  20. data/lib/terraspace/cli/{cloud → tfc}/runs.rb +4 -4
  21. data/lib/terraspace/compiler/builder.rb +4 -1
  22. data/lib/terraspace/compiler/dirs_concern.rb +11 -1
  23. data/lib/terraspace/compiler/helper_extender.rb +3 -3
  24. data/lib/terraspace/compiler/select.rb +28 -0
  25. data/lib/terraspace/compiler/strategy/tfvar.rb +16 -4
  26. data/lib/terraspace/compiler/strategy/tfvar/layer.rb +75 -52
  27. data/lib/terraspace/ext.rb +1 -0
  28. data/lib/terraspace/ext/core/string.rb +5 -0
  29. data/lib/terraspace/layering.rb +24 -0
  30. data/lib/terraspace/logger.rb +8 -1
  31. data/lib/terraspace/mod.rb +18 -3
  32. data/lib/terraspace/plugin/expander/friendly.rb +10 -0
  33. data/lib/terraspace/plugin/expander/interface.rb +6 -1
  34. data/lib/terraspace/plugin/summary/interface.rb +1 -1
  35. data/lib/terraspace/shell.rb +16 -1
  36. data/lib/terraspace/shell/error.rb +1 -1
  37. data/lib/terraspace/terraform/api/runs.rb +13 -2
  38. data/lib/terraspace/terraform/api/token.rb +2 -2
  39. data/lib/terraspace/terraform/api/var.rb +1 -1
  40. data/lib/terraspace/terraform/api/vars.rb +1 -1
  41. data/lib/terraspace/terraform/api/vars/base.rb +2 -0
  42. data/lib/terraspace/terraform/api/vars/json.rb +13 -1
  43. data/lib/terraspace/terraform/api/workspace.rb +10 -3
  44. data/lib/terraspace/terraform/args/default.rb +23 -13
  45. data/lib/terraspace/terraform/ihooks/after/plan.rb +17 -0
  46. data/lib/terraspace/terraform/ihooks/base.rb +8 -0
  47. data/lib/terraspace/terraform/ihooks/before/plan.rb +14 -0
  48. data/lib/terraspace/terraform/remote_state/fetcher.rb +1 -1
  49. data/lib/terraspace/terraform/runner.rb +12 -0
  50. data/lib/terraspace/terraform/{cloud → tfc}/runs.rb +1 -1
  51. data/lib/terraspace/terraform/{cloud → tfc}/runs/base.rb +1 -1
  52. data/lib/terraspace/terraform/{cloud → tfc}/runs/item_presenter.rb +1 -1
  53. data/lib/terraspace/terraform/{cloud → tfc}/runs/lister.rb +1 -1
  54. data/lib/terraspace/terraform/{cloud → tfc}/runs/pruner.rb +1 -1
  55. data/lib/terraspace/terraform/{cloud → tfc}/sync.rb +2 -2
  56. data/lib/terraspace/terraform/{cloud → tfc}/syncer.rb +1 -1
  57. data/lib/terraspace/terraform/{cloud → tfc}/workspace.rb +2 -3
  58. data/lib/terraspace/util/pretty.rb +2 -1
  59. data/lib/terraspace/version.rb +1 -1
  60. metadata +26 -18
  61. data/lib/terraspace/app/hooks.rb +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ab8d16e8890ccbd14785cdc20245e47a126593337d0330bfecbb902336a32d8
4
- data.tar.gz: 51f9b735befd7ea059ff6541414e3f80631a9bc5b511fc69f4e1f489e6f9a72e
3
+ metadata.gz: f9b4a9918ee0ab0e10c6c4d2d0ed1a88851fda09b7a6b1475db084c6f7cb1699
4
+ data.tar.gz: 2b66a6e8be57c94aaf24334a073943c28e11fbcd77f1d7853cf0885e9e87ec9e
5
5
  SHA512:
6
- metadata.gz: b3d6fca3b2b9b2fcdabd48d6b093e7a3dcfafe4f53a482dc7fffb3a001bca89a743b294b12ccc92e2cb7010799e0d147e402406afaa93de48149d94fd9c894f3
7
- data.tar.gz: 5a36c2d3d9f847989f639829be9fae0b5b1a9a6e48f636478b1560a94a45fca2ff74db5800ebaa8ed97977c2b5e83a72a99292f8737c6737ebabd1ba748bd026
6
+ metadata.gz: dcabae82c7a30ddcc364a13ce85f73ce461307cde54ab95fd2fb1d2c21558c03123058c8d282e339ae4f47f0fd927061eee12d74ba71f403cc6b7cb9f7fd8e3e
7
+ data.tar.gz: f8c625671745fccdb13139efcd13c737b6f4a2ee0161badc75677bdedc544a94566c0eb8e865c2c68635bab7c648232d7275b88f20d0f9a8677d74b74c95c75f
data/CHANGELOG.md CHANGED
@@ -3,6 +3,30 @@
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.6.3] - 2021-03-12
7
+ - [#91](https://github.com/boltops-tools/terraspace/pull/91) Camelcase
8
+ - [#92](https://github.com/boltops-tools/terraspace/pull/92) disable terraform.plugin_cache by default
9
+ - skip build config/helpers
10
+
11
+ ## [0.6.2] - 2021-03-05
12
+ - [#90](https://github.com/boltops-tools/terraspace/pull/90) Boot hooks: new and improved boot hooks interface
13
+ - remove old config.hooks.on_boot
14
+
15
+ ## [0.6.1] - 2021-03-04
16
+ - [#89](https://github.com/boltops-tools/terraspace/pull/89) rename option to enable_names.expansion
17
+
18
+ ## [0.6.0] - 2021-03-03
19
+ - [#87](https://github.com/boltops-tools/terraspace/pull/87) rename cloud to tfc command and improvements
20
+ - [#88](https://github.com/boltops-tools/terraspace/pull/88) custom layering support
21
+ - Improve stdout handling, so this works: `terraspace show demo --json | jq`
22
+ - `terraspace plan --output plan.save` writes to relative cache path.
23
+ - `terraspace up --plan plan.save` copies plan.save to cache path.
24
+ - Add state command. Initial simple version.
25
+
26
+ ## [0.5.12] - 2021-02-27
27
+ - [#79](https://github.com/boltops-tools/terraspace/pull/79) Fix syntax issue
28
+ - [#85](https://github.com/boltops-tools/terraspace/pull/85) Add all.include_stacks option and fix all.ignore_stacks option when building dependency graph
29
+
6
30
  ## [0.5.11] - 2021-02-11
7
31
  - [#76](https://github.com/boltops-tools/terraspace/pull/76) dont use auto generated plan when both yes and plan options used
8
32
  - fix plan path when 2 stacks of same name run at the same time
@@ -104,7 +128,7 @@ This project *loosely tries* to adhere to [Semantic Versioning](http://semver.or
104
128
  * fix build for edge case when app/modules exist but app/stacks do not
105
129
  * terraspace new project: do not generate spec folder by default
106
130
  * improve all output summary
107
- * remove redundant `terraspace cloud setup`, instead use: `terraspace cloud sync`
131
+ * remove redundant `terraspace tfc setup`, instead use: `terraspace tfc sync`
108
132
  * improve terraspace info output
109
133
  * fix integration test pipeline
110
134
 
@@ -123,8 +147,8 @@ This project *loosely tries* to adhere to [Semantic Versioning](http://semver.or
123
147
  * Terraspace log: view and tail log files
124
148
  * Terraspace logs management commands: `terraspace logs truncate` and `terraspace logs remove`
125
149
  * TFC/TFE: Improve support. `config.cloud.vars`, `config.cloud.workspace.attrs`
126
- * TFC commands: terraspace cloud runs list, terraspace cloud runs prune
127
- * TFC VCS also sync as part of deploy. Also separate `terraspace cloud sync` command
150
+ * TFC commands: terraspace tfc runs list, terraspace tfc runs prune
151
+ * TFC VCS also sync as part of deploy. Also separate `terraspace tfc sync` command
128
152
  * Logger improvements: configurable formatter, log to stderr by default
129
153
  * Rename: `cloud.relative_root` to `cloud.working_dir_prefix`
130
154
  * Run a plan to capture the diff as part of `-y` option. IE: `terraspace up demo -y`
@@ -157,11 +181,11 @@ This project *loosely tries* to adhere to [Semantic Versioning](http://semver.or
157
181
  * New expander variables: TYPE_INSTANCE, INSTANCE, CACHE_ROOT. Also added strip trailing - and / behavior.
158
182
  * Timeout for terraform init. The default timeout is 10m and will then print out the terraform init log.
159
183
  * Terraspace 0.2.x is compatible with terraspace\_plugin_aws 0.2.x, terraspace\_plugin_google 0.2.x, and terraspace\_plugin_azurerm 0.2.x
160
- * New commands: terraspace list, terraspace cloud list, terraspace cloud setup, terraspace cloud destroy, terraspace new shim, terraspace new git_hook
184
+ * New commands: terraspace list, terraspace tfc list, terraspace tfc setup, terraspace tfc destroy, terraspace new shim, terraspace new git_hook
161
185
  * terraspace list: list of modules and stacks
162
- * terraspace cloud list: shows list of TFC workspaces
163
- * terraspace cloud setup: setups up TFC workspace for VCS-driven workflow. This automatically happens for the TFC CLI-driven workflow.
164
- * terraspace cloud destroy: destroys the TFC workspace associated with the stack. Can also use the `terraspace down demo --destroy-workspace` option.
186
+ * terraspace tfc list: shows list of TFC workspaces
187
+ * terraspace tfc setup: setups up TFC workspace for VCS-driven workflow. This automatically happens for the TFC CLI-driven workflow.
188
+ * terraspace tfc destroy: destroys the TFC workspace associated with the stack. Can also use the `terraspace down demo --destroy-workspace` option.
165
189
  * terraspace new shim: An quick way to generate a terraspace shim.
166
190
  * terraspace new git_hook: An quick way to set up a git pre-push hook for the TFC VCS-driven workflow.
167
191
  * terraspace down: works even if there's no app/stacks folder. A fake stack is built.
data/README.md CHANGED
@@ -10,6 +10,8 @@
10
10
 
11
11
  The Terraform Framework.
12
12
 
13
+ Please **watch/star** this repo to help grow and support the project.
14
+
13
15
  Official Docs Site: [terraspace.cloud](https://terraspace.cloud)
14
16
 
15
17
  Quick Start Demo:
@@ -1,7 +1,9 @@
1
1
  module Terraspace
2
2
  class App
3
- include Singleton
3
+ extend Memoist
4
4
  include DslEvaluator
5
+ include Singleton
6
+ include Terraspace::Util::Logging
5
7
 
6
8
  attr_reader :config
7
9
  def initialize
@@ -9,15 +11,14 @@ module Terraspace
9
11
  end
10
12
 
11
13
  def defaults
12
- ts_logger = Logger.new(ENV['TS_LOG_PATH'] || $stderr)
13
-
14
14
  config = ActiveSupport::OrderedOptions.new
15
15
  config.all = ActiveSupport::OrderedOptions.new
16
16
  config.all.concurrency = 5
17
17
  config.all.exit_on_fail = ActiveSupport::OrderedOptions.new
18
18
  config.all.exit_on_fail.down = true
19
19
  config.all.exit_on_fail.up = true
20
- config.all.ignore_stacks = []
20
+ config.all.ignore_stacks = nil
21
+ config.all.include_stacks = nil
21
22
  config.allow = ActiveSupport::OrderedOptions.new
22
23
  config.allow.envs = nil
23
24
  config.allow.regions = nil
@@ -28,17 +29,6 @@ module Terraspace
28
29
  config.build.clean_cache = nil # defaults to /full/path/to/.terraspace-cache
29
30
  config.bundle = ActiveSupport::OrderedOptions.new
30
31
  config.bundle.logger = ts_logger
31
- config.cloud = ActiveSupport::OrderedOptions.new
32
- config.cloud.auto_sync = true
33
- config.cloud.hostname = nil
34
- config.cloud.vars = ActiveSupport::OrderedOptions.new
35
- config.cloud.vars.overwrite = true
36
- config.cloud.vars.overwrite_sensitive = true
37
- config.cloud.vars.show_message = "create"
38
- config.cloud.working_dir_prefix = nil
39
- config.cloud.workspace = ActiveSupport::OrderedOptions.new
40
- config.cloud.workspace.attrs = ActiveSupport::OrderedOptions.new
41
- config.hooks = Hooks.new
42
32
  config.init = ActiveSupport::OrderedOptions.new
43
33
  config.init.mode = "auto" # auto, never, always
44
34
  config.log = ActiveSupport::OrderedOptions.new
@@ -46,22 +36,53 @@ module Terraspace
46
36
  config.logger = ts_logger
47
37
  config.logger.formatter = Logger::Formatter.new
48
38
  config.logger.level = ENV['TS_LOG_LEVEL'] || :info
39
+ config.layering = ActiveSupport::OrderedOptions.new
40
+ config.layering.names = {}
41
+ config.layering.enable_names = ActiveSupport::OrderedOptions.new
42
+ config.layering.enable_names.expansion = true
43
+ config.summary = ActiveSupport::OrderedOptions.new
44
+ config.summary.prune = false
49
45
  config.terraform = ActiveSupport::OrderedOptions.new
50
46
  config.terraform.plugin_cache = ActiveSupport::OrderedOptions.new
51
47
  config.terraform.plugin_cache.dir = ENV['TF_PLUGIN_CACHE_DIR'] || "#{Terraspace.tmp_root}/plugin_cache"
52
- config.terraform.plugin_cache.enabled = true
48
+ config.terraform.plugin_cache.enabled = false
53
49
  config.terraform.plugin_cache.purge_on_error = true
54
50
  config.test_framework = "rspec"
51
+ config.tfc = ActiveSupport::OrderedOptions.new
52
+ config.tfc.auto_sync = true
53
+ config.tfc.hostname = nil
54
+ config.tfc.vars = ActiveSupport::OrderedOptions.new
55
+ config.tfc.vars.overwrite = true
56
+ config.tfc.vars.overwrite_sensitive = true
57
+ config.tfc.vars.show_message = "create"
58
+ config.tfc.working_dir_prefix = nil
59
+ config.tfc.workspace = ActiveSupport::OrderedOptions.new
60
+ config.tfc.workspace.attrs = ActiveSupport::OrderedOptions.new
55
61
  config
56
62
  end
57
63
 
64
+ def ts_logger
65
+ Logger.new(ENV['TS_LOG_PATH'] || $stderr)
66
+ end
67
+ memoize :ts_logger
68
+
58
69
  def configure
59
70
  yield(@config)
60
71
  end
61
72
 
62
73
  def load_project_config
63
74
  evaluate_file("#{Terraspace.root}/config/app.rb")
75
+
76
+ # deprecated config/env for config/envs
64
77
  path = "#{Terraspace.root}/config/env/#{Terraspace.env}.rb"
78
+ if File.exist?(path)
79
+ # so early on in the boot process that logger.info is unavailable, use ts_logger which is available and same thing.
80
+ ts_logger.info "DEPRECATED: Please rename config/env to config/envs. IE:".color(:yellow)
81
+ ts_logger.info " mv config/env config/envs"
82
+ evaluate_file(path)
83
+ end
84
+
85
+ path = "#{Terraspace.root}/config/envs/#{Terraspace.env}.rb"
65
86
  evaluate_file(path)
66
87
  end
67
88
  end
@@ -0,0 +1,13 @@
1
+ class Terraspace::App
2
+ class Inits
3
+ class << self
4
+ include DslEvaluator
5
+
6
+ def run_all
7
+ Dir.glob("#{Terraspace.root}/config/inits/*.rb").each do |path|
8
+ evaluate_file(path)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,10 +1,10 @@
1
1
  module Terraspace
2
2
  module Booter
3
3
  def boot
4
+ run_hooks
4
5
  Terraspace::Bundle.require # load plugins
5
6
  load_plugin_default_configs
6
- Terraspace.config # load project config
7
- Terraspace::App::Hooks.run_hook(:on_boot)
7
+ Terraspace::App::Inits.run_all
8
8
  set_plugin_cache!
9
9
  end
10
10
 
@@ -23,6 +23,23 @@ module Terraspace
23
23
  dir
24
24
  end
25
25
 
26
+ # Special boot hooks run super early, even before plugins are loaded.
27
+ # Useful for setting env vars and other early things.
28
+ #
29
+ # config/boot.rb
30
+ # config/boot/dev.rb
31
+ #
32
+ def run_hooks
33
+ run_hook
34
+ run_hook(Terraspace.env)
35
+ end
36
+
37
+ def run_hook(env=nil)
38
+ name = env ? "boot/#{env}" : "boot"
39
+ path = "#{Terraspace.root}/config/#{name}.rb"
40
+ require path if File.exist?(path)
41
+ end
42
+
26
43
  extend self
27
44
  end
28
45
  end
@@ -10,7 +10,7 @@ module Terraspace
10
10
  option :format, desc: "output formats: json, text"
11
11
  }
12
12
  out_option = Proc.new {
13
- option :out, aliases: :o, desc: "write the output to path"
13
+ option :out, aliases: :o, desc: "Write the output to path"
14
14
  }
15
15
  input_option = Proc.new {
16
16
  option :input, type: :boolean, desc: "Ask for input for variables if not directly set."
@@ -36,14 +36,14 @@ module Terraspace
36
36
  long_desc Help.text(:clean)
37
37
  subcommand "clean", Clean
38
38
 
39
- desc "cloud SUBCOMMAND", "cloud subcommands"
40
- long_desc Help.text(:cloud)
41
- subcommand "cloud", Cloud
42
-
43
39
  desc "new SUBCOMMAND", "new subcommands"
44
40
  long_desc Help.text(:new)
45
41
  subcommand "new", New
46
42
 
43
+ desc "tfc SUBCOMMAND", "tfc subcommands"
44
+ long_desc Help.text(:tfc)
45
+ subcommand "tfc", Tfc
46
+
47
47
  desc "build [STACK]", "Build project."
48
48
  long_desc Help.text(:build)
49
49
  option :quiet, type: :boolean, desc: "quiet output"
@@ -123,6 +123,7 @@ module Terraspace
123
123
  instance_option.call
124
124
  out_option.call
125
125
  reconfigure_option.call
126
+ option :copy_to_root, type: :boolean, default: true, desc: "Copy plan file generated in the cache folder back to project root"
126
127
  def plan(mod)
127
128
  Commander.new("plan", options.merge(mod: mod)).run
128
129
  end
@@ -144,7 +145,7 @@ module Terraspace
144
145
  desc "seed STACK", "Build starer seed tfvars file."
145
146
  long_desc Help.text(:seed)
146
147
  option :yes, aliases: :y, type: :boolean, desc: "bypass prompts and force overwrite files"
147
- option :where, desc: "where to create file. either under app or seed folder structure. values: app or stack"
148
+ option :where, desc: "where to create file. either under app or seed folder structure. values: seed or stack"
148
149
  init_option.call
149
150
  instance_option.call
150
151
  def seed(mod)
@@ -169,6 +170,12 @@ module Terraspace
169
170
  Commander.new("show", options.merge(mod: mod)).run
170
171
  end
171
172
 
173
+ desc "state SUBCOMMAND STACK", "Run state."
174
+ long_desc Help.text(:state)
175
+ def state(subcommand, mod)
176
+ State.new(options.merge(subcommand: subcommand, mod: mod)).run
177
+ end
178
+
172
179
  desc "test", "Run test."
173
180
  long_desc Help.text(:test)
174
181
  def test
@@ -26,7 +26,12 @@ module Terraspace::CLI::Build
26
26
 
27
27
  # Used by: terraspace build placeholder
28
28
  def find_stack
29
- mod_path = Dir.glob("{app,vendor}/stacks/*").last
29
+ stack_paths = Dir.glob("{app,vendor}/stacks/*")
30
+ stack_paths.select! do |path|
31
+ select = Terraspace::Compiler::Select.new(path)
32
+ select.selected?
33
+ end
34
+ mod_path = stack_paths.last
30
35
  unless mod_path
31
36
  logger.info "No stacks found."
32
37
  exit 0
@@ -7,7 +7,7 @@ class Terraspace::CLI
7
7
 
8
8
  def run
9
9
  Terraspace::Builder.new(@options).run unless @options[:build] # Up already ran build
10
- Init.new(@options.merge(calling_command: @name)).run
10
+ Init.new(@options).run
11
11
  Terraspace::Terraform::Runner.new(@name, @options).run
12
12
  end
13
13
  end
@@ -14,7 +14,7 @@ class Terraspace::CLI
14
14
 
15
15
  def destroy
16
16
  Commander.new("destroy", @options.merge(command: "down")).run
17
- Terraspace::Terraform::Cloud::Workspace.new(@options).destroy if @options[:destroy_workspace]
17
+ Terraspace::Terraform::Tfc::Workspace.new(@options).destroy if @options[:destroy_workspace]
18
18
  end
19
19
  end
20
20
  end
@@ -1,6 +1,6 @@
1
1
  ## Example
2
2
 
3
- $ terraspace cloud destroy demo
3
+ $ terraspace tfc destroy demo
4
4
  You are about to delete the workspace: demo-dev-us-west-2
5
5
  All variables, settings, run history, and state history will be removed.
6
6
  This cannot be undone.
@@ -1,6 +1,6 @@
1
1
  ## Example
2
2
 
3
- $ terraspace cloud list
3
+ $ terraspace tfc list
4
4
  Workspaces for boltops:
5
5
  demo-dev-us-west-2
6
6
  demo2-dev-us-west-2
@@ -2,7 +2,7 @@
2
2
 
3
3
  Statuses of pending and planned are shown by default.
4
4
 
5
- $ terraspace cloud runs list demo
5
+ $ terraspace tfc runs list demo
6
6
  +----------------------+---------+---------------------------------+---------------------+
7
7
  | Id | Status | Message | Created At |
8
8
  +----------------------+---------+---------------------------------+---------------------+
@@ -13,7 +13,7 @@ Statuses of pending and planned are shown by default.
13
13
 
14
14
  To see all most recent runs, use `--status all`.
15
15
 
16
- $ terraspace cloud runs list demo --status all
16
+ $ terraspace tfc runs list demo --status all
17
17
  +----------------------+-----------+--------------------------------+---------------------+
18
18
  | Id | Status | Message | Created At |
19
19
  +----------------------+-----------+--------------------------------+---------------------+
@@ -26,7 +26,7 @@ To see all most recent runs, use `--status all`.
26
26
 
27
27
  You can provide a list of statuses to the `--status` filter option.
28
28
 
29
- $ terraspace cloud runs list demo --status canceled discarded
29
+ $ terraspace tfc runs list demo --status canceled discarded
30
30
  +----------------------+-----------+--------------------------------+---------------------+
31
31
  | Id | Status | Message | Created At |
32
32
  +----------------------+-----------+--------------------------------+---------------------+
@@ -2,12 +2,12 @@ This leaves the top run alone. The top run usually starts immediately planning o
2
2
 
3
3
  ## Examples
4
4
 
5
- terraspace cloud runs prune demo --noop
6
- terraspace cloud runs prune demo # live run
5
+ terraspace tfc runs prune demo --noop
6
+ terraspace tfc runs prune demo # live run
7
7
 
8
8
  ## Example with Output
9
9
 
10
- $ terraspace cloud runs prune demo
10
+ $ terraspace tfc runs prune demo
11
11
  Will keep:
12
12
 
13
13
  run-9muMrjrd22vhsP4u pending test 2020-09-18T12:47:11
@@ -2,7 +2,7 @@
2
2
 
3
3
  Sync all stacks:
4
4
 
5
- $ terraspace cloud sync
5
+ $ terraspace tfc sync
6
6
  About to sync these project stacks with Terraform Cloud workspaces:
7
7
 
8
8
  Stack => Workspace
@@ -22,7 +22,7 @@ Sync all stacks:
22
22
 
23
23
  Sync specific stacks:
24
24
 
25
- $ terraspace cloud sync demo
25
+ $ terraspace tfc sync demo
26
26
  About to sync these project stacks with Terraform Cloud workspaces:
27
27
 
28
28
  Stack => Workspace
@@ -40,4 +40,4 @@ Sync specific stacks:
40
40
 
41
41
  Can also specify multiple stacks:
42
42
 
43
- terraspace cloud sync demo demo2
43
+ terraspace tfc sync demo demo2
@@ -3,10 +3,9 @@ require 'timeout'
3
3
  class Terraspace::CLI
4
4
  class Init < Base
5
5
  def initialize(options={})
6
- # Original calling command. Can be from Commander which is a terraform command. IE: terraform apply
7
- # Or can be from terraspace cloud setup. Which will be cloud-setup.
8
- @calling_command = options[:calling_command]
9
- super(options)
6
+ # terraform init output goes to default Terraspace.logger.info which is stderr
7
+ # Unless the logger has been overridden.
8
+ super(options.merge(log_to_stderr: true))
10
9
  end
11
10
 
12
11
  def run
@@ -29,7 +28,11 @@ class Terraspace::CLI
29
28
  end
30
29
 
31
30
  def sync_cloud
32
- Terraspace::Terraform::Cloud::Sync.new(@options).run if %w[apply plan destroy cloud-setup].include?(@calling_command)
31
+ Terraspace::Terraform::Tfc::Sync.new(@options).run if sync_cloud?
32
+ end
33
+
34
+ def sync_cloud?
35
+ %w[apply down plan up].include?(calling_command)
33
36
  end
34
37
 
35
38
  # Currently only handles remote modules only one-level deep.
@@ -54,16 +57,21 @@ class Terraspace::CLI
54
57
 
55
58
  def auto?
56
59
  # command is only passed from CLI in the update specifically for this check
57
- @options[:auto] && @calling_command == "apply"
60
+ @options[:auto] && calling_command == "up"
58
61
  end
59
62
  private
60
63
  def local_source?(s)
61
64
  s =~ %r{^\.} || s =~ %r{^/}
62
65
  end
63
66
 
67
+ def auto_init?
68
+ # terraspace commands not terraform commands. included some extra terraform commands here in case terrapace adds those later
69
+ commands = %w[all apply console down output plan providers refresh show state up validate]
70
+ commands.include?(calling_command)
71
+ end
72
+
64
73
  def run_init?
65
- commands = %w[apply console destroy output plan providers refresh show validate cloud-setup]
66
- return false unless commands.include?(@calling_command)
74
+ return false unless auto_init?
67
75
  mode = ENV['TS_INIT_MODE'] || Terraspace.config.init.mode
68
76
  case mode.to_sym
69
77
  when :auto
@@ -87,5 +95,10 @@ class Terraspace::CLI
87
95
  end
88
96
  !!provider
89
97
  end
98
+
99
+ # only top level command considered
100
+ def calling_command
101
+ ARGV[0]
102
+ end
90
103
  end
91
104
  end