Skip to content

Commit

Permalink
Chef Spanner + Fixing Puppet Spanner (#377)
Browse files Browse the repository at this point in the history
Merged PR #377.
  • Loading branch information
rambleraptor authored and modular-magician committed Aug 1, 2018
1 parent faf4672 commit 83b5501
Show file tree
Hide file tree
Showing 26 changed files with 396 additions and 39 deletions.
4 changes: 2 additions & 2 deletions .ci/ci.yml.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% set chef_modules = ['compute', 'sql', 'storage', 'container', 'dns'] %}
{% set puppet_modules = ['bigquery', 'compute', 'sql', 'storage', 'container', 'dns', 'pubsub', 'resourcemanager'] %}
{% set chef_modules = ['compute', 'sql', 'storage', 'spanner', 'container', 'dns'] %}
{% set puppet_modules = ['bigquery', 'compute', 'sql', 'storage', 'spanner', 'container', 'dns', 'pubsub', 'resourcemanager'] %}
{% set terraform_enabled = true %}
{% set ansible_enabled = true %}
{% macro names_as_list(repo, names) -%}
Expand Down
2 changes: 2 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ this PR's changes from the commit messages for downstream commits.
# [all]
## [terraform]
## [puppet]
### [puppet-bigquery]
### [puppet-compute]
### [puppet-container]
### [puppet-dns]
Expand All @@ -35,6 +36,7 @@ this PR's changes from the commit messages for downstream commits.
### [chef-container]
### [chef-dns]
### [chef-logging]
### [chef-spanner]
### [chef-sql]
### [chef-storage]
## [ansible]
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,6 @@
[submodule "build/puppet/bigquery"]
path = build/puppet/bigquery
url = git@github.com:GoogleCloudPlatform/puppet-google-bigquery.git
[submodule "build/chef/spanner"]
path = build/chef/spanner
url = git@github.com:GoogleCloudPlatform/chef-google-spanner.git
2 changes: 1 addition & 1 deletion build/chef/container
2 changes: 1 addition & 1 deletion build/chef/dns
1 change: 1 addition & 0 deletions build/chef/spanner
Submodule spanner added at 07ffdf
2 changes: 1 addition & 1 deletion build/chef/sql
4 changes: 2 additions & 2 deletions products/spanner/ansible.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ overrides: !ruby/object:Provider::ResourceOverrides
custom_create_resource: true
custom_update_resource: true
provider_helpers:
- 'products/spanner/helpers/instance_helpers.py.erb'
- 'products/spanner/helpers/python/instance_helpers.py.erb'
Database: !ruby/object:Provider::Ansible::ResourceOverride
transport: !ruby/object:Api::Resource::Transport
encoder: encode_request
decoder: decode_response
provider_helpers:
- 'products/spanner/helpers/database_helpers.py.erb'
- 'products/spanner/helpers/python/database_helpers.py.erb'
# Virtual => true objects that don't need dedicated resources.
InstanceConfig: !ruby/object:Provider::Ansible::ResourceOverride
exclude: true
Expand Down
131 changes: 131 additions & 0 deletions products/spanner/chef.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Copyright 2017 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

--- !ruby/object:Provider::Chef::Config
manifest: !ruby/object:Provider::Chef::Manifest
version: '0.1.0'
source: 'https://github.com/GoogleCloudPlatform/chef-google-spanner'
issues: 'https://github.com/GoogleCloudPlatform/chef-google-spanner/issues'
summary: 'A Chef cookbook to manage Google Cloud Spanner resources'
description: |
This cookbook provides the built-in types and services for Chef to manage
Google Cloud Spanner resources, as native Chef types.
depends:
- !ruby/object:Provider::Config::Requirements
name: 'google-gauth'
versions: '< 0.2.0'
operating_systems:
<%= indent(include('provider/chef/common~operating_systems.yaml'), 4) %>
overrides: !ruby/object:Provider::ResourceOverrides
Database: !ruby/object:Provider::Chef::ResourceOverride
handlers: !ruby/object:Provider::Chef::Handlers
resource_to_request_patch: |
request[:create_statement] = "CREATE DATABASE `#{request[:name]}`"
request.delete(:name)
collection: |
URI.join(
'https://spanner.googleapis.com/v1/',
expand_variables(
'projects/{{project}}/instances/{{instance}}/databases',
data
).split('/').map { |p| p.gsub('%3A', ':') }
.join('/')
)
self_link: |
URI.join(
'https://spanner.googleapis.com/v1/',
expand_variables(
'projects/{{project}}/instances/{{instance}}/databases/{{name}}',
data
).split('/').map { |p| p.gsub('%3A', ':') }
.join('/')
)
provider_helpers:
- 'products/spanner/helpers/ruby/database_helpers.rb.erb'
Instance: !ruby/object:Provider::Chef::ResourceOverride
custom_create_resource: true
custom_update_resource: true
handlers: !ruby/object:Provider::Chef::Handlers
collection: |
URI.join(
'https://spanner.googleapis.com/v1/',
expand_variables(
'projects/{{project}}/instances',
data
).split('/').map { |p| p.gsub('%3A', ':') }
.join('/')
)
self_link: |
URI.join(
'https://spanner.googleapis.com/v1/',
expand_variables(
'projects/{{project}}/instances/{{name}}',
data
).split('/').map { |p| p.gsub('%3A', ':') }
.join('/')
)
provider_helpers:
- 'products/spanner/helpers/ruby/instance_helpers.rb.erb'
- 'products/spanner/helpers/chef/instance_helpers.rb.erb'
InstanceConfig: !ruby/object:Provider::Chef::ResourceOverride
deprecated: true
handlers: !ruby/object:Provider::Chef::Handlers
collection: |
URI.join(
'https://spanner.googleapis.com/v1/',
expand_variables(
'projects/{{project}}/instanceConfigs',
data
).split('/').map { |p| p.gsub('%3A', ':') }
.join('/')
)
self_link: |
URI.join(
'https://spanner.googleapis.com/v1/',
expand_variables(
'projects/{{project}}/instanceConfigs/{{name}}',
data
).split('/').map { |p| p.gsub('%3A', ':') }
.join('/')
)
provider_helpers:
- 'products/spanner/helpers/ruby/instance_config_helpers.rb.erb'
tests: !ruby/object:Api::Resource::HashArray
<%= indent(include('products/spanner/test.yaml'), 2) %>
examples: !ruby/object:Api::Resource::HashArray
Database:
- database.rb
Instance:
- delete_instance.rb
- instance.rb
files: !ruby/object:Provider::Config::Files
copy:
<%= indent(compile('provider/chef/common~copy.yaml'), 4) %>
compile:
<%= indent(include('provider/chef/common~compile~before.yaml'), 4) %>
<%= indent(include('provider/chef/common~compile~after.yaml'), 4) %>
<% # common~compile~after.yaml should be the last line of compile: section -%>
test_data: !ruby/object:Provider::Config::TestData
network: !ruby/object:Api::Resource::HashArray
Instance:
- success1~name
- success1~title
- success2~name
- success2~title
- success3~name
- success3~title
changelog:
- !ruby/object:Provider::Config::Changelog
version: '0.1.0'
date: 2017-10-10T06:00:00-0700
general: 'Initial release'
47 changes: 47 additions & 0 deletions products/spanner/examples/chef/database.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<% if false # the license inside this if block assertains to this file -%>
# Copyright 2017 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
<% end -%>
<% unless name == 'README.md' -%>

