Skip to content

Commit

Permalink
Add support for cloud scheduler job
Browse files Browse the repository at this point in the history
  • Loading branch information
slevenick committed Nov 1, 2019
1 parent bb0c90f commit 2dd3f59
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 0 deletions.
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

0 comments on commit 2dd3f59

Please sign in to comment.