title | platform |
---|---|
About the google_compute_forwarding_rules Resource |
gcp |
Use the google_compute_forwarding_rules
InSpec audit resource to test properties of all, or a filtered group of, GCP compute forwarding_rules for a project and region.
A google_compute_forwarding_rules
resource block collects GCP forwarding_rules by project and region, then tests that group.
describe google_compute_forwarding_rules(project: 'chef-inspec-gcp', region: 'europe-west2') do
it { should exist }
end
Use this InSpec resource to enumerate IDs then test in-depth using google_compute_forwarding_rule
.
google_compute_forwarding_rules(project: 'chef-inspec-gcp', region:'europe-west2').forwarding_rule_names.each do |forwarding_rule_name|
describe google_compute_forwarding_rule(project: 'chef-inspec-gcp', region: 'europe-west2', name: forwarding_rule_name) do
its('creation_timestamp_date') { should be > Time.now - 365*60*60*24*10 }
its('network') { should match "gcp_network_name" }
its('load_balancing_scheme') { should match "INTERNAL" }
end
end
The following examples show how to use this InSpec audit resource.
Test that there are no more than a specified number of forwarding_rules available for the project and region
describe google_compute_forwarding_rules(project: 'chef-inspec-gcp', region: 'europe-west2') do
its('count') { should be <= 100}
end
describe google_compute_forwarding_rules(project: 'chef-inspec-gcp', region: 'europe-west2') do
its('forwarding_rule_ids') { should include 12345678975432 }
end
describe google_compute_forwarding_rules(project: 'chef-inspec-gcp', region: 'europe-west2') do
its('forwarding_rule_names') { should include "forwarding_rule-name" }
end
describe google_compute_forwarding_rules(project: 'chef-inspec-gcp', region: 'europe-west2') do
its('forwarding_rule_networks') { should not include "network-name" }
end
This resource supports the following filter criteria: forwarding_rule_id
; forwarding_rule_name
; forwarding_rule_load_balancing_scheme
and forwarding_rule_network
. Any of these may be used with where
, as a block or as a method.
forwarding_rule_ids
- an array of google_compute_forwarding_rule identifier integersforwarding_rule_names
- an array of google_compute_forwarding_rule name stringsforwarding_rule_networks
- an array of google_compute_network name stringsforwarding_rule_load_balancing_schemes
- an array of load_balancing_scheme strings
Ensure the Compute Engine API is enabled for the project where the resource is located.