terraspace 0.3.4 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +33 -0
- data/README.md +56 -29
- data/lib/templates/base/project/README.md +1 -1
- data/lib/terraspace/all/preview.rb +1 -1
- data/lib/terraspace/all/runner.rb +1 -0
- data/lib/terraspace/all/summary.rb +8 -1
- data/lib/terraspace/app.rb +9 -5
- data/lib/terraspace/builder.rb +10 -6
- data/lib/terraspace/cli.rb +11 -16
- data/lib/terraspace/cli/all.rb +6 -0
- data/lib/terraspace/cli/bundle.rb +2 -1
- data/lib/terraspace/cli/clean.rb +18 -6
- data/lib/terraspace/cli/clean/all.rb +18 -0
- data/lib/terraspace/cli/clean/base.rb +15 -0
- data/lib/terraspace/cli/clean/cache.rb +25 -0
- data/lib/terraspace/cli/{logs/tasks.rb → clean/logs.rb} +16 -5
- data/lib/terraspace/cli/help/all/init.md +33 -0
- data/lib/terraspace/cli/help/clean/all.md +10 -0
- data/lib/terraspace/cli/help/clean/cache.md +12 -0
- data/lib/terraspace/cli/help/clean/logs.md +17 -0
- data/lib/terraspace/cli/help/logs.md +48 -0
- data/lib/terraspace/cli/init.rb +3 -7
- data/lib/terraspace/cli/list.rb +2 -1
- data/lib/terraspace/cli/logs.rb +106 -9
- data/lib/terraspace/cli/{log → logs}/concern.rb +2 -1
- data/lib/terraspace/cli/new/helper.rb +9 -2
- data/lib/terraspace/compiler/dependencies/helpers.rb +34 -0
- data/lib/terraspace/compiler/dsl/syntax/helpers/common.rb +0 -26
- data/lib/terraspace/compiler/dsl/syntax/tfvar.rb +1 -0
- data/lib/terraspace/compiler/erb/context.rb +1 -1
- data/lib/terraspace/compiler/erb/helpers.rb +6 -0
- data/lib/terraspace/dependency/helper/base.rb +7 -0
- data/lib/terraspace/dependency/helper/depends_on.rb +12 -0
- data/lib/terraspace/dependency/helper/output.rb +11 -0
- data/lib/terraspace/hooks/builder.rb +52 -0
- data/lib/terraspace/hooks/concern.rb +9 -0
- data/lib/terraspace/{terraform/hooks → hooks}/dsl.rb +3 -2
- data/lib/terraspace/hooks/runner.rb +23 -0
- data/lib/terraspace/mod.rb +11 -2
- data/lib/terraspace/plugin/summary/interface.rb +3 -1
- data/lib/terraspace/shell.rb +15 -10
- data/lib/terraspace/terraform/args/custom.rb +1 -1
- data/lib/terraspace/terraform/args/default.rb +9 -19
- data/lib/terraspace/terraform/remote_state/fetcher.rb +13 -4
- data/lib/terraspace/terraform/remote_state/marker/output.rb +3 -1
- data/lib/terraspace/terraform/remote_state/output_proxy.rb +18 -14
- data/lib/terraspace/terraform/remote_state/unresolved.rb +40 -0
- data/lib/terraspace/terraform/runner.rb +3 -8
- data/lib/terraspace/version.rb +1 -1
- data/spec/fixtures/dependencies/app/stacks/a1/tfvars/dev.tfvars +1 -0
- data/spec/fixtures/fetcher/c1.json +4 -0
- data/spec/terraspace/compiler/erb/render_spec.rb +15 -0
- data/spec/terraspace/dependency/helper/depends_on_spec.rb +27 -0
- data/spec/terraspace/dependency/helper/output_spec.rb +29 -0
- data/spec/terraspace/{terraform/hooks → hooks}/builder_spec.rb +4 -5
- data/spec/terraspace/terraform/remote_state/fetcher_spec.rb +108 -27
- data/spec/terraspace/terraform/remote_state/marker/output_spec.rb +36 -0
- data/spec/terraspace/terraform/remote_state/output_proxy_spec.rb +69 -0
- data/terraspace.gemspec +1 -1
- metadata +38 -13
- data/lib/terraspace/cli/help/clean.md +0 -5
- data/lib/terraspace/cli/help/log.md +0 -48
- data/lib/terraspace/cli/log.rb +0 -112
- data/lib/terraspace/terraform/hooks/builder.rb +0 -40
@@ -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
|
data/lib/terraspace/cli/log.rb
DELETED
@@ -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
|