terraspace_plugin_google 0.0.0 → 0.1.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 +3 -4
- data/Gemfile +1 -2
- data/README.md +2 -2
- data/git st +25 -0
- 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 +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/test/rspec/module/test/spec/fixtures/stack/main.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/stack/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 +4 -9
- data/lib/terraspace_plugin_google/interfaces/summary.rb +30 -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: 5cf0133e608b9d6aad667aa5f4c1ea70c77f98a6b8d52a56396f47153fc26e75
|
4
|
+
data.tar.gz: 8956a3a1461da92d9d250971e170df0ac66ea637e6f1ac89d4200bd894c7d8b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22eb1640abc543c3812c35873353e360cb70df65f3c39da53b6083cbe9b03707b0697aeadf93a7e4852321be184fd3c9ac16cc1e3ba95fc8e0b13f57a0bf8eb9
|
7
|
+
data.tar.gz: f3ae41ed56e36b351d101f2b4931c7270b3dd5df3de6841e88f174df02359d4a7e80e0b789e5c0971413b5f4603a6ffc32cc160b4bc600fb24899f5731ff7f29
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,7 @@
|
|
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.0
|
7
|
-
-
|
8
|
-
|
6
|
+
## [0.1.0]
|
7
|
+
- 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 = "<%%= 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
|
+
}
|
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 = "bucket-${random_pet.
|
8
|
+
name = "bucket-${random_pet.this.id}"
|
9
9
|
bucket_policy_only = var.bucket_policy_only
|
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 = "bucket-${random_pet.
|
8
|
+
name = "bucket-${random_pet.this.id}"
|
9
9
|
bucket_policy_only = var.bucket_policy_only
|
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
|
@@ -5,23 +5,18 @@ module TerraspacePluginGoogle::Interfaces
|
|
5
5
|
extend Memoist
|
6
6
|
|
7
7
|
# interface method
|
8
|
-
def
|
9
|
-
|
8
|
+
def namespace
|
9
|
+
GcpData.project
|
10
10
|
end
|
11
11
|
|
12
12
|
# interface method
|
13
|
-
|
14
|
-
|
15
|
-
gcp_data.project
|
13
|
+
def region
|
14
|
+
GcpData.region
|
16
15
|
end
|
17
16
|
|
18
17
|
# interface method
|
19
18
|
def provider
|
20
19
|
"google"
|
21
20
|
end
|
22
|
-
|
23
|
-
def gcp_data
|
24
|
-
GcpData
|
25
|
-
end
|
26
21
|
end
|
27
22
|
end
|
@@ -0,0 +1,30 @@
|
|
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
|
+
bucket.files(prefix: @folder).all do |f|
|
15
|
+
file = bucket.file(f.name)
|
16
|
+
# Note the f.name already includes the folder
|
17
|
+
local_path = "#{@dest}/#{f.name}"
|
18
|
+
FileUtils.mkdir_p(File.dirname(local_path))
|
19
|
+
file.download(local_path)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# interface method
|
24
|
+
def delete_empty_statefile(key)
|
25
|
+
bucket = storage.bucket(@bucket)
|
26
|
+
file = bucket.file(key)
|
27
|
+
file.delete
|
28
|
+
end
|
29
|
+
end
|
30
|
+
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.1.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-07-23 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/stack/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
|
-
}
|