terraspace-bundler 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d61db038a37cd472b7be9b5f3d15a2388254a4b2a3c0d3af3dabb2e10e8c4fc1
4
- data.tar.gz: 83630195dceb5e35dee5be326311806cb8b06a3eedad4ca10f6b98c4962fe0bb
3
+ metadata.gz: c21958fbce8f8bf1da181ab8d0fa28959ce010d8dda1b39aa179a10d4a1bd4fe
4
+ data.tar.gz: 3b7603b433569c0f3882ebab829103a1d76857a0b09ca798aa95466ba5d2e590
5
5
  SHA512:
6
- metadata.gz: 7d4cc8ad358e17708a27085a4a523e4fcddfb007c81d507c07a7c736a851c48f5ed93ca4d9f6b5f64561c822a1e813a4850d7076f1c419869e01626f91e12682
7
- data.tar.gz: 322b70b512a594212f3530d7d0b99d0f55fa15ecfa496c4aee13f0df0bede32f7628c541179697171a1384e81a07a18871378d348dfe90b2bd131c0592e4008a
6
+ metadata.gz: 5cd549097ef26f461dd14d2b462020f7925ab0522d00437e5002c17c5a052876ead3a9b45e534559aa5c03f73a1762f98b92c4457a9b3c778d5a1da3e52722b2
7
+ data.tar.gz: bb2b95860f590d7e30a3ae1972dc227cf31abb7f14fa32f897b8b49242c1955052f7fd931c73973988c3992a52d94315fdf099404e9e64649fdf04af9686eca9
data/CHANGELOG.md CHANGED
@@ -3,6 +3,10 @@
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.4.3] - 2021-11-20
7
+ - [#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
8
+ - [#15](https://github.com/boltops-tools/terraspace-bundler/pull/15) terraspace bundle example command
9
+
6
10
  ## [0.4.2] - 2021-10-02
7
11
  - stack src option: also understand example and name
8
12
 
@@ -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
@@ -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 = @version.sub(/^v/,'') if @version # v1.0 => 1.0
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,3 +1,3 @@
1
1
  module TerraspaceBundler
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
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.2
4
+ version: 0.4.3
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-10-02 00:00:00.000000000 Z
11
+ date: 2021-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -230,6 +230,7 @@ files:
230
230
  - lib/terraspace_bundler/cli/base.rb
231
231
  - lib/terraspace_bundler/cli/bundle.rb
232
232
  - lib/terraspace_bundler/cli/help.rb
233
+ - lib/terraspace_bundler/cli/help/bundle/example.md
233
234
  - lib/terraspace_bundler/cli/help/bundle/info.md
234
235
  - lib/terraspace_bundler/cli/help/bundle/install.md
235
236
  - lib/terraspace_bundler/cli/help/bundle/list.md
@@ -245,6 +246,7 @@ files:
245
246
  - lib/terraspace_bundler/core.rb
246
247
  - lib/terraspace_bundler/dsl.rb
247
248
  - lib/terraspace_bundler/dsl/syntax.rb
249
+ - lib/terraspace_bundler/example.rb
248
250
  - lib/terraspace_bundler/exporter.rb
249
251
  - lib/terraspace_bundler/exporter/base.rb
250
252
  - lib/terraspace_bundler/exporter/copy.rb