terraspace 0.3.6 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +32 -0
  3. data/README.md +57 -30
  4. data/lib/templates/base/project/README.md +1 -1
  5. data/lib/terraspace.rb +3 -1
  6. data/lib/terraspace/all/runner.rb +1 -0
  7. data/lib/terraspace/all/summary.rb +8 -1
  8. data/lib/terraspace/app.rb +9 -5
  9. data/lib/terraspace/builder.rb +10 -6
  10. data/lib/terraspace/cli.rb +12 -16
  11. data/lib/terraspace/cli/all.rb +6 -0
  12. data/lib/terraspace/cli/bundle.rb +2 -1
  13. data/lib/terraspace/cli/clean.rb +18 -6
  14. data/lib/terraspace/cli/clean/all.rb +18 -0
  15. data/lib/terraspace/cli/clean/base.rb +15 -0
  16. data/lib/terraspace/cli/clean/cache.rb +25 -0
  17. data/lib/terraspace/cli/{logs/tasks.rb → clean/logs.rb} +8 -9
  18. data/lib/terraspace/cli/cloud.rb +2 -0
  19. data/lib/terraspace/cli/help/all/init.md +33 -0
  20. data/lib/terraspace/cli/help/clean/all.md +10 -0
  21. data/lib/terraspace/cli/help/clean/cache.md +12 -0
  22. data/lib/terraspace/cli/help/clean/logs.md +17 -0
  23. data/lib/terraspace/cli/help/logs.md +48 -0
  24. data/lib/terraspace/cli/info.rb +12 -0
  25. data/lib/terraspace/cli/init.rb +3 -7
  26. data/lib/terraspace/cli/list.rb +2 -1
  27. data/lib/terraspace/cli/logs.rb +105 -10
  28. data/lib/terraspace/cli/{log → logs}/concern.rb +2 -1
  29. data/lib/terraspace/cli/new/helper.rb +9 -2
  30. data/lib/terraspace/dependency/helper/output.rb +1 -1
  31. data/lib/terraspace/hooks/builder.rb +52 -0
  32. data/lib/terraspace/hooks/concern.rb +9 -0
  33. data/lib/terraspace/{terraform/hooks → hooks}/dsl.rb +3 -2
  34. data/lib/terraspace/hooks/runner.rb +23 -0
  35. data/lib/terraspace/mod.rb +11 -2
  36. data/lib/terraspace/plugin/summary/interface.rb +3 -1
  37. data/lib/terraspace/shell.rb +5 -28
  38. data/lib/terraspace/shell/error.rb +46 -0
  39. data/lib/terraspace/terraform/args/custom.rb +1 -1
  40. data/lib/terraspace/terraform/args/default.rb +9 -19
  41. data/lib/terraspace/terraform/remote_state/output_proxy.rb +3 -3
  42. data/lib/terraspace/terraform/remote_state/{null_object.rb → unresolved.rb} +1 -1
  43. data/lib/terraspace/terraform/runner.rb +8 -21
  44. data/lib/terraspace/terraform/runner/retryer.rb +65 -0
  45. data/lib/terraspace/version.rb +1 -1
  46. data/spec/terraspace/{terraform/hooks → hooks}/builder_spec.rb +4 -5
  47. data/spec/terraspace/terraform/remote_state/output_proxy_spec.rb +3 -3
  48. data/terraspace.gemspec +1 -1
  49. metadata +23 -14
  50. data/lib/terraspace/cli/help/clean.md +0 -5
  51. data/lib/terraspace/cli/help/log.md +0 -48
  52. data/lib/terraspace/cli/log.rb +0 -112
  53. data/lib/terraspace/terraform/hooks/builder.rb +0 -40
@@ -1,3 +1,3 @@
1
1
  module Terraspace
2
- VERSION = "0.3.6"
2
+ VERSION = "0.4.4"
3
3
  end
@@ -1,7 +1,6 @@
1
- describe Terraspace::Terraform::Hooks::Builder do
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(:file) { fixture("terraform/hooks/single.rb") }
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(:file) { fixture("terraform/hooks/multiple.rb") }
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
- NullObject = Terraspace::Terraform::RemoteState::NullObject
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 NullObject" do
13
+ it "always return Unresolved" do
14
14
  value = proxy.to_s
15
- expect(value).to be_a(NullObject)
15
+ expect(value).to be_a(Unresolved)
16
16
  expect(value.to_str).to eq "(unresolved)"
17
17
  end
18
18
  end
@@ -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.2.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.3.6
4
+ version: 0.4.4
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-01 00:00:00.000000000 Z
11
+ date: 2020-11-02 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.2.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.2.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
@@ -477,6 +481,7 @@ files:
477
481
  - lib/terraspace/cli/help.rb
478
482
  - lib/terraspace/cli/help/all/down.md
479
483
  - lib/terraspace/cli/help/all/graph.md
484
+ - lib/terraspace/cli/help/all/init.md
480
485
  - lib/terraspace/cli/help/all/output.md
481
486
  - lib/terraspace/cli/help/all/plan.md
482
487
  - lib/terraspace/cli/help/all/providers.md
@@ -487,7 +492,9 @@ files:
487
492
  - lib/terraspace/cli/help/build.md
488
493
  - lib/terraspace/cli/help/bundle.md
489
494
  - lib/terraspace/cli/help/check_setup.md
490
- - lib/terraspace/cli/help/clean.md
495
+ - lib/terraspace/cli/help/clean/all.md
496
+ - lib/terraspace/cli/help/clean/cache.md
497
+ - lib/terraspace/cli/help/clean/logs.md
491
498
  - lib/terraspace/cli/help/cloud/destroy.md
