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
@@ -0,0 +1,6 @@
1
+ ## Example
2
+
3
+ $ terraspace build
4
+ Building .terraspace-cache/us-west-2/dev/stacks/demo
5
+ Built in .terraspace-cache/us-west-2/dev/stacks/demo
6
+ $
@@ -4,11 +4,15 @@
4
4
 
5
5
  ## More commands
6
6
 
7
- terraspace bundle install # same as bundle
8
- terraspace bundle update # Updates Terrafile.lock
9
- terraspace bundle clean # removes /tmp terraspace bundler folder
7
+ terraspace bundle install # same as bundle
8
+ terraspace bundle update # Updates Terrafile.lock
9
+ terraspace bundle purge_cache # removes /tmp terraspace bundler folder
10
10
 
11
11
  ## Update a single module
12
12
 
13
- terraspace bundle update MOD_NAME
14
- terraspace bundle update demo
13
+ terraspace bundle update MODULE
14
+ terraspace bundle update demo
15
+
16
+ ## Info on a module
17
+
18
+ terraspace bundle info MODULE
@@ -0,0 +1,9 @@
1
+ ## Example
2
+
3
+ $ terraspace check_setup
4
+ Detected Terrspace version: 0.3.3
5
+ Detected Terraform bin: /home/ec2-user/.tfenv/bin/terraform
6
+ Detected Terraform v0.13.2
7
+ Terraspace requires Terraform v0.12.x and above
8
+ You're all set!
9
+ $
@@ -0,0 +1,10 @@
1
+ ## Examples
2
+
3
+ $ terraspace clean all
4
+ Will remove Terraspace cache and logs.
5
+ Are you sure? (y/N) y
6
+ Removed .terraspace-cache
7
+ Removed /tmp/terraspace
8
+ Removing all files in log/
9
+ Logs removed
10
+ $
@@ -0,0 +1,12 @@
1
+ ## Example
2
+
3
+ $ terraspace clean cache
4
+ Will remove these folders and all their files:
5
+
6
+ .terraspace-cache
7
+ /tmp/terraspace
8
+
9
+ Are you sure? (y/N)
10
+ Removed .terraspace-cache
11
+ Removed /tmp/terraspace
12
+ $
@@ -0,0 +1,17 @@
1
+ ## Examples
2
+
3
+ Remove logs completely:
4
+
5
+ $ terraspace clean logs
6
+ Will remove all the log files in log/ folder
7
+ Are you sure? (y/N) y
8
+ Removing all files in log/
9
+ Logs removed
10
+
11
+ Truncate logs. IE: Keeps the files but removes contents and zero bytes the files.
12
+
13
+ $ terraspace clean logs --truncate
14
+ Will truncate all the log files in log/ folder
15
+ Are you sure? (y/N) y
16
+ Logs truncated
17
+ $
@@ -0,0 +1,16 @@
1
+ ## Example
2
+
3
+ $ terraspace cloud destroy demo
4
+ You are about to delete the workspace: demo-dev-us-west-2
5
+ All variables, settings, run history, and state history will be removed.
6
+ This cannot be undone.
7
+
8
+ This will NOT remove any infrastructure managed by this workspace.
9
+ If needed, destroy the infrastructure prior to deleting the workspace with:
10
+
11
+ terraspace down demo
12
+
13
+ This will delete the workspace: demo-dev-us-west-2.
14
+ Are you sure? (y/N) y
15
+ Destroying workspace demo-dev-us-west-2
16
+ $
@@ -0,0 +1,7 @@
1
+ ## Example
2
+
3
+ $ terraspace cloud list
4
+ Workspaces for boltops:
5
+ demo-dev-us-west-2
6
+ demo2-dev-us-west-2
7
+ $
@@ -2,7 +2,7 @@
2
2
 
3
3
  Statuses of pending and planned are shown by default.
4
4
 
5
- $ terraspace cloud runs list pet
5
+ $ terraspace cloud 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 pet --status all
16
+ $ terraspace cloud 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 pet --status canceled discarded
29
+ $ terraspace cloud runs list demo --status canceled discarded
30
30
  +----------------------+-----------+--------------------------------+---------------------+
31
31
  | Id | Status | Message | Created At |
32
32
  +----------------------+-----------+--------------------------------+---------------------+
@@ -1,4 +1,4 @@
1
- This leaves the to most recent run alone. The top run will immediately start planning. Runs that are also in "Needs Confirmation" will be cancelled.
1
+ This leaves the top run alone. The top run usually starts immediately planning once the other runs are pruned. Runs that are also in "Needs Confirmation" will be cancelled.
2
2
 
3
3
  ## Examples
4
4
 
@@ -7,7 +7,7 @@ This leaves the to most recent run alone. The top run will immediately start pla
7
7
 
8
8
  ## Example with Output
9
9
 
10
- $ terraspace cloud runs prune pet
10
+ $ terraspace cloud runs prune demo
11
11
  Will keep:
12
12
 
13
13
  run-9muMrjrd22vhsP4u pending test 2020-09-18T12:47:11
