Skip to content

Commit

Permalink
Add compute global address to InSpec (#1309)
Browse files Browse the repository at this point in the history
Merged PR #1309.
  • Loading branch information
slevenick authored and modular-magician committed Jan 28, 2019
1 parent 107fcae commit d435677
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 4 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
GlobalAddress: !ruby/object:Overrides::Inspec::ResourceOverride
exclude: true
GlobalForwardingRule: !ruby/object:Overrides::Inspec::ResourceOverride
exclude: true
Image: !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_address = attribute('global_address', default: <%= JSON.pretty_generate(grab_attributes['global_address']) -%>, description: 'Compute Global Address definition')
10 changes: 10 additions & 0 deletions templates/inspec/examples/google_compute_global_address.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<% gcp_project_id = "#{external_attribute('gcp_project_id', doc_generation)}" -%>
<% global_address = grab_attributes['global_address'] -%>
describe google_compute_global_address(project: <%= gcp_project_id -%>, name: <%= doc_generation ? "'#{global_address['name']}'" : "global_address['name']" -%>) do
it { should exist }
its('ip_version') { should eq <%= doc_generation ? "'#{global_address['ip_version']}'" : "global_address['ip_version']" -%> }
end

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

variable "global_address" {
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 @@ -223,4 +227,10 @@ resource "google_compute_instance_template" "gcp-inspec-instance-template" {
service_account {
scopes = ["${var.instance_template["service_account_scope"]}"]
}
}

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"]}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,8 @@ instance_template:
disk_auto_delete: true
disk_boot: true
network_interface_network: default
service_account_scope: storage-ro
service_account_scope: storage-ro

global_address:
name: inspec-gcp-global-address
ip_version: IPV6

0 comments on commit d435677

Please sign in to comment.