Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add InSpec support for cloud scheduler job #2577

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions products/cloudscheduler/inspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2019 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<% gcp_project_id = "#{external_attribute('gcp_project_id', doc_generation)}" -%>
<% scheduler_job = grab_attributes['scheduler_job'] -%>
describe google_cloud_scheduler_job(project: <%= doc_generation ? "#{gcp_project_id}" : "gcp_project_id" -%>, region: <%= doc_generation ? "#{scheduler_job['region']}" : "scheduler_job['region']" -%>, name: <%= doc_generation ? "'#{scheduler_job['name']}'" : "scheduler_job['name']" -%>) do
it { should exist }

its('description') { should cmp <%= doc_generation ? "'#{scheduler_job['description']}'" : "scheduler_job['description']" -%> }
its('schedule') { should cmp <%= doc_generation ? "'#{scheduler_job['schedule']}'" : "scheduler_job['schedule']" -%> }
its('time_zone') { should cmp <%= doc_generation ? "'#{scheduler_job['time_zone']}'" : "scheduler_job['time_zone']" -%> }
its('http_target.http_method') { should cmp <%= doc_generation ? "'#{scheduler_job['http_method']}'" : "scheduler_job['http_method']" -%> }
its('http_target.uri') { should cmp <%= doc_generation ? "'#{scheduler_job['http_target_uri']}'" : "scheduler_job['http_target_uri']" -%> }
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gcp_project_id = attribute(:gcp_project_id, default: '<%= external_attribute('gcp_project_id') -%>', description: 'The GCP project identifier.')
scheduler_job = attribute('scheduler_job', default: <%= JSON.pretty_generate(grab_attributes['scheduler_job']) -%>, description: 'Cloud Scheduler Job configuration')
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<% gcp_project_id = "#{external_attribute('gcp_project_id', doc_generation)}" -%>
<% scheduler_job = grab_attributes['scheduler_job'] -%>
google_cloud_scheduler_jobs(project: <%= doc_generation ? "#{gcp_project_id}" : "gcp_project_id" -%>, region: <%= doc_generation ? "#{scheduler_job['location']}" : "scheduler_job['location']" -%>).names.each do |name|
describe google_cloud_scheduler_job(project: <%= doc_generation ? "#{gcp_project_id}" : "gcp_project_id" -%>, region: <%= doc_generation ? "#{scheduler_job['region']}" : "scheduler_job['region']" -%>, name: name) do
it { should exist }

its('description') { should cmp <%= doc_generation ? "'#{scheduler_job['description']}'" : "scheduler_job['description']" -%> }
its('schedule') { should cmp <%= doc_generation ? "'#{scheduler_job['schedule']}'" : "scheduler_job['schedule']" -%> }
its('time_zone') { should cmp <%= doc_generation ? "'#{scheduler_job['time_zone']}'" : "scheduler_job['time_zone']" -%> }
its('http_target.http_method') { should cmp <%= doc_generation ? "'#{scheduler_job['http_method']}'" : "scheduler_job['http_method']" -%> }
its('http_target.uri') { should cmp <%= doc_generation ? "'#{scheduler_job['http_target_uri']}'" : "scheduler_job['http_target_uri']" -%> }
end
end
18 changes: 18 additions & 0 deletions templates/inspec/tests/integration/build/gcp-mm.tf
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ variable "spannerdatabase" {
type = "map"
}

variable "scheduler_job" {
type = "map"
}


resource "google_compute_ssl_policy" "custom-ssl-policy" {
name = "${var.ssl_policy["name"]}"
Expand Down Expand Up @@ -893,3 +897,17 @@ resource "google_spanner_database" "database" {
name = "${var.spannerdatabase["name"]}"
ddl = ["${var.spannerdatabase["ddl"]}"]
}

resource "google_cloud_scheduler_job" "job" {
project = var.gcp_project_id
region = var.scheduler_job["region"]
name = var.scheduler_job["name"]
description = var.scheduler_job["description"]
schedule = var.scheduler_job["schedule"]
time_zone = var.scheduler_job["time_zone"]

http_target {
http_method = var.scheduler_job["http_method"]
uri = var.scheduler_job["http_target_uri"]
}
}
10 changes: 10 additions & 0 deletions templates/inspec/tests/integration/configuration/mm-attributes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,13 @@ spannerdatabase:
name: spdatabase
instance: spinstance
ddl: "CREATE TABLE test (test STRING(MAX),) PRIMARY KEY (test)"

scheduler_job:
# region must match where the appengine instance is deployed
region: us-central1
name: job-name
description: A description
schedule: "*/8 * * * *"
time_zone: America/New_York
http_method: POST
http_target_uri: https://example.com/ping