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

Inspec url map #1310

Merged
merged 2 commits into from
Jan 28, 2019
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
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
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