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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 10ba87e72c39cdfc8032d3c12f859fd6d442bd2c7cf9c093cca723b32df4e4c5
4
- data.tar.gz: 15d820fbb4ce87d09ead970b12c9a2266b9cb34d68c8a928ad819cf7af5aba22
3
+ metadata.gz: 5cf0133e608b9d6aad667aa5f4c1ea70c77f98a6b8d52a56396f47153fc26e75
4
+ data.tar.gz: 8956a3a1461da92d9d250971e170df0ac66ea637e6f1ac89d4200bd894c7d8b4
5
5
  SHA512:
6
- metadata.gz: eec0abc226f2cbbcad26d3e9d33c1689887818f2f8182224c639838d8ccc9a9e31708b5d16793482e832719c4a1de46f8eead150b3e27acb507e714a41e0a688
7
- data.tar.gz: 3350a30114e280ccbb024de1ce07e9a9fa2423e62f097ae4e49b270e9d65659d2515277686914632c950e4314ce67f4c36d6eb25da6ce44acb6d61d9cf9d4d46
6
+ metadata.gz: 22eb1640abc543c3812c35873353e360cb70df65f3c39da53b6083cbe9b03707b0697aeadf93a7e4852321be184fd3c9ac16cc1e3ba95fc8e0b13f57a0bf8eb9
7
+ data.tar.gz: f3ae41ed56e36b351d101f2b4931c7270b3dd5df3de6841e88f174df02359d4a7e80e0b789e5c0971413b5f4603a6ffc32cc160b4bc600fb24899f5731ff7f29
@@ -1,8 +1,7 @@
1
- # Change Log
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.1]
7
- - terraspace dep for dev only
8
-
6
+ ## [0.1.0]
7
+ - Initial release
data/Gemfile CHANGED
@@ -7,6 +7,5 @@ gem "rake", "~> 12.0"
7
7
  gem "rspec", "~> 3.0"
8
8
 
9
9
  group :development, :test do
10
- base = ENV['TS_EDGE_ROOT'] || "#{ENV['HOME']}/environment/terraspace-edge"
11
- gem "terraspace", path: "#{base}/terraspace"
10
+ gem "terraspace"
12
11
  end
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:
@@ -0,0 +1,25 @@
1
+ diff --git a/CHANGELOG.md b/CHANGELOG.md
2
+ index 7e94c34..2fdf029 100644
3
+ --- a/CHANGELOG.md
4
+ +++ b/CHANGELOG.md
5
+ @@ -1,8 +1,7 @@
6
+ -# Change Log
7
+ +# Changelog
8
+ 
9
+ All notable changes to this project will be documented in this file.
10
+ This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/).
11
+ 
12
+ -## [0.0.1]
13
+ -- terraspace dep for dev only
14
+ -
15
+ +## [0.1.0]
16
+ +- Initial release
17
+ diff --git a/lib/terraspace_plugin_google/version.rb b/lib/terraspace_plugin_google/version.rb
18
+ index b771e2b..75e5bdc 100644
19
+ --- a/lib/terraspace_plugin_google/version.rb
20
+ +++ b/lib/terraspace_plugin_google/version.rb
21
+ @@ -1,3 +1,3 @@
22
+ module TerraspacePluginGoogle
23
+ - VERSION = "0.0.0"
24
+ + VERSION = "0.1.0"
25
+ end
@@ -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
+ }
@@ -1,10 +1,10 @@
1
- resource "random_pet" "bucket" {
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.bucket.id}"
8
+ name = "bucket-${random_pet.this.id}"
9
9
  bucket_policy_only = var.bucket_policy_only
10
10
  }
@@ -1,10 +1,10 @@
1
- resource "random_pet" "bucket" {
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.bucket.id}"
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
  )
@@ -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
- config_instance: TerraspacePluginGoogle::Interfaces::Config.instance,
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
- puts "ERROR: no bucket value provided in your terraform backend config".color(:red)
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
- # puts "Bucket already exist: #{bucket}"
15
+ logger.debug "Bucket already exist: #{bucket}"
14
16
  else
15
- puts "Creating bucket: #{bucket}"
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
- puts "#{e.class}: #{e.message}"
31
- puts "ERROR: Bucket is not available: #{name}".color(:red)
32
- puts "Bucket might be owned by someone else or is on another one of your Google accounts."
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
@@ -4,6 +4,8 @@ module TerraspacePluginGoogle::Interfaces
4
4
  class Expander
5
5
  include Terraspace::Plugin::Expander::Interface
6
6
  delegate :project, :region, to: :gcp_data
7
+ alias_method :namespace, :project
8
+ alias_method :location, :region
7
9
 
8
10
  def gcp_data
9
11
  GcpData
@@ -5,23 +5,18 @@ module TerraspacePluginGoogle::Interfaces
5
5
  extend Memoist
6
6
 
7
7
  # interface method
8
- def region
9
- gcp_data.region
8
+ def namespace
9
+ GcpData.project
10
10
  end
11
11
 
12
12
  # interface method
13
- # not a typo, mapping project to "account" to confirm to interface
14
- def account
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
@@ -1,3 +1,3 @@
1
1
  module TerraspacePluginGoogle
2
- VERSION = "0.0.0"
2
+ VERSION = "0.1.0"
3
3
  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.0.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-05-31 00:00:00.000000000 Z
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/templates/backend.tf.tt
89
- - lib/templates/hcl/project/config/templates/provider.tf
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/templates/backend.rb.tt
97
- - lib/templates/ruby/project/config/templates/provider.rb
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
- }