terraspace_plugin_google 0.0.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -3
- data/Gemfile +1 -2
- data/README.md +2 -2
- data/git st +25 -0
- data/lib/templates/hcl/module/main.tf +2 -2
- data/lib/templates/hcl/module/variables.tf +2 -2
- data/lib/templates/hcl/project/config/terraform/backend.tf.tt +6 -0
- data/lib/templates/hcl/project/config/{templates → terraform}/provider.tf +0 -0
- data/lib/templates/hcl/stack/main.tf +3 -3
- data/lib/templates/hcl/stack/variables.tf +2 -2
- data/lib/templates/ruby/module/main.rb +2 -2
- data/lib/templates/ruby/module/variables.rb +2 -2
- data/lib/templates/ruby/project/config/{templates → terraform}/backend.rb.tt +0 -0
- data/lib/templates/ruby/project/config/{templates → terraform}/provider.rb +0 -0
- data/lib/templates/ruby/stack/variables.rb +2 -2
- data/lib/templates/test/rspec/module/test/spec/fixtures/stack/main.tf +3 -3
- data/lib/templates/test/rspec/module/test/spec/fixtures/stack/variables.tf +2 -2
- data/lib/templates/test/rspec/module/test/spec/main_spec.rb.tt +2 -2
- data/lib/templates/test/rspec/project/spec/fixtures/tfvars/demo.tfvars +0 -0
- data/lib/templates/test/rspec/project/spec/stacks/demo/main_spec.rb +26 -0
- data/lib/terraspace_plugin_google.rb +6 -4
- data/lib/terraspace_plugin_google/interfaces/backend.rb +12 -6
- data/lib/terraspace_plugin_google/interfaces/config.rb +4 -0
- data/lib/terraspace_plugin_google/interfaces/expander.rb +2 -0
- data/lib/terraspace_plugin_google/interfaces/layer.rb +5 -14
- data/lib/terraspace_plugin_google/interfaces/summary.rb +35 -0
- data/lib/terraspace_plugin_google/version.rb +1 -1
- metadata +10 -6
- data/lib/templates/hcl/project/config/templates/backend.tf.tt +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f481b6c88c1de06a78da5d9a3097517202c3e17ceae6f81434bcb66abfd9468f
|
4
|
+
data.tar.gz: db7d7abd653cd1e0c7b780b69228645d840909a242fb920f44707fbdd19423db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0d816df268ff24c79488afa29105ff493c75f602fcf3a066befe8fbb9824d54ad8ef8c3d3ea8c57fa4be691ed057291e9ca061cf54eb5e4b86c49fa13f408f1
|
7
|
+
data.tar.gz: f960ab4f7c2488112b6d954b6f0b747f3fb2e6999be626d0ebe8d2ec634154b56c8e3cea4cdfe2d900f6395d45ffe4abca61a0880ac5f42742745a428a67c3d4
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,20 @@
|
|
1
|
-
#
|
1
|
+
# Changelog
|
2
2
|
|
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.
|
7
|
-
-
|
6
|
+
## [0.2.2]
|
7
|
+
- #4 fix test template: folder rename to stacks
|
8
8
|
|
9
|
+
## [0.2.1]
|
10
|
+
- #3 update starter example template: bucket_policy_only deprecated for uniform_bucket_level_access
|
11
|
+
- edge case: graceful error when bucket doesnt exist yet
|
12
|
+
|
13
|
+
## [0.2.0]
|
14
|
+
- #2 include layer interface, update template to use expansion method
|
15
|
+
|
16
|
+
## [0.1.1]
|
17
|
+
- summary command: fix edge case when files are deleted mid-loop
|
18
|
+
|
19
|
+
## [0.1.0]
|
20
|
+
- Initial release
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -18,17 +18,17 @@ config/plugins/google.rb
|
|
18
18
|
|
19
19
|
```ruby
|
20
20
|
TerraspacePluginGoogle.configure do |config|
|
21
|
+
config.auto_create = true # set to false to completely disable auto creation
|
21
22
|
config.gcs.versioning = true
|
22
23
|
end
|
23
24
|
```
|
24
25
|
|
25
26
|
By default:
|
26
27
|
|
27
|
-
* GCS Buckets have versioning enabled.
|
28
|
+
* GCS Buckets have [versioning](https://cloud.google.com/storage/docs/object-versioning) enabled.
|
28
29
|
|
29
30
|
The settings generally only apply if the gcs bucket does not yet exist yet and is created for the first time.
|
30
31
|
|
31
|
-
|
32
32
|
## Versioning
|
33
33
|
|
34
34
|
To confirm that the GCS bucket has versioning enabled:
|
data/git st
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
[1mdiff --git a/CHANGELOG.md b/CHANGELOG.md[m
|
2
|
+
[1mindex 7e94c34..2fdf029 100644[m
|
3
|
+
[1m--- a/CHANGELOG.md[m
|
4
|
+
[1m+++ b/CHANGELOG.md[m
|
5
|
+
[36m@@ -1,8 +1,7 @@[m
|
6
|
+
[31m-# Change Log[m
|
7
|
+
[32m+[m[32m# Changelog[m
|
8
|
+
[m
|
9
|
+
All notable changes to this project will be documented in this file.[m
|
10
|
+
This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/).[m
|
11
|
+
[m
|
12
|
+
[31m-## [0.0.1][m
|
13
|
+
[31m-- terraspace dep for dev only[m
|
14
|
+
[31m-[m
|
15
|
+
[32m+[m[32m## [0.1.0][m
|
16
|
+
[32m+[m[32m- Initial release[m
|
17
|
+
[1mdiff --git a/lib/terraspace_plugin_google/version.rb b/lib/terraspace_plugin_google/version.rb[m
|
18
|
+
[1mindex b771e2b..75e5bdc 100644[m
|
19
|
+
[1m--- a/lib/terraspace_plugin_google/version.rb[m
|
20
|
+
[1m+++ b/lib/terraspace_plugin_google/version.rb[m
|
21
|
+
[36m@@ -1,3 +1,3 @@[m
|
22
|
+
module TerraspacePluginGoogle[m
|
23
|
+
[31m- VERSION = "0.0.0"[m
|
24
|
+
[32m+[m[32m VERSION = "0.1.0"[m
|
25
|
+
end[m
|
@@ -0,0 +1,6 @@
|
|
1
|
+
terraform {
|
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
|
5
|
+
}
|
6
|
+
}
|
File without changes
|
@@ -1,10 +1,10 @@
|
|
1
|
-
resource "random_pet" "
|
1
|
+
resource "random_pet" "this" {
|
2
2
|
length = 2
|
3
3
|
}
|
4
4
|
|
5
5
|
module "bucket" {
|
6
6
|
source = "../../modules/example"
|
7
7
|
|
8
|
-
name
|
9
|
-
|
8
|
+
name = "bucket-${random_pet.this.id}"
|
9
|
+
uniform_bucket_level_access = var.uniform_bucket_level_access
|
10
10
|
}
|
File without changes
|
File without changes
|
@@ -1,10 +1,10 @@
|
|
1
|
-
resource "random_pet" "
|
1
|
+
resource "random_pet" "this" {
|
2
2
|
length = 2
|
3
3
|
}
|
4
4
|
|
5
5
|
module "bucket" {
|
6
6
|
source = "../../modules/example"
|
7
7
|
|
8
|
-
name
|
9
|
-
|
8
|
+
name = "bucket-${random_pet.this.id}"
|
9
|
+
uniform_bucket_level_access = var.uniform_bucket_level_access
|
10
10
|
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# This starter example of a spec that creates a test harness and provisions a real s3 bucket.
|
2
2
|
# The test harness will be created at:
|
3
3
|
#
|
4
|
-
# /tmp/terraspace-test-harnesses/<%= @name
|
4
|
+
# /tmp/terraspace-test-harnesses/<%= @name %>-harness
|
5
5
|
#
|
6
6
|
# It's recommended to run this on a test AWS account.
|
7
7
|
#
|
@@ -9,7 +9,7 @@ describe "main" do
|
|
9
9
|
before(:all) do
|
10
10
|
mod_path = File.expand_path("../..", __dir__)
|
11
11
|
terraspace.build_test_harness(
|
12
|
-
name: "<%= @name
|
12
|
+
name: "<%= @name %>-harness",
|
13
13
|
modules: {example: mod_path},
|
14
14
|
stacks: {example: "#{mod_path}/test/spec/fixtures/stack"},
|
15
15
|
)
|
File without changes
|
@@ -0,0 +1,26 @@
|
|
1
|
+
describe "main" do
|
2
|
+
before(:all) do
|
3
|
+
# Build terraspace project to use as a test harness
|
4
|
+
# Will be located at: /tmp/terraspace/test-harnesses/demo-harness
|
5
|
+
terraspace.build_test_harness(
|
6
|
+
name: "demo-harness",
|
7
|
+
modules: "app/modules", # include all modules in this folder
|
8
|
+
stacks: "app/stacks", # include all stacks in this folder
|
9
|
+
# override demo stack tfvars for testing
|
10
|
+
# copied over to test harness' app/stacks/demo/tfvars/test.tfvars
|
11
|
+
tfvars: {demo: "spec/fixtures/tfvars/demo.tfvars"},
|
12
|
+
# create config if needed. The folder will be copied over
|
13
|
+
# config: "spec/fixtures/config",
|
14
|
+
)
|
15
|
+
terraspace.up("demo") # provision real resources
|
16
|
+
end
|
17
|
+
after(:all) do
|
18
|
+
terraspace.down("demo") # destroy real resources
|
19
|
+
end
|
20
|
+
|
21
|
+
it "successful deploy" do
|
22
|
+
# Example
|
23
|
+
bucket_url = terraspace.output("demo", "bucket_url") # IE: gs://bucket-free-coyote
|
24
|
+
expect(bucket_url).to include("gs://bucket-")
|
25
|
+
end
|
26
|
+
end
|
@@ -1,6 +1,3 @@
|
|
1
|
-
lib = File.expand_path("../../../", __FILE__)
|
2
|
-
$:.unshift(lib)
|
3
|
-
|
4
1
|
require "memoist"
|
5
2
|
require "terraspace" # for interface
|
6
3
|
|
@@ -20,12 +17,17 @@ module TerraspacePluginGoogle
|
|
20
17
|
def configure(&block)
|
21
18
|
Interfaces::Config.instance.configure(&block)
|
22
19
|
end
|
20
|
+
|
21
|
+
def config
|
22
|
+
Interfaces::Config.instance.config
|
23
|
+
end
|
24
|
+
|
23
25
|
extend self
|
24
26
|
end
|
25
27
|
|
26
28
|
Terraspace::Plugin.register("google",
|
27
29
|
backend: "gcs",
|
28
|
-
|
30
|
+
config_class: TerraspacePluginGoogle::Interfaces::Config,
|
29
31
|
layer_class: TerraspacePluginGoogle::Interfaces::Layer,
|
30
32
|
root: File.dirname(__dir__),
|
31
33
|
)
|
@@ -4,15 +4,17 @@ module TerraspacePluginGoogle::Interfaces
|
|
4
4
|
include TerraspacePluginGoogle::Clients
|
5
5
|
|
6
6
|
def call
|
7
|
+
return unless TerraspacePluginGoogle.config.auto_create
|
8
|
+
|
7
9
|
bucket = @info["bucket"]
|
8
10
|
unless bucket # not bucket provided
|
9
|
-
|
11
|
+
logger.error "ERROR: no bucket value provided in your terraform backend config"
|
10
12
|
exit 1
|
11
13
|
end
|
12
14
|
if exist?(bucket)
|
13
|
-
|
15
|
+
logger.debug "Bucket already exist: #{bucket}"
|
14
16
|
else
|
15
|
-
|
17
|
+
logger.info "Creating bucket: #{bucket}"
|
16
18
|
create_bucket(bucket)
|
17
19
|
end
|
18
20
|
end
|
@@ -27,10 +29,14 @@ module TerraspacePluginGoogle::Interfaces
|
|
27
29
|
def exist?(name)
|
28
30
|
!!storage.bucket(name)
|
29
31
|
rescue Google::Cloud::PermissionDeniedError => e
|
30
|
-
|
31
|
-
|
32
|
-
|
32
|
+
logger.error "#{e.class}: #{e.message}"
|
33
|
+
logger.error "ERROR: Bucket is not available: #{name}".color(:red)
|
34
|
+
logger.error "Bucket might be owned by someone else or is on another one of your Google accounts."
|
33
35
|
exit 1
|
34
36
|
end
|
37
|
+
|
38
|
+
def logger
|
39
|
+
Terraspace.logger
|
40
|
+
end
|
35
41
|
end
|
36
42
|
end
|
@@ -3,12 +3,16 @@ module TerraspacePluginGoogle::Interfaces
|
|
3
3
|
include Terraspace::Plugin::Config::Interface
|
4
4
|
include Singleton
|
5
5
|
|
6
|
+
# interface method
|
7
|
+
# load_project_config: config/plugins/google.rb
|
6
8
|
def provider
|
7
9
|
"google"
|
8
10
|
end
|
9
11
|
|
12
|
+
# interface method
|
10
13
|
def defaults
|
11
14
|
c = ActiveSupport::OrderedOptions.new
|
15
|
+
c.auto_create = true
|
12
16
|
c.gcs = ActiveSupport::OrderedOptions.new
|
13
17
|
c.gcs.versioning = true
|
14
18
|
c
|
@@ -2,26 +2,17 @@ require "gcp_data"
|
|
2
2
|
|
3
3
|
module TerraspacePluginGoogle::Interfaces
|
4
4
|
class Layer
|
5
|
+
include Terraspace::Plugin::Layer::Interface
|
5
6
|
extend Memoist
|
6
7
|
|
7
8
|
# interface method
|
8
|
-
def
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
# interface method
|
13
|
-
# not a typo, mapping project to "account" to confirm to interface
|
14
|
-
def account
|
15
|
-
gcp_data.project
|
9
|
+
def namespace
|
10
|
+
GcpData.project
|
16
11
|
end
|
17
12
|
|
18
13
|
# interface method
|
19
|
-
def
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
def gcp_data
|
24
|
-
GcpData
|
14
|
+
def region
|
15
|
+
GcpData.region
|
25
16
|
end
|
26
17
|
end
|
27
18
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module TerraspacePluginGoogle::Interfaces
|
2
|
+
class Summary
|
3
|
+
include Terraspace::Plugin::Summary::Interface
|
4
|
+
include TerraspacePluginGoogle::Clients
|
5
|
+
|
6
|
+
# interface method
|
7
|
+
def key_field
|
8
|
+
'prefix'
|
9
|
+
end
|
10
|
+
|
11
|
+
# interface method
|
12
|
+
def download
|
13
|
+
bucket = storage.bucket(@bucket)
|
14
|
+
unless bucket
|
15
|
+
logger.error "ERROR: bucket #{@bucket} does not exist".color(:red)
|
16
|
+
exit 1
|
17
|
+
end
|
18
|
+
bucket.files(prefix: @folder).all do |f|
|
19
|
+
file = bucket.file(f.name)
|
20
|
+
next if file.nil? # in case file has been removed since .files
|
21
|
+
# Note the f.name already includes the folder
|
22
|
+
local_path = "#{@dest}/#{f.name}"
|
23
|
+
FileUtils.mkdir_p(File.dirname(local_path))
|
24
|
+
file.download(local_path)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# interface method
|
29
|
+
def delete_empty_statefile(key)
|
30
|
+
bucket = storage.bucket(@bucket)
|
31
|
+
file = bucket.file(key)
|
32
|
+
file.delete
|
33
|
+
end
|
34
|
+
end
|
35
|
+
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.2.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-
|
11
|
+
date: 2020-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gcp_data
|
@@ -82,19 +82,20 @@ files:
|
|
82
82
|
- Rakefile
|
83
83
|
- bin/console
|
84
84
|
- bin/setup
|
85
|
+
- git st
|
85
86
|
- lib/templates/hcl/module/main.tf
|
86
87
|
- lib/templates/hcl/module/outputs.tf
|
87
88
|
- lib/templates/hcl/module/variables.tf
|
88
|
-
- lib/templates/hcl/project/config/
|
89
|
-
- lib/templates/hcl/project/config/
|
89
|
+
- lib/templates/hcl/project/config/terraform/backend.tf.tt
|
90
|
+
- lib/templates/hcl/project/config/terraform/provider.tf
|
90
91
|
- lib/templates/hcl/stack/main.tf
|
91
92
|
- lib/templates/hcl/stack/outputs.tf
|
92
93
|
- lib/templates/hcl/stack/variables.tf
|
93
94
|
- lib/templates/ruby/module/main.rb
|
94
95
|
- lib/templates/ruby/module/outputs.rb
|
95
96
|
- lib/templates/ruby/module/variables.rb
|
96
|
-
- lib/templates/ruby/project/config/
|
97
|
-
- lib/templates/ruby/project/config/
|
97
|
+
- lib/templates/ruby/project/config/terraform/backend.rb.tt
|
98
|
+
- lib/templates/ruby/project/config/terraform/provider.rb
|
98
99
|
- lib/templates/ruby/stack/main.rb
|
99
100
|
- lib/templates/ruby/stack/outputs.rb
|
100
101
|
- lib/templates/ruby/stack/variables.rb
|
@@ -105,6 +106,8 @@ files:
|
|
105
106
|
- lib/templates/test/rspec/module/test/spec/fixtures/stack/variables.tf
|
106
107
|
- lib/templates/test/rspec/module/test/spec/main_spec.rb.tt
|
107
108
|
- lib/templates/test/rspec/module/test/spec/spec_helper.rb
|
109
|
+
- lib/templates/test/rspec/project/spec/fixtures/tfvars/demo.tfvars
|
110
|
+
- lib/templates/test/rspec/project/spec/stacks/demo/main_spec.rb
|
108
111
|
- lib/terraspace_plugin_google.rb
|
109
112
|
- lib/terraspace_plugin_google/autoloader.rb
|
110
113
|
- lib/terraspace_plugin_google/clients.rb
|
@@ -112,6 +115,7 @@ files:
|
|
112
115
|
- lib/terraspace_plugin_google/interfaces/config.rb
|
113
116
|
- lib/terraspace_plugin_google/interfaces/expander.rb
|
114
117
|
- lib/terraspace_plugin_google/interfaces/layer.rb
|
118
|
+
- lib/terraspace_plugin_google/interfaces/summary.rb
|
115
119
|
- lib/terraspace_plugin_google/version.rb
|
116
120
|
- terraspace_plugin_google.gemspec
|
117
121
|
homepage: https://github.com/boltops-tools/terraspace_plugin_google
|
@@ -1,6 +0,0 @@
|
|
1
|
-
terraform {
|
2
|
-
backend "gcs" {
|
3
|
-
bucket = "<%%= backend_expand("gcs", "terraform-state-:PROJECT-:REGION-:ENV") %>" # expanded by terraspace IE: terraform-state-project-us-central1-dev
|
4
|
-
prefix = "<%%= backend_expand("gcs", ":REGION/:ENV/:BUILD_DIR") %>" # expanded by terraspace IE: us-central1/dev/modules/vm
|
5
|
-
}
|
6
|
-
}
|