terraspace-bundler 0.1.0 → 0.2.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 +13 -0
- data/README.md +72 -24
- data/lib/terraspace_bundler.rb +1 -0
- data/lib/terraspace_bundler/cli/base.rb +9 -1
- data/lib/terraspace_bundler/cli/bundle.rb +26 -12
- data/lib/terraspace_bundler/cli/help/bundle/info.md +8 -0
- data/lib/terraspace_bundler/cli/help/bundle/install.md +1 -1
- data/lib/terraspace_bundler/cli/help/bundle/list.md +9 -0
- data/lib/terraspace_bundler/cli/help/bundle/update.md +6 -0
- data/lib/terraspace_bundler/cli/{clean.rb → purge_cache.rb} +3 -3
- data/lib/terraspace_bundler/cli/{install.rb → runner.rb} +1 -1
- data/lib/terraspace_bundler/config.rb +15 -2
- data/lib/terraspace_bundler/core.rb +9 -4
- data/lib/terraspace_bundler/dsl.rb +6 -3
- data/lib/terraspace_bundler/dsl/concern.rb +7 -0
- data/lib/terraspace_bundler/dsl/syntax.rb +8 -0
- data/lib/terraspace_bundler/exporter.rb +47 -0
- data/lib/terraspace_bundler/info.rb +25 -0
- data/lib/terraspace_bundler/installer.rb +15 -33
- data/lib/terraspace_bundler/list.rb +22 -0
- data/lib/terraspace_bundler/lockfile.rb +70 -0
- data/lib/terraspace_bundler/lockfile/version_comparer.rb +43 -0
- data/lib/terraspace_bundler/lockfile/yamler.rb +37 -0
- data/lib/terraspace_bundler/logger.rb +0 -20
- data/lib/terraspace_bundler/logger/formatter.rb +7 -0
- data/lib/terraspace_bundler/mod.rb +31 -63
- data/lib/terraspace_bundler/mod/downloader.rb +55 -0
- data/lib/terraspace_bundler/mod/{tmp_paths.rb → path_concern.rb} +1 -1
- data/lib/terraspace_bundler/mod/props_builder.rb +57 -0
- data/lib/terraspace_bundler/mod/props_extension.rb +15 -0
- data/lib/terraspace_bundler/mod/registry.rb +8 -6
- data/lib/terraspace_bundler/syncer.rb +62 -4
- data/lib/terraspace_bundler/terrafile.rb +39 -0
- data/lib/terraspace_bundler/util/git.rb +31 -0
- data/lib/terraspace_bundler/{logging.rb → util/logging.rb} +1 -1
- data/lib/terraspace_bundler/version.rb +1 -1
- data/spec/fixtures/Terrafile +2 -2
- data/spec/terraform_bundler/runner_spec.rb +17 -0
- metadata +24 -17
- data/lib/terraspace_bundler/cli/update.rb +0 -7
- data/lib/terraspace_bundler/helper/git.rb +0 -21
- data/lib/terraspace_bundler/mod/export.rb +0 -23
- data/lib/terraspace_bundler/mod/locked.rb +0 -48
- data/lib/terraspace_bundler/mod/sync.rb +0 -53
- data/lib/terraspace_bundler/setup.rb +0 -20
- data/lib/terraspace_bundler/updater.rb +0 -49
- data/lib/terraspace_bundler/updater/lockfile.rb +0 -48
- data/lib/terraspace_bundler/util/registry.rb +0 -24
- data/spec/terraform_bundler/installer_spec.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 500271ff2f8e5799a55febd3ec25261bcf4126bff456b83360ae0e2a96bb6357
|
4
|
+
data.tar.gz: ee45f81805b893d5287fdea6777c9b28ac39936273806c3d97275f6c314a8cd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94af4d341ed3e43445bf2eb0eae1e3383fe064a6df708c449658b8eb5a958163a225be2ddae121356573ae7e099e87669c5cb9c54808423b9db685faf27d7837
|
7
|
+
data.tar.gz: d68d1825f89b91ac4d9ad7525a4b4b95cc709ce1e2f3c10d83aa6ad5c6b27a89b3c6ae1ad9bc1ee3179b08345ac73fc551d1467769f702cc43d69b6f3b38b577
|
data/CHANGELOG.md
CHANGED
@@ -3,5 +3,18 @@
|
|
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.2.0]
|
7
|
+
- #1 Rework implementation. Better Terrafile syncing
|
8
|
+
- clearer implementation: Terrafile and Lockfile classes build standard mods object.
|
9
|
+
- add commands: info, list
|
10
|
+
- sync of Terrafile with vendor/modules
|
11
|
+
- rename command: terraspace bundle purge_cache
|
12
|
+
- rename option to relative_root for modules within a subfolder within a repo
|
13
|
+
- prune exported modules by default
|
14
|
+
- export_prune option
|
15
|
+
- Allow configuring the logger formatter
|
16
|
+
- validate org is set if used
|
17
|
+
- mod export_to option
|
18
|
+
|
6
19
|
## [0.1.0]
|
7
20
|
- Initial release.
|
data/README.md
CHANGED
@@ -1,12 +1,6 @@
|
|
1
1
|
# terraspace-bundler
|
2
2
|
|
3
|
-
Bundles terraform modules based on a `Terrafile` to the `vendor/modules` folder.
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
To install:
|
8
|
-
|
9
|
-
gem install terraspace-bundler
|
3
|
+
Bundles terraform modules based on a `Terrafile` to the `vendor/modules` folder. Used by the [Terraspace Terraform Framework](https://terraspace.cloud/).
|
10
4
|
|
11
5
|
## Usage
|
12
6
|
|
@@ -26,56 +20,110 @@ mod "rds", source: "boltopspro/terraform-aws-rds", version: "v0.1.0"
|
|
26
20
|
mod "sg", source: "terraform-aws-modules/security-group/aws", version: "3.10.0"
|
27
21
|
```
|
28
22
|
|
29
|
-
|
23
|
+
## Install
|
24
|
+
|
25
|
+
Running `terraspace bundle` creates the `Terrafile.lock` file, which locks the versions.
|
30
26
|
|
31
27
|
terraspace bundle
|
32
28
|
|
33
29
|
## Updating
|
34
30
|
|
35
|
-
To update all the locked versions in `Terrafile.lock` run `terraspace bundle update`. You can also
|
31
|
+
To update all the locked versions in `Terrafile.lock` run `terraspace bundle update`. You can also delete the `Terrafile.lock` file first.
|
36
32
|
|
37
33
|
terraspace bundle update
|
38
34
|
|
39
|
-
You can selectively update
|
35
|
+
You can selectively update multiple modules:
|
40
36
|
|
41
|
-
terraspace bundle update
|
37
|
+
terraspace bundle update MODS
|
38
|
+
terraspace bundle update mod1 mod2
|
42
39
|
|
43
|
-
##
|
40
|
+
## List & Info
|
44
41
|
|
45
|
-
|
42
|
+
terraspace bundle list
|
43
|
+
terraspace bundle info mod1
|
46
44
|
|
47
|
-
|
48
|
-
|
45
|
+
## DSL Methods
|
46
|
+
|
47
|
+
Some of these are methods that apply globally at the Terrafile level. Some of these are options that apply the at the mod method level.
|
49
48
|
|
50
|
-
|
49
|
+
### Terrafile level
|
50
|
+
|
51
|
+
Name | Description | Default
|
52
|
+
--- | --- | ---
|
53
|
+
base_clone_url | Base clone url to use | git@gihtub.com:
|
54
|
+
export_path | Where the modules get exported to saved to. | vendor/modules
|
55
|
+
export_purge | Where or not to clean up all existing exported modules folder first. | true
|
56
|
+
|
57
|
+
### Mod Method level
|
58
|
+
|
59
|
+
Name | Description | Default
|
60
|
+
--- | --- | ---
|
61
|
+
subfolder | The subfolder where the module lives within the repo. | nil
|
62
|
+
export_to | Overrides the export_path Terrafile level option. With this one-off option, other modules in this folder will not be purged. | nil
|
63
|
+
|
64
|
+
Examples of some of the options are below:
|
65
|
+
|
66
|
+
### base url
|
51
67
|
|
52
68
|
The base url used for clone is `git@github.com:`. You can change it with `base_url`, example:
|
53
69
|
|
54
70
|
```ruby
|
55
|
-
org "boltops-tools" # set default org
|
56
71
|
base_url "https://github.com/" # default base url for git clone
|
57
|
-
|
58
|
-
mod "s3", source: "terraform-aws-s3", version: "master"
|
72
|
+
# ...
|
59
73
|
```
|
60
74
|
|
61
|
-
|
75
|
+
### export_path
|
62
76
|
|
63
77
|
The default export path is `vendor/modules`, you can change it:
|
64
78
|
|
65
79
|
```ruby
|
66
|
-
org "boltops-tools" # set default org
|
67
80
|
export_path "app/modules"
|
81
|
+
# ...
|
82
|
+
```
|
83
|
+
|
84
|
+
## prune
|
68
85
|
|
69
|
-
|
86
|
+
The `terraspace bundle` commands removes all files in the export_path, `vendor/modules`, by default. You can disable this behavior with:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
export_purge false
|
90
|
+
# ...
|
70
91
|
```
|
71
92
|
|
93
|
+
### subfolder
|
94
|
+
|
95
|
+
The default export path is `vendor/modules`, you can change it:
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
# ...
|
99
|
+
mod "s3", source: "terraform-aws-s3", subfolder: "path/to/module/s3"
|
100
|
+
```
|
101
|
+
|
102
|
+
## Config Options
|
103
|
+
|
104
|
+
You can also configure some behavior with `TB.config`. IE: `TB.config.terrafile = "/path/to/Terrafile"`
|
105
|
+
|
106
|
+
Name | Description | Default
|
107
|
+
--- | --- | ---
|
108
|
+
base_clone_url | Base git url to use for cloning | git@github.com:
|
109
|
+
export_path | Where to export the modules to. Can also be set with the env var TB_EXPORT_PATH | vendor/modules
|
110
|
+
export_purge | Whether or not to prune all the modules | true
|
111
|
+
logger | Logger instance
|
112
|
+
terrafile | The Terrafile path. Can also be set with the env TB_TERRAFILE || "Terrafile"
|
113
|
+
|
114
|
+
## Installation
|
115
|
+
|
116
|
+
To install:
|
117
|
+
|
118
|
+
gem install terraspace-bundler
|
119
|
+
|
72
120
|
## Notes
|
73
121
|
|
74
|
-
*
|
122
|
+
* This is a simple implementation for [Terraspace](https://terraspace.cloud/) use.
|
75
123
|
* Handles updating the `Terrafile.lock` based on the `Terrafile`
|
76
124
|
* Others running the `terraspace bundle install` will install the exact same module versions based the `Terrafile.lock`.
|
77
125
|
* To update `Terraform.lock` run `terraspace bundle update`.
|
78
|
-
* The repos are downloaded to `/tmp/terraspace-bundler` area as a cache. Delete the cache by running `terraspace bundle
|
126
|
+
* The repos are downloaded to `/tmp/terraspace-bundler` area as a cache. Delete the cache by running `terraspace bundle purge_cache`.
|
79
127
|
|
80
128
|
## Contributing
|
81
129
|
|
data/lib/terraspace_bundler.rb
CHANGED
@@ -1,9 +1,17 @@
|
|
1
1
|
class TerraspaceBundler::CLI
|
2
2
|
class Base
|
3
|
-
include TB::Logging
|
3
|
+
include TB::Util::Logging
|
4
4
|
|
5
5
|
def initialize(options={})
|
6
6
|
@options = options
|
7
|
+
set_config!
|
8
|
+
end
|
9
|
+
|
10
|
+
def set_config!
|
11
|
+
return unless @options[:terrafile]
|
12
|
+
TB.config.terrafile = @options[:terrafile]
|
13
|
+
TB.config.lockfile = "#{@options[:terrafile]}.lock"
|
14
|
+
TB.config
|
7
15
|
end
|
8
16
|
end
|
9
17
|
end
|
@@ -1,27 +1,41 @@
|
|
1
1
|
class TerraspaceBundler::CLI
|
2
2
|
class Bundle < TerraspaceBundler::Command
|
3
3
|
terrafile_option = Proc.new {
|
4
|
-
option :terrafile, default: "Terrafile", desc: "Terrafile to use"
|
4
|
+
option :terrafile, default: ENV['TB_TERRAFILE'] || "Terrafile", desc: "Terrafile to use"
|
5
5
|
}
|
6
6
|
|
7
|
-
desc "
|
8
|
-
long_desc Help.text("bundle/
|
7
|
+
desc "list", "List bundled modules included by Terrafile."
|
8
|
+
long_desc Help.text("bundle/list")
|
9
9
|
terrafile_option.call
|
10
|
-
def
|
11
|
-
|
10
|
+
def list
|
11
|
+
TB::List.new(options).run
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "info MOD", "Provide info about a bundled module."
|
15
|
+
long_desc Help.text("bundle/info")
|
16
|
+
terrafile_option.call
|
17
|
+
def info(mod)
|
18
|
+
TB::Info.new(options.merge(mod: mod)).run
|
12
19
|
end
|
13
20
|
|
14
|
-
desc "
|
21
|
+
desc "install", "Install modules from the Terrafile."
|
15
22
|
long_desc Help.text("bundle/install")
|
16
23
|
terrafile_option.call
|
17
|
-
def
|
18
|
-
|
24
|
+
def install
|
25
|
+
Runner.new(options).run
|
26
|
+
end
|
27
|
+
|
28
|
+
desc "purge_cache", "Purge cache."
|
29
|
+
long_desc Help.text("bundle/purge_cache")
|
30
|
+
def purge_cache
|
31
|
+
PurgeCache.new(options).run
|
19
32
|
end
|
20
33
|
|
21
|
-
desc "
|
22
|
-
long_desc Help.text("bundle/
|
23
|
-
|
24
|
-
|
34
|
+
desc "update [MOD]", "Update bundled modules."
|
35
|
+
long_desc Help.text("bundle/update")
|
36
|
+
terrafile_option.call
|
37
|
+
def update(*mods)
|
38
|
+
Runner.new(options.merge(mods: mods, mode: "update")).run
|
25
39
|
end
|
26
40
|
end
|
27
41
|
end
|
@@ -5,11 +5,24 @@ module TerraspaceBundler
|
|
5
5
|
|
6
6
|
def config
|
7
7
|
config = ActiveSupport::OrderedOptions.new
|
8
|
-
config.
|
9
|
-
config.
|
8
|
+
config.base_clone_url = "git@github.com:"
|
9
|
+
config.export_path = ENV['TB_EXPORT_PATH'] || "vendor/modules"
|
10
|
+
config.export_purge = ENV['TB_EXPORT_PRUNE'] == '0' ? false : true
|
10
11
|
config.lockfile = "#{config.terrafile}.lock"
|
12
|
+
config.logger = new_logger
|
13
|
+
config.terrafile = ENV['TB_TERRAFILE'] || "Terrafile"
|
11
14
|
config
|
12
15
|
end
|
13
16
|
memoize :config
|
17
|
+
|
18
|
+
# Note: When using terraspace, Terraspace uses its own logger
|
19
|
+
# So these settings dont affect: terraspace bundle
|
20
|
+
# Instead, set the log level in the terraspace project: config/app.rb
|
21
|
+
def new_logger
|
22
|
+
logger = Logger.new(ENV['TB_LOG_PATH'] || $stderr)
|
23
|
+
logger.level = ENV['TB_LOG_LEVEL'] || :info
|
24
|
+
logger.formatter = Logger::Formatter.new
|
25
|
+
logger
|
26
|
+
end
|
14
27
|
end
|
15
28
|
end
|
@@ -4,10 +4,7 @@ module TerraspaceBundler
|
|
4
4
|
|
5
5
|
@@logger = nil
|
6
6
|
def logger
|
7
|
-
|
8
|
-
@@logger = Logger.new($stdout)
|
9
|
-
@@logger.level = ENV['TB_LOG_LEVEL'] || 'info'
|
10
|
-
@@logger
|
7
|
+
config.logger
|
11
8
|
end
|
12
9
|
|
13
10
|
def logger=(v)
|
@@ -17,5 +14,13 @@ module TerraspaceBundler
|
|
17
14
|
def config
|
18
15
|
Config.instance.config
|
19
16
|
end
|
17
|
+
|
18
|
+
# DSL is evaluated once lazily when it get used
|
19
|
+
def dsl
|
20
|
+
dsl = Dsl.new
|
21
|
+
dsl.run
|
22
|
+
dsl
|
23
|
+
end
|
24
|
+
memoize :dsl
|
20
25
|
end
|
21
26
|
end
|
@@ -3,16 +3,19 @@ module TerraspaceBundler
|
|
3
3
|
include DslEvaluator
|
4
4
|
include Syntax
|
5
5
|
|
6
|
-
class_attribute :meta
|
7
|
-
self.meta = {global: {}, mods: []}
|
6
|
+
class_attribute :meta, default: {global: {}, mods: []}
|
8
7
|
|
9
8
|
def run
|
10
9
|
evaluate_file(TB.config.terrafile)
|
11
|
-
self
|
10
|
+
self
|
12
11
|
end
|
13
12
|
|
14
13
|
def meta
|
15
14
|
self.class.meta
|
16
15
|
end
|
16
|
+
|
17
|
+
def global
|
18
|
+
meta[:global]
|
19
|
+
end
|
17
20
|
end
|
18
21
|
end
|
@@ -5,10 +5,18 @@ class TerraspaceBundler::Dsl
|
|
5
5
|
end
|
6
6
|
alias_method :user, :org
|
7
7
|
|
8
|
+
def base_clone_url(value)
|
9
|
+
TB.config.base_clone_url = value
|
10
|
+
end
|
11
|
+
|
8
12
|
def export_path(path)
|
9
13
|
global[:export_path] = path
|
10
14
|
end
|
11
15
|
|
16
|
+
def export_purge(value)
|
17
|
+
TB.config.export_purge = value
|
18
|
+
end
|
19
|
+
|
12
20
|
def mod(*args, **options)
|
13
21
|
meta[:mods] << {args: args, options: options}
|
14
22
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module TerraspaceBundler
|
2
|
+
class Exporter
|
3
|
+
include TB::Mod::PathConcern
|
4
|
+
include TB::Util::Logging
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
@options = options
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
purge
|
12
|
+
lockfile.mods.each do |mod|
|
13
|
+
export(mod)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def export(mod)
|
18
|
+
downloader = Mod::Downloader.new(mod)
|
19
|
+
downloader.switch_version(mod.sha)
|
20
|
+
|
21
|
+
stage_path = stage_path(mod.full_repo)
|
22
|
+
stage_path = "#{stage_path}/#{mod.subfolder}" if mod.subfolder
|
23
|
+
mod_path = mod_path(mod)
|
24
|
+
FileUtils.rm_rf(mod_path)
|
25
|
+
FileUtils.mkdir_p(File.dirname(mod_path))
|
26
|
+
FileUtils.cp_r(stage_path, mod_path)
|
27
|
+
FileUtils.rm_rf("#{mod_path}/.git")
|
28
|
+
logger.debug "Exported: #{mod_path}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def mod_path(mod)
|
32
|
+
name = mod.name
|
33
|
+
export_to = mod.export_to || TB.config.export_path
|
34
|
+
"#{export_to}/#{name}"
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def purge
|
39
|
+
return unless TB.config.export_purge
|
40
|
+
FileUtils.rm_rf(TB.config.export_path)
|
41
|
+
end
|
42
|
+
|
43
|
+
def lockfile
|
44
|
+
Lockfile.instance
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|