terraspace_plugin_google 0.2.0 → 0.3.1

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: 60aa63a18ee7e8e607a58f0e00534bf68158a117070c1cbddd7c13eb9ed2d148
4
- data.tar.gz: 969b365d1168cc6a5b3d4ed5a03d88699d701ec54e2490162f00f89d5b511ee5
3
+ metadata.gz: 628fdc35ca018bb08c245ade973b52cb1791ae4cae8858dac9cc787312c81be6
4
+ data.tar.gz: 73c858a9d4452668896b68c58aa51f0b23f6dcbb5d2f07cce9c3df1b4273cebb
5
5
  SHA512:
6
- metadata.gz: 06ce418b5be6190d68246b9f7066045cd40781c4d75db40c4f04792b1004aeeb7306644dafd843fe732fe3e39d175d63bec42fb4aafae433332f1c1fa4a28b81
7
- data.tar.gz: 78398add7a43d881056f85910873ebf283c287fd0f139ba864e0ad45dcb22059800fc9cfb4756bcf395ac8294091cc1e4ed952bd7c996cd9d0a8a9d1f69f771d
6
+ metadata.gz: a157213a221b74251896316d3bd879496e25a68dced1d44a294958e51c0ba3e830959fe07cd869f115cd73ea220660a20128484349c3328eadd87bbd2ca2ed5e
7
+ data.tar.gz: 24297c26f98c24ad85f689fc82c1e14acf64583e909da9b566524bd263b0e48cdb8fd6281753702dbc5595f010fddb47578f8432530e91af78ec30fa1324a1c7
data/CHANGELOG.md CHANGED
@@ -3,6 +3,20 @@
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.1] - 2021-11-13
7
+ - [#7](https://github.com/boltops-tools/terraspace_provider_google/pull/7) get google project number via api
8
+
9
+ ## [0.3.0] - 2020-11-15
10
+ - [#5](https://github.com/boltops-tools/terraspace_provider_google/pull/5) helper and secrets support
11
+ - google secret
12
+
13
+ ## [0.2.2]
14
+ - #4 fix test template: folder rename to stacks
15
+
16
+ ## [0.2.1]
17
+ - #3 update starter example template: bucket_policy_only deprecated for uniform_bucket_level_access
18
+ - edge case: graceful error when bucket doesnt exist yet
19
+
6
20
  ## [0.2.0]
7
21
  - #2 include layer interface, update template to use expansion method
8
22
 
@@ -1,4 +1,4 @@
1
1
  resource "google_storage_bucket" "this" {
2
- name = var.name
3
- bucket_policy_only = var.bucket_policy_only
2
+ name = var.name
3
+ uniform_bucket_level_access = var.uniform_bucket_level_access
4
4
  }
@@ -3,8 +3,8 @@ variable "name" {
3
3
  type = string
4
4
  }
5
5
 
6
- variable "bucket_policy_only" {
7
- description = "bucket_policy_only"
6
+ variable "uniform_bucket_level_access" {
7
+ description = "uniform_bucket_level_access"
8
8
  type = bool
9
9
  default = false
10
10
  }
@@ -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
  }
@@ -5,6 +5,6 @@ resource "random_pet" "this" {
5
5
  module "bucket" {
6
6
  source = "../../modules/example"
7
7
 
8
- name = "bucket-${random_pet.this.id}"
9
- bucket_policy_only = var.bucket_policy_only
8
+ name = "bucket-${random_pet.this.id}"
9
+ uniform_bucket_level_access = var.uniform_bucket_level_access
10
10
  }
@@ -1,5 +1,5 @@
1
- variable "bucket_policy_only" {
2
- description = "bucket_policy_only"
1
+ variable "uniform_bucket_level_access" {
2
+ description = "uniform_bucket_level_access"
3
3
  type = bool
4
4
  default = false
5
5
  }
@@ -1,4 +1,4 @@
1
1
  resource("google_storage_bucket", "this",
2
- name: var.name,
3
- bucket_policy_only:var.bucket_policy_only,
2
+ name: var.name,
3
+ uniform_bucket_level_access: var.uniform_bucket_level_access,
4
4
  )
@@ -3,8 +3,8 @@ variable("name",
3
3
  type: "string",
4
4
  )
5
5
 
6
- variable("bucket_policy_only",
7
- description: "bucket_policy_only",
6
+ variable("uniform_bucket_level_access",
7
+ description: "uniform_bucket_level_access",
8
8
  type: "bool",
9
9
  default: false,
10
10
  )
@@ -1,5 +1,5 @@
1
- variable("bucket_policy_only",
2
- description: "bucket_policy_only",
1
+ variable("uniform_bucket_level_access",
2
+ description: "uniform_bucket_level_access",
3
3
  type: "bool",
4
4
  default: false,
5
5
  )
@@ -5,6 +5,6 @@ resource "random_pet" "this" {
5
5
  module "bucket" {
6
6
  source = "../../modules/example"
7
7
 
8
- name = "bucket-${random_pet.this.id}"
9
- bucket_policy_only = var.bucket_policy_only
8
+ name = "bucket-${random_pet.this.id}"
9
+ uniform_bucket_level_access = var.uniform_bucket_level_access
10
10
  }
@@ -1,5 +1,5 @@
1
- variable "bucket_policy_only" {
2
- description = "bucket_policy_only"
1
+ variable "uniform_bucket_level_access" {
2
+ description = "uniform_bucket_level_access"
3
3
  type = bool
4
4
  default = false
5
5
  }
@@ -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
@@ -11,6 +11,10 @@ module TerraspacePluginGoogle::Interfaces
11
11
  # interface method
12
12
  def download
13
13
  bucket = storage.bucket(@bucket)
14
+ unless bucket
15
+ logger.error "ERROR: bucket #{@bucket} does not exist".color(:red)
16
+ exit 1
17
+ end
14
18
  bucket.files(prefix: @folder).all do |f|
15
19
  file = bucket.file(f.name)
16
20
  next if file.nil? # in case file has been removed since .files
@@ -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.0"
2
+ VERSION = "0.3.1"
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.0
4
+ version: 0.3.1
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-08-20 00:00:00.000000000 Z
11
+ date: 2021-11-13 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