terraspace 0.3.3 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) 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 -0
  6. data/README.md +1 -1
  7. data/lib/templates/base/project/README.md +1 -1
  8. data/lib/terraspace.rb +1 -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 +10 -6
  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/init.md +33 -0
  27. data/lib/terraspace/cli/help/all/output.md +22 -0
  28. data/lib/terraspace/cli/help/all/plan.md +25 -0
  29. data/lib/terraspace/cli/help/all/providers.md +21 -0
  30. data/lib/terraspace/cli/help/all/refresh.md +17 -0
  31. data/lib/terraspace/cli/help/all/show.md +21 -0
  32. data/lib/terraspace/cli/help/all/up.md +27 -0
  33. data/lib/terraspace/cli/help/all/validate.md +21 -0
  34. data/lib/terraspace/cli/help/build.md +6 -0
  35. data/lib/terraspace/cli/help/bundle.md +9 -5
  36. data/lib/terraspace/cli/help/check_setup.md +9 -0
  37. data/lib/terraspace/cli/help/clean/all.md +10 -0
  38. data/lib/terraspace/cli/help/clean/cache.md +12 -0
  39. data/lib/terraspace/cli/help/clean/logs.md +17 -0
  40. data/lib/terraspace/cli/help/cloud/destroy.md +16 -0
  41. data/lib/terraspace/cli/help/cloud/list.md +7 -0
  42. data/lib/terraspace/cli/help/cloud/runs/list.md +3 -3
  43. data/lib/terraspace/cli/help/cloud/runs/prune.md +1 -1
  44. data/lib/terraspace/cli/help/cloud/sync.md +26 -2
  45. data/lib/terraspace/cli/help/console.md +8 -0
  46. data/lib/terraspace/cli/help/down.md +26 -0
  47. data/lib/terraspace/cli/help/info.md +43 -0
  48. data/lib/terraspace/cli/help/init.md +37 -0
  49. data/lib/terraspace/cli/help/list.md +20 -0
  50. data/lib/terraspace/cli/help/logs.md +48 -0
  51. data/lib/terraspace/cli/help/logs/remove.md +5 -0
  52. data/lib/terraspace/cli/help/logs/truncate.md +5 -0
  53. data/lib/terraspace/cli/help/new/bootstrap_test.md +8 -0
  54. data/lib/terraspace/cli/help/new/example.md +8 -0
  55. data/lib/terraspace/cli/help/new/git_hook.md +6 -0
  56. data/lib/terraspace/cli/help/new/module.md +9 -0
  57. data/lib/terraspace/cli/help/new/module_test.md +12 -0
  58. data/lib/terraspace/cli/help/new/plugin.md +49 -0
  59. data/lib/terraspace/cli/help/new/project.md +40 -0
  60. data/lib/terraspace/cli/help/new/project_test.md +8 -0
  61. data/lib/terraspace/cli/help/new/shim.md +21 -0
  62. data/lib/terraspace/cli/help/new/stack.md +9 -0
  63. data/lib/terraspace/cli/help/output.md +6 -0
  64. data/lib/terraspace/cli/help/plan.md +29 -0
  65. data/lib/terraspace/cli/help/providers.md +18 -0
  66. data/lib/terraspace/cli/help/refresh.md +11 -0
  67. data/lib/terraspace/cli/help/seed.md +7 -0
  68. data/lib/terraspace/cli/help/show.md +36 -0
  69. data/lib/terraspace/cli/help/summary.md +11 -0
  70. data/lib/terraspace/cli/help/test.md +35 -0
  71. data/lib/terraspace/cli/help/up.md +30 -0
  72. data/lib/terraspace/cli/help/validate.md +9 -0
  73. data/lib/terraspace/cli/info.rb +4 -16
  74. data/lib/terraspace/cli/init.rb +3 -7
  75. data/lib/terraspace/cli/list.rb +2 -1
  76. data/lib/terraspace/cli/logs.rb +106 -9
  77. data/lib/terraspace/cli/{log → logs}/concern.rb +1 -1
  78. data/lib/terraspace/cli/new.rb +18 -18
  79. data/lib/terraspace/cli/new/git_hook.rb +4 -1
  80. data/lib/terraspace/cli/new/helper.rb +9 -2
  81. data/lib/terraspace/cli/new/project.rb +1 -1
  82. data/lib/terraspace/cli/summary.rb +2 -2
  83. data/lib/terraspace/command.rb +1 -1
  84. data/lib/terraspace/compiler/dependencies/helpers.rb +34 -0
  85. data/lib/terraspace/compiler/dsl/syntax/helpers/common.rb +0 -26
  86. data/lib/terraspace/compiler/dsl/syntax/tfvar.rb +1 -0
  87. data/lib/terraspace/compiler/erb/context.rb +1 -1
  88. data/lib/terraspace/compiler/erb/helpers.rb +6 -0
  89. data/lib/terraspace/dependency/graph.rb +2 -1
  90. data/lib/terraspace/dependency/helper/base.rb +7 -0
  91. data/lib/terraspace/dependency/helper/depends_on.rb +12 -0
  92. data/lib/terraspace/dependency/helper/output.rb +11 -0
  93. data/lib/terraspace/hooks/builder.rb +52 -0
  94. data/lib/terraspace/hooks/concern.rb +9 -0
  95. data/lib/terraspace/{terraform/hooks → hooks}/dsl.rb +3 -2
  96. data/lib/terraspace/hooks/runner.rb +23 -0
  97. data/lib/terraspace/mod.rb +11 -2
  98. data/lib/terraspace/plugin/summary/interface.rb +4 -2
  99. data/lib/terraspace/shell.rb +29 -14
  100. data/lib/terraspace/terraform/args/custom.rb +1 -1
  101. data/lib/terraspace/terraform/cloud/runs/lister.rb +0 -2
  102. data/lib/terraspace/terraform/cloud/syncer.rb +2 -2
  103. data/lib/terraspace/terraform/cloud/workspace.rb +0 -9
  104. data/lib/terraspace/terraform/remote_state/fetcher.rb +13 -4
  105. data/lib/terraspace/terraform/remote_state/marker/output.rb +3 -1
  106. data/lib/terraspace/terraform/remote_state/output_proxy.rb +18 -14
  107. data/lib/terraspace/terraform/remote_state/unresolved.rb +40 -0
  108. data/lib/terraspace/terraform/runner.rb +2 -7
  109. data/lib/terraspace/version.rb +1 -1
  110. data/spec/fixtures/dependencies/app/stacks/a1/tfvars/dev.tfvars +1 -0
  111. data/spec/fixtures/fetcher/c1.json +4 -0
  112. data/spec/terraspace/all/summary_spec.rb +1 -1
  113. data/spec/terraspace/compiler/erb/render_spec.rb +15 -0
  114. data/spec/terraspace/dependency/helper/depends_on_spec.rb +27 -0
  115. data/spec/terraspace/dependency/helper/output_spec.rb +29 -0
  116. data/spec/terraspace/{terraform/hooks → hooks}/builder_spec.rb +4 -5
  117. data/spec/terraspace/terraform/remote_state/fetcher_spec.rb +108 -27
  118. data/spec/terraspace/terraform/remote_state/marker/output_spec.rb +36 -0
  119. data/spec/terraspace/terraform/remote_state/output_proxy_spec.rb +69 -0
  120. data/terraspace.gemspec +1 -1
  121. metadata +78 -13
  122. data/lib/terraspace/cli/help/log.md +0 -46
  123. data/lib/terraspace/cli/help/update.md +0 -5
  124. data/lib/terraspace/cli/log.rb +0 -112
  125. data/lib/terraspace/terraform/hooks/builder.rb +0 -40
@@ -1,46 +0,0 @@
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 log -f
8
-
9
- ## View Logs
10
-
11
- View last 10 lines of each log file.
12
-
13
- terraspace log up network # view up log on specific stack
14
- terraspace log up # view all up logs
15
- terraspace log down # view all down logs
16
- terraspace log # view all logs: up, down, etc
17
-
18
- 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.
19
-
20
- terraspace log -n 2 # view last 2 lines of all logs: up, down, etc
21
-
22
- To show all logs, use the `-a` option.
23
-
24
- terraspace log up -a
25
-
26
- 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`.
27
-
28
- ## Tail Logs
29
-
30
- To tail logs, use the `-f` option.
31
-
32
- terraspace log up network -f # view up log on specific stack
33
- terraspace log up -f # view all up logs
34
- terraspace log down -f # view all down logs
35
- terraspace log -f # view all logs: up, down, etc
36
-
37
- ## Timestamps
38
-
39
- 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.
40
-
41
- terraspace log up # timestamps will be shown in this case
42
- terraspace log up network # timestamps not be shown in this case
43
-
44
- To show timestamps:
45
-
46
- terraspace up up network --timestamps
@@ -1,5 +0,0 @@
1
- ## Examples
2
-
3
- terraspace update MODULE
4
- terraspace update instance
5
- terraspace up instance
@@ -1,112 +0,0 @@
1
- require "eventmachine"
2
- require "eventmachine-tail"
3
-
4
- class Terraspace::CLI
5
- class Log < Base
6
- include Log::Concern
7
-
8
- def initialize(options={})
9
- super
10
- @action, @stack = options[:action], options[:stack]
11
- @action ||= '**'
12
- @stack ||= '*'
13
- end
14
-
15
- def run
16
- check_logs!
17
- if @options[:follow]
18
- follow_logs
19
- else
20
- all_log_paths.each { |path| show_log(path) }
21
- end
22
- end
23
-
24
- def follow_logs
25
- glob_path = "#{Terraspace.log_root}/#{@action}/#{@stack}.log"
26
- Dir.glob(glob_path).each do |path|
27
- puts "Following #{pretty(path)}".color(:purple)
28
- end
29
- EventMachine.run do
30
- interval = Integer(ENV['TS_LOG_GLOB_INTERNAL'] || 1)
31
- EventMachine::FileGlobWatchTail.new(glob_path, nil, interval) do |filetail, line|
32
- puts line # always show timestamp in follow mode
33
- end
34
- end
35
- end
36
-
37
- def show_log(path)
38
- report_log(path)
39
- lines = readlines(path)
40
- lines = apply_limit(lines)
41
- lines.each do |line|
42
- puts format(line)
43
- end
44
- end
45
-
46
- def report_log(path)
47
- pretty_path = pretty(path)
48
- if File.exist?(path)
49
- puts "Showing: #{pretty_path}".color(:purple)
50
- end
51
- end
52
-
53
- def format(line)
54
- if timestamps
55
- line
56
- else
57
- line.sub(/.*\]: /,'')
58
- end
59
- end
60
-
61
- def all_log_paths
62
- Dir.glob("#{Terraspace.log_root}/#{@action}/#{@stack}.log")
63
- end
64
-
65
- def check_logs!
66
- return unless all_log_paths.empty?
67
- puts "WARN: No logs found".color(:yellow)
68
- end
69
-
70
- # Only need to check if both action and stack are provided. Otherwise the Dir.globs are used to discover the files
71
- def check_log!
72
- return unless single_log?
73
- path = "#{Terraspace.log_root}/#{@action}/#{@stack}.log"
74
- return if File.exist?(path)
75
- puts "ERROR: Log file was not found: #{pretty(path)}".color(:red)
76
- exit 1
77
- end
78
-
79
- def single_log?
80
- @action != '**' && @stack != '*'
81
- end
82
-
83
- def apply_limit(lines)
84
- return lines if all
85
- left = limit * -1
86
- lines[left..-1] || []
87
- end
88
-
89
- def all
90
- if single_log?
91
- @options[:all].nil? ? true : @options[:all]
92
- else # multiple
93
- @options[:all].nil? ? false : @options[:all]
94
- end
95
- end
96
-
97
- def limit
98
- @options[:limit].nil? ? 10 : @options[:limit]
99
- end
100
-
101
- def timestamps
102
- if single_log?
103
- @options[:timestamps].nil? ? false : @options[:timestamps]
104
- else
105
- @options[:timestamps].nil? ? true : @options[:timestamps]
106
- end
107
- end
108
- def pretty(path)
109
- Terraspace::Util.pretty_path(path)
110
- end
111
- end
112
- end
@@ -1,40 +0,0 @@
1
- module Terraspace::Terraform::Hooks
2
- class Builder
3
- extend Memoist
4
- include Dsl
5
- include DslEvaluator
6
- include Terraspace::Util
7
-
8
- attr_accessor :name
9
- def initialize(mod, name)
10
- @mod, @name = mod, name
11
- @file = "#{Terraspace.root}/config/cli/hooks.rb"
12
- @hooks = {before: {}, after: {}}
13
- end
14
-
15
- def build
16
- return @hooks unless File.exist?(@file)
17
- evaluate_file(@file)
18
- @hooks.deep_stringify_keys!
19
- end
20
- memoize :build
21
-
22
- def run_hooks
23
- build
24
- run_hook("before")
25
- yield if block_given?
26
- run_hook("after")
27
- end
28
-
29
- def run_hook(type)
30
- execute = @hooks.dig(type, @name.to_s, "execute")
31
- return unless execute
32
-
33
- exit_on_fail = @hooks.dig(type, @name.to_s, "exit_on_fail")
34
- exit_on_fail = exit_on_fail.nil? ? true : exit_on_fail
35
-
36
- logger.info "Running #{type} hook"
37
- Terraspace::Shell.new(@mod, execute, exit_on_fail: exit_on_fail).run
38
- end
39
- end
40
- end