terraspace_plugin_google 0.2.2 → 0.3.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 +4 -0
- data/lib/templates/hcl/project/config/terraform/backend.tf.tt +2 -2
- data/lib/terraspace_plugin_google.rb +10 -0
- data/lib/terraspace_plugin_google/clients.rb +6 -0
- data/lib/terraspace_plugin_google/interfaces/helper.rb +10 -0
- data/lib/terraspace_plugin_google/interfaces/helper/secret.rb +43 -0
- data/lib/terraspace_plugin_google/logging.rb +7 -0
- data/lib/terraspace_plugin_google/version.rb +1 -1
- data/terraspace_plugin_google.gemspec +1 -0
- metadata +20 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e63e836f63ed2b6731dbdf64bdd6a7635bacea437bb0e6430f5723552f83899
|
4
|
+
data.tar.gz: b7c5eb01564d29cae316d07bf52310bd4c110500d869392135a26275b196068f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbc69e11cc8e24f636ea4fe3d9996d13d4d373dd7678018d2bf078e0a971762e55be7b61ec2cc0b39bfe321ffa9b0113715bc0075aa6110cf071c98774b39d11
|
7
|
+
data.tar.gz: 3aa893e192eb8004641bb0131da7ee2fffcb97b07d58ca09674ad5d5935806d7103e892538aae9896457a35b5241a73822bc59045cfdfc7d8506c49d08fc8308
|
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/).
|
5
5
|
|
6
|
+
## [0.3.0] - 2020-11-15
|
7
|
+
- [#5](https://github.com/boltops-tools/terraspace_provider_google/pull/5) helper and secrets support
|
8
|
+
- google secret
|
9
|
+
|
6
10
|
## [0.2.2]
|
7
11
|
- #4 fix test template: folder rename to stacks
|
8
12
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
terraform {
|
2
2
|
backend "gcs" {
|
3
|
-
bucket = "<%%= expansion('terraform-state-:PROJECT-:REGION-:ENV') %>"
|
4
|
-
prefix = "<%%= expansion(':REGION/:ENV/:BUILD_DIR') %>"
|
3
|
+
bucket = "<%%= expansion('terraform-state-:PROJECT-:REGION-:ENV') %>"
|
4
|
+
prefix = "<%%= expansion(':REGION/:ENV/:BUILD_DIR') %>"
|
5
5
|
}
|
6
6
|
}
|
@@ -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
|
)
|
@@ -1,9 +1,15 @@
|
|
1
|
+
require "google-cloud-secret_manager"
|
1
2
|
require "google/cloud/storage"
|
2
3
|
|
3
4
|
module TerraspacePluginGoogle
|
4
5
|
module Clients
|
5
6
|
extend Memoist
|
6
7
|
|
8
|
+
def secret_manager_service
|
9
|
+
Google::Cloud::SecretManager.secret_manager_service
|
10
|
+
end
|
11
|
+
memoize :secret_manager_service
|
12
|
+
|
7
13
|
def storage
|
8
14
|
Google::Cloud::Storage.new
|
9
15
|
end
|
@@ -0,0 +1,43 @@
|
|
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
|
+
# TODO: Get the project from the list project api instead. Unsure where the docs are for this.
|
31
|
+
# If someone knows, let me know.
|
32
|
+
# Right now grabbing the first secret to then be able to get the google project number
|
33
|
+
@@project_number = nil
|
34
|
+
def project_number
|
35
|
+
return @@project_number if @@project_number
|
36
|
+
|
37
|
+
parent = "projects/#{@project_id}"
|
38
|
+
resp = secret_manager_service.list_secrets(parent: parent) # note: page_size doesnt seem to get respected
|
39
|
+
name = resp.first.name # IE: projects/111111111111/secrets/demo-dev-db_host
|
40
|
+
@@project_number = name.split('/')[1]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
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.
|
4
|
+
version: 0.3.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: 2020-
|
11
|
+
date: 2020-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gcp_data
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: google-cloud-secret_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'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: memoist
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,8 +128,11 @@ files:
|
|
114
128
|
- lib/terraspace_plugin_google/interfaces/backend.rb
|
115
129
|
- lib/terraspace_plugin_google/interfaces/config.rb
|
116
130
|
- lib/terraspace_plugin_google/interfaces/expander.rb
|
131
|
+
- lib/terraspace_plugin_google/interfaces/helper.rb
|
132
|
+
- lib/terraspace_plugin_google/interfaces/helper/secret.rb
|
117
133
|
- lib/terraspace_plugin_google/interfaces/layer.rb
|
118
134
|
- lib/terraspace_plugin_google/interfaces/summary.rb
|
135
|
+
- lib/terraspace_plugin_google/logging.rb
|
119
136
|
- lib/terraspace_plugin_google/version.rb
|
120
137
|
- terraspace_plugin_google.gemspec
|
121
138
|
homepage: https://github.com/boltops-tools/terraspace_plugin_google
|
@@ -138,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
155
|
- !ruby/object:Gem::Version
|
139
156
|
version: '0'
|
140
157
|
requirements: []
|
141
|
-
rubygems_version: 3.1.
|
158
|
+
rubygems_version: 3.1.4
|
142
159
|
signing_key:
|
143
160
|
specification_version: 4
|
144
161
|
summary: Terraspace Google Cloud Plugin
|