terraspace 0.6.3 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/terraspace/cli.rb +6 -0
- data/lib/terraspace/cli/concerns/source_dirs.rb +13 -0
- data/lib/terraspace/cli/fmt.rb +21 -0
- data/lib/terraspace/cli/fmt/runner.rb +64 -0
- data/lib/terraspace/cli/help/fmt.md +10 -0
- data/lib/terraspace/cli/list.rb +3 -2
- data/lib/terraspace/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 56392f488a05d42760586d379da36022589979733b654ea3f5f3d5fcb879de26
|
|
4
|
+
data.tar.gz: 690b3d0fa3e192aee02fd34ae187ab4628caccd335a1733ce10040ff2ef55b32
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4dcc7b6c1d1f2d21be6115d02cc34bbeb9f773e6ece16e8549ac3a8e6a4167fb6392a2917399399a0ba0ddde4ff880c9dff8de2ee5261def5250fc2525527ce1
|
|
7
|
+
data.tar.gz: 476d2c10897c2915a3cd601b556e783a639cb29a97c11505b5e34f32d8079c311e5ad8f6efeeee6cf9a143a2f63b9b46b76a9b6741d78802fd53baf8de319b29
|
data/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
|
|
5
5
|
|
|
6
|
+
## [0.6.4] - 2021-03-22
|
|
7
|
+
- [#94](https://github.com/boltops-tools/terraspace/pull/94) terraspace fmt command
|
|
8
|
+
|
|
6
9
|
## [0.6.3] - 2021-03-12
|
|
7
10
|
- [#91](https://github.com/boltops-tools/terraspace/pull/91) Camelcase
|
|
8
11
|
- [#92](https://github.com/boltops-tools/terraspace/pull/92) disable terraform.plugin_cache by default
|
data/lib/terraspace/cli.rb
CHANGED
|
@@ -82,6 +82,12 @@ module Terraspace
|
|
|
82
82
|
Down.new(options.merge(mod: mod)).run
|
|
83
83
|
end
|
|
84
84
|
|
|
85
|
+
desc "fmt", "Run terraform fmt"
|
|
86
|
+
long_desc Help.text(:fmt)
|
|
87
|
+
def fmt
|
|
88
|
+
Fmt.new(options).run
|
|
89
|
+
end
|
|
90
|
+
|
|
85
91
|
desc "info STACK", "Get info about stack."
|
|
86
92
|
long_desc Help.text(:info)
|
|
87
93
|
instance_option.call
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Terraspace::CLI::Concerns
|
|
2
|
+
module SourceDirs
|
|
3
|
+
# used by list
|
|
4
|
+
def source_dirs
|
|
5
|
+
Dir.glob("{app,vendor}/{modules,stacks}/*").select { |p| File.directory?(p) }.sort
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# dont include vendor: used by fmt
|
|
9
|
+
def app_source_dirs
|
|
10
|
+
Dir.glob("{app}/{modules,stacks}/*").select { |p| File.directory?(p) }.sort
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
class Terraspace::CLI
|
|
2
|
+
class Fmt
|
|
3
|
+
include Concerns::SourceDirs
|
|
4
|
+
include Terraspace::Util::Logging
|
|
5
|
+
|
|
6
|
+
def initialize(options={})
|
|
7
|
+
@options = options
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def run
|
|
11
|
+
logger.info "Formating terraform files"
|
|
12
|
+
app_source_dirs.each do |dir|
|
|
13
|
+
format(dir)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def format(dir)
|
|
18
|
+
Runner.new(dir).format!
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
class Terraspace::CLI::Fmt
|
|
2
|
+
class Runner
|
|
3
|
+
include Terraspace::CLI::Concerns::SourceDirs
|
|
4
|
+
include Terraspace::Util::Logging
|
|
5
|
+
SKIP_PATTERN = /\.skip$/
|
|
6
|
+
|
|
7
|
+
def initialize(dir)
|
|
8
|
+
@dir = dir
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def format!
|
|
12
|
+
logger.info @dir.color(:green)
|
|
13
|
+
Dir.chdir(@dir) do
|
|
14
|
+
skip_rename
|
|
15
|
+
begin
|
|
16
|
+
terraform_fmt
|
|
17
|
+
ensure
|
|
18
|
+
restore_rename
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def skip_rename
|
|
24
|
+
tf_files.each do |path|
|
|
25
|
+
if !skip?(path) && erb?(path)
|
|
26
|
+
FileUtils.mv(path, "#{path}.skip")
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def terraform_fmt
|
|
32
|
+
sh "terraform fmt"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def sh(command)
|
|
36
|
+
logger.debug("=> #{command}")
|
|
37
|
+
success = system(command)
|
|
38
|
+
return if success
|
|
39
|
+
logger.info "WARN: There were some errors running terraform fmt for files in #{@dir}:".color(:yellow)
|
|
40
|
+
logger.info "The errors are shown above"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def restore_rename
|
|
44
|
+
tf_files.each do |path|
|
|
45
|
+
if skip?(path) && erb?(path)
|
|
46
|
+
FileUtils.mv(path, path.sub(SKIP_PATTERN, '')) # original name
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
def skip?(path)
|
|
53
|
+
!!(path =~ SKIP_PATTERN)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def erb?(path)
|
|
57
|
+
IO.readlines(path).detect { |l| l.include?('<%') }
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def tf_files
|
|
61
|
+
Dir.glob("#{Terraspace.root}/#{@dir}/**/*.{tf,skip}").select { |p| File.file?(p) }
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
data/lib/terraspace/cli/list.rb
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
class Terraspace::CLI
|
|
2
2
|
class List
|
|
3
|
+
include Concerns::SourceDirs
|
|
4
|
+
|
|
3
5
|
def initialize(options={})
|
|
4
6
|
@options = options
|
|
5
7
|
@type_dir = normalized_type
|
|
6
8
|
end
|
|
7
9
|
|
|
8
10
|
def run
|
|
9
|
-
|
|
10
|
-
dirs.sort.each do |path|
|
|
11
|
+
source_dirs.each do |path|
|
|
11
12
|
if @type_dir
|
|
12
13
|
puts path if path.include?("/#{@type_dir}/")
|
|
13
14
|
else
|
data/lib/terraspace/version.rb
CHANGED
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.6.
|
|
4
|
+
version: 0.6.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: 2021-03-
|
|
11
|
+
date: 2021-03-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -482,7 +482,10 @@ files:
|
|
|
482
482
|
- lib/terraspace/cli/completer.rb
|
|
483
483
|
- lib/terraspace/cli/completer/script.rb
|
|
484
484
|
- lib/terraspace/cli/completer/script.sh
|
|
485
|
+
- lib/terraspace/cli/concerns/source_dirs.rb
|
|
485
486
|
- lib/terraspace/cli/down.rb
|
|
487
|
+
- lib/terraspace/cli/fmt.rb
|
|
488
|
+
- lib/terraspace/cli/fmt/runner.rb
|
|
486
489
|
- lib/terraspace/cli/help.rb
|
|
487
490
|
- lib/terraspace/cli/help/all/down.md
|
|
488
491
|
- lib/terraspace/cli/help/all/graph.md
|
|
@@ -504,6 +507,7 @@ files:
|
|
|
504
507
|
- lib/terraspace/cli/help/completion_script.md
|
|
505
508
|
- lib/terraspace/cli/help/console.md
|
|
506
509
|
- lib/terraspace/cli/help/down.md
|
|
510
|
+
- lib/terraspace/cli/help/fmt.md
|
|
507
511
|
- lib/terraspace/cli/help/info.md
|
|
508
512
|
- lib/terraspace/cli/help/init.md
|
|
509
513
|
- lib/terraspace/cli/help/list.md
|