<%= compile 'templates/license.erb' -%>
<%= lines(autogen_notice :chef) -%>

<%= compile 'templates/chef/example~auth.rb.erb' -%>
<% end -%>
gspanner_instance <%= example_resource_name('my-spanner') -%> do
action :create
display_name 'My Spanner Instance'
node_count 2
labels({
'cost-center' => 'ti-1700004'
})
config 'regional-us-central1'
project ENV['PROJECT']
credential 'mycred'
end

gspanner_database <%= example_resource_name('webstore') -%> do
action :create
instance <%= example_resource_name('my-spanner') %>
extra_statements [
'CREATE TABLE customers (
customer_id INT64 NOT NULL,
last_name STRING(MAX)
) PRIMARY KEY (customer_id)'
]
project ENV['PROJECT']
credential 'mycred'
end
28 changes: 28 additions & 0 deletions products/spanner/examples/chef/delete_instance.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<% if false # the license inside this if block assertains to this file -%>
# Copyright 2017 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
<% end -%>
<% unless name == 'README.md' -%>

<%= compile 'templates/license.erb' -%>
<%= lines(autogen_notice :chef) -%>

<%= compile 'templates/chef/example~auth.rb.erb' -%>
<% end -%>
gspanner_instance <%= example_resource_name('my-spanner') -%> do
action :delete
project ENV['PROJECT']
credential 'mycred'
end
34 changes: 34 additions & 0 deletions products/spanner/examples/chef/instance.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<% if false # the license inside this if block assertains to this file -%>
# Copyright 2017 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
<% end -%>
<% unless name == 'README.md' -%>

<%= compile 'templates/license.erb' -%>
<%= lines(autogen_notice :chef) -%>

<%= compile 'templates/chef/example~auth.rb.erb' -%>
<% end -%>
gspanner_instance <%= example_resource_name('my-spanner') -%> do
action :create
display_name 'My Spanner Instance'
node_count 2
labels({
'cost-center' => 'ti-1700004'
})
config 'regional-us-central1'
project ENV['PROJECT']
credential 'mycred'
end
23 changes: 23 additions & 0 deletions products/spanner/examples/chef/instance_config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<% if false # the license inside this if block assertains to this file -%>
# Copyright 2017 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
<% end -%>
<% unless name == 'README.md' -%>

<%= compile 'templates/license.erb' -%>
<%= lines(autogen_notice :chef) -%>

<%= compile 'templates/chef/example~auth.rb.erb' -%>
<% end -%>
49 changes: 49 additions & 0 deletions products/spanner/examples/chef/readme.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<% if false # the license inside this if block assertains to this file -%>
# Copyright 2017 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
<% end -%>
<% unless name == 'README.md' -%>

<%= compile 'templates/license.erb' -%>
<%= lines(autogen_notice :chef) -%>

<%= compile 'templates/chef/example~auth.rb.erb' -%>
<% end -%>
gspanner_instance <%= example_resource_name('my-spanner') -%> do
action :create
display_name 'My Spanner Instance'
node_count 2
labels [
{
'cost-center' => 'ti-1700004'
}
]
config 'regional-us-central1'
project ENV['PROJECT']
credential 'mycred'
end

gspanner_database <%= example_resource_name('webstore') -%> do
action :create
instance <%= example_resource_name('my-spanner') %>
extra_statements [
'CREATE TABLE customers (
customer_id INT64 NOT NULL,
last_name STRING(MAX)
) PRIMARY KEY (customer_id)'
]
project ENV['PROJECT']
credential 'mycred'
end
Loading

0 comments on commit 83b5501

Please sign in to comment.