terraspace 0.6.0 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -2
- data/lib/terraspace/app.rb +2 -3
- data/lib/terraspace/booter.rb +18 -2
- data/lib/terraspace/cli.rb +11 -1
- data/lib/terraspace/cli/concerns/source_dirs.rb +13 -0
- data/lib/terraspace/cli/fmt.rb +40 -0
- data/lib/terraspace/cli/fmt/runner.rb +64 -0
- data/lib/terraspace/cli/help/fmt.md +22 -0
- data/lib/terraspace/cli/list.rb +3 -2
- data/lib/terraspace/cli/new/helper.rb +2 -2
- data/lib/terraspace/compiler/builder.rb +3 -2
- data/lib/terraspace/compiler/helper_extender.rb +3 -3
- data/lib/terraspace/ext.rb +1 -0
- data/lib/terraspace/ext/core/string.rb +5 -0
- data/lib/terraspace/plugin/expander/interface.rb +1 -1
- data/lib/terraspace/version.rb +1 -1
- metadata +7 -3
- data/lib/terraspace/app/hooks.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75c6662ef1dbdb9fc52cdde609425bf17c780b20989692491f30cae96f04a10d
|
4
|
+
data.tar.gz: 6f3723c71e6e895633f3108950afb0cabace1d927216661aad06416e588bfdd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc9c700c27a5e725532c940955316c4cad16e724a094885df3ea419b40d26fb26d9be959af5131114602efa73a5329fd9fab60b1cd09e86856efcd4f4f0942c2
|
7
|
+
data.tar.gz: 5f2f327d1aebf535ad92864c9c2cf312b426bd0e814273e12e718351015bd8652487ba34978e0bc3aeab464fb3ebf7362dba08412f02ef83fd76d1ec9ea47d60
|
data/CHANGELOG.md
CHANGED
@@ -3,11 +3,27 @@
|
|
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.5] - 2021-03-24
|
7
|
+
- [#96](https://github.com/boltops-tools/terraspace/pull/96) terraspace fmt: ability to specific module or stack
|
8
|
+
|
9
|
+
## [0.6.4] - 2021-03-22
|
10
|
+
- [#94](https://github.com/boltops-tools/terraspace/pull/94) terraspace fmt command
|
11
|
+
|
12
|
+
## [0.6.3] - 2021-03-12
|
13
|
+
- [#91](https://github.com/boltops-tools/terraspace/pull/91) Camelcase
|
14
|
+
- [#92](https://github.com/boltops-tools/terraspace/pull/92) disable terraform.plugin_cache by default
|
15
|
+
- skip build config/helpers
|
16
|
+
|
17
|
+
## [0.6.2] - 2021-03-05
|
18
|
+
- [#90](https://github.com/boltops-tools/terraspace/pull/90) Boot hooks: new and improved boot hooks interface
|
19
|
+
- remove old config.hooks.on_boot
|
20
|
+
|
21
|
+
## [0.6.1] - 2021-03-04
|
22
|
+
- [#89](https://github.com/boltops-tools/terraspace/pull/89) rename option to enable_names.expansion
|
23
|
+
|
6
24
|
## [0.6.0] - 2021-03-03
|
7
|
-
- Update README.md
|
8
25
|
- [#87](https://github.com/boltops-tools/terraspace/pull/87) rename cloud to tfc command and improvements
|
9
26
|
- [#88](https://github.com/boltops-tools/terraspace/pull/88) custom layering support
|
10
|
-
- Rename `terraspace cloud` to `terraspace tfc` and tfc improvements
|
11
27
|
- Improve stdout handling, so this works: `terraspace show demo --json | jq`
|
12
28
|
- `terraspace plan --output plan.save` writes to relative cache path.
|
13
29
|
- `terraspace up --plan plan.save` copies plan.save to cache path.
|
data/lib/terraspace/app.rb
CHANGED
@@ -29,7 +29,6 @@ module Terraspace
|
|
29
29
|
config.build.clean_cache = nil # defaults to /full/path/to/.terraspace-cache
|
30
30
|
config.bundle = ActiveSupport::OrderedOptions.new
|
31
31
|
config.bundle.logger = ts_logger
|
32
|
-
config.hooks = Hooks.new
|
33
32
|
config.init = ActiveSupport::OrderedOptions.new
|
34
33
|
config.init.mode = "auto" # auto, never, always
|
35
34
|
config.log = ActiveSupport::OrderedOptions.new
|
@@ -40,13 +39,13 @@ module Terraspace
|
|
40
39
|
config.layering = ActiveSupport::OrderedOptions.new
|
41
40
|
config.layering.names = {}
|
42
41
|
config.layering.enable_names = ActiveSupport::OrderedOptions.new
|
43
|
-
config.layering.enable_names.
|
42
|
+
config.layering.enable_names.expansion = true
|
44
43
|
config.summary = ActiveSupport::OrderedOptions.new
|
45
44
|
config.summary.prune = false
|
46
45
|
config.terraform = ActiveSupport::OrderedOptions.new
|
47
46
|
config.terraform.plugin_cache = ActiveSupport::OrderedOptions.new
|
48
47
|
config.terraform.plugin_cache.dir = ENV['TF_PLUGIN_CACHE_DIR'] || "#{Terraspace.tmp_root}/plugin_cache"
|
49
|
-
config.terraform.plugin_cache.enabled =
|
48
|
+
config.terraform.plugin_cache.enabled = false
|
50
49
|
config.terraform.plugin_cache.purge_on_error = true
|
51
50
|
config.test_framework = "rspec"
|
52
51
|
config.tfc = ActiveSupport::OrderedOptions.new
|
data/lib/terraspace/booter.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
module Terraspace
|
2
2
|
module Booter
|
3
3
|
def boot
|
4
|
+
run_hooks
|
4
5
|
Terraspace::Bundle.require # load plugins
|
5
6
|
load_plugin_default_configs
|
6
|
-
Terraspace.config # load project config
|
7
|
-
Terraspace::App::Hooks.run_hook(:on_boot)
|
8
7
|
Terraspace::App::Inits.run_all
|
9
8
|
set_plugin_cache!
|
10
9
|
end
|
@@ -24,6 +23,23 @@ module Terraspace
|
|
24
23
|
dir
|
25
24
|
end
|
26
25
|
|
26
|
+
# Special boot hooks run super early, even before plugins are loaded.
|
27
|
+
# Useful for setting env vars and other early things.
|
28
|
+
#
|
29
|
+
# config/boot.rb
|
30
|
+
# config/boot/dev.rb
|
31
|
+
#
|
32
|
+
def run_hooks
|
33
|
+
run_hook
|
34
|
+
run_hook(Terraspace.env)
|
35
|
+
end
|
36
|
+
|
37
|
+
def run_hook(env=nil)
|
38
|
+
name = env ? "boot/#{env}" : "boot"
|
39
|
+
path = "#{Terraspace.root}/config/#{name}.rb"
|
40
|
+
require path if File.exist?(path)
|
41
|
+
end
|
42
|
+
|
27
43
|
extend self
|
28
44
|
end
|
29
45
|
end
|
data/lib/terraspace/cli.rb
CHANGED
@@ -27,6 +27,9 @@ module Terraspace
|
|
27
27
|
reconfigure_option = Proc.new {
|
28
28
|
option :reconfigure, type: :boolean, desc: "Add terraform -reconfigure option"
|
29
29
|
}
|
30
|
+
type_option = Proc.new {
|
31
|
+
option :type, default: "stack", aliases: %w[t], desc: "Type: stack, module, or all"
|
32
|
+
}
|
30
33
|
|
31
34
|
desc "all SUBCOMMAND", "all subcommands"
|
32
35
|
long_desc Help.text(:all)
|
@@ -82,6 +85,13 @@ module Terraspace
|
|
82
85
|
Down.new(options.merge(mod: mod)).run
|
83
86
|
end
|
84
87
|
|
88
|
+
desc "fmt", "Run terraform fmt"
|
89
|
+
long_desc Help.text(:fmt)
|
90
|
+
type_option.call
|
91
|
+
def fmt(mod=nil)
|
92
|
+
Fmt.new(options.merge(mod: mod)).run
|
93
|
+
end
|
94
|
+
|
85
95
|
desc "info STACK", "Get info about stack."
|
86
96
|
long_desc Help.text(:info)
|
87
97
|
instance_option.call
|
@@ -100,7 +110,7 @@ module Terraspace
|
|
100
110
|
|
101
111
|
desc "list", "List stacks and modules."
|
102
112
|
long_desc Help.text(:list)
|
103
|
-
|
113
|
+
type_option.call
|
104
114
|
def list
|
105
115
|
List.new(options).run
|
106
116
|
end
|
@@ -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,40 @@
|
|
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
|
+
@mod_name = options[:mod]
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
logger.info "Formating terraform files"
|
13
|
+
dirs.each do |dir|
|
14
|
+
format(dir)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def format(dir)
|
19
|
+
Runner.new(dir).format!
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def dirs
|
24
|
+
if @mod_name
|
25
|
+
type_dirs.select { |p| p.include?(@mod_name) }
|
26
|
+
else
|
27
|
+
type_dirs
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def type_dirs
|
32
|
+
type = @options[:type]
|
33
|
+
if type
|
34
|
+
app_source_dirs.select { |p| p.include?("/#{type.pluralize}/") }
|
35
|
+
else
|
36
|
+
app_source_dirs
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
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
|
@@ -0,0 +1,22 @@
|
|
1
|
+
## Example
|
2
|
+
|
3
|
+
Format all source files.
|
4
|
+
|
5
|
+
$ terraspace fmt
|
6
|
+
Formating terraform files
|
7
|
+
app/modules/example
|
8
|
+
main.tf
|
9
|
+
outputs.tf
|
10
|
+
variables.tf
|
11
|
+
app/stacks/demo
|
12
|
+
main.tf
|
13
|
+
|
14
|
+
Format specific module or stack.
|
15
|
+
|
16
|
+
$ terraspace fmt stack1
|
17
|
+
$ terraspace fmt module1
|
18
|
+
|
19
|
+
Format scoping to module or stack types. In case there's a module and stack with the same name.
|
20
|
+
|
21
|
+
$ terraspace fmt example -t module
|
22
|
+
$ terraspace fmt demo -t stacke
|
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
|
@@ -26,9 +26,9 @@ class Terraspace::CLI::New
|
|
26
26
|
|
27
27
|
def helper_class
|
28
28
|
if type == "project"
|
29
|
-
"Terraspace::#{type.
|
29
|
+
"Terraspace::#{type.camelcase}::#{name.camelcase}Helper"
|
30
30
|
else
|
31
|
-
"Terraspace::#{type.
|
31
|
+
"Terraspace::#{type.camelcase}::#{stack.camelcase}::#{name.camelcase}Helper"
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -74,10 +74,11 @@ module Terraspace::Compiler
|
|
74
74
|
def skip?(src_path)
|
75
75
|
return true unless File.file?(src_path)
|
76
76
|
# certain folders will be skipped
|
77
|
-
src_path.include?("#{@mod.root}/tfvars") ||
|
78
77
|
src_path.include?("#{@mod.root}/config/args") ||
|
78
|
+
src_path.include?("#{@mod.root}/config/helpers") ||
|
79
79
|
src_path.include?("#{@mod.root}/config/hooks") ||
|
80
|
-
src_path.include?("#{@mod.root}/test")
|
80
|
+
src_path.include?("#{@mod.root}/test") ||
|
81
|
+
src_path.include?("#{@mod.root}/tfvars")
|
81
82
|
end
|
82
83
|
end
|
83
84
|
end
|
@@ -5,7 +5,7 @@ module Terraspace::Compiler
|
|
5
5
|
full_dir = "#{@mod.root}/config/helpers"
|
6
6
|
Dir.glob("#{full_dir}/**/*").each do |path|
|
7
7
|
regexp = Regexp.new(".*/helpers/")
|
8
|
-
klass = path.sub(regexp, '').sub('.rb','').
|
8
|
+
klass = path.sub(regexp, '').sub('.rb','').camelcase
|
9
9
|
klass = "#{mod_namespace}::#{klass}"
|
10
10
|
require path # able to use require instead of load since each helper has unique namespace
|
11
11
|
send :extend, klass.constantize
|
@@ -15,8 +15,8 @@ module Terraspace::Compiler
|
|
15
15
|
# IE: mod_namespace = Terraspace::Module::Demo
|
16
16
|
# Use separate namespaces scope with module name so custom helper methods from different modules are isolated.
|
17
17
|
def mod_namespace
|
18
|
-
mod_name = @mod.name.
|
19
|
-
ns = "Terraspace::#{@mod.type.
|
18
|
+
mod_name = @mod.name.camelcase
|
19
|
+
ns = "Terraspace::#{@mod.type.camelcase}".constantize # IE: Terraspace::Module or Terraspace::Stack
|
20
20
|
if ns.const_defined?(mod_name.to_sym)
|
21
21
|
"#{ns}::#{mod_name}".constantize
|
22
22
|
else
|
data/lib/terraspace/ext.rb
CHANGED
@@ -70,7 +70,7 @@ module Terraspace::Plugin::Expander
|
|
70
70
|
def var_value(name)
|
71
71
|
name = name.sub(':','').downcase
|
72
72
|
value = send(name)
|
73
|
-
if name == "namespace" && Terraspace.config.layering.enable_names.
|
73
|
+
if name == "namespace" && Terraspace.config.layering.enable_names.expansion
|
74
74
|
value = friendly_name(value)
|
75
75
|
end
|
76
76
|
value
|
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.5
|
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-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -461,7 +461,6 @@ files:
|
|
461
461
|
- lib/terraspace/all/runner.rb
|
462
462
|
- lib/terraspace/all/summary.rb
|
463
463
|
- lib/terraspace/app.rb
|
464
|
-
- lib/terraspace/app/hooks.rb
|
465
464
|
- lib/terraspace/app/inits.rb
|
466
465
|
- lib/terraspace/autoloader.rb
|
467
466
|
- lib/terraspace/booter.rb
|
@@ -483,7 +482,10 @@ files:
|
|
483
482
|
- lib/terraspace/cli/completer.rb
|
484
483
|
- lib/terraspace/cli/completer/script.rb
|
485
484
|
- lib/terraspace/cli/completer/script.sh
|
485
|
+
- lib/terraspace/cli/concerns/source_dirs.rb
|
486
486
|
- lib/terraspace/cli/down.rb
|
487
|
+
- lib/terraspace/cli/fmt.rb
|
488
|
+
- lib/terraspace/cli/fmt/runner.rb
|
487
489
|
- lib/terraspace/cli/help.rb
|
488
490
|
- lib/terraspace/cli/help/all/down.md
|
489
491
|
- lib/terraspace/cli/help/all/graph.md
|
@@ -505,6 +507,7 @@ files:
|
|
505
507
|
- lib/terraspace/cli/help/completion_script.md
|
506
508
|
- lib/terraspace/cli/help/console.md
|
507
509
|
- lib/terraspace/cli/help/down.md
|
510
|
+
- lib/terraspace/cli/help/fmt.md
|
508
511
|
- lib/terraspace/cli/help/info.md
|
509
512
|
- lib/terraspace/cli/help/init.md
|
510
513
|
- lib/terraspace/cli/help/list.md
|
@@ -624,6 +627,7 @@ files:
|
|
624
627
|
- lib/terraspace/ext.rb
|
625
628
|
- lib/terraspace/ext/bundler.rb
|
626
629
|
- lib/terraspace/ext/core/module.rb
|
630
|
+
- lib/terraspace/ext/core/string.rb
|
627
631
|
- lib/terraspace/hooks/builder.rb
|
628
632
|
- lib/terraspace/hooks/concern.rb
|
629
633
|
- lib/terraspace/hooks/dsl.rb
|
data/lib/terraspace/app/hooks.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
class Terraspace::App
|
2
|
-
class Hooks
|
3
|
-
class_attribute :hooks
|
4
|
-
self.hooks = {}
|
5
|
-
|
6
|
-
def on_boot(&block)
|
7
|
-
self.class.hooks[:on_boot] = block
|
8
|
-
end
|
9
|
-
|
10
|
-
class << self
|
11
|
-
def run_hook(name)
|
12
|
-
name = name.to_sym
|
13
|
-
hook = hooks[name]
|
14
|
-
hook.call if hook
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|