title | platform |
---|---|
About the google_compute_subnetworks Resource |
gcp |
Use the google_compute_subnetworks
InSpec audit resource to test properties of all, or a filtered group of, GCP compute subnetworks for a project and region.
A google_compute_subnetworks
resource block collects GCP subnetworks by project and region, then tests that group.
describe google_compute_subnetworks(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_subnetwork
.
google_compute_subnetworks(project: 'chef-inspec-gcp', region:'europe-west2').subnetwork_names.each do |subnetwork_name|
describe google_compute_subnetwork(project: 'chef-inspec-gcp', region: 'europe-west2', name: name: subnetwork_name) do
its('creation_timestamp_date') { should be > Time.now - 365*60*60*24*10 }
its('ip_cidr_range') { should eq "10.2.0.0/29" }
its('network') { should match "gcp_network_name" }
its('private_ip_google_access') { should be false }
end
end
The following examples show how to use this InSpec audit resource.
Test that there are no more than a specified number of subnetworks available for the project and region
describe google_compute_subnetworks(project: 'chef-inspec-gcp', region: 'europe-west2') do
its('count') { should be <= 100}
end
describe google_compute_subnetworks(project: 'chef-inspec-gcp', region: 'europe-west2') do
its('subnetwork_ids') { should include 12345678975432 }
end
describe google_compute_subnetworks(project: 'chef-inspec-gcp', region: 'europe-west2') do
its('subnetwork_names') { should include "subnetwork-name" }
end
describe google_compute_subnetworks(project: 'chef-inspec-gcp', region: 'europe-west2') do
its('subnetwork_networks') { should not include "network-name" }
end
This resource supports the following filter criteria: subnetwork_id
; subnetwork_name
; enable_flow_logs
and subnetwork_network
. Any of these may be used with where
, as a block or as a method.
subnetwork_ids
- an array of google_compute_subnetwork identifier integerssubnetwork_names
- an array of google_compute_subnetwork name stringssubnetwork_networks
- an array of google_compute_network name stringsenable_flow_logs
- an array of enable_flow_log booleans
Ensure the Compute Engine API is enabled for the project where the resource is located.