terraspace 0.3.6 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/lib/templates/base/project/README.md +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 +10 -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} +8 -9
- 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/{log.md → logs.md} +14 -14
- data/lib/terraspace/cli/init.rb +3 -7
- data/lib/terraspace/cli/logs.rb +105 -10
- data/lib/terraspace/cli/{log → logs}/concern.rb +1 -1
- data/lib/terraspace/cli/new/helper.rb +9 -2
- data/lib/terraspace/dependency/helper/output.rb +1 -1
- 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/remote_state/output_proxy.rb +3 -3
- data/lib/terraspace/terraform/remote_state/{null_object.rb → unresolved.rb} +1 -1
- data/lib/terraspace/terraform/runner.rb +2 -7
- data/lib/terraspace/version.rb +1 -1
- data/spec/terraspace/{terraform/hooks → hooks}/builder_spec.rb +4 -5
- data/spec/terraspace/terraform/remote_state/output_proxy_spec.rb +3 -3
- data/terraspace.gemspec +1 -1
- metadata +20 -14
- data/lib/terraspace/cli/help/clean.md +0 -5
- data/lib/terraspace/cli/log.rb +0 -112
- data/lib/terraspace/terraform/hooks/builder.rb +0 -40
data/lib/terraspace/version.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
describe Terraspace::
|
1
|
+
describe Terraspace::Hooks::Builder do
|
2
2
|
let(:builder) do
|
3
|
-
builder = described_class.new(mod, name)
|
4
|
-
builder.instance_variable_set(:@file, file) # override @file for spec
|
3
|
+
builder = described_class.new(mod, dsl_file, name)
|
5
4
|
builder
|
6
5
|
end
|
7
6
|
let(:mod) do
|
@@ -11,7 +10,7 @@ describe Terraspace::Terraform::Hooks::Builder do
|
|
11
10
|
end
|
12
11
|
|
13
12
|
context "single" do
|
14
|
-
let(:
|
13
|
+
let(:dsl_file) { fixture("terraform/hooks/single.rb") }
|
15
14
|
let(:name) { "apply" }
|
16
15
|
it "build creates the @hooks structure" do
|
17
16
|
hooks = builder.build
|
@@ -25,7 +24,7 @@ describe Terraspace::Terraform::Hooks::Builder do
|
|
25
24
|
end
|
26
25
|
|
27
26
|
context "multiple" do
|
28
|
-
let(:
|
27
|
+
let(:dsl_file) { fixture("terraform/hooks/multiple.rb") }
|
29
28
|
let(:name) { "apply" }
|
30
29
|
it "build creates the @hooks structure" do
|
31
30
|
hooks = builder.build
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
Unresolved = Terraspace::Terraform::RemoteState::Unresolved
|
2
2
|
|
3
3
|
describe Terraspace::Terraform::RemoteState::OutputProxy do
|
4
4
|
let(:proxy) do
|
@@ -10,9 +10,9 @@ describe Terraspace::Terraform::RemoteState::OutputProxy do
|
|
10
10
|
|
11
11
|
context "unresolved" do
|
12
12
|
before(:each) { mod.resolved = false }
|
13
|
-
it "always return
|
13
|
+
it "always return Unresolved" do
|
14
14
|
value = proxy.to_s
|
15
|
-
expect(value).to be_a(
|
15
|
+
expect(value).to be_a(Unresolved)
|
16
16
|
expect(value.to_str).to eq "(unresolved)"
|
17
17
|
end
|
18
18
|
end
|
data/terraspace.gemspec
CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_dependency "memoist"
|
29
29
|
spec.add_dependency "rainbow"
|
30
30
|
spec.add_dependency "render_me_pretty"
|
31
|
-
spec.add_dependency "terraspace-bundler", "~> 0.
|
31
|
+
spec.add_dependency "terraspace-bundler", "~> 0.3.0"
|
32
32
|
spec.add_dependency "thor"
|
33
33
|
spec.add_dependency "tty-tree"
|
34
34
|
spec.add_dependency "zeitwerk"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: terraspace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tung Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -156,14 +156,14 @@ dependencies:
|
|
156
156
|
requirements:
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: 0.
|
159
|
+
version: 0.3.0
|
160
160
|
type: :runtime
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: 0.
|
166
|
+
version: 0.3.0
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: thor
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -470,6 +470,10 @@ files:
|
|
470
470
|
- lib/terraspace/cli/bundle.rb
|
471
471
|
- lib/terraspace/cli/check_setup.rb
|
472
472
|
- lib/terraspace/cli/clean.rb
|
473
|
+
- lib/terraspace/cli/clean/all.rb
|
474
|
+
- lib/terraspace/cli/clean/base.rb
|
475
|
+
- lib/terraspace/cli/clean/cache.rb
|
476
|
+
- lib/terraspace/cli/clean/logs.rb
|
473
477
|
- lib/terraspace/cli/cloud.rb
|
474
478
|
- lib/terraspace/cli/cloud/runs.rb
|
475
479
|
- lib/terraspace/cli/commander.rb
|
@@ -487,7 +491,9 @@ files:
|
|
487
491
|
- lib/terraspace/cli/help/build.md
|
488
492
|
- lib/terraspace/cli/help/bundle.md
|
489
493
|
- lib/terraspace/cli/help/check_setup.md
|
490
|
-
- lib/terraspace/cli/help/clean.md
|
494
|
+
- lib/terraspace/cli/help/clean/all.md
|
495
|
+
- lib/terraspace/cli/help/clean/cache.md
|
496
|
+
- lib/terraspace/cli/help/clean/logs.md
|
491
497
|
- lib/terraspace/cli/help/cloud/destroy.md
|
492
498
|
- lib/terraspace/cli/help/cloud/list.md
|
493
499
|
- lib/terraspace/cli/help/cloud/runs/list.md
|
@@ -500,7 +506,7 @@ files:
|
|
500
506
|
- lib/terraspace/cli/help/info.md
|
501
507
|
- lib/terraspace/cli/help/init.md
|
502
508
|
- lib/terraspace/cli/help/list.md
|
503
|
-
- lib/terraspace/cli/help/
|
509
|
+
- lib/terraspace/cli/help/logs.md
|
504
510
|
- lib/terraspace/cli/help/logs/remove.md
|
505
511
|
- lib/terraspace/cli/help/logs/truncate.md
|
506
512
|
- lib/terraspace/cli/help/new/bootstrap_test.md
|
@@ -526,10 +532,8 @@ files:
|
|
526
532
|
- lib/terraspace/cli/info.rb
|
527
533
|
- lib/terraspace/cli/init.rb
|
528
534
|
- lib/terraspace/cli/list.rb
|
529
|
-
- lib/terraspace/cli/log.rb
|
530
|
-
- lib/terraspace/cli/log/concern.rb
|
531
535
|
- lib/terraspace/cli/logs.rb
|
532
|
-
- lib/terraspace/cli/logs/
|
536
|
+
- lib/terraspace/cli/logs/concern.rb
|
533
537
|
- lib/terraspace/cli/new.rb
|
534
538
|
- lib/terraspace/cli/new/git_hook.rb
|
535
539
|
- lib/terraspace/cli/new/helper.rb
|
@@ -610,6 +614,10 @@ files:
|
|
610
614
|
- lib/terraspace/ext.rb
|
611
615
|
- lib/terraspace/ext/bundler.rb
|
612
616
|
- lib/terraspace/ext/core/module.rb
|
617
|
+
- lib/terraspace/hooks/builder.rb
|
618
|
+
- lib/terraspace/hooks/concern.rb
|
619
|
+
- lib/terraspace/hooks/dsl.rb
|
620
|
+
- lib/terraspace/hooks/runner.rb
|
613
621
|
- lib/terraspace/logger.rb
|
614
622
|
- lib/terraspace/logger/formatter.rb
|
615
623
|
- lib/terraspace/mod.rb
|
@@ -655,13 +663,11 @@ files:
|
|
655
663
|
- lib/terraspace/terraform/cloud/sync.rb
|
656
664
|
- lib/terraspace/terraform/cloud/syncer.rb
|
657
665
|
- lib/terraspace/terraform/cloud/workspace.rb
|
658
|
-
- lib/terraspace/terraform/hooks/builder.rb
|
659
|
-
- lib/terraspace/terraform/hooks/dsl.rb
|
660
666
|
- lib/terraspace/terraform/remote_state/fetcher.rb
|
661
667
|
- lib/terraspace/terraform/remote_state/marker/output.rb
|
662
668
|
- lib/terraspace/terraform/remote_state/marker/pretty_tracer.rb
|
663
|
-
- lib/terraspace/terraform/remote_state/null_object.rb
|
664
669
|
- lib/terraspace/terraform/remote_state/output_proxy.rb
|
670
|
+
- lib/terraspace/terraform/remote_state/unresolved.rb
|
665
671
|
- lib/terraspace/terraform/runner.rb
|
666
672
|
- lib/terraspace/tester.rb
|
667
673
|
- lib/terraspace/tester/finder.rb
|
@@ -791,11 +797,11 @@ files:
|
|
791
797
|
- spec/terraspace/dependency/graph_spec.rb
|
792
798
|
- spec/terraspace/dependency/helper/depends_on_spec.rb
|
793
799
|
- spec/terraspace/dependency/helper/output_spec.rb
|
800
|
+
- spec/terraspace/hooks/builder_spec.rb
|
794
801
|
- spec/terraspace/provider/expander/generic_spec.rb
|
795
802
|
- spec/terraspace/seeder/content_spec.rb
|
796
803
|
- spec/terraspace/seeder_spec.rb
|
797
804
|
- spec/terraspace/terraform/args/custom_spec.rb
|
798
|
-
- spec/terraspace/terraform/hooks/builder_spec.rb
|
799
805
|
- spec/terraspace/terraform/remote_state/fetcher_spec.rb
|
800
806
|
- spec/terraspace/terraform/remote_state/marker/output_spec.rb
|
801
807
|
- spec/terraspace/terraform/remote_state/output_proxy_spec.rb
|
@@ -944,11 +950,11 @@ test_files:
|
|
944
950
|
- spec/terraspace/dependency/graph_spec.rb
|
945
951
|
- spec/terraspace/dependency/helper/depends_on_spec.rb
|
946
952
|
- spec/terraspace/dependency/helper/output_spec.rb
|
953
|
+
- spec/terraspace/hooks/builder_spec.rb
|
947
954
|
- spec/terraspace/provider/expander/generic_spec.rb
|
948
955
|
- spec/terraspace/seeder/content_spec.rb
|
949
956
|
- spec/terraspace/seeder_spec.rb
|
950
957
|
- spec/terraspace/terraform/args/custom_spec.rb
|
951
|
-
- spec/terraspace/terraform/hooks/builder_spec.rb
|
952
958
|
- spec/terraspace/terraform/remote_state/fetcher_spec.rb
|
953
959
|
- spec/terraspace/terraform/remote_state/marker/output_spec.rb
|
954
960
|
- spec/terraspace/terraform/remote_state/output_proxy_spec.rb
|
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
|