From f87a2a2b6d51ae282f109f567e075cdee5b91f25 Mon Sep 17 00:00:00 2001 From: "Patel, Prakash P" Date: Wed, 16 Oct 2019 15:02:12 -0400 Subject: [PATCH 01/13] inspec changes for cloud spanner instance only --- products/spanner/inspec.yaml | 22 +++++++++++++++++++ .../google_spanner_instance.erb | 11 ++++++++++ .../google_spanner_instance_attributes.erb | 2 ++ .../google_spanner_instances.erb | 6 +++++ .../inspec/tests/integration/build/gcp-mm.tf | 11 ++++++++++ .../configuration/mm-attributes.yml | 11 +++++++++- 6 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 products/spanner/inspec.yaml create mode 100644 templates/inspec/examples/google_spanner_instance/google_spanner_instance.erb create mode 100644 templates/inspec/examples/google_spanner_instance/google_spanner_instance_attributes.erb create mode 100644 templates/inspec/examples/google_spanner_instance/google_spanner_instances.erb diff --git a/products/spanner/inspec.yaml b/products/spanner/inspec.yaml new file mode 100644 index 000000000000..1f0ae2ce39a4 --- /dev/null +++ b/products/spanner/inspec.yaml @@ -0,0 +1,22 @@ +# 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::Inspec::Config +overrides: !ruby/object:Overrides::ResourceOverrides + InstanceConfig: !ruby/object:Overrides::Inspec::ResourceOverride + exclude: true + Instance: !ruby/object:Overrides::Inspec::ResourceOverride + exclude: false + Database: !ruby/object:Overrides::Inspec::ResourceOverride + exclude: true + \ No newline at end of file diff --git a/templates/inspec/examples/google_spanner_instance/google_spanner_instance.erb b/templates/inspec/examples/google_spanner_instance/google_spanner_instance.erb new file mode 100644 index 000000000000..00749c3c92ef --- /dev/null +++ b/templates/inspec/examples/google_spanner_instance/google_spanner_instance.erb @@ -0,0 +1,11 @@ +<% gcp_project_id = "#{external_attribute('gcp_project_id', doc_generation)}" -%> +<% spannerinstance = grab_attributes['spannerinstance'] -%> + +describe google_spanner_instance(project: <%= gcp_project_id -%>, name: <%= doc_generation ? "'#{spannerinstance['name']}'" : "spannerinstance['name']" -%>, config: <%= doc_generation ? "'#{spannerinstance['config']}'" : "spannerinstance['config']" -%>) do + it { should exist } + its('config') { should eq <%= doc_generation ? "'projects/#{gcp_project_id}/instanceConfigs/#{spannerinstance['config']}'" : "projects/#{gcp_project_id}/instanceConfigs/spannerinstance['config']" -%> } + its('name') { should eq <%= doc_generation ? "'#{spannerinstance['name']}'" : "spannerinstance['name']" -%> } + its('display_name') { should eq <%= doc_generation ? "'#{spannerinstance['display_name']}'" : "spannerinstance['display_name']" -%> } + its('node_count') { should eq <%= doc_generation ? "'#{spannerinstance['node_count']}'" : "spannerinstance['node_count']" -%> } + its('labels') { should eq <%= doc_generation ? "'#{spannerinstance['labels']}'" : "spannerinstance['labels']" -%> } +end \ No newline at end of file diff --git a/templates/inspec/examples/google_spanner_instance/google_spanner_instance_attributes.erb b/templates/inspec/examples/google_spanner_instance/google_spanner_instance_attributes.erb new file mode 100644 index 000000000000..ba0396d56f0e --- /dev/null +++ b/templates/inspec/examples/google_spanner_instance/google_spanner_instance_attributes.erb @@ -0,0 +1,2 @@ +gcp_project_id = attribute(:gcp_project_id, default: '<%= external_attribute('gcp_project_id') -%>', description: 'The GCP project identifier.') +spannerinstance = attribute('spannerinstance', default: <%= JSON.pretty_generate(grab_attributes['spannerinstance']) -%>, description: 'Cloud Spanner definition') diff --git a/templates/inspec/examples/google_spanner_instance/google_spanner_instances.erb b/templates/inspec/examples/google_spanner_instance/google_spanner_instances.erb new file mode 100644 index 000000000000..2dbc126ef9aa --- /dev/null +++ b/templates/inspec/examples/google_spanner_instance/google_spanner_instances.erb @@ -0,0 +1,6 @@ +<% gcp_project_id = "#{external_attribute('gcp_project_id', doc_generation)}" -%> +<% spannerinstance = grab_attributes['spannerinstance'] -%> + +describe google_spanner_instances(project: <%= gcp_project_id -%>, config: <%= doc_generation ? "'#{spannerinstance['config']}'" : "spannerinstance['config']" -%>) do + its('config') { should eq <%= doc_generation ? "'#{spannerinstance['config']}'" : "spannerinstance['config']" -%> } +end \ No newline at end of file diff --git a/templates/inspec/tests/integration/build/gcp-mm.tf b/templates/inspec/tests/integration/build/gcp-mm.tf index 73c6e6791755..972ce17f9935 100644 --- a/templates/inspec/tests/integration/build/gcp-mm.tf +++ b/templates/inspec/tests/integration/build/gcp-mm.tf @@ -836,3 +836,14 @@ resource "google_compute_node_group" "inspec-node-group" { size = var.node_group["size"] node_template = "${google_compute_node_template.inspec-template.self_link}" } + +resource "google_spanner_instance" "spanner_instance" { + project = "${var.gcp_project_id}" + config = "${var.spannerinstance["config"]}" + name = "${var.spannerinstance["name"]}" + display_name = "${var.spannerinstance["display_name"]}" + node_count = "${var.spannerinstance["node_count"]}" + labels = { + "${var.spannerinstance["label_key"]}" = "${var.spannerinstance["label_value"]}" + } +} diff --git a/templates/inspec/tests/integration/configuration/mm-attributes.yml b/templates/inspec/tests/integration/configuration/mm-attributes.yml index 92b6cfdcba4d..af755215e560 100644 --- a/templates/inspec/tests/integration/configuration/mm-attributes.yml +++ b/templates/inspec/tests/integration/configuration/mm-attributes.yml @@ -315,4 +315,13 @@ node_template: node_group: name: inspec-node-group description: A description of the node group - size: 0 \ No newline at end of file + size: 0 + +spannerinstance: + config: regional-us-east1 + name: inspec_inst + display_name: inspectest + node_count: 2 + label_key: env + label_value: test + \ No newline at end of file From f0623f2dc80695c89e0c9b3699209dffad1c2864 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Wed, 16 Oct 2019 13:00:57 -0700 Subject: [PATCH 02/13] [Ansible] Stop building deprecated facts modules in collections (#2476) Merged PR #2476. --- build/ansible | 2 +- provider/ansible.rb | 9 --------- templates/ansible/facts.erb | 9 +-------- 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/build/ansible b/build/ansible index e5ab367a20e3..bc4c90ad080d 160000 --- a/build/ansible +++ b/build/ansible @@ -1 +1 @@ -Subproject commit e5ab367a20e34b45076858cc2c1e45a8641b36b3 +Subproject commit bc4c90ad080d16e4ff8e402b6edd7a318541fa2e diff --git a/provider/ansible.rb b/provider/ansible.rb index 4bfca7a2e351..58a11aee5e90 100644 --- a/provider/ansible.rb +++ b/provider/ansible.rb @@ -290,15 +290,6 @@ def compile_datasource(data) File.join(target_folder, "plugins/modules/#{name}_info.py"), self) - - # Generate symlink for old `facts` modules. - return if version_added(data.object, :facts) >= '2.9' - - deprecated_facts_path = File.join(target_folder, - "plugins/modules/_#{name}_facts.py") - return if File.exist?(deprecated_facts_path) - - File.symlink "#{name}_info.py", deprecated_facts_path end def generate_objects(output_folder, types) diff --git a/templates/ansible/facts.erb b/templates/ansible/facts.erb index a7b16bbffc23..c7d7506672c4 100644 --- a/templates/ansible/facts.erb +++ b/templates/ansible/facts.erb @@ -26,9 +26,7 @@ DOCUMENTATION = ''' --- <%= ansible_style_yaml({ 'module' => "#{module_name(object)}_info", - 'description' => ["Gather info for GCP #{object.name}", - (version_added(object, :facts) < '2.9' ? "This module was called C(#{module_name(object)}_facts) before Ansible 2.9. The usage has not changed." : nil) - ].compact, + 'description' => ["Gather info for GCP #{object.name}"], 'short_description' => "Gather info for GCP #{object.name}", 'version_added' => version_added(object, :facts), 'author' => "Google Inc. (@googlecloudplatform)", @@ -91,11 +89,6 @@ def main(): })), 12) -%> ) -<% if version_added(object, :facts) < '2.9' -%> - - if module._name == '<%= module_name(object) -%>_facts': - module.deprecate("The '<%= module_name(object) -%>_facts' module has been renamed to '<%= module_name(object) -%>_info'", version='2.13') -<% end -%> if not module.params['scopes']: module.params['scopes'] = <%= python_literal(object.__product.scopes) %> From aa6b6881f41989c3e7cbd4f7a7019dbbdf49c4e9 Mon Sep 17 00:00:00 2001 From: Dana Hoffman Date: Wed, 16 Oct 2019 13:27:54 -0700 Subject: [PATCH 03/13] use IsStable in (R)IGM instead of CurrentActions (#2382) Merged PR #2382. --- build/terraform | 2 +- build/terraform-beta | 2 +- .../resource_compute_region_instance_group_manager.go.erb | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build/terraform b/build/terraform index e7dac2b6e377..33af39fd11b6 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit e7dac2b6e377ad0cc01c00f69b4b365bff3de12d +Subproject commit 33af39fd11b6abaa8d5ece60f388dbb07c677d51 diff --git a/build/terraform-beta b/build/terraform-beta index 1eb072f64bcf..f90234310ce9 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit 1eb072f64bcf7f80076f66dc83132b66e95732c9 +Subproject commit f90234310ce9678ac85195d83d85486b9598af79 diff --git a/third_party/terraform/resources/resource_compute_region_instance_group_manager.go.erb b/third_party/terraform/resources/resource_compute_region_instance_group_manager.go.erb index e78916d774a7..9459ebf1bad5 100644 --- a/third_party/terraform/resources/resource_compute_region_instance_group_manager.go.erb +++ b/third_party/terraform/resources/resource_compute_region_instance_group_manager.go.erb @@ -430,10 +430,10 @@ func waitForInstancesRefreshFunc(f getInstanceManagerFunc, d *schema.ResourceDat log.Printf("[WARNING] Error in fetching manager while waiting for instances to come up: %s\n", err) return nil, "error", err } - if done := m.CurrentActions.None; done < m.TargetSize { - return done, "creating", nil + if m.Status.IsStable { + return true, "created", nil } else { - return done, "created", nil + return false, "creating", nil } } } From 20cb3f5a6c5931930b18a1c8a1124a01db5f44be Mon Sep 17 00:00:00 2001 From: "Patel, Prakash P" Date: Wed, 16 Oct 2019 16:35:17 -0400 Subject: [PATCH 04/13] Added spanner database --- products/spanner/inspec.yaml | 8 +++++++- .../google_spanner_database/google_spanner_database.erb | 7 +++++++ .../google_spanner_database_attributes.erb | 2 ++ .../google_spanner_database/google_spanner_databases.erb | 7 +++++++ .../google_spanner_instance/google_spanner_instance.erb | 2 +- .../google_spanner_instance/google_spanner_instances.erb | 2 +- templates/inspec/tests/integration/build/gcp-mm.tf | 7 +++++++ templates/inspec/tests/integration/configuration/ddl.sql | 0 .../tests/integration/configuration/mm-attributes.yml | 5 ++++- 9 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 templates/inspec/examples/google_spanner_database/google_spanner_database.erb create mode 100644 templates/inspec/examples/google_spanner_database/google_spanner_database_attributes.erb create mode 100644 templates/inspec/examples/google_spanner_database/google_spanner_databases.erb create mode 100644 templates/inspec/tests/integration/configuration/ddl.sql diff --git a/products/spanner/inspec.yaml b/products/spanner/inspec.yaml index 1f0ae2ce39a4..f48471c3f9f3 100644 --- a/products/spanner/inspec.yaml +++ b/products/spanner/inspec.yaml @@ -17,6 +17,12 @@ overrides: !ruby/object:Overrides::ResourceOverrides exclude: true Instance: !ruby/object:Overrides::Inspec::ResourceOverride exclude: false + properties: + state: !ruby/object:Overrides::Inspec::PropertyOverride + exclude: true Database: !ruby/object:Overrides::Inspec::ResourceOverride - exclude: true + exclude: false + properties: + state: !ruby/object:Overrides::Inspec::PropertyOverride + exclude: true \ No newline at end of file diff --git a/templates/inspec/examples/google_spanner_database/google_spanner_database.erb b/templates/inspec/examples/google_spanner_database/google_spanner_database.erb new file mode 100644 index 000000000000..ca950a1f760b --- /dev/null +++ b/templates/inspec/examples/google_spanner_database/google_spanner_database.erb @@ -0,0 +1,7 @@ +<% gcp_project_id = "#{external_attribute('gcp_project_id', doc_generation)}" -%> +<% spannerdatabase = grab_attributes['spannerdatabase'] -%> + +describe google_spanner_database(project: <%= gcp_project_id -%>, name: <%= doc_generation ? "'#{spannerdatabase['name']}'" : "spannerdatabase['name']" -%>) do + it { should exist } + its('name') { should eq <%= doc_generation ? "'#{spannerdatabase['name']}'" : "spannerdatabase['name']" -%> } +end \ No newline at end of file diff --git a/templates/inspec/examples/google_spanner_database/google_spanner_database_attributes.erb b/templates/inspec/examples/google_spanner_database/google_spanner_database_attributes.erb new file mode 100644 index 000000000000..93a24ba09df1 --- /dev/null +++ b/templates/inspec/examples/google_spanner_database/google_spanner_database_attributes.erb @@ -0,0 +1,2 @@ +gcp_project_id = attribute(:gcp_project_id, default: '<%= external_attribute('gcp_project_id') -%>', description: 'The GCP project identifier.') +spannerdatabase = attribute('spannerdatabase', default: <%= JSON.pretty_generate(grab_attributes['spannerdatabase']) -%>, description: 'Cloud Spanner definition') diff --git a/templates/inspec/examples/google_spanner_database/google_spanner_databases.erb b/templates/inspec/examples/google_spanner_database/google_spanner_databases.erb new file mode 100644 index 000000000000..45a1f1915bdf --- /dev/null +++ b/templates/inspec/examples/google_spanner_database/google_spanner_databases.erb @@ -0,0 +1,7 @@ +<% gcp_project_id = "#{external_attribute('gcp_project_id', doc_generation)}" -%> +<% spannerdatabase = grab_attributes['spannerdatabase'] -%> + +describe google_spanner_databases(project: <%= gcp_project_id -%>, name: <%= doc_generation ? "'#{spannerdatabase['name']}'" : "spannerdatabase['name']" -%>) do + it { should exist } + its('name') { should eq <%= doc_generation ? "'#{spannerdatabase['name']}'" : "spannerdatabase['name']" -%> } +end \ No newline at end of file diff --git a/templates/inspec/examples/google_spanner_instance/google_spanner_instance.erb b/templates/inspec/examples/google_spanner_instance/google_spanner_instance.erb index 00749c3c92ef..5d215ab8481d 100644 --- a/templates/inspec/examples/google_spanner_instance/google_spanner_instance.erb +++ b/templates/inspec/examples/google_spanner_instance/google_spanner_instance.erb @@ -8,4 +8,4 @@ describe google_spanner_instance(project: <%= gcp_project_id -%>, name: <%= doc_ its('display_name') { should eq <%= doc_generation ? "'#{spannerinstance['display_name']}'" : "spannerinstance['display_name']" -%> } its('node_count') { should eq <%= doc_generation ? "'#{spannerinstance['node_count']}'" : "spannerinstance['node_count']" -%> } its('labels') { should eq <%= doc_generation ? "'#{spannerinstance['labels']}'" : "spannerinstance['labels']" -%> } -end \ No newline at end of file +end diff --git a/templates/inspec/examples/google_spanner_instance/google_spanner_instances.erb b/templates/inspec/examples/google_spanner_instance/google_spanner_instances.erb index 2dbc126ef9aa..79d74768fccd 100644 --- a/templates/inspec/examples/google_spanner_instance/google_spanner_instances.erb +++ b/templates/inspec/examples/google_spanner_instance/google_spanner_instances.erb @@ -3,4 +3,4 @@ describe google_spanner_instances(project: <%= gcp_project_id -%>, config: <%= doc_generation ? "'#{spannerinstance['config']}'" : "spannerinstance['config']" -%>) do its('config') { should eq <%= doc_generation ? "'#{spannerinstance['config']}'" : "spannerinstance['config']" -%> } -end \ No newline at end of file +end diff --git a/templates/inspec/tests/integration/build/gcp-mm.tf b/templates/inspec/tests/integration/build/gcp-mm.tf index 972ce17f9935..6f6917027a38 100644 --- a/templates/inspec/tests/integration/build/gcp-mm.tf +++ b/templates/inspec/tests/integration/build/gcp-mm.tf @@ -847,3 +847,10 @@ resource "google_spanner_instance" "spanner_instance" { "${var.spannerinstance["label_key"]}" = "${var.spannerinstance["label_value"]}" } } + +resource "google_spanner_instance" "database" { + project = "${var.gcp_project_id}" + instance = "${google_spanner_instance.spanner_instance.name}" + name = "${var.spannerdatabase["name"]}" + ddl = "${split("\n", file("ddl.sql"))}" +} diff --git a/templates/inspec/tests/integration/configuration/ddl.sql b/templates/inspec/tests/integration/configuration/ddl.sql new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/templates/inspec/tests/integration/configuration/mm-attributes.yml b/templates/inspec/tests/integration/configuration/mm-attributes.yml index af755215e560..bb82a74988ae 100644 --- a/templates/inspec/tests/integration/configuration/mm-attributes.yml +++ b/templates/inspec/tests/integration/configuration/mm-attributes.yml @@ -319,9 +319,12 @@ node_group: spannerinstance: config: regional-us-east1 - name: inspec_inst + name: spinstance display_name: inspectest node_count: 2 label_key: env label_value: test + +spannerdatabase: + name: spdatabase \ No newline at end of file From fd5b4b180149476cadf4feb8445d20ecb8bd3cc2 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Wed, 16 Oct 2019 14:13:05 -0700 Subject: [PATCH 05/13] adding fields to compute#instance.accessConfigs[] (#2437) Merged PR #2437. --- build/ansible | 2 +- build/inspec | 2 +- products/compute/ansible_version_added.yaml | 12 +++++ products/compute/api.yaml | 50 +++++++++++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/build/ansible b/build/ansible index bc4c90ad080d..e0d101beccb2 160000 --- a/build/ansible +++ b/build/ansible @@ -1 +1 @@ -Subproject commit bc4c90ad080d16e4ff8e402b6edd7a318541fa2e +Subproject commit e0d101beccb2e021491ee749bde49dce1c5f0235 diff --git a/build/inspec b/build/inspec index 735f38f2505b..fcc076d77165 160000 --- a/build/inspec +++ b/build/inspec @@ -1 +1 @@ -Subproject commit 735f38f2505b6fdbeffb5ba0629051a8ac74992b +Subproject commit fcc076d77165d672797a5063a4501e4fb733118d diff --git a/products/compute/ansible_version_added.yaml b/products/compute/ansible_version_added.yaml index 125cd8ebfa3d..539e36710653 100644 --- a/products/compute/ansible_version_added.yaml +++ b/products/compute/ansible_version_added.yaml @@ -619,6 +619,12 @@ :version_added: '2.6' :type: :version_added: '2.6' + :setPublicPtr: + :version_added: '2.10' + :publicPtrDomainName: + :version_added: '2.10' + :networkTier: + :version_added: '2.10' :aliasIpRanges: :version_added: '2.6' :ipCidrRange: @@ -767,6 +773,12 @@ :version_added: '2.6' :type: :version_added: '2.6' + :setPublicPtr: + :version_added: '2.10' + :publicPtrDomainName: + :version_added: '2.10' + :networkTier: + :version_added: '2.10' :aliasIpRanges: :version_added: '2.6' :ipCidrRange: diff --git a/products/compute/api.yaml b/products/compute/api.yaml index c2b5ff879c46..47065b6558e7 100644 --- a/products/compute/api.yaml +++ b/products/compute/api.yaml @@ -3836,6 +3836,31 @@ objects: values: - :ONE_TO_ONE_NAT required: true + - !ruby/object:Api::Type::Boolean + name: 'setPublicPtr' + description: | + Specifies whether a public DNS PTR record should be + created to map the external IP address of the instance + to a DNS domain name. + - !ruby/object:Api::Type::String + name: 'publicPtrDomainName' + description: | + The DNS domain name for the public PTR record. You can + set this field only if the setPublicPtr field is + enabled. + - !ruby/object:Api::Type::Enum + name: 'networkTier' + description: | + This signifies the networking tier used for configuring + this access configuration. If an AccessConfig is + specified without a valid external IP address, an + ephemeral IP will be created with this networkTier. If an + AccessConfig with a valid external IP address is + specified, it must match that of the networkTier + associated with the Address resource owning that IP. + values: + - :PREMIUM + - :STANDARD - !ruby/object:Api::Type::Array name: 'aliasIpRanges' description: | @@ -4634,6 +4659,31 @@ objects: values: - :ONE_TO_ONE_NAT required: true + - !ruby/object:Api::Type::Boolean + name: 'setPublicPtr' + description: | + Specifies whether a public DNS PTR record should be + created to map the external IP address of the instance + to a DNS domain name. + - !ruby/object:Api::Type::String + name: 'publicPtrDomainName' + description: | + The DNS domain name for the public PTR record. You can + set this field only if the setPublicPtr field is + enabled. + - !ruby/object:Api::Type::Enum + name: 'networkTier' + description: | + This signifies the networking tier used for configuring + this access configuration. If an AccessConfig is + specified without a valid external IP address, an + ephemeral IP will be created with this networkTier. If an + AccessConfig with a valid external IP address is + specified, it must match that of the networkTier + associated with the Address resource owning that IP. + values: + - :PREMIUM + - :STANDARD - !ruby/object:Api::Type::Array name: 'aliasIpRanges' description: | From bb4342d60907f6e21245a37a3c4c49c038590099 Mon Sep 17 00:00:00 2001 From: Riley Karson Date: Wed, 16 Oct 2019 14:37:36 -0700 Subject: [PATCH 06/13] Add GKE Stackdriver Monitoring changes to upgrade guide (#2472) Merged PR #2472. --- build/terraform | 2 +- build/terraform-beta | 2 +- .../docs/version_3_upgrade.html.markdown | 33 +++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/build/terraform b/build/terraform index 33af39fd11b6..66e689ac6685 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit 33af39fd11b6abaa8d5ece60f388dbb07c677d51 +Subproject commit 66e689ac66853db952f05c3ab9535e6a8a3357da diff --git a/build/terraform-beta b/build/terraform-beta index f90234310ce9..075403f9746f 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit f90234310ce9678ac85195d83d85486b9598af79 +Subproject commit 075403f9746f8677c08e50a2fdb6da358988eb38 diff --git a/third_party/terraform/website/docs/version_3_upgrade.html.markdown b/third_party/terraform/website/docs/version_3_upgrade.html.markdown index b4794acb005e..52907f077b41 100644 --- a/third_party/terraform/website/docs/version_3_upgrade.html.markdown +++ b/third_party/terraform/website/docs/version_3_upgrade.html.markdown @@ -50,6 +50,7 @@ so Terraform knows to manage them. ## Upgrade Topics +- [Resource: `google_container_cluster`](#resource-google_container_cluster) - [Resource: `google_project_services`](#resource-google_project_services) @@ -90,6 +91,38 @@ provider "google" { } ``` +## Resource: `google_container_cluster` + +### `logging_service` and `monitoring_service` defaults changed + +GKE Stackdriver Monitoring (the GKE-specific Stackdriver experience) is now +enabled at cluster creation by default, similar to the default in GKE `1.14` +through other tools. + +Terraform will now detect changes out of band when the field(s) are not defined +in config, attempting to return them to their new defaults, and will be clear +about what values will be set when creating a cluster. + +`terraform plan` will report changes upon upgrading if the field was previously +unset. Applying this change will enable the new Stackdriver service without +recreating clusters. Users who wish to use another value should record their +intended value in config; the old default values can be added to a +`google_container_cluster` resource config block to preserve them. + +#### Old Defaults + +```hcl +logging_service = "logging.googleapis.com" +monitoring_service = "monitoring.googleapis.com" +``` + +#### New Defaults + +```hcl +logging_service = "logging.googleapis.com/kubernetes" +monitoring_service = "monitoring.googleapis.com/kubernetes" +``` + ## Resource: `google_project_services` ### `google_project_services` has been removed from the provider From 13c7429a76c2a96ce63258b019ef396110178034 Mon Sep 17 00:00:00 2001 From: Riley Karson Date: Wed, 16 Oct 2019 14:43:03 -0700 Subject: [PATCH 07/13] Add support for one-field-at-a-time update to Subnetwork (#2475) Merged PR #2475. --- api/type.rb | 14 ++++++++ products/compute/ansible.yaml | 5 +++ products/compute/api.yaml | 9 +++-- .../ansible/service_account_key_template.erb | 2 +- .../helpers/ansible/object_template.erb | 2 +- provider/core.rb | 25 ++++++++++--- spec/provider_terraform_spec.rb | 21 +++++++++-- templates/ansible/resource.erb | 2 +- templates/terraform/resource.erb | 29 ++++++++++++--- .../tests/resource_compute_subnetwork_test.go | 35 +++++++++++++++++++ 10 files changed, 127 insertions(+), 17 deletions(-) diff --git a/api/type.rb b/api/type.rb index 9b67c2c530c0..4e1698ff2c6a 100644 --- a/api/type.rb +++ b/api/type.rb @@ -35,8 +35,20 @@ module Fields attr_reader :input # If set to true value is used only on creation attr_reader :url_param_only # If, true will not be send in request body attr_reader :required + attr_reader :update_verb attr_reader :update_url + # Some updates only allow updating certain fields at once (generally each + # top-level field can be updated one-at-a-time). If this is set, we group + # fields to update by (verb, url, fingerprint, id) instead of just + # (verb, url, fingerprint), to allow multiple fields to reuse the same + # endpoints. + attr_reader :update_id + # THe fingerprint value required to update this field. Downstreams should + # GET the resource and parse the fingerprint value while doing each update + # call. This ensures we can supply the fingerprint to each distinct + # request. + attr_reader :fingerprint_name # If true, we will include the empty value in requests made including # this attribute (both creates and updates). This rarely needs to be # set to true, and corresponds to both the "NullFields" and @@ -91,6 +103,8 @@ def validate default: @__resource&.update_verb check :update_url, type: ::String + check :update_id, type: ::String + check :fingerprint_name, type: ::String check :pattern, type: ::String check_default_value_property diff --git a/products/compute/ansible.yaml b/products/compute/ansible.yaml index d57496681b73..bf95933f6c79 100644 --- a/products/compute/ansible.yaml +++ b/products/compute/ansible.yaml @@ -272,6 +272,11 @@ overrides: !ruby/object:Overrides::ResourceOverrides * https://www.googleapis.com/compute/v1/projects/project/global/gateways/default-internet-gateway * projects/project/global/gateways/default-internet-gateway * global/gateways/default-internet-gateway + Subnetwork: !ruby/object:Overrides::Ansible::ResourceOverride + properties: + fingerprint: !ruby/object:Overrides::Ansible::PropertyOverride + update_verb: :PATCH + update_url: projects/{{project}}/regions/{{region}}/subnetworks/{{name}} TargetPool: !ruby/object:Overrides::Ansible::ResourceOverride transport: !ruby/object:Overrides::Ansible::Transport encoder: encode_request diff --git a/products/compute/api.yaml b/products/compute/api.yaml index 47065b6558e7..0582c47e414b 100644 --- a/products/compute/api.yaml +++ b/products/compute/api.yaml @@ -8722,14 +8722,15 @@ objects: Whether to enable flow logging for this subnetwork. update_verb: :PATCH update_url: projects/{{project}}/regions/{{region}}/subnetworks/{{name}} + update_id: 'enableFlowLogs' + fingerprint_name: 'fingerprint' send_empty_value: true + # TODO(rileykarson): Work with rambleraptor to remove this field from downstreams. - !ruby/object:Api::Type::Fingerprint name: 'fingerprint' description: | Fingerprint of this resource. This field is used internally during updates of this resource. - update_verb: :PATCH - update_url: projects/{{project}}/regions/{{region}}/subnetworks/{{name}} - !ruby/object:Api::Type::Enum name: 'purpose' min_version: beta @@ -8750,6 +8751,8 @@ objects: min_version: beta update_verb: :PATCH update_url: projects/{{project}}/regions/{{region}}/subnetworks/{{name}} + update_id: 'role' + fingerprint_name: 'fingerprint' values: - :ACTIVE - :BACKUP @@ -8768,6 +8771,8 @@ objects: to either primary or secondary ranges. update_verb: :PATCH update_url: projects/{{project}}/regions/{{region}}/subnetworks/{{name}} + update_id: 'secondaryIpRanges' + fingerprint_name: 'fingerprint' item_type: !ruby/object:Api::Type::NestedObject properties: - !ruby/object:Api::Type::String diff --git a/products/iam/helpers/ansible/service_account_key_template.erb b/products/iam/helpers/ansible/service_account_key_template.erb index 027b06d75607..0c9b69a3a261 100644 --- a/products/iam/helpers/ansible/service_account_key_template.erb +++ b/products/iam/helpers/ansible/service_account_key_template.erb @@ -21,7 +21,7 @@ __metaclass__ = type -%> <% - update_props = properties_by_custom_update(object.all_user_properties) + update_props = properties_by_custom_update(object.all_user_properties, :old) import = 'from ansible.module_utils.gcp_utils import navigate_hash, GcpSession, GcpModule, GcpRequest' import += ', remove_nones_from_dict' unless properties_with_classes(object.all_user_properties).empty? import += ', replace_resource_dict' if nonreadonly_rrefs(object) diff --git a/products/storage/helpers/ansible/object_template.erb b/products/storage/helpers/ansible/object_template.erb index 2b9d1b01c66b..1309077ccb9d 100644 --- a/products/storage/helpers/ansible/object_template.erb +++ b/products/storage/helpers/ansible/object_template.erb @@ -21,7 +21,7 @@ __metaclass__ = type -%> <% - update_props = properties_by_custom_update(object.all_user_properties) + update_props = properties_by_custom_update(object.all_user_properties, :old) import = 'from ansible.module_utils.gcp_utils import navigate_hash, GcpSession, GcpModule, GcpRequest' import += ', remove_nones_from_dict' unless properties_with_classes(object.all_user_properties).empty? import += ', replace_resource_dict' if nonreadonly_rrefs(object) diff --git a/provider/core.rb b/provider/core.rb index a67f1566caa6..8cf273f19ebf 100644 --- a/provider/core.rb +++ b/provider/core.rb @@ -282,12 +282,25 @@ def build_env # Filter the properties to keep only the ones requiring custom update # method and group them by update url & verb. - def properties_by_custom_update(properties) + def properties_by_custom_update(properties, behavior = :new) update_props = properties.reject do |p| p.update_url.nil? || p.update_verb.nil? || p.update_verb == :NOOP end - update_props.group_by do |p| - { update_url: p.update_url, update_verb: p.update_verb } + + # TODO(rambleraptor): Add support to Ansible for one-at-a-time updates. + if behavior == :old + update_props.group_by do |p| + { update_url: p.update_url, update_verb: p.update_verb } + end + else + update_props.group_by do |p| + { + update_url: p.update_url, + update_verb: p.update_verb, + update_id: p.update_id, + fingerprint_name: p.fingerprint_name + } + end end end @@ -295,9 +308,11 @@ def properties_by_custom_update(properties) # that can be updated at that URL. This allows flattened objects # to determine which parent property in the API should be updated with # the contents of the flattened object - def custom_update_properties_by_url(properties, update_url) + def custom_update_properties_by_key(properties, key) properties_by_custom_update(properties).select do |k, _| - k[:update_url] == update_url + k[:update_url] == key[:update_url] && + k[:update_id] == key[:update_id] && + k[:fingerprint_name] == key[:fingerprint_name] end.first.last # .first is to grab the element from the select which returns a list # .last is because properties_by_custom_update returns a list of diff --git a/spec/provider_terraform_spec.rb b/spec/provider_terraform_spec.rb index f7c1cba477ef..76fdff0f9e17 100644 --- a/spec/provider_terraform_spec.rb +++ b/spec/provider_terraform_spec.rb @@ -117,10 +117,25 @@ class << self it do is_expected.to eq( - { update_url: 'url1', update_verb: :POST } => + { + update_url: 'url1', + update_verb: :POST, + update_id: nil, + fingerprint_name: nil + } => [postUrl1, otherPostUrl1], - { update_url: 'url2', update_verb: :POST } => [postUrl2], - { update_url: 'url2', update_verb: :PUT } => [putUrl2] + { + update_url: 'url2', + update_verb: :POST, + update_id: nil, + fingerprint_name: nil + } => [postUrl2], + { + update_url: 'url2', + update_verb: :PUT, + update_id: nil, + fingerprint_name: nil + } => [putUrl2] ) end end diff --git a/templates/ansible/resource.erb b/templates/ansible/resource.erb index 26e6ce161c6f..ec4e12aafb53 100644 --- a/templates/ansible/resource.erb +++ b/templates/ansible/resource.erb @@ -19,7 +19,7 @@ __metaclass__ = type .map(&:resource_ref) .uniq - update_props = properties_by_custom_update(object.all_user_properties) + update_props = properties_by_custom_update(object.all_user_properties, :old) -%> <% diff --git a/templates/terraform/resource.erb b/templates/terraform/resource.erb index 88e4789967a3..0eaf2f530220 100644 --- a/templates/terraform/resource.erb +++ b/templates/terraform/resource.erb @@ -344,7 +344,28 @@ func resource<%= resource_name -%>Update(d *schema.ResourceData, meta interface{ <% properties_by_custom_update(object.root_properties).each do |key, props| -%> if <%= props.map { |prop| "d.HasChange(\"#{prop.name.underscore}\")" }.join ' || ' -%> { obj := make(map[string]interface{}) -<% custom_update_properties_by_url(properties, key[:update_url]).each do |prop| -%> + +<%- unless key[:fingerprint_name] == nil -%> + getUrl, err := replaceVars(d, config, "<%= "{{#{object.__product.name}BasePath}}#{object.self_link_uri}" -%>") + if err != nil { + return err + } + +<% if has_project -%> + project, err := getProject(d, config) + if err != nil { + return err + } +<% end -%> + getRes, err := sendRequest(config, "<%= object.read_verb.to_s.upcase -%>", <% if has_project %>project<% else %>""<% end %>, getUrl, nil) + if err != nil { + return handleNotFoundError(err, d, fmt.Sprintf("<%= resource_name -%> %q", d.Id())) + } + + obj["<%= key[:fingerprint_name] %>"] = getRes["<%= key[:fingerprint_name] %>"] + +<% end # unless key[:fingerprint_name] -%> +<% custom_update_properties_by_key(properties, key).each do |prop| -%> <% schemaPrefix = prop.flatten_object ? "nil" : "d.Get( \"#{prop.name.underscore}\" )" -%> <%= prop.api_name -%>Prop, err := expand<%= resource_name -%><%= titlelize_property(prop) -%>(<%= schemaPrefix -%>, d, config) if err != nil { @@ -398,13 +419,13 @@ if <%= props.map { |prop| "d.HasChange(\"#{prop.name.underscore}\")" }.join ' || } <% if !object.async.nil? && object.async.allow?('update') -%> -<% if object.autogen_async -%> +<% if object.autogen_async -%> err = <%= client_name_camel -%>OperationWaitTime( config, res, <% if has_project -%> project, <% end -%> "Updating <%= object.name -%>", int(d.Timeout(schema.TimeoutUpdate).Minutes())) -<% else -%> +<% else -%> op := &<%= client_name_lower -%>.Operation{} err = Convert(res, op) if err != nil { @@ -415,7 +436,7 @@ if <%= props.map { |prop| "d.HasChange(\"#{prop.name.underscore}\")" }.join ' || config.client<%= client_name_pascal -%>, op, <% if has_project -%> project, <% end -%> "Updating <%= object.name -%>", int(d.Timeout(schema.TimeoutUpdate).Minutes())) -<% end -%> +<% end -%> if err != nil { return err } diff --git a/third_party/terraform/tests/resource_compute_subnetwork_test.go b/third_party/terraform/tests/resource_compute_subnetwork_test.go index 20441163f349..c3294c5343f0 100644 --- a/third_party/terraform/tests/resource_compute_subnetwork_test.go +++ b/third_party/terraform/tests/resource_compute_subnetwork_test.go @@ -123,6 +123,19 @@ func TestAccComputeSubnetwork_update(t *testing.T) { "google_compute_subnetwork.network-with-private-google-access", &subnetwork), ), }, + { + // Add a secondary range and enable flow logs at once + Config: testAccComputeSubnetwork_update3(cnName, "10.2.0.0/24", subnetworkName), + Check: resource.ComposeTestCheckFunc( + testAccCheckComputeSubnetworkExists( + "google_compute_subnetwork.network-with-private-google-access", &subnetwork), + ), + }, + { + ResourceName: "google_compute_subnetwork.network-with-private-google-access", + ImportState: true, + ImportStateVerify: true, + }, }, }) @@ -356,6 +369,28 @@ resource "google_compute_subnetwork" "network-with-private-google-access" { `, cnName, subnetworkName, cidrRange) } +func testAccComputeSubnetwork_update3(cnName, cidrRange, subnetworkName string) string { + return fmt.Sprintf(` +resource "google_compute_network" "custom-test" { + name = "%s" + auto_create_subnetworks = false +} + +resource "google_compute_subnetwork" "network-with-private-google-access" { + name = "%s" + ip_cidr_range = "%s" + region = "us-central1" + network = "${google_compute_network.custom-test.self_link}" + + enable_flow_logs = true + secondary_ip_range { + range_name = "tf-test-secondary-range-update" + ip_cidr_range = "192.168.10.0/24" + } +} +`, cnName, subnetworkName, cidrRange) +} + func testAccComputeSubnetwork_secondaryIpRanges_update1(cnName, subnetworkName string) string { return fmt.Sprintf(` resource "google_compute_network" "custom-test" { From 50d6d1ca0fa65e3492ab4d6662fd300b2b636898 Mon Sep 17 00:00:00 2001 From: Riley Karson Date: Wed, 16 Oct 2019 16:27:05 -0700 Subject: [PATCH 08/13] Remove built-in version from service client basepaths (#2483) Merged PR #2483. --- build/terraform | 2 +- build/terraform-beta | 2 +- build/terraform-mapper | 2 +- third_party/terraform/utils/config.go.erb | 14 +++++++------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build/terraform b/build/terraform index 66e689ac6685..f058c31cf97d 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit 66e689ac66853db952f05c3ab9535e6a8a3357da +Subproject commit f058c31cf97df1f2dcb04306334668ff332e0c19 diff --git a/build/terraform-beta b/build/terraform-beta index 075403f9746f..2e8d2b2075f3 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit 075403f9746f8677c08e50a2fdb6da358988eb38 +Subproject commit 2e8d2b2075f307751114375e1def035c89e9db6c diff --git a/build/terraform-mapper b/build/terraform-mapper index 1d5c7659d772..a5b16ba9fbb0 160000 --- a/build/terraform-mapper +++ b/build/terraform-mapper @@ -1 +1 @@ -Subproject commit 1d5c7659d77251835a1d1430561520189aad38b4 +Subproject commit a5b16ba9fbb0853df76e12bece176aa93df56f61 diff --git a/third_party/terraform/utils/config.go.erb b/third_party/terraform/utils/config.go.erb index d6d507dff358..e08703748e80 100644 --- a/third_party/terraform/utils/config.go.erb +++ b/third_party/terraform/utils/config.go.erb @@ -231,7 +231,7 @@ func (c *Config) LoadAndValidate() error { // while most only want the host URL, some older ones also want the version and some // of those "projects" as well. You can find out if this is required by looking at // the basePath value in the client library file. - computeClientBasePath := removeBasePathVersion(c.ComputeBasePath) + "v1/projects/" + computeClientBasePath := c.ComputeBasePath + "projects/" log.Printf("[INFO] Instantiating GCE client for path %s", computeClientBasePath) c.clientCompute, err = compute.NewService(context, option.WithHTTPClient(client)) if err != nil { @@ -240,7 +240,7 @@ func (c *Config) LoadAndValidate() error { c.clientCompute.UserAgent = userAgent c.clientCompute.BasePath = computeClientBasePath - computeBetaClientBasePath := removeBasePathVersion(c.ComputeBetaBasePath) + "beta/projects/" + computeBetaClientBasePath := c.ComputeBetaBasePath + "projects/" log.Printf("[INFO] Instantiating GCE Beta client for path %s", computeBetaClientBasePath) c.clientComputeBeta, err = computeBeta.NewService(context, option.WithHTTPClient(client)) if err != nil { @@ -267,7 +267,7 @@ func (c *Config) LoadAndValidate() error { c.clientContainerBeta.UserAgent = userAgent c.clientContainerBeta.BasePath = containerBetaClientBasePath - dnsClientBasePath := removeBasePathVersion(c.DNSBasePath) + "v1/projects/" + dnsClientBasePath := c.DNSBasePath + "projects/" log.Printf("[INFO] Instantiating Google Cloud DNS client for path %s", dnsClientBasePath) c.clientDns, err = dns.NewService(context, option.WithHTTPClient(client)) if err != nil { @@ -276,7 +276,7 @@ func (c *Config) LoadAndValidate() error { c.clientDns.UserAgent = userAgent c.clientDns.BasePath = dnsClientBasePath - dnsBetaClientBasePath := removeBasePathVersion(c.DnsBetaBasePath) + "v1beta2/projects/" + dnsBetaClientBasePath := c.DnsBetaBasePath + "projects/" log.Printf("[INFO] Instantiating Google Cloud DNS Beta client for path %s", dnsBetaClientBasePath) c.clientDnsBeta, err = dnsBeta.NewService(context, option.WithHTTPClient(client)) if err != nil { @@ -303,7 +303,7 @@ func (c *Config) LoadAndValidate() error { c.clientLogging.UserAgent = userAgent c.clientLogging.BasePath = loggingClientBasePath - storageClientBasePath := removeBasePathVersion(c.StorageBasePath) + "v1/" + storageClientBasePath := c.StorageBasePath log.Printf("[INFO] Instantiating Google Storage client for path %s", storageClientBasePath) c.clientStorage, err = storage.NewService(context, option.WithHTTPClient(client)) if err != nil { @@ -312,7 +312,7 @@ func (c *Config) LoadAndValidate() error { c.clientStorage.UserAgent = userAgent c.clientStorage.BasePath = storageClientBasePath - sqlClientBasePath := removeBasePathVersion(c.SQLBasePath) + "v1beta4/" + sqlClientBasePath := c.SQLBasePath log.Printf("[INFO] Instantiating Google SqlAdmin client for path %s", sqlClientBasePath) c.clientSqlAdmin, err = sqladmin.NewService(context, option.WithHTTPClient(client)) if err != nil { @@ -432,7 +432,7 @@ func (c *Config) LoadAndValidate() error { c.clientBuild.UserAgent = userAgent c.clientBuild.BasePath = cloudBuildClientBasePath - bigQueryClientBasePath := removeBasePathVersion(c.BigQueryBasePath) + "v2/" + bigQueryClientBasePath := c.BigQueryBasePath log.Printf("[INFO] Instantiating Google Cloud BigQuery client for path %s", bigQueryClientBasePath) c.clientBigQuery, err = bigquery.NewService(context, option.WithHTTPClient(client)) if err != nil { From eb875a443a629b4e7d29b401830900753fb90b2e Mon Sep 17 00:00:00 2001 From: Riley Karson Date: Wed, 16 Oct 2019 16:45:00 -0700 Subject: [PATCH 09/13] Add note about using 2.13.0 in google_project_services deprecation messages (#2480) Merged PR #2480. --- .../terraform/resources/resource_google_project_services.go | 3 ++- .../terraform/website/docs/version_3_upgrade.html.markdown | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/third_party/terraform/resources/resource_google_project_services.go b/third_party/terraform/resources/resource_google_project_services.go index e31f85d0a8a8..30c8a0eb11d5 100644 --- a/third_party/terraform/resources/resource_google_project_services.go +++ b/third_party/terraform/resources/resource_google_project_services.go @@ -26,7 +26,8 @@ func resourceGoogleProjectServices() *schema.Resource { DeprecationMessage: "google_project_services is deprecated - many users reported " + "issues with dependent services that were not resolvable. Please use google_project_service or the " + "https://github.com/terraform-google-modules/terraform-google-project-factory/tree/master/modules/project_services" + - " module. This resource will be removed in version 3.0.0.", + " module. It's recommended that you use a provider version of 2.13.0 or higher when you migrate so that requests are" + + " batched to the API, reducing the request rate. This resource will be removed in version 3.0.0.", Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(20 * time.Minute), diff --git a/third_party/terraform/website/docs/version_3_upgrade.html.markdown b/third_party/terraform/website/docs/version_3_upgrade.html.markdown index 52907f077b41..201bcc10dce5 100644 --- a/third_party/terraform/website/docs/version_3_upgrade.html.markdown +++ b/third_party/terraform/website/docs/version_3_upgrade.html.markdown @@ -147,6 +147,11 @@ Users should migrate to using `google_project_service` resources, or using the [`"terraform-google-modules/project-factory/google//modules/project_services"`](https://registry.terraform.io/modules/terraform-google-modules/project-factory/google/3.3.0/submodules/project_services) module for a similar interface to `google_project_services`. +-> Prior to `2.13.0`, each `google_project_service` sent separate API enablement +requests. From `2.13.0` onwards, those requests are batched. It's recommended +that you upgrade to `2.13.0+` before migrating if you encounter quota issues +when you migrate off `google_project_services`. + #### Old Config ```hcl From 5e520349773f6d101a9f32697dac8a5b0175d6cc Mon Sep 17 00:00:00 2001 From: "Patel, Prakash P" Date: Wed, 16 Oct 2019 15:02:12 -0400 Subject: [PATCH 10/13] inspec changes for cloud spanner instance only --- products/spanner/inspec.yaml | 22 +++++++++++++++++++ .../google_spanner_instance.erb | 11 ++++++++++ .../google_spanner_instance_attributes.erb | 2 ++ .../google_spanner_instances.erb | 6 +++++ .../inspec/tests/integration/build/gcp-mm.tf | 11 ++++++++++ .../configuration/mm-attributes.yml | 11 +++++++++- 6 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 products/spanner/inspec.yaml create mode 100644 templates/inspec/examples/google_spanner_instance/google_spanner_instance.erb create mode 100644 templates/inspec/examples/google_spanner_instance/google_spanner_instance_attributes.erb create mode 100644 templates/inspec/examples/google_spanner_instance/google_spanner_instances.erb diff --git a/products/spanner/inspec.yaml b/products/spanner/inspec.yaml new file mode 100644 index 000000000000..1f0ae2ce39a4 --- /dev/null +++ b/products/spanner/inspec.yaml @@ -0,0 +1,22 @@ +# 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::Inspec::Config +overrides: !ruby/object:Overrides::ResourceOverrides + InstanceConfig: !ruby/object:Overrides::Inspec::ResourceOverride + exclude: true + Instance: !ruby/object:Overrides::Inspec::ResourceOverride + exclude: false + Database: !ruby/object:Overrides::Inspec::ResourceOverride + exclude: true + \ No newline at end of file diff --git a/templates/inspec/examples/google_spanner_instance/google_spanner_instance.erb b/templates/inspec/examples/google_spanner_instance/google_spanner_instance.erb new file mode 100644 index 000000000000..00749c3c92ef --- /dev/null +++ b/templates/inspec/examples/google_spanner_instance/google_spanner_instance.erb @@ -0,0 +1,11 @@ +<% gcp_project_id = "#{external_attribute('gcp_project_id', doc_generation)}" -%> +<% spannerinstance = grab_attributes['spannerinstance'] -%> + +describe google_spanner_instance(project: <%= gcp_project_id -%>, name: <%= doc_generation ? "'#{spannerinstance['name']}'" : "spannerinstance['name']" -%>, config: <%= doc_generation ? "'#{spannerinstance['config']}'" : "spannerinstance['config']" -%>) do + it { should exist } + its('config') { should eq <%= doc_generation ? "'projects/#{gcp_project_id}/instanceConfigs/#{spannerinstance['config']}'" : "projects/#{gcp_project_id}/instanceConfigs/spannerinstance['config']" -%> } + its('name') { should eq <%= doc_generation ? "'#{spannerinstance['name']}'" : "spannerinstance['name']" -%> } + its('display_name') { should eq <%= doc_generation ? "'#{spannerinstance['display_name']}'" : "spannerinstance['display_name']" -%> } + its('node_count') { should eq <%= doc_generation ? "'#{spannerinstance['node_count']}'" : "spannerinstance['node_count']" -%> } + its('labels') { should eq <%= doc_generation ? "'#{spannerinstance['labels']}'" : "spannerinstance['labels']" -%> } +end \ No newline at end of file diff --git a/templates/inspec/examples/google_spanner_instance/google_spanner_instance_attributes.erb b/templates/inspec/examples/google_spanner_instance/google_spanner_instance_attributes.erb new file mode 100644 index 000000000000..ba0396d56f0e --- /dev/null +++ b/templates/inspec/examples/google_spanner_instance/google_spanner_instance_attributes.erb @@ -0,0 +1,2 @@ +gcp_project_id = attribute(:gcp_project_id, default: '<%= external_attribute('gcp_project_id') -%>', description: 'The GCP project identifier.') +spannerinstance = attribute('spannerinstance', default: <%= JSON.pretty_generate(grab_attributes['spannerinstance']) -%>, description: 'Cloud Spanner definition') diff --git a/templates/inspec/examples/google_spanner_instance/google_spanner_instances.erb b/templates/inspec/examples/google_spanner_instance/google_spanner_instances.erb new file mode 100644 index 000000000000..2dbc126ef9aa --- /dev/null +++ b/templates/inspec/examples/google_spanner_instance/google_spanner_instances.erb @@ -0,0 +1,6 @@ +<% gcp_project_id = "#{external_attribute('gcp_project_id', doc_generation)}" -%> +<% spannerinstance = grab_attributes['spannerinstance'] -%> + +describe google_spanner_instances(project: <%= gcp_project_id -%>, config: <%= doc_generation ? "'#{spannerinstance['config']}'" : "spannerinstance['config']" -%>) do + its('config') { should eq <%= doc_generation ? "'#{spannerinstance['config']}'" : "spannerinstance['config']" -%> } +end \ No newline at end of file diff --git a/templates/inspec/tests/integration/build/gcp-mm.tf b/templates/inspec/tests/integration/build/gcp-mm.tf index 73c6e6791755..972ce17f9935 100644 --- a/templates/inspec/tests/integration/build/gcp-mm.tf +++ b/templates/inspec/tests/integration/build/gcp-mm.tf @@ -836,3 +836,14 @@ resource "google_compute_node_group" "inspec-node-group" { size = var.node_group["size"] node_template = "${google_compute_node_template.inspec-template.self_link}" } + +resource "google_spanner_instance" "spanner_instance" { + project = "${var.gcp_project_id}" + config = "${var.spannerinstance["config"]}" + name = "${var.spannerinstance["name"]}" + display_name = "${var.spannerinstance["display_name"]}" + node_count = "${var.spannerinstance["node_count"]}" + labels = { + "${var.spannerinstance["label_key"]}" = "${var.spannerinstance["label_value"]}" + } +} diff --git a/templates/inspec/tests/integration/configuration/mm-attributes.yml b/templates/inspec/tests/integration/configuration/mm-attributes.yml index 92b6cfdcba4d..af755215e560 100644 --- a/templates/inspec/tests/integration/configuration/mm-attributes.yml +++ b/templates/inspec/tests/integration/configuration/mm-attributes.yml @@ -315,4 +315,13 @@ node_template: node_group: name: inspec-node-group description: A description of the node group - size: 0 \ No newline at end of file + size: 0 + +spannerinstance: + config: regional-us-east1 + name: inspec_inst + display_name: inspectest + node_count: 2 + label_key: env + label_value: test + \ No newline at end of file From f96be16490cf4b39faa886f9b1e0a9f7cbd4749e Mon Sep 17 00:00:00 2001 From: "Patel, Prakash P" Date: Wed, 16 Oct 2019 16:35:17 -0400 Subject: [PATCH 11/13] Added spanner database --- products/spanner/inspec.yaml | 8 +++++++- .../google_spanner_database/google_spanner_database.erb | 7 +++++++ .../google_spanner_database_attributes.erb | 2 ++ .../google_spanner_database/google_spanner_databases.erb | 7 +++++++ .../google_spanner_instance/google_spanner_instance.erb | 2 +- .../google_spanner_instance/google_spanner_instances.erb | 2 +- templates/inspec/tests/integration/build/gcp-mm.tf | 7 +++++++ templates/inspec/tests/integration/configuration/ddl.sql | 0 .../tests/integration/configuration/mm-attributes.yml | 5 ++++- 9 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 templates/inspec/examples/google_spanner_database/google_spanner_database.erb create mode 100644 templates/inspec/examples/google_spanner_database/google_spanner_database_attributes.erb create mode 100644 templates/inspec/examples/google_spanner_database/google_spanner_databases.erb create mode 100644 templates/inspec/tests/integration/configuration/ddl.sql diff --git a/products/spanner/inspec.yaml b/products/spanner/inspec.yaml index 1f0ae2ce39a4..f48471c3f9f3 100644 --- a/products/spanner/inspec.yaml +++ b/products/spanner/inspec.yaml @@ -17,6 +17,12 @@ overrides: !ruby/object:Overrides::ResourceOverrides exclude: true Instance: !ruby/object:Overrides::Inspec::ResourceOverride exclude: false + properties: + state: !ruby/object:Overrides::Inspec::PropertyOverride + exclude: true Database: !ruby/object:Overrides::Inspec::ResourceOverride - exclude: true + exclude: false + properties: + state: !ruby/object:Overrides::Inspec::PropertyOverride + exclude: true \ No newline at end of file diff --git a/templates/inspec/examples/google_spanner_database/google_spanner_database.erb b/templates/inspec/examples/google_spanner_database/google_spanner_database.erb new file mode 100644 index 000000000000..ca950a1f760b --- /dev/null +++ b/templates/inspec/examples/google_spanner_database/google_spanner_database.erb @@ -0,0 +1,7 @@ +<% gcp_project_id = "#{external_attribute('gcp_project_id', doc_generation)}" -%> +<% spannerdatabase = grab_attributes['spannerdatabase'] -%> + +describe google_spanner_database(project: <%= gcp_project_id -%>, name: <%= doc_generation ? "'#{spannerdatabase['name']}'" : "spannerdatabase['name']" -%>) do + it { should exist } + its('name') { should eq <%= doc_generation ? "'#{spannerdatabase['name']}'" : "spannerdatabase['name']" -%> } +end \ No newline at end of file diff --git a/templates/inspec/examples/google_spanner_database/google_spanner_database_attributes.erb b/templates/inspec/examples/google_spanner_database/google_spanner_database_attributes.erb new file mode 100644 index 000000000000..93a24ba09df1 --- /dev/null +++ b/templates/inspec/examples/google_spanner_database/google_spanner_database_attributes.erb @@ -0,0 +1,2 @@ +gcp_project_id = attribute(:gcp_project_id, default: '<%= external_attribute('gcp_project_id') -%>', description: 'The GCP project identifier.') +spannerdatabase = attribute('spannerdatabase', default: <%= JSON.pretty_generate(grab_attributes['spannerdatabase']) -%>, description: 'Cloud Spanner definition') diff --git a/templates/inspec/examples/google_spanner_database/google_spanner_databases.erb b/templates/inspec/examples/google_spanner_database/google_spanner_databases.erb new file mode 100644 index 000000000000..45a1f1915bdf --- /dev/null +++ b/templates/inspec/examples/google_spanner_database/google_spanner_databases.erb @@ -0,0 +1,7 @@ +<% gcp_project_id = "#{external_attribute('gcp_project_id', doc_generation)}" -%> +<% spannerdatabase = grab_attributes['spannerdatabase'] -%> + +describe google_spanner_databases(project: <%= gcp_project_id -%>, name: <%= doc_generation ? "'#{spannerdatabase['name']}'" : "spannerdatabase['name']" -%>) do + it { should exist } + its('name') { should eq <%= doc_generation ? "'#{spannerdatabase['name']}'" : "spannerdatabase['name']" -%> } +end \ No newline at end of file diff --git a/templates/inspec/examples/google_spanner_instance/google_spanner_instance.erb b/templates/inspec/examples/google_spanner_instance/google_spanner_instance.erb index 00749c3c92ef..5d215ab8481d 100644 --- a/templates/inspec/examples/google_spanner_instance/google_spanner_instance.erb +++ b/templates/inspec/examples/google_spanner_instance/google_spanner_instance.erb @@ -8,4 +8,4 @@ describe google_spanner_instance(project: <%= gcp_project_id -%>, name: <%= doc_ its('display_name') { should eq <%= doc_generation ? "'#{spannerinstance['display_name']}'" : "spannerinstance['display_name']" -%> } its('node_count') { should eq <%= doc_generation ? "'#{spannerinstance['node_count']}'" : "spannerinstance['node_count']" -%> } its('labels') { should eq <%= doc_generation ? "'#{spannerinstance['labels']}'" : "spannerinstance['labels']" -%> } -end \ No newline at end of file +end diff --git a/templates/inspec/examples/google_spanner_instance/google_spanner_instances.erb b/templates/inspec/examples/google_spanner_instance/google_spanner_instances.erb index 2dbc126ef9aa..79d74768fccd 100644 --- a/templates/inspec/examples/google_spanner_instance/google_spanner_instances.erb +++ b/templates/inspec/examples/google_spanner_instance/google_spanner_instances.erb @@ -3,4 +3,4 @@ describe google_spanner_instances(project: <%= gcp_project_id -%>, config: <%= doc_generation ? "'#{spannerinstance['config']}'" : "spannerinstance['config']" -%>) do its('config') { should eq <%= doc_generation ? "'#{spannerinstance['config']}'" : "spannerinstance['config']" -%> } -end \ No newline at end of file +end diff --git a/templates/inspec/tests/integration/build/gcp-mm.tf b/templates/inspec/tests/integration/build/gcp-mm.tf index 972ce17f9935..6f6917027a38 100644 --- a/templates/inspec/tests/integration/build/gcp-mm.tf +++ b/templates/inspec/tests/integration/build/gcp-mm.tf @@ -847,3 +847,10 @@ resource "google_spanner_instance" "spanner_instance" { "${var.spannerinstance["label_key"]}" = "${var.spannerinstance["label_value"]}" } } + +resource "google_spanner_instance" "database" { + project = "${var.gcp_project_id}" + instance = "${google_spanner_instance.spanner_instance.name}" + name = "${var.spannerdatabase["name"]}" + ddl = "${split("\n", file("ddl.sql"))}" +} diff --git a/templates/inspec/tests/integration/configuration/ddl.sql b/templates/inspec/tests/integration/configuration/ddl.sql new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/templates/inspec/tests/integration/configuration/mm-attributes.yml b/templates/inspec/tests/integration/configuration/mm-attributes.yml index af755215e560..bb82a74988ae 100644 --- a/templates/inspec/tests/integration/configuration/mm-attributes.yml +++ b/templates/inspec/tests/integration/configuration/mm-attributes.yml @@ -319,9 +319,12 @@ node_group: spannerinstance: config: regional-us-east1 - name: inspec_inst + name: spinstance display_name: inspectest node_count: 2 label_key: env label_value: test + +spannerdatabase: + name: spdatabase \ No newline at end of file From 7d116e42b0556857245aef4620ee448affde80de Mon Sep 17 00:00:00 2001 From: "Patel, Prakash P" Date: Wed, 16 Oct 2019 20:17:43 -0400 Subject: [PATCH 12/13] Added spanner database --- .../google_spanner_database/google_spanner_database.erb | 2 +- .../google_spanner_database/google_spanner_databases.erb | 5 ++--- .../inspec/tests/integration/configuration/mm-attributes.yml | 1 + 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/inspec/examples/google_spanner_database/google_spanner_database.erb b/templates/inspec/examples/google_spanner_database/google_spanner_database.erb index ca950a1f760b..4842a2c06a0d 100644 --- a/templates/inspec/examples/google_spanner_database/google_spanner_database.erb +++ b/templates/inspec/examples/google_spanner_database/google_spanner_database.erb @@ -1,7 +1,7 @@ <% gcp_project_id = "#{external_attribute('gcp_project_id', doc_generation)}" -%> <% spannerdatabase = grab_attributes['spannerdatabase'] -%> -describe google_spanner_database(project: <%= gcp_project_id -%>, name: <%= doc_generation ? "'#{spannerdatabase['name']}'" : "spannerdatabase['name']" -%>) do +describe google_spanner_database(project: <%= gcp_project_id -%>, , instance: <%= doc_generation ? "'#{spannerdatabase['instance']}'" : "spannerdatabase['instance']" -%>, name: <%= doc_generation ? "'#{spannerdatabase['name']}'" : "spannerdatabase['name']" -%>) do it { should exist } its('name') { should eq <%= doc_generation ? "'#{spannerdatabase['name']}'" : "spannerdatabase['name']" -%> } end \ No newline at end of file diff --git a/templates/inspec/examples/google_spanner_database/google_spanner_databases.erb b/templates/inspec/examples/google_spanner_database/google_spanner_databases.erb index 45a1f1915bdf..2ed9d2754750 100644 --- a/templates/inspec/examples/google_spanner_database/google_spanner_databases.erb +++ b/templates/inspec/examples/google_spanner_database/google_spanner_databases.erb @@ -1,7 +1,6 @@ <% gcp_project_id = "#{external_attribute('gcp_project_id', doc_generation)}" -%> <% spannerdatabase = grab_attributes['spannerdatabase'] -%> -describe google_spanner_databases(project: <%= gcp_project_id -%>, name: <%= doc_generation ? "'#{spannerdatabase['name']}'" : "spannerdatabase['name']" -%>) do - it { should exist } - its('name') { should eq <%= doc_generation ? "'#{spannerdatabase['name']}'" : "spannerdatabase['name']" -%> } +describe google_spanner_databases(project: <%= gcp_project_id -%>, , instance: <%= doc_generation ? "'#{spannerdatabase['instance']}'" : "spannerdatabase['instance']" -%>) do + its('instance') { should eq <%= doc_generation ? "'#{spannerdatabase['instance']}'" : "spannerdatabase['instance']" -%> } end \ No newline at end of file diff --git a/templates/inspec/tests/integration/configuration/mm-attributes.yml b/templates/inspec/tests/integration/configuration/mm-attributes.yml index bb82a74988ae..283a7a46a409 100644 --- a/templates/inspec/tests/integration/configuration/mm-attributes.yml +++ b/templates/inspec/tests/integration/configuration/mm-attributes.yml @@ -327,4 +327,5 @@ spannerinstance: spannerdatabase: name: spdatabase + instance: spinstance \ No newline at end of file From 7496dda8d2b56c6e38a274c5270e55b96673d1d9 Mon Sep 17 00:00:00 2001 From: "Patel, Prakash P" Date: Wed, 16 Oct 2019 21:48:50 -0400 Subject: [PATCH 13/13] Test --- .../google_spanner_database/google_spanner_database.erb | 4 ---- .../google_spanner_database/google_spanner_databases.erb | 6 ------ 2 files changed, 10 deletions(-) diff --git a/templates/inspec/examples/google_spanner_database/google_spanner_database.erb b/templates/inspec/examples/google_spanner_database/google_spanner_database.erb index b446ca2acc99..4842a2c06a0d 100644 --- a/templates/inspec/examples/google_spanner_database/google_spanner_database.erb +++ b/templates/inspec/examples/google_spanner_database/google_spanner_database.erb @@ -1,11 +1,7 @@ <% gcp_project_id = "#{external_attribute('gcp_project_id', doc_generation)}" -%> <% spannerdatabase = grab_attributes['spannerdatabase'] -%> -<<<<<<< HEAD describe google_spanner_database(project: <%= gcp_project_id -%>, , instance: <%= doc_generation ? "'#{spannerdatabase['instance']}'" : "spannerdatabase['instance']" -%>, name: <%= doc_generation ? "'#{spannerdatabase['name']}'" : "spannerdatabase['name']" -%>) do -======= -describe google_spanner_database(project: <%= gcp_project_id -%>, name: <%= doc_generation ? "'#{spannerdatabase['name']}'" : "spannerdatabase['name']" -%>) do ->>>>>>> 20cb3f5a6c5931930b18a1c8a1124a01db5f44be it { should exist } its('name') { should eq <%= doc_generation ? "'#{spannerdatabase['name']}'" : "spannerdatabase['name']" -%> } end \ No newline at end of file diff --git a/templates/inspec/examples/google_spanner_database/google_spanner_databases.erb b/templates/inspec/examples/google_spanner_database/google_spanner_databases.erb index 9978ff0722aa..2ed9d2754750 100644 --- a/templates/inspec/examples/google_spanner_database/google_spanner_databases.erb +++ b/templates/inspec/examples/google_spanner_database/google_spanner_databases.erb @@ -1,12 +1,6 @@ <% gcp_project_id = "#{external_attribute('gcp_project_id', doc_generation)}" -%> <% spannerdatabase = grab_attributes['spannerdatabase'] -%> -<<<<<<< HEAD describe google_spanner_databases(project: <%= gcp_project_id -%>, , instance: <%= doc_generation ? "'#{spannerdatabase['instance']}'" : "spannerdatabase['instance']" -%>) do its('instance') { should eq <%= doc_generation ? "'#{spannerdatabase['instance']}'" : "spannerdatabase['instance']" -%> } -======= -describe google_spanner_databases(project: <%= gcp_project_id -%>, name: <%= doc_generation ? "'#{spannerdatabase['name']}'" : "spannerdatabase['name']" -%>) do - it { should exist } - its('name') { should eq <%= doc_generation ? "'#{spannerdatabase['name']}'" : "spannerdatabase['name']" -%> } ->>>>>>> 20cb3f5a6c5931930b18a1c8a1124a01db5f44be end \ No newline at end of file