@@ -1,4 +1,6 @@
1
- ## Example
1
+ ## Examples
2
+
3
+ Sync all stacks:
2
4
 
3
5
  $ terraspace cloud sync
4
6
  About to sync these project stacks with Terraform Cloud workspaces:
@@ -16,4 +18,26 @@
16
18
  Are you sure? (y/N) y
17
19
  Syncing to Terraform Cloud: demo => demo-dev-us-west-2
18
20
  Syncing to Terraform Cloud: demo2 => demo2-dev-us-west-2
19
- $
21
+ $
22
+
23
+ Sync specific stacks:
24
+
25
+ $ terraspace cloud sync demo
26
+ About to sync these project stacks with Terraform Cloud workspaces:
27
+
28
+ Stack => Workspace
29
+ demo => demo-dev-us-west-2
30
+
31
+ A sync does the following for each workspace:
32
+
33
+ 1. Create or update workspace, including the VCS settings.
34
+ 2. Set the working dir.
35
+ 3. Set env and terraform variables.
36
+
37
+ Are you sure? (y/N) y
38
+ Syncing to Terraform Cloud: demo => demo-dev-us-west-2
39
+ $
40
+
41
+ Can also specify multiple stacks:
42
+
43
+ terraspace cloud sync demo demo2
@@ -0,0 +1,8 @@
1
+ ## Example
2
+
3
+ $ terraspace console demo
4
+ Building .terraspace-cache/us-west-2/dev/stacks/demo
5
+ Built in .terraspace-cache/us-west-2/dev/stacks/demo
6
+ Current directory: .terraspace-cache/us-west-2/dev/stacks/demo
7
+ => terraform console
8
+ >
@@ -0,0 +1,26 @@
1
+ ## Example
2
+
3
+ $ terraspace down demo
4
+ Building .terraspace-cache/us-west-2/dev/stacks/demo
5
+ Built in .terraspace-cache/us-west-2/dev/stacks/demo
6
+ Current directory: .terraspace-cache/us-west-2/dev/stacks/demo
7
+ => terraform destroy
8
+ # ...
9
+ Plan: 0 to add, 0 to change, 2 to destroy.
10
+
11
+ Changes to Outputs:
12
+ - bucket_name = "bucket-trusty-marmoset" -> null
13
+
14
+ Do you really want to destroy all resources?
15
+ Terraform will destroy all your managed infrastructure, as shown above.
16
+ There is no undo. Only 'yes' will be accepted to confirm.
17
+ Enter a value: yes
18
+
19
+ module.bucket.aws_s3_bucket.this: Destroying... [id=bucket-trusty-marmoset]
20
+ module.bucket.aws_s3_bucket.this: Destruction complete after 0s
21
+ random_pet.this: Destroying... [id=trusty-marmoset]
22
+ random_pet.this: Destruction complete after 0s
23
+
24
+ Destroy complete! Resources: 2 destroyed.
25
+ Time took: 21s
26
+ $
@@ -0,0 +1,43 @@
1
+ ## Example
2
+
3
+ $ terraspace info demo
4
+ +-----------+---------------------------------------------+
5
+ | Name | Value |
6
+ +-----------+---------------------------------------------+
7
+ | build_dir | stacks/demo |
8
+ | cache_dir | .terraspace-cache/us-west-2/dev/stacks/demo |
9
+ | name | demo |
10
+ | root | app/stacks/demo |
11
+ | type | stack |
12
+ | type_dir | stacks |
13
+ +-----------+---------------------------------------------+
14
+
15
+ You can also format the output in json:
16
+
17
+ $ terraspace info demo --format json
18
+ [
19
+ {
20
+ "Name": "build_dir",
21
+ "Value": "stacks/demo"
22
+ },
23
+ {
24
+ "Name": "cache_dir",
25
+ "Value": ".terraspace-cache/us-west-2/dev/stacks/demo"
26
+ },
27
+ {
28
+ "Name": "name",
29
+ "Value": "demo"
30
+ },
31
+ {
32
+ "Name": "root",
33
+ "Value": "app/stacks/demo"
34
+ },
35
+ {
36
+ "Name": "type",
37
+ "Value": "stack"
38
+ },
39
+ {
40
+ "Name": "type_dir",
41
+ "Value": "stacks"
42
+ }
43
+ ]
@@ -0,0 +1,37 @@
1
+ Typically, Terrasapce auto init should handle initialization. You can run init if you need to though.
2
+
3
+ ## Example
4
+
5
+ $ terraspace init demo
6
+ Building .terraspace-cache/us-west-2/dev/stacks/demo
7
+ Built in .terraspace-cache/us-west-2/dev/stacks/demo
8
+ Current directory: .terraspace-cache/us-west-2/dev/stacks/demo
9
+ => terraform init -get
10
+ Initializing modules...
11
+
12
+ Initializing the backend...
13
+
14
+ Initializing provider plugins...
15
+ - Using previously-installed hashicorp/aws v3.7.0
16
+ - Using previously-installed hashicorp/random v2.3.0
17
+
18
+ The following providers do not have any version constraints in configuration,
19
+ so the latest version was installed.
20
+
21
+ To prevent automatic upgrades to new major versions that may contain breaking
22
+ changes, we recommend adding version constraints in a required_providers block
23
+ in your configuration, with the constraint strings suggested below.
24
+
25
+ * hashicorp/aws: version = "~> 3.7.0"
26
+ * hashicorp/random: version = "~> 2.3.0"
27
+
28
+ Terraform has been successfully initialized!
29
+
30
+ You may now begin working with Terraform. Try running "terraform plan" to see
31
+ any changes that are required for your infrastructure. All Terraform commands
32
+ should now work.
33
+
34
+ If you ever set or change modules or backend configuration for Terraform,
35
+ rerun this command to reinitialize your working directory. If you forget, other
36
+ commands will detect it and remind you to do so if necessary.
37
+ $
@@ -0,0 +1,20 @@
1
+ ## Examples
2
+
3
+ List both modules and stacks.
4
+
5
+ $ terraspace list
6
+ app/modules/example
7
+ app/stacks/demo
8
+ $
9
+
10
+ List only stacks.
11
+
12
+ $ terraspace list -t stack
13
+ app/stacks/demo
14
+ $
15
+
16
+ List only modules.
17
+
18
+ $ terraspace list -t module
19
+ app/modules/example
20
+ $
@@ -0,0 +1,48 @@
1
+ The log commands will filter out the logs for the last ran terraspace command. It does this by filtering for the last found PID in the log files.
2
+
3
+ ## Quick Start
4
+
5
+ Follow all the logs as you're running `terraspace all up`:
6
+
7
+ terraspace logs -f
8
+
9
+ Note, Terraspace automatically checks every second for new logs and adds them to be followed.
10
+
11
+ ## View Logs
12
+
13
+ View last 10 lines of each log file.
14
+
15
+ terraspace logs up network # view up log on specific stack
16
+ terraspace logs up # view all up logs
17
+ terraspace logs down # view all down logs
18
+ terraspace logs # view all logs: up, down, etc
19
+
20
+ By default, the log command shows the last 10 lines of the logs for each log file. You can use the `-n` option to adjust this.
21
+
22
+ terraspace logs -n 2 # view last 2 lines of all logs: up, down, etc
23
+
24
+ To show all logs, use the `-a` option.
25
+
26
+ terraspace logs up -a
27
+
28
+ Note, if both an action and stack is specified, then it defaults to showing all logs. If you want not to show all logs, use `--no-all`.
29
+
30
+ ## Tail Logs
31
+
32
+ To tail logs, use the `-f` option.
33
+
34
+ terraspace logs up network -f # view up log on specific stack
35
+ terraspace logs up -f # view all up logs
36
+ terraspace logs down -f # view all down logs
37
+ terraspace logs -f # view all logs: up, down, etc
38
+
39
+ ## Timestamps
40
+
41
+ The timestamps are shown by default when you are looking for multiple files. When you specify both the action and stack for a single log file, then timestamps are not shown.
42
+
43
+ terraspace logs up # timestamps will be shown in this case
44
+ terraspace logs up network # timestamps not be shown in this case
45
+
46
+ To show timestamps:
47
+
48
+ terraspace logs up network --timestamps
@@ -0,0 +1,5 @@
1
+ ## Example
2
+
3
+ $ terraspace logs remove
4
+ Removing all files in log/
5
+ $
@@ -0,0 +1,5 @@
1
+ ## Example
2
+
3
+ $ terraspace logs truncate
4
+ Truncating log files in log/
5
+ $
@@ -0,0 +1,8 @@
1
+ ## Example
2
+
3
+ $ terraspace new bootstrap_test
4
+ => Creating test bootstrap structure
5
+ exist
6
+ create .rspec
7
+ create spec/spec_helper.rb
8
+ $
@@ -0,0 +1,8 @@
1
+ ## Example
2
+
3
+ => Creating test for new module: example
4
+ create app/modules/example
5
+ create app/modules/example/main.tf
6
+ create app/modules/example/outputs.tf
7
+ create app/modules/example/variables.tf
8
+ $
@@ -0,0 +1,6 @@
1
+ ## Example
2
+
3
+ $ terraspace new git_hook
4
+ create .git/hooks/pre-push
5
+ chmod .git/hooks/pre-push
6
+ $
@@ -0,0 +1,9 @@
1
+ ## Example
2
+
3
+ $ terraspace new module example
4
+ => Creating test for new module: example
5
+ create app/modules/example
6
+ create app/modules/example/main.tf
7
+ create app/modules/example/outputs.tf
8
+ create app/modules/example/variables.tf
9
+ $
@@ -0,0 +1,12 @@
1
+ ## Example
2
+
3
+ $ terraspace new module_test example
4
+ => Creating module test: example
5
+ exist app/modules/example
6
+ create app/modules/example/test/.rspec
7
+ create app/modules/example/test/Gemfile
8
+ create app/modules/example/test/spec/fixtures/stack/main.tf
9
+ create app/modules/example/test/spec/fixtures/stack/outputs.tf
10
+ create app/modules/example/test/spec/main_spec.rb
11
+ create app/modules/example/test/spec/spec_helper.rb
12
+ $