terraspace-bundler 0.4.1 → 0.5.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 +10 -0
- data/lib/terraspace_bundler/cli/bundle.rb +10 -0
- data/lib/terraspace_bundler/cli/help/bundle/example.md +9 -0
- data/lib/terraspace_bundler/dsl/syntax.rb +2 -2
- data/lib/terraspace_bundler/example.rb +39 -0
- data/lib/terraspace_bundler/exporter/stacks/stack.rb +2 -1
- data/lib/terraspace_bundler/mod/concerns/notation_concern.rb +20 -3
- data/lib/terraspace_bundler/mod/concerns/path_concern.rb +4 -17
- data/lib/terraspace_bundler/mod/fetcher/gcs.rb +22 -1
- data/lib/terraspace_bundler/mod/fetcher/git.rb +6 -5
- data/lib/terraspace_bundler/mod/org_repo.rb +65 -0
- data/lib/terraspace_bundler/mod/props/typer.rb +3 -1
- data/lib/terraspace_bundler/mod/props.rb +23 -1
- data/lib/terraspace_bundler/mod/registry.rb +11 -6
- data/lib/terraspace_bundler/mod.rb +8 -19
- data/lib/terraspace_bundler/version.rb +1 -1
- data/lib/terraspace_bundler.rb +2 -0
- data/readme/qa/Terrafile +39 -0
- data/spec/terraform_bundler/mod/concerns/notation_concern_spec.rb +35 -0
- data/spec/terraform_bundler/mod/org_repo_spec.rb +45 -0
- data/spec/terraform_bundler/mod/props_spec.rb +130 -0
- data/terraspace-bundler.gemspec +0 -1
- metadata +11 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1917be53c7c75191b7630d35198eac5c1d3d9e606dd2663f1874093c469eba73
|
4
|
+
data.tar.gz: 54bd018c6a82eee7b35035984342db92c98d8ff2f8028c492b9d3780417520ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59c11be8fb8ae722b15e2e60f00dd0d240c428370f9307b6df15fcd5b056912422fbceb1dddb521a38c8cd2a7b4c70b2f41c1018ad278dfd201ce370a7c0dae7
|
7
|
+
data.tar.gz: 8d2ec411f5f520bde8f6f04efc5eb5587a6362d5674bd5192f2b9ba03ded77dac92bdcf42948ed6cb73320110146e34f7fecba182c3bc0a5976a8de2dc4265bb
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,16 @@
|
|
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.5.0] - 2022-01-15
|
7
|
+
- [#17](https://github.com/boltops-tools/terraspace-bundler/pull/17) ssh notation support
|
8
|
+
|
9
|
+
## [0.4.3] - 2021-11-20
|
10
|
+
- [#14](https://github.com/boltops-tools/terraspace-bundler/pull/14) get version and use only that part of api since the latest version is currently down with a 502
|
11
|
+
- [#15](https://github.com/boltops-tools/terraspace-bundler/pull/15) terraspace bundle example command
|
12
|
+
|
13
|
+
## [0.4.2] - 2021-10-02
|
14
|
+
- stack src option: also understand example and name
|
15
|
+
|
6
16
|
## [0.4.1] - 2021-09-30
|
7
17
|
- [#13](https://github.com/boltops-tools/terraspace-bundler/pull/13) fix stacks Array option
|
8
18
|
|
@@ -39,5 +39,15 @@ class TerraspaceBundler::CLI
|
|
39
39
|
TB.update_mode = true
|
40
40
|
TB::Runner.new(options.merge(mods: mods)).run
|
41
41
|
end
|
42
|
+
|
43
|
+
desc "example MOD EXAMPLE", "Import example from module as a stack"
|
44
|
+
long_desc Help.text("bundle/example")
|
45
|
+
terrafile_option.call
|
46
|
+
option :name, desc: "The stack name. IE: app/stacks/NAME. By default, the mod's name is used. "
|
47
|
+
option :dest, default: "app/stacks", desc: "The default destination folder is app/stacks. Though you can change it to locations like vendor/stacks, it’s recommended to keep the default."
|
48
|
+
option :purge, type: :boolean, default: true, desc: "If set to `true`, then the existing `app/stacks/vpc` folder is removed."
|
49
|
+
def example(mod, example)
|
50
|
+
TB::Example.new(options.merge(mod: mod, example: example)).run
|
51
|
+
end
|
42
52
|
end
|
43
53
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
## Examples
|
2
|
+
|
3
|
+
$ terraspace bundle example eks managed_node_groups
|
4
|
+
Example from vendor/modules/eks/examples/managed_node_groups imported to app/stacks/managed_node_groups
|
5
|
+
|
6
|
+
Specify the stack name:
|
7
|
+
|
8
|
+
$ terraspace bundle example eks managed_node_groups --name eks
|
9
|
+
Example from vendor/modules/eks/examples/managed_node_groups imported to app/stacks/eks
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module TerraspaceBundler
|
2
|
+
class Example < TB::CLI::Base
|
3
|
+
def run
|
4
|
+
check_mod!
|
5
|
+
stack = Exporter::Stacks::Stack.new(mod, stack_options)
|
6
|
+
stack.export
|
7
|
+
logger.info "Example from vendor/modules/#{@options[:mod]}/examples/#{@src} imported to #{@dest}/#{@name}"
|
8
|
+
end
|
9
|
+
|
10
|
+
def stack_options
|
11
|
+
@name = @options[:name] || @options[:example]
|
12
|
+
@purge = @options[:purge].nil? ? true : @options[:purge]
|
13
|
+
@dest = @options[:dest] || "app/stacks"
|
14
|
+
@src = @options[:example]
|
15
|
+
{
|
16
|
+
name: @name,
|
17
|
+
src: @src,
|
18
|
+
dest: @dest,
|
19
|
+
purge: @purge,
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def mod
|
24
|
+
lockfile.mods.find { |mod| mod.name == @options[:mod] }
|
25
|
+
end
|
26
|
+
|
27
|
+
def check_mod!
|
28
|
+
unless mod
|
29
|
+
logger.error "ERROR: mod #{@options[:mod]} not found in Terrafile.lock".color(:red)
|
30
|
+
exit 1
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def lockfile
|
36
|
+
Lockfile.instance
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -3,6 +3,7 @@ class TerraspaceBundler::Exporter::Stacks
|
|
3
3
|
attr_reader :mod
|
4
4
|
def initialize(mod, options={})
|
5
5
|
@mod, @options = mod, options
|
6
|
+
@src = @options[:src] || @options[:example] || @options[:name]
|
6
7
|
end
|
7
8
|
|
8
9
|
def export
|
@@ -25,7 +26,7 @@ class TerraspaceBundler::Exporter::Stacks
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def src
|
28
|
-
src = @
|
29
|
+
src = @src
|
29
30
|
without_examples = [mod_path, src].compact.join('/')
|
30
31
|
with_examples = [examples_folder, src].compact.join('/')
|
31
32
|
paths = [with_examples, without_examples]
|
@@ -11,7 +11,8 @@ module TerraspaceBundler::Mod::Concerns
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def remove_subfolder_notation(source)
|
14
|
-
|
14
|
+
clean = clean_notation(source)
|
15
|
+
parts = clean.split('//')
|
15
16
|
if parts.size == 2 # has subfolder
|
16
17
|
source.split('//')[0..-2].join('//') # remove only subfolder, keep rest of original source
|
17
18
|
else
|
@@ -20,7 +21,8 @@ module TerraspaceBundler::Mod::Concerns
|
|
20
21
|
end
|
21
22
|
|
22
23
|
def subfolder(source)
|
23
|
-
|
24
|
+
clean = clean_notation(source)
|
25
|
+
parts = clean.split('//')
|
24
26
|
if parts.size == 2 # has subfolder
|
25
27
|
remove_ref_notation(parts.last)
|
26
28
|
end
|
@@ -35,8 +37,23 @@ module TerraspaceBundler::Mod::Concerns
|
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
40
|
+
|
38
41
|
def clean_notation(source)
|
39
|
-
|
42
|
+
clean = source
|
43
|
+
.sub(/.*::/,'') # remove git::
|
44
|
+
.sub(%r{http[s?]://},'') # remove https://
|
45
|
+
.sub(%r{git@(.*?):},'') # remove git@word
|
46
|
+
remove_host(clean)
|
47
|
+
end
|
48
|
+
|
49
|
+
def remove_host(clean)
|
50
|
+
return clean unless clean.include?('ssh://')
|
51
|
+
if clean.count(':') == 1
|
52
|
+
uri = URI(clean)
|
53
|
+
uri.path
|
54
|
+
else
|
55
|
+
clean.split(':').last
|
56
|
+
end
|
40
57
|
end
|
41
58
|
end
|
42
59
|
end
|
@@ -18,11 +18,11 @@ module TerraspaceBundler::Mod::Concerns
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def cache_path(name)
|
21
|
-
[cache_root,
|
21
|
+
[cache_root, @mod.type, name].compact.join('/')
|
22
22
|
end
|
23
23
|
|
24
24
|
def stage_path(name)
|
25
|
-
[stage_root,
|
25
|
+
[stage_root, @mod.type, name].compact.join('/')
|
26
26
|
end
|
27
27
|
|
28
28
|
# Fetcher: Downloader/Local copies to a slightly different folder.
|
@@ -41,21 +41,8 @@ module TerraspaceBundler::Mod::Concerns
|
|
41
41
|
when 'http'
|
42
42
|
path = type_path # https://www.googleapis.com/storage/v1/BUCKET_NAME/PATH/TO/module.zip
|
43
43
|
remove_ext(path) # terraform-example-modules/modules/example-module
|
44
|
-
|
45
|
-
@mod.
|
46
|
-
else # inferred git, registry
|
47
|
-
@mod.full_repo # tongueroo/example-module
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def parent_stage_folder
|
52
|
-
case @mod.type
|
53
|
-
when 'local'
|
54
|
-
'local'
|
55
|
-
when 'http'
|
56
|
-
'http'
|
57
|
-
else # gcs, s3, git, registry
|
58
|
-
@mod.vcs_provider
|
44
|
+
else # inferred git, registry, git::, ssh://, git::ssh://
|
45
|
+
@mod.repo_folder # tongueroo/example-module
|
59
46
|
end
|
60
47
|
end
|
61
48
|
|
@@ -1,4 +1,25 @@
|
|
1
|
-
|
1
|
+
begin
|
2
|
+
require "google/cloud/storage"
|
3
|
+
rescue LoadError => e
|
4
|
+
$stderr.puts "#{e.class}: #{e.message}".color(:red)
|
5
|
+
$stderr.puts <<~EOL
|
6
|
+
|
7
|
+
Unable to: require "google/cloud/storage"
|
8
|
+
|
9
|
+
In order to use gcs as a terraspace bundler source,
|
10
|
+
please add the google-cloud-storage gem to
|
11
|
+
your Terraspace project's Gemfile and run bundle.
|
12
|
+
|
13
|
+
To add the gem to your Gemfile, you can run:
|
14
|
+
|
15
|
+
bundle add google-cloud-storage
|
16
|
+
|
17
|
+
Then download modules in defined your Terrafile with:
|
18
|
+
|
19
|
+
terraspace bundle
|
20
|
+
EOL
|
21
|
+
exit 1
|
22
|
+
end
|
2
23
|
|
3
24
|
class TerraspaceBundler::Mod::Fetcher
|
4
25
|
class Gcs < Base
|
@@ -4,11 +4,11 @@ class TerraspaceBundler::Mod::Fetcher
|
|
4
4
|
|
5
5
|
def run
|
6
6
|
setup_tmp
|
7
|
-
|
8
|
-
FileUtils.mkdir_p(
|
7
|
+
org_folder = cache_path(@mod.org_folder)
|
8
|
+
FileUtils.mkdir_p(org_folder)
|
9
9
|
|
10
|
-
Dir.chdir(
|
11
|
-
logger.debug "Current root dir: #{
|
10
|
+
Dir.chdir(org_folder) do
|
11
|
+
logger.debug "Current root dir: #{org_folder}"
|
12
12
|
clone unless File.exist?(@mod.repo)
|
13
13
|
|
14
14
|
Dir.chdir(@mod.repo) do
|
@@ -45,12 +45,13 @@ class TerraspaceBundler::Mod::Fetcher
|
|
45
45
|
if found
|
46
46
|
found.split(':').last.strip
|
47
47
|
else
|
48
|
-
'master'
|
48
|
+
ENV['TS_GIT_DEFAULT_BRANCH'] || 'master'
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
def switch_version(version)
|
53
53
|
stage_path = stage_path(rel_dest_dir)
|
54
|
+
logger.debug "stage_path #{stage_path}"
|
54
55
|
Dir.chdir(stage_path) do
|
55
56
|
git "checkout #{version}"
|
56
57
|
@sha = git("rev-parse HEAD").strip
|
@@ -0,0 +1,65 @@
|
|
1
|
+
class TerraspaceBundler::Mod
|
2
|
+
class OrgRepo
|
3
|
+
def initialize(url)
|
4
|
+
@url = url.sub('ssh://','') # important to copy so dont change the string reference
|
5
|
+
end
|
6
|
+
|
7
|
+
def repo
|
8
|
+
org_repo_words[-1]
|
9
|
+
end
|
10
|
+
|
11
|
+
def org
|
12
|
+
s = org_folder.split('/').last
|
13
|
+
s ? s.split('/').last : 'none'
|
14
|
+
end
|
15
|
+
|
16
|
+
def org_folder
|
17
|
+
org_repo_words[-2] # second to last word
|
18
|
+
end
|
19
|
+
|
20
|
+
def repo_folder
|
21
|
+
org_repo_words.join('/')
|
22
|
+
end
|
23
|
+
|
24
|
+
def org_repo_words
|
25
|
+
if @url.include?(':') && !@url.match(%r{http[s?]://}) # user@host:repo git@github.com:org/repo
|
26
|
+
folder, repo = handle_string_with_colon
|
27
|
+
else # IE: https://github.com/org/repo, org/repo, etc
|
28
|
+
parts = @url.split('/')
|
29
|
+
folder = parts[0..-2].join('/')
|
30
|
+
repo = parts.last
|
31
|
+
end
|
32
|
+
|
33
|
+
org_path = clean_folder(folder)
|
34
|
+
repo = strip_dot_git(repo)
|
35
|
+
[org_path, repo]
|
36
|
+
end
|
37
|
+
|
38
|
+
def clean_folder(folder)
|
39
|
+
folder.sub(%r{.*@},'') # remove user@
|
40
|
+
.sub(%r{http[s?]://},'') # remove https://
|
41
|
+
end
|
42
|
+
|
43
|
+
# user@host:repo git@github.com:org/repo
|
44
|
+
def handle_string_with_colon
|
45
|
+
host, path = @url.split(':')
|
46
|
+
if path.size == 2
|
47
|
+
folder, repo = path.split(':')
|
48
|
+
else
|
49
|
+
folder = join(host, File.dirname(path))
|
50
|
+
repo = File.basename(path)
|
51
|
+
end
|
52
|
+
[folder, repo]
|
53
|
+
end
|
54
|
+
|
55
|
+
def join(*path)
|
56
|
+
path.compact!
|
57
|
+
path[1] = path[1].sub('/','') if path[1].starts_with?('/')
|
58
|
+
path.reject(&:blank?).join('/')
|
59
|
+
end
|
60
|
+
|
61
|
+
def strip_dot_git(s)
|
62
|
+
s.sub(/\.git$/,'')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -66,6 +66,20 @@ class TerraspaceBundler::Mod
|
|
66
66
|
end
|
67
67
|
|
68
68
|
# git_source_url is normalized
|
69
|
+
#
|
70
|
+
# See: https://stackoverflow.com/questions/6167905/git-clone-through-ssh
|
71
|
+
#
|
72
|
+
# ssh://username@host.xz/absolute/path/to/repo.git/ - just a forward slash for absolute path on server
|
73
|
+
# username@host.xz:relative/path/to/repo.git/ - just a colon (it mustn't have the ssh:// for relative path on server (relative to home dir of username on server machine)
|
74
|
+
#
|
75
|
+
# When colon is separator for relative path do not want ssh prepended
|
76
|
+
#
|
77
|
+
# git clone ec2-user@localhost:repo
|
78
|
+
#
|
79
|
+
# When slash is separator for absolute path want ssh prepended
|
80
|
+
#
|
81
|
+
# git clone ssh://ec2-user@localhost/path/to/repo => valid URI
|
82
|
+
#
|
69
83
|
def git_source_url
|
70
84
|
if @source.include?('http') || @source.include?(':')
|
71
85
|
# Examples:
|
@@ -76,7 +90,15 @@ class TerraspaceBundler::Mod
|
|
76
90
|
# mod "example3", source: "git::https://example.com/example-module.git"
|
77
91
|
#
|
78
92
|
# sub to allow for generic git repo notiation
|
79
|
-
@source.sub('git::','')
|
93
|
+
source = @source.sub('git::','')
|
94
|
+
if source.include?('ssh://')
|
95
|
+
if source.count(':') == 1
|
96
|
+
return source
|
97
|
+
else
|
98
|
+
return source.sub('ssh://', '')
|
99
|
+
end
|
100
|
+
end
|
101
|
+
source
|
80
102
|
else
|
81
103
|
# Examples:
|
82
104
|
# mod "pet", source: "tongueroo/pet"
|
@@ -85,20 +85,17 @@ class TerraspaceBundler::Mod
|
|
85
85
|
def public_github_url
|
86
86
|
base_site = "https://registry.terraform.io"
|
87
87
|
base_url = "#{base_site}/v1/modules"
|
88
|
-
version =
|
88
|
+
version = get_version(base_url)
|
89
89
|
api_url = [base_url, @source, version, "download"].compact.join('/')
|
90
90
|
|
91
91
|
resp = http_request(api_url)
|
92
92
|
|
93
93
|
case resp.code.to_i
|
94
|
-
when 204
|
95
|
-
download_url = resp.header["x-terraform-get"]
|
96
|
-
when 302
|
97
|
-
next_url = "#{base_site}#{resp.header["location"]}"
|
98
|
-
resp = http_request(next_url)
|
94
|
+
when 204 # IE: curl -v https://registry.terraform.io/v1/modules/terraform-aws-modules/security-group/aws/3.10.0/download
|
99
95
|
download_url = resp.header["x-terraform-get"]
|
100
96
|
else
|
101
97
|
logger.error "ERROR: Unable to lookup up module in Terraform Registry: #{@source}".color(:red)
|
98
|
+
logger.error "api_url: #{api_url}"
|
102
99
|
puts "resp.code #{resp.code}"
|
103
100
|
pp resp
|
104
101
|
exit 1
|
@@ -109,6 +106,14 @@ class TerraspaceBundler::Mod
|
|
109
106
|
url.sub(/^git::/,'').sub(/\?.*/,'')
|
110
107
|
end
|
111
108
|
|
109
|
+
def get_version(base_url)
|
110
|
+
return @version.sub(/^v/,'') if @version # v1.0 => 1.0
|
111
|
+
api_url = [base_url, @source].join('/')
|
112
|
+
resp = http_request(api_url)
|
113
|
+
data = JSON.load(resp.body)
|
114
|
+
data['version']
|
115
|
+
end
|
116
|
+
|
112
117
|
private
|
113
118
|
def auth_error_exit!(resp=nil, domain=nil)
|
114
119
|
logger.error <<~EOL.color(:red)
|
@@ -1,7 +1,9 @@
|
|
1
1
|
module TerraspaceBundler
|
2
2
|
class Mod
|
3
|
+
extend Memoist
|
3
4
|
extend Props::Extension
|
4
5
|
props :export_to, :name, :sha, :source, :subfolder, :type, :url, :clone_with
|
6
|
+
delegate :repo, :org, :repo_folder, :org_folder, to: :org_repo
|
5
7
|
|
6
8
|
include Concerns::StackConcern
|
7
9
|
include Concerns::LocalConcern
|
@@ -18,22 +20,6 @@ module TerraspaceBundler
|
|
18
20
|
@version || @ref || @tag || @branch
|
19
21
|
end
|
20
22
|
|
21
|
-
# use url instead of source because for registry modules, the repo name is different
|
22
|
-
def repo
|
23
|
-
url_words[-1].sub(/\.git$/,'')
|
24
|
-
end
|
25
|
-
|
26
|
-
# https://github.com/tongueroo/pet - 2nd to last word
|
27
|
-
# git@github.com:tongueroo/pet - 2nd to last word without chars before :
|
28
|
-
def org
|
29
|
-
s = url_words[-2] # second to last word
|
30
|
-
s.split(':').last # in case of git@github.com:tongueroo/pet form
|
31
|
-
end
|
32
|
-
|
33
|
-
def full_repo
|
34
|
-
"#{org}/#{repo}"
|
35
|
-
end
|
36
|
-
|
37
23
|
def latest_sha
|
38
24
|
fetcher = Fetcher.new(self).instance
|
39
25
|
fetcher.run
|
@@ -44,15 +30,18 @@ module TerraspaceBundler
|
|
44
30
|
if url.include?('http')
|
45
31
|
# "https://github.com/org/repo" => github.com
|
46
32
|
url.match(%r{http[s]?://(.*?)/})[1]
|
47
|
-
|
33
|
+
elsif url.include?('http') # git@
|
48
34
|
# "git@github.com:org/repo" => github.com
|
49
35
|
url.match(%r{git@(.*?):})[1]
|
36
|
+
else # ssh://user@domain.com/path/to/repo
|
37
|
+
'none'
|
50
38
|
end
|
51
39
|
end
|
52
40
|
|
53
41
|
private
|
54
|
-
def
|
55
|
-
|
42
|
+
def org_repo
|
43
|
+
OrgRepo.new(url)
|
56
44
|
end
|
45
|
+
memoize :org_repo
|
57
46
|
end
|
58
47
|
end
|
data/lib/terraspace_bundler.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
$:.unshift(File.expand_path("../", __FILE__))
|
2
|
+
require "active_support"
|
2
3
|
require "active_support/core_ext/class"
|
3
4
|
require "active_support/core_ext/hash"
|
4
5
|
require "active_support/core_ext/string"
|
5
6
|
require "active_support/ordered_options"
|
6
7
|
require "dsl_evaluator"
|
7
8
|
require "fileutils"
|
9
|
+
require "json"
|
8
10
|
require "memoist"
|
9
11
|
require "rainbow/ext/string"
|
10
12
|
require "singleton"
|
data/readme/qa/Terrafile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Here's an example Terrafile that can be used to qa the different types of sources.
|
2
|
+
# Based on: https://terraspace.cloud/docs/terrafile/sources/
|
3
|
+
# Note: Actually need to make sure that have access to the sources, IE: s3, gcs, github, etc
|
4
|
+
# This is still useful as an example to help with QA.
|
5
|
+
|
6
|
+
# Use modules from the Terraform registry
|
7
|
+
mod "sqs", source: "terraform-aws-modules/sqs/aws"
|
8
|
+
mod "s3", source: "git@github.com:boltops-tools/terraform-aws-s3"
|
9
|
+
mod "s3test", source: "boltops-tools/terraform-aws-s3"
|
10
|
+
|
11
|
+
mod "test1", source: "git::https://github.com/boltops-tools/terraform-aws-s3"
|
12
|
+
mod "test2", source: "git::ssh://ec2-user@localhost:/home/ec2-user/environment/repo"
|
13
|
+
mod "test3", source: "git::ssh://ec2-user@localhost:environment/repo"
|
14
|
+
mod "test4", source: "git::ssh://localhost:environment/repo"
|
15
|
+
mod "test5", source: "ssh://ec2-user@localhost/home/ec2-user/environment/repo"
|
16
|
+
mod "test6", source: "ssh://ec2-user@localhost:/home/ec2-user/environment/repo"
|
17
|
+
mod "test7", source: "ssh://ec2-user@localhost:/home/ec2-user/environment/repo//subfolder"
|
18
|
+
mod "test8", source: "ssh://ec2-user@localhost:environment/repo"
|
19
|
+
mod "test9", source: "ssh://ec2-user@localhost:repo"
|
20
|
+
|
21
|
+
mod "pet1", source: "tongueroo/pet"
|
22
|
+
mod "pet2", source: "https://github.com/tongueroo/pet"
|
23
|
+
mod "example1", source: "git@bitbucket.org:tongueroo/example-module.git"
|
24
|
+
mod "example2", source: "git@gitlab.com:tongueroo/example-module"
|
25
|
+
|
26
|
+
org "tongueroo"
|
27
|
+
mod "pet3", source: "pet" # inferred org
|
28
|
+
|
29
|
+
mod "sg", source: "terraform-aws-modules/security-group/aws" # terraform registry public example
|
30
|
+
mod "pet4", source: "app.terraform.io/boltops/pet/random" # , clone_with: "https"
|
31
|
+
|
32
|
+
mod "demo1", source: "s3::https://s3-us-west-2.amazonaws.com/demo-terraform-test/modules/example-module.tgz"
|
33
|
+
mod "demo2", source: "s3::https://s3-us-west-2.amazonaws.com/demo-terraform-test/modules/example-module.zip"
|
34
|
+
mod "demo3", source: "gcs::https://www.googleapis.com/storage/v1/terraform-example-modules/modules/example-module.zip//subfolder"
|
35
|
+
mod "demo4", source: "gcs::https://www.googleapis.com/storage/v1/terraform-example-modules/modules/example-module.tgz//subfolder"
|
36
|
+
|
37
|
+
mod "local1", source: "/home/ec2-user/environment/downloads/example-module"
|
38
|
+
mod "local2", source: "./example-module"
|
39
|
+
mod "local3", source: "~/environment/infra-terrafile/example-module"
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class NotationTest
|
2
|
+
include TB::Mod::Concerns::NotationConcern
|
3
|
+
end
|
4
|
+
|
5
|
+
describe NotationTest do
|
6
|
+
let(:notation) { described_class.new }
|
7
|
+
|
8
|
+
context "clean_notation" do
|
9
|
+
it "cleans" do
|
10
|
+
source = "git::ssh://ec2-user@localhost:/home/ec2-user/environment/repo"
|
11
|
+
cleaned = notation.clean_notation(source)
|
12
|
+
expect(cleaned).to eq "/home/ec2-user/environment/repo"
|
13
|
+
|
14
|
+
source = "ssh://ec2-user@localhost:/home/ec2-user/environment/repo"
|
15
|
+
cleaned = notation.clean_notation(source)
|
16
|
+
expect(cleaned).to eq "/home/ec2-user/environment/repo"
|
17
|
+
|
18
|
+
source = "ssh://ec2-user@localhost:/home/ec2-user/environment/repo//subfolder"
|
19
|
+
cleaned = notation.clean_notation(source)
|
20
|
+
expect(cleaned).to eq "/home/ec2-user/environment/repo//subfolder"
|
21
|
+
|
22
|
+
source = "git::ssh://ec2-user@localhost:environment/repo"
|
23
|
+
cleaned = notation.clean_notation(source)
|
24
|
+
expect(cleaned).to eq "environment/repo"
|
25
|
+
|
26
|
+
source = "ssh://ec2-user@localhost:~/environment/repo"
|
27
|
+
cleaned = notation.clean_notation(source)
|
28
|
+
expect(cleaned).to eq "~/environment/repo"
|
29
|
+
|
30
|
+
source = "git::ssh://localhost:environment/repo"
|
31
|
+
cleaned = notation.clean_notation(source)
|
32
|
+
expect(cleaned).to eq "environment/repo"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
describe TB::Mod::OrgRepo do
|
2
|
+
let(:org_repo) { described_class.new(url) }
|
3
|
+
|
4
|
+
context "ssh://ec2-user@localhost/repo" do
|
5
|
+
let(:url) { "ssh://ec2-user@localhost/repo" }
|
6
|
+
it "org repo" do
|
7
|
+
# puts "org_repo.org #{org_repo.org}"
|
8
|
+
# puts "org_repo.repo #{org_repo.repo}"
|
9
|
+
expect(org_repo.org_folder).to eq "localhost"
|
10
|
+
expect(org_repo.repo_folder).to eq "localhost/repo"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context "ssh://ec2-user@localhost/long/path/to/repo" do
|
15
|
+
let(:url) { "ssh://ec2-user@localhost/long/path/to/repo" }
|
16
|
+
it "org repo" do
|
17
|
+
expect(org_repo.org_folder).to eq "localhost/long/path/to"
|
18
|
+
expect(org_repo.repo_folder).to eq "localhost/long/path/to/repo"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "ec2-user@localhost:long/path/to/repo" do
|
23
|
+
let(:url) { "ec2-user@localhost:long/path/to/repo" }
|
24
|
+
it "org repo" do
|
25
|
+
expect(org_repo.org_folder).to eq "localhost/long/path/to"
|
26
|
+
expect(org_repo.repo_folder).to eq "localhost/long/path/to/repo"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "git@github.com:org/repo" do
|
31
|
+
let(:url) { "git@github.com:org/repo" }
|
32
|
+
it "org repo" do
|
33
|
+
expect(org_repo.org_folder).to eq "github.com/org"
|
34
|
+
expect(org_repo.repo_folder).to eq "github.com/org/repo"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "https://github.com/org/repo" do
|
39
|
+
let(:url) { "https://github.com/org/repo" }
|
40
|
+
it "org repo" do
|
41
|
+
expect(org_repo.org_folder).to eq "github.com/org"
|
42
|
+
expect(org_repo.repo_folder).to eq "github.com/org/repo"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -31,4 +31,134 @@ describe TB::Mod::Props do
|
|
31
31
|
expect(url).to eq "git@gitlab.com:tongueroo/example-module.git"
|
32
32
|
end
|
33
33
|
end
|
34
|
+
|
35
|
+
# context terrafile = evaulated Terrafile DSL results in these type of options being passed to Props#build
|
36
|
+
context "terrafile" do
|
37
|
+
let(:params) do
|
38
|
+
{
|
39
|
+
:args=>["repo"],
|
40
|
+
:options=>{:source=>source},
|
41
|
+
:source=>"git::ssh://ec2-user@localhost:/home/ec2-user/environment/repo",
|
42
|
+
:name=>"repo",
|
43
|
+
:type=>"git",
|
44
|
+
:url=>"ssh:",
|
45
|
+
:subfolder=>"ec2-user@localhost:/home/ec2-user/environment/repo", :ref=>nil
|
46
|
+
|
47
|
+
}
|
48
|
+
end
|
49
|
+
context "git@github.com source" do
|
50
|
+
let(:source) { "git@github.com:boltops-tools/terraform-aws-s3" }
|
51
|
+
it "properties" do
|
52
|
+
result = props.build
|
53
|
+
expect(result).to eq(
|
54
|
+
{:source=>"git@github.com:boltops-tools/terraform-aws-s3",
|
55
|
+
:name=>"repo",
|
56
|
+
:type=>"git",
|
57
|
+
:url=>"git@github.com:boltops-tools/terraform-aws-s3",
|
58
|
+
:subfolder=>nil,
|
59
|
+
:ref=>nil}
|
60
|
+
)
|
61
|
+
expect(props.url).to eq "git@github.com:boltops-tools/terraform-aws-s3"
|
62
|
+
expect(props.type).to eq "git"
|
63
|
+
expect(props.source).to eq "git@github.com:boltops-tools/terraform-aws-s3"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
context "https://github.com source" do
|
67
|
+
let(:source) { "https://github.com/boltops-tools/random_pet" }
|
68
|
+
it "properties" do
|
69
|
+
expect(props.url).to eq "https://github.com/boltops-tools/random_pet"
|
70
|
+
expect(props.type).to eq "git"
|
71
|
+
expect(props.source).to eq "https://github.com/boltops-tools/random_pet"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
context "explicit org source" do
|
75
|
+
let(:source) { "boltopspro/terraform-aws-elasticache" }
|
76
|
+
it "properties" do
|
77
|
+
expect(props.url).to eq "https://github.com/boltopspro/terraform-aws-elasticache"
|
78
|
+
expect(props.type).to eq "git"
|
79
|
+
expect(props.source).to eq "boltopspro/terraform-aws-elasticache"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
context "terraform registry source" do
|
83
|
+
let(:source) { "terraform-aws-modules/security-group/aws" }
|
84
|
+
it "properties" do
|
85
|
+
expect(props.url).to eq "https://github.com/terraform-aws-modules/terraform-aws-security-group"
|
86
|
+
expect(props.type).to eq "registry"
|
87
|
+
expect(props.source).to eq "terraform-aws-modules/security-group/aws"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
context "ssh with explicit user source" do
|
91
|
+
let(:source) { "ssh://user@host:/path/to/repo" }
|
92
|
+
it "properties" do
|
93
|
+
result = props.build
|
94
|
+
expect(result).to eq(
|
95
|
+
{:source=>"ssh://user@host:/path/to/repo",
|
96
|
+
:name=>"repo",
|
97
|
+
:type=>"git",
|
98
|
+
:url=>"user@host:/path/to/repo",
|
99
|
+
:subfolder=>nil,
|
100
|
+
:ref=>nil}
|
101
|
+
)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
context "ssh with implied user source" do
|
105
|
+
let(:source) { "ssh://host:/path/to/repo" }
|
106
|
+
it "properties" do
|
107
|
+
result = props.build
|
108
|
+
expect(result).to eq(
|
109
|
+
{:source=>"ssh://host:/path/to/repo",
|
110
|
+
:name=>"repo",
|
111
|
+
:type=>"git",
|
112
|
+
:url=>"host:/path/to/repo",
|
113
|
+
:subfolder=>nil,
|
114
|
+
:ref=>nil}
|
115
|
+
)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context "ssh 2-level folder source" do
|
120
|
+
let(:source) { "ssh://ec2-user@localhost:environment/repo" }
|
121
|
+
it "properties" do
|
122
|
+
result = props.build
|
123
|
+
expect(result).to eq(
|
124
|
+
{:source=>"ssh://ec2-user@localhost:environment/repo",
|
125
|
+
:name=>"repo",
|
126
|
+
:type=>"git",
|
127
|
+
:url=>"ec2-user@localhost:environment/repo",
|
128
|
+
:subfolder=>nil,
|
129
|
+
:ref=>nil}
|
130
|
+
)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context "ssh 1-level folder source" do
|
135
|
+
let(:source) { "ssh://ec2-user@localhost:repo" }
|
136
|
+
it "properties" do
|
137
|
+
result = props.build
|
138
|
+
expect(result).to eq(
|
139
|
+
{:source=>"ssh://ec2-user@localhost:repo",
|
140
|
+
:name=>"repo",
|
141
|
+
:type=>"git",
|
142
|
+
:url=>"ec2-user@localhost:repo",
|
143
|
+
:subfolder=>nil,
|
144
|
+
:ref=>nil}
|
145
|
+
)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
context "ssh without colon supports only absolute path source" do
|
150
|
+
let(:source) { "ssh://ec2-user@localhost/home/ec2-user/repo" }
|
151
|
+
it "properties" do
|
152
|
+
result = props.build
|
153
|
+
expect(result).to eq(
|
154
|
+
{:source=>"ssh://ec2-user@localhost/home/ec2-user/repo",
|
155
|
+
:name=>"repo",
|
156
|
+
:type=>"git",
|
157
|
+
:url=>"ssh://ec2-user@localhost/home/ec2-user/repo",
|
158
|
+
:subfolder=>nil,
|
159
|
+
:ref=>nil}
|
160
|
+
)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
34
164
|
end
|
data/terraspace-bundler.gemspec
CHANGED
@@ -21,7 +21,6 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_dependency "activesupport"
|
22
22
|
spec.add_dependency "aws-sdk-s3"
|
23
23
|
spec.add_dependency "dsl_evaluator"
|
24
|
-
spec.add_dependency "google-cloud-storage"
|
25
24
|
spec.add_dependency "memoist"
|
26
25
|
spec.add_dependency "nokogiri"
|
27
26
|
spec.add_dependency "rainbow"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: terraspace-bundler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.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:
|
11
|
+
date: 2022-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: google-cloud-storage
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: memoist
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -230,6 +216,7 @@ files:
|
|
230
216
|
- lib/terraspace_bundler/cli/base.rb
|
231
217
|
- lib/terraspace_bundler/cli/bundle.rb
|
232
218
|
- lib/terraspace_bundler/cli/help.rb
|
219
|
+
- lib/terraspace_bundler/cli/help/bundle/example.md
|
233
220
|
- lib/terraspace_bundler/cli/help/bundle/info.md
|
234
221
|
- lib/terraspace_bundler/cli/help/bundle/install.md
|
235
222
|
- lib/terraspace_bundler/cli/help/bundle/list.md
|
@@ -245,6 +232,7 @@ files:
|
|
245
232
|
- lib/terraspace_bundler/core.rb
|
246
233
|
- lib/terraspace_bundler/dsl.rb
|
247
234
|
- lib/terraspace_bundler/dsl/syntax.rb
|
235
|
+
- lib/terraspace_bundler/example.rb
|
248
236
|
- lib/terraspace_bundler/exporter.rb
|
249
237
|
- lib/terraspace_bundler/exporter/base.rb
|
250
238
|
- lib/terraspace_bundler/exporter/copy.rb
|
@@ -275,6 +263,7 @@ files:
|
|
275
263
|
- lib/terraspace_bundler/mod/fetcher/s3.rb
|
276
264
|
- lib/terraspace_bundler/mod/http/concern.rb
|
277
265
|
- lib/terraspace_bundler/mod/http/source.rb
|
266
|
+
- lib/terraspace_bundler/mod/org_repo.rb
|
278
267
|
- lib/terraspace_bundler/mod/props.rb
|
279
268
|
- lib/terraspace_bundler/mod/props/extension.rb
|
280
269
|
- lib/terraspace_bundler/mod/props/typer.rb
|
@@ -286,6 +275,7 @@ files:
|
|
286
275
|
- lib/terraspace_bundler/util/logging.rb
|
287
276
|
- lib/terraspace_bundler/util/sure.rb
|
288
277
|
- lib/terraspace_bundler/version.rb
|
278
|
+
- readme/qa/Terrafile
|
289
279
|
- spec/fixtures/Terrafile
|
290
280
|
- spec/fixtures/rewrite/example-subfolder.tf
|
291
281
|
- spec/fixtures/rewrite/module-subfolder.tf
|
@@ -298,6 +288,8 @@ files:
|
|
298
288
|
- spec/fixtures/terrafiles/example/Terrafile
|
299
289
|
- spec/spec_helper.rb
|
300
290
|
- spec/terraform_bundler/exporter/stacks/rewrite_spec.rb
|
291
|
+
- spec/terraform_bundler/mod/concerns/notation_concern_spec.rb
|
292
|
+
- spec/terraform_bundler/mod/org_repo_spec.rb
|
301
293
|
- spec/terraform_bundler/mod/props_spec.rb
|
302
294
|
- spec/terraform_bundler/mod_spec.rb
|
303
295
|
- spec/terraform_bundler/runner_spec.rb
|
@@ -321,7 +313,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
321
313
|
- !ruby/object:Gem::Version
|
322
314
|
version: '0'
|
323
315
|
requirements: []
|
324
|
-
rubygems_version: 3.
|
316
|
+
rubygems_version: 3.2.32
|
325
317
|
signing_key:
|
326
318
|
specification_version: 4
|
327
319
|
summary: Bundles terraform modules
|
@@ -338,6 +330,8 @@ test_files:
|
|
338
330
|
- spec/fixtures/terrafiles/example/Terrafile
|
339
331
|
- spec/spec_helper.rb
|
340
332
|
- spec/terraform_bundler/exporter/stacks/rewrite_spec.rb
|
333
|
+
- spec/terraform_bundler/mod/concerns/notation_concern_spec.rb
|
334
|
+
- spec/terraform_bundler/mod/org_repo_spec.rb
|
341
335
|
- spec/terraform_bundler/mod/props_spec.rb
|
342
336
|
- spec/terraform_bundler/mod_spec.rb
|
343
337
|
- spec/terraform_bundler/runner_spec.rb
|