Skip to content

Commit

Permalink
Merge 78b1d10 into d435677
Browse files Browse the repository at this point in the history
  • Loading branch information
slevenick authored Jan 28, 2019
2 parents d435677 + 78b1d10 commit edbd273
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 2 deletions.
2 changes: 0 additions & 2 deletions products/compute/inspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides
exclude: true
TargetSslProxy: !ruby/object:Overrides::Inspec::ResourceOverride
exclude: true
UrlMap: !ruby/object:Overrides::Inspec::ResourceOverride
exclude: true
VpnTunnel: !ruby/object:Overrides::Inspec::ResourceOverride
exclude: true
Zone: !ruby/object:Overrides::Inspec::ResourceOverride
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
gcp_project_id = attribute(:gcp_project_id, default: '<%= external_attribute('gcp_project_id') -%>', description: 'The GCP project identifier.')
url_map = attribute('url_map', default: <%= JSON.pretty_generate(grab_attributes['url_map']) -%>, description: 'Compute URL map definition')
backend_service = attribute('backend_service', default: <%= JSON.pretty_generate(grab_attributes['backend_service']) -%>, description: 'Backend service definition')
19 changes: 19 additions & 0 deletions templates/inspec/examples/google_compute_url_map.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<% gcp_project_id = "#{external_attribute('gcp_project_id', doc_generation)}" -%>
<% url_map = grab_attributes['url_map'] -%>
<% backend_service = grab_attributes['backend_service'] -%>
describe google_compute_url_map(project: <%= gcp_project_id -%>, name: <%= doc_generation ? "'#{url_map['name']}'" : "url_map['name']" -%>) do
it { should exist }
its('description') { should eq <%= doc_generation ? "'#{url_map['description']}'" : "url_map['description']" -%> }
its('default_service') { should match /\/<%= "#{grab_attributes['backend_service']['name']}" -%>$/ }
its('host_rules.count') { should eq 1 }
its('host_rules.first.hosts') { should include <%= doc_generation ? "'#{url_map['host_rule_host']}'" : "url_map['host_rule_host']" -%> }
its('path_matchers.count') { should eq 1 }
its('path_matchers.first.default_service') { should match /\/<%= "#{grab_attributes['backend_service']['name']}" -%>$/ }
its('tests.count') { should eq 1 }
its('tests.first.host') { should eq <%= doc_generation ? "'#{url_map['test_host']}'" : "url_map['test_host']" -%> }
its('tests.first.path') { should eq <%= doc_generation ? "'#{url_map['test_path']}'" : "url_map['test_path']" -%> }
end

describe google_compute_url_map(project: <%= doc_generation ? "#{gcp_project_id}" : "gcp_project_id" -%>, name: 'nonexistent') do
it { should_not exist }
end
6 changes: 6 additions & 0 deletions templates/inspec/examples/google_compute_url_maps.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<% gcp_project_id = "#{external_attribute('gcp_project_id', doc_generation)}" -%>
<% url_map = grab_attributes['url_map'] -%>
<% backend_service = grab_attributes['backend_service'] -%>
describe google_compute_url_maps(project: <%= gcp_project_id -%>) do
its('names') { should include <%= doc_generation ? "'#{url_map['name']}'" : "url_map['name']" -%> }
end
33 changes: 33 additions & 0 deletions templates/inspec/tests/integration/build/gcp-mm.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ variable "global_address" {
type = "map"
}

variable "url_map" {
type = "map"
}

resource "google_compute_ssl_policy" "custom-ssl-policy" {
name = "${var.ssl_policy["name"]}"
min_tls_version = "${var.ssl_policy["min_tls_version"]}"
Expand Down Expand Up @@ -233,4 +237,33 @@ resource "google_compute_global_address" "gcp-inspec-global-address" {
project = "${var.gcp_project_id}"
name = "${var.global_address["name"]}"
ip_version = "${var.global_address["ip_version"]}"
}

resource "google_compute_url_map" "gcp-inspec-url-map" {
project = "${var.gcp_project_id}"
name = "${var.url_map["name"]}"
description = "${var.url_map["description"]}"

default_service = "${google_compute_backend_service.gcp-inspec-backend-service.self_link}"

host_rule {
hosts = ["${var.url_map["host_rule_host"]}"]
path_matcher = "${var.url_map["path_matcher_name"]}"
}

path_matcher {
name = "${var.url_map["path_matcher_name"]}"
default_service = "${google_compute_backend_service.gcp-inspec-backend-service.self_link}"

path_rule {
paths = ["${var.url_map["path_rule_path"]}"]
service = "${google_compute_backend_service.gcp-inspec-backend-service.self_link}"
}
}

test {
service = "${google_compute_backend_service.gcp-inspec-backend-service.self_link}"
host = "${var.url_map["test_host"]}"
path = "${var.url_map["test_path"]}"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,12 @@ instance_template:
global_address:
name: inspec-gcp-global-address
ip_version: IPV6

url_map:
name: inspec-gcp-url-map
description: URL map description
host_rule_host: site.com
path_matcher_name: allpaths
path_rule_path: /home
test_host: test.com
test_path: /home

0 comments on commit edbd273

Please sign in to comment.