Skip to content

Commit

Permalink
Add global forwarding rule generation to InSpec (#1319)
Browse files Browse the repository at this point in the history
Merged PR #1319.
  • Loading branch information
slevenick authored and modular-magician committed Jan 29, 2019
1 parent 58c1a72 commit 6e74928
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 3 deletions.
2 changes: 0 additions & 2 deletions products/compute/inspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides
end
ForwardingRule: !ruby/object:Overrides::Inspec::ResourceOverride
exclude: true
GlobalForwardingRule: !ruby/object:Overrides::Inspec::ResourceOverride
exclude: true
Image: !ruby/object:Overrides::Inspec::ResourceOverride
exclude: true
Instance: !ruby/object:Overrides::Inspec::ResourceOverride
Expand Down
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.')
global_forwarding_rule = attribute('global_forwarding_rule', default: <%= JSON.pretty_generate(grab_attributes['global_forwarding_rule']) -%>, description: 'Compute global forwarding rule definition')
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<% gcp_project_id = "#{external_attribute('gcp_project_id', doc_generation)}" -%>
<% global_forwarding_rule = grab_attributes['global_forwarding_rule'] -%>
describe google_compute_global_forwarding_rule(project: <%= doc_generation ? "#{gcp_project_id}" : "gcp_project_id" -%>, name: <%= doc_generation ? "'#{global_forwarding_rule['name']}'" : "global_forwarding_rule['name']" -%>) do
it { should exist }
its('port_range') { should eq <%= doc_generation ? "'#{global_forwarding_rule['port_range']}'" : "global_forwarding_rule['port_range']" -%> }
its('target') { should match /\/<%= "#{grab_attributes['http_proxy']['name']}" -%>$/ }
end

describe google_compute_global_forwarding_rule(project: <%= doc_generation ? "#{gcp_project_id}" : "gcp_project_id" -%>, name: 'nonexistent') do
it { should_not exist }
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<% gcp_project_id = "#{external_attribute('gcp_project_id', doc_generation)}" -%>
<% global_forwarding_rule = grab_attributes['global_forwarding_rule'] -%>
describe google_compute_global_forwarding_rules(project: <%= doc_generation ? "#{gcp_project_id}" : "gcp_project_id" -%>) do
its('count') { should be >= 1 }
its('port_ranges') { should include <%= doc_generation ? "'#{global_forwarding_rule['port_range']}'" : "global_forwarding_rule['port_range']" -%> }
end
11 changes: 11 additions & 0 deletions templates/inspec/tests/integration/build/gcp-mm.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ variable "http_proxy" {
type = "map"
}

variable "global_forwarding_rule" {
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 @@ -277,4 +281,11 @@ resource "google_compute_target_http_proxy" "gcp-inspec-http-proxy" {
name = "${var.http_proxy["name"]}"
url_map = "${google_compute_url_map.gcp-inspec-url-map.self_link}"
description = "${var.http_proxy["description"]}"
}

resource "google_compute_global_forwarding_rule" "gcp-inspec-global-forwarding-rule" {
project = "${var.gcp_project_id}"
name = "${var.global_forwarding_rule["name"]}"
target = "${google_compute_target_http_proxy.gcp-inspec-http-proxy.self_link}"
port_range = "${var.global_forwarding_rule["port_range"]}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,7 @@ url_map:
http_proxy:
name: inspec-gcp-http-proxy
description: A HTTP proxy

global_forwarding_rule:
name: inspec-gcp-global-forwarding-rule
port_range: 80-80

0 comments on commit 6e74928

Please sign in to comment.