terraspace_plugin_google 0.2.1 → 0.3.2

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: b210bb6190e4c84d5e1dc299d98761541bdbefdc8c68f7c81487a95586785529
4
- data.tar.gz: 6e2a0b9fad7a7a702b143ac0c2569109c07326693b75aa5cb7c09cee820dc7f3
3
+ metadata.gz: b1969fbb36af32fab94f9351578d4807c893066757463883a59782c431a5a56f
4
+ data.tar.gz: d1cdf9f00fc64526cf1e935d74b201eb24a71bd1204f0a1a0e6b3c7cef05257d
5
5
  SHA512:
6
- metadata.gz: df87fc25c96629faed3c64e193cddf5ca18d40a43564b483e2f077b2b9a9dd62adda07de6e3e0ae729456a716b2785eea3ce9d5e437a257dfdea3f05b419e5ac
7
- data.tar.gz: 2fd58bbfb84efb5de44bbf4603efc296e53d407920a64b7739c0e052ae5c027ef8ad187606b4059b7b965c86bfc015c311ea260c244eb0aa37c831698f611ccf
6
+ metadata.gz: 18e36296b55e061e6a093b2726006a4b860f0815630d5401a95ced5b5054825db13b014638795df4963c8ae797b81d8933f1958b71296883967279c43e1a39ab
7
+ data.tar.gz: 5e04f12177cd156b327ff86fbb7b0df7887043616b96d544c8412e2a44f66c2de6fe45e80f8603a758eaaebaef733315e3d357ae6c2d966cca3e6db41f93ef37
data/CHANGELOG.md CHANGED
@@ -3,6 +3,19 @@
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/).
5
5
 
6
+ ## [0.3.2] - 2021-11-25
7
+ - [#8](https://github.com/boltops-tools/terraspace_provider_google/pull/8) update example templates to include bucket location which is now required
8
+
9
+ ## [0.3.1] - 2021-11-13
10
+ - [#7](https://github.com/boltops-tools/terraspace_provider_google/pull/7) get google project number via api
11
+
12
+ ## [0.3.0] - 2020-11-15
13
+ - [#5](https://github.com/boltops-tools/terraspace_provider_google/pull/5) helper and secrets support
14
+ - google secret
15
+
16
+ ## [0.2.2]
17
+ - #4 fix test template: folder rename to stacks
18
+
6
19
  ## [0.2.1]
7
20
  - #3 update starter example template: bucket_policy_only deprecated for uniform_bucket_level_access
8
21
  - edge case: graceful error when bucket doesnt exist yet
@@ -1,4 +1,5 @@
1
1
  resource "google_storage_bucket" "this" {
2
2
  name = var.name
3
3
  uniform_bucket_level_access = var.uniform_bucket_level_access
4
+ location = var.location
4
5
  }
@@ -8,3 +8,9 @@ variable "uniform_bucket_level_access" {
8
8
  type = bool
9
9
  default = false
10
10
  }
11
+
12
+ variable "location" {
13
+ description = "location"
14
+ type = string
15
+ default = "US"
16
+ }
@@ -1,6 +1,6 @@
1
1
  terraform {
2
2
  backend "gcs" {
3
- bucket = "<%%= expansion('terraform-state-:PROJECT-:REGION-:ENV') %>" # expanded by terraspace IE: terraform-state-project-us-central1-dev
4
- prefix = "<%%= expansion(':REGION/:ENV/:BUILD_DIR') %>" # expanded by terraspace IE: us-central1/dev/modules/vm
3
+ bucket = "<%%= expansion('terraform-state-:PROJECT-:REGION-:ENV') %>"
4
+ prefix = "<%%= expansion(':REGION/:ENV/:BUILD_DIR') %>"
5
5
  }
6
6
  }
@@ -7,4 +7,5 @@ module "bucket" {
7
7
 
8
8
  name = "bucket-${random_pet.this.id}"
9
9
  uniform_bucket_level_access = var.uniform_bucket_level_access
10
+ location = var.location
10
11
  }
@@ -3,3 +3,9 @@ variable "uniform_bucket_level_access" {
3
3
  type = bool
4
4
  default = false
5
5
  }
6
+
7
+ variable "location" {
8
+ description = "location"
9
+ type = string
10
+ default = "US"
11
+ }
@@ -1,12 +1,24 @@
1
+ require "google-cloud-resource_manager"
2
+ require "google-cloud-secret_manager"
1
3
  require "google/cloud/storage"
2
4
 
3
5
  module TerraspacePluginGoogle
4
6
  module Clients
5
7
  extend Memoist
6
8
 
9
+ def secret_manager_service
10
+ Google::Cloud::SecretManager.secret_manager_service
11
+ end
12
+ memoize :secret_manager_service
13
+
7
14
  def storage
8
15
  Google::Cloud::Storage.new
9
16
  end
10
17
  memoize :storage
18
+
19
+ def resource_manager
20
+ Google::Cloud.new.resource_manager
21
+ end
22
+ memoize :resource_manager
11
23
  end
12
24
  end
@@ -0,0 +1,38 @@
1
+ require "base64"
2
+
3
+ module TerraspacePluginGoogle::Interfaces::Helper
4
+ class Secret
5
+ include TerraspacePluginGoogle::Clients
6
+ include TerraspacePluginGoogle::Logging
7
+
8
+ def initialize(options={})
9
+ @options = options
10
+ @base64 = options[:base64]
11
+ @project_id = options[:google_project] || ENV['GOOGLE_PROJECT'] || raise("GOOGLE_PROJECT env variable is not set. It's required.")
12
+ end
13
+
14
+ def fetch(short_name, version: "latest")
15
+ value = fetch_value(short_name, version)
16
+ value = Base64.strict_encode64(value).strip if @base64
17
+ value
18
+ end
19
+
20
+ def fetch_value(short_name, version="latest")
21
+ name = "projects/#{project_number}/secrets/#{short_name}/versions/#{version}"
22
+ version = secret_manager_service.access_secret_version(name: name)
23
+ version.payload.data
24
+ rescue Google::Cloud::NotFoundError => e
25
+ logger.info "WARN: secret #{name} not found".color(:yellow)
26
+ logger.info e.message
27
+ "NOT FOUND #{name}" # simple string so Kubernetes YAML is valid
28
+ end
29
+
30
+ private
31
+ @@project_number = nil
32
+ def project_number
33
+ return @@project_number if @@project_number
34
+ project = resource_manager.project(@project_id)
35
+ @@project_number = project.project_number
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,10 @@
1
+ module TerraspacePluginGoogle::Interfaces
2
+ module Helper
3
+ include Terraspace::Plugin::Helper::Interface
4
+
5
+ def google_secret(name, options={})
6
+ Secret.new(options).fetch(name)
7
+ end
8
+ cache_helper :google_secret
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module TerraspacePluginGoogle
2
+ module Logging
3
+ def logger
4
+ Terraspace.logger
5
+ end
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module TerraspacePluginGoogle
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.2"
3
3
  end
@@ -22,12 +22,22 @@ module TerraspacePluginGoogle
22
22
  Interfaces::Config.instance.config
23
23
  end
24
24
 
25
+ @@logger = nil
26
+ def logger
27
+ @@logger ||= Terraspace.logger
28
+ end
29
+
30
+ def logger=(v)
31
+ @@logger = v
32
+ end
33
+
25
34
  extend self
26
35
  end
27
36
 
28
37
  Terraspace::Plugin.register("google",
29
38
  backend: "gcs",
30
39
  config_class: TerraspacePluginGoogle::Interfaces::Config,
40
+ helper_class: TerraspacePluginGoogle::Interfaces::Helper,
31
41
  layer_class: TerraspacePluginGoogle::Interfaces::Layer,
32
42
  root: File.dirname(__dir__),
33
43
  )
@@ -24,6 +24,8 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.add_dependency "gcp_data"
26
26
  spec.add_dependency "google-cloud-storage"
27
+ spec.add_dependency "google-cloud-resource_manager"
28
+ spec.add_dependency "google-cloud-secret_manager"
27
29
  spec.add_dependency "memoist"
28
30
  spec.add_dependency "zeitwerk"
29
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terraspace_plugin_google
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-19 00:00:00.000000000 Z
11
+ date: 2021-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gcp_data
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: google-cloud-resource_manager
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: google-cloud-secret_manager
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'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: memoist
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -107,15 +135,18 @@ files:
107
135
  - lib/templates/test/rspec/module/test/spec/main_spec.rb.tt
108
136
  - lib/templates/test/rspec/module/test/spec/spec_helper.rb
109
137
  - lib/templates/test/rspec/project/spec/fixtures/tfvars/demo.tfvars
110
- - lib/templates/test/rspec/project/spec/stack/demo/main_spec.rb
138
+ - lib/templates/test/rspec/project/spec/stacks/demo/main_spec.rb
111
139
  - lib/terraspace_plugin_google.rb
112
140
  - lib/terraspace_plugin_google/autoloader.rb
113
141
  - lib/terraspace_plugin_google/clients.rb
114
142
  - lib/terraspace_plugin_google/interfaces/backend.rb
115
143
  - lib/terraspace_plugin_google/interfaces/config.rb
116
144
  - lib/terraspace_plugin_google/interfaces/expander.rb
145
+ - lib/terraspace_plugin_google/interfaces/helper.rb
146
+ - lib/terraspace_plugin_google/interfaces/helper/secret.rb
117
147
  - lib/terraspace_plugin_google/interfaces/layer.rb
118
148
  - lib/terraspace_plugin_google/interfaces/summary.rb
149
+ - lib/terraspace_plugin_google/logging.rb
119
150
  - lib/terraspace_plugin_google/version.rb
120
151
  - terraspace_plugin_google.gemspec
121
152
  homepage: https://github.com/boltops-tools/terraspace_plugin_google
@@ -138,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
169
  - !ruby/object:Gem::Version
139
170
  version: '0'
140
171
  requirements: []
141
- rubygems_version: 3.1.2
172
+ rubygems_version: 3.1.6
142
173
  signing_key:
143
174
  specification_version: 4
144
175
  summary: Terraspace Google Cloud Plugin