From f87a2a2b6d51ae282f109f567e075cdee5b91f25 Mon Sep 17 00:00:00 2001 From: "Patel, Prakash P" Date: Wed, 16 Oct 2019 15:02:12 -0400 Subject: [PATCH] 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