terraspace 0.3.5 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -0
  3. data/README.md +56 -29
  4. data/lib/templates/base/project/README.md +1 -1
  5. data/lib/terraspace/all/runner.rb +1 -0
  6. data/lib/terraspace/all/summary.rb +8 -1
  7. data/lib/terraspace/app.rb +9 -5
  8. data/lib/terraspace/builder.rb +10 -6
  9. data/lib/terraspace/cli.rb +12 -16
  10. data/lib/terraspace/cli/all.rb +6 -0
  11. data/lib/terraspace/cli/bundle.rb +2 -1
  12. data/lib/terraspace/cli/clean.rb +18 -6
  13. data/lib/terraspace/cli/clean/all.rb +18 -0
  14. data/lib/terraspace/cli/clean/base.rb +15 -0
  15. data/lib/terraspace/cli/clean/cache.rb +25 -0
  16. data/lib/terraspace/cli/{logs/tasks.rb → clean/logs.rb} +16 -5
  17. data/lib/terraspace/cli/help/all/init.md +33 -0
  18. data/lib/terraspace/cli/help/clean/all.md +10 -0
  19. data/lib/terraspace/cli/help/clean/cache.md +12 -0
  20. data/lib/terraspace/cli/help/clean/logs.md +17 -0
  21. data/lib/terraspace/cli/help/logs.md +48 -0
  22. data/lib/terraspace/cli/info.rb +12 -0
  23. data/lib/terraspace/cli/init.rb +3 -7
  24. data/lib/terraspace/cli/list.rb +2 -1
  25. data/lib/terraspace/cli/logs.rb +106 -9
  26. data/lib/terraspace/cli/{log → logs}/concern.rb +2 -1
  27. data/lib/terraspace/cli/new/helper.rb +9 -2
  28. data/lib/terraspace/dependency/helper/output.rb +1 -1
  29. data/lib/terraspace/hooks/builder.rb +52 -0
  30. data/lib/terraspace/hooks/concern.rb +9 -0
  31. data/lib/terraspace/{terraform/hooks → hooks}/dsl.rb +3 -2
  32. data/lib/terraspace/hooks/runner.rb +23 -0
  33. data/lib/terraspace/mod.rb +11 -2
  34. data/lib/terraspace/plugin/summary/interface.rb +3 -1
  35. data/lib/terraspace/shell.rb +15 -10
  36. data/lib/terraspace/terraform/args/custom.rb +1 -1
  37. data/lib/terraspace/terraform/args/default.rb +9 -19
  38. data/lib/terraspace/terraform/remote_state/output_proxy.rb +3 -3
  39. data/lib/terraspace/terraform/remote_state/{null_object.rb → unresolved.rb} +1 -1
  40. data/lib/terraspace/terraform/runner.rb +3 -8
  41. data/lib/terraspace/version.rb +1 -1
  42. data/spec/terraspace/{terraform/hooks → hooks}/builder_spec.rb +4 -5
  43. data/spec/terraspace/terraform/remote_state/output_proxy_spec.rb +3 -3
  44. data/terraspace.gemspec +1 -1
  45. metadata +21 -14
  46. data/lib/terraspace/cli/help/clean.md +0 -5
  47. data/lib/terraspace/cli/help/log.md +0 -48
  48. data/lib/terraspace/cli/log.rb +0 -112
  49. data/lib/terraspace/terraform/hooks/builder.rb +0 -40
@@ -1,5 +0,0 @@
1
- ## Example
2
-
3
- $ terraspace clean
4
- Removed .terraspace-cache
5
- $
@@ -1,48 +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
- 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 log up network # view up log on specific stack
16
- terraspace log up # view all up logs
17
- terraspace log down # view all down logs
18
- terraspace log # 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 log -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 log 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 log up network -f # view up log on specific stack
35
- terraspace log up -f # view all up logs
36
- terraspace log down -f # view all down logs
37
- terraspace log -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 log up # timestamps will be shown in this case
44
- terraspace log up network # timestamps not be shown in this case
45
-
46
- To show timestamps:
47
-
48
- terraspace up up network --timestamps
@@ -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