492
499
  - lib/terraspace/cli/help/cloud/list.md
493
500
  - lib/terraspace/cli/help/cloud/runs/list.md
@@ -500,7 +507,7 @@ files:
500
507
  - lib/terraspace/cli/help/info.md
501
508
  - lib/terraspace/cli/help/init.md
502
509
  - lib/terraspace/cli/help/list.md
503
- - lib/terraspace/cli/help/log.md
510
+ - lib/terraspace/cli/help/logs.md
504
511
  - lib/terraspace/cli/help/logs/remove.md
505
512
  - lib/terraspace/cli/help/logs/truncate.md
506
513
  - lib/terraspace/cli/help/new/bootstrap_test.md
@@ -526,10 +533,8 @@ files:
526
533
  - lib/terraspace/cli/info.rb
527
534
  - lib/terraspace/cli/init.rb
528
535
  - lib/terraspace/cli/list.rb
529
- - lib/terraspace/cli/log.rb
530
- - lib/terraspace/cli/log/concern.rb
531
536
  - lib/terraspace/cli/logs.rb
532
- - lib/terraspace/cli/logs/tasks.rb
537
+ - lib/terraspace/cli/logs/concern.rb
533
538
  - lib/terraspace/cli/new.rb
534
539
  - lib/terraspace/cli/new/git_hook.rb
535
540
  - lib/terraspace/cli/new/helper.rb
@@ -610,6 +615,10 @@ files:
610
615
  - lib/terraspace/ext.rb
611
616
  - lib/terraspace/ext/bundler.rb
612
617
  - lib/terraspace/ext/core/module.rb
618
+ - lib/terraspace/hooks/builder.rb
619
+ - lib/terraspace/hooks/concern.rb
620
+ - lib/terraspace/hooks/dsl.rb
621
+ - lib/terraspace/hooks/runner.rb
613
622
  - lib/terraspace/logger.rb
614
623
  - lib/terraspace/logger/formatter.rb
615
624
  - lib/terraspace/mod.rb
@@ -630,6 +639,7 @@ files:
630
639
  - lib/terraspace/seeder/content.rb
631
640
  - lib/terraspace/seeder/where.rb
632
641
  - lib/terraspace/shell.rb
642
+ - lib/terraspace/shell/error.rb
633
643
  - lib/terraspace/terraform/api.rb
634
644
  - lib/terraspace/terraform/api/base.rb
635
645
  - lib/terraspace/terraform/api/client.rb
@@ -655,14 +665,13 @@ files:
655
665
  - lib/terraspace/terraform/cloud/sync.rb
656
666
  - lib/terraspace/terraform/cloud/syncer.rb
657
667
  - lib/terraspace/terraform/cloud/workspace.rb
658
- - lib/terraspace/terraform/hooks/builder.rb
659
- - lib/terraspace/terraform/hooks/dsl.rb
660
668
  - lib/terraspace/terraform/remote_state/fetcher.rb
661
669
  - lib/terraspace/terraform/remote_state/marker/output.rb
662
670
  - lib/terraspace/terraform/remote_state/marker/pretty_tracer.rb
663
- - lib/terraspace/terraform/remote_state/null_object.rb
664
671
  - lib/terraspace/terraform/remote_state/output_proxy.rb
672
+ - lib/terraspace/terraform/remote_state/unresolved.rb
665
673
  - lib/terraspace/terraform/runner.rb
674
+ - lib/terraspace/terraform/runner/retryer.rb
666
675
  - lib/terraspace/tester.rb
667
676
  - lib/terraspace/tester/finder.rb
668
677
  - lib/terraspace/tester/meta.rb
@@ -791,11 +800,11 @@ files:
791
800
  - spec/terraspace/dependency/graph_spec.rb
792
801
  - spec/terraspace/dependency/helper/depends_on_spec.rb
793
802
  - spec/terraspace/dependency/helper/output_spec.rb
803
+ - spec/terraspace/hooks/builder_spec.rb
794
804
  - spec/terraspace/provider/expander/generic_spec.rb
795
805
  - spec/terraspace/seeder/content_spec.rb
796
806
  - spec/terraspace/seeder_spec.rb
797
807
  - spec/terraspace/terraform/args/custom_spec.rb
798
- - spec/terraspace/terraform/hooks/builder_spec.rb
799
808
  - spec/terraspace/terraform/remote_state/fetcher_spec.rb
800
809
  - spec/terraspace/terraform/remote_state/marker/output_spec.rb
801
810
  - spec/terraspace/terraform/remote_state/output_proxy_spec.rb
@@ -944,11 +953,11 @@ test_files:
944
953
  - spec/terraspace/dependency/graph_spec.rb
945
954
  - spec/terraspace/dependency/helper/depends_on_spec.rb
946
955
  - spec/terraspace/dependency/helper/output_spec.rb
956
+ - spec/terraspace/hooks/builder_spec.rb
947
957
  - spec/terraspace/provider/expander/generic_spec.rb
948
958
  - spec/terraspace/seeder/content_spec.rb
949
959
  - spec/terraspace/seeder_spec.rb
950
960
  - spec/terraspace/terraform/args/custom_spec.rb
951
- - spec/terraspace/terraform/hooks/builder_spec.rb
952
961
  - spec/terraspace/terraform/remote_state/fetcher_spec.rb
953
962
  - spec/terraspace/terraform/remote_state/marker/output_spec.rb
954
963
  - spec/terraspace/terraform/remote_state/output_proxy_spec.rb
@@ -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