title | platform |
---|---|
About the google_compute_networks Resource |
gcp |
Use the google_compute_networks
InSpec audit resource to test properties of all, or a filtered group of, GCP compute networks for a project.
A google_compute_networks
resource block collects GCP networks by project then tests that group.
describe google_compute_networks(project: 'chef-inspec-gcp') do
it { should exist }
end
Use this InSpec resource to enumerate IDs then test in-depth using google_compute_network
.
google_compute_networks(project: 'chef-inspec-gcp').network_names.each do |network_name|
describe google_compute_network(project: 'chef-inspec-gcp', name: network_name) do
its ('subnetworks.count') { should be < 10 }
its ('creation_timestamp_date') { should be > Time.now - 365*60*60*24*10 }
its ('routing_config.routing_mode') { should eq "REGIONAL" }
its ('auto_create_subnetworks'){ should be false }
end
end
The following examples show how to use this InSpec audit resource.
describe google_compute_networks(project: 'chef-inspec-gcp') do
its('count') { should be <= 100}
end
describe google_compute_networks(project: 'chef-inspec-gcp') do
its('network_ids') { should include 12345678975432 }
end
describe google_compute_networks(project: 'chef-inspec-gcp') do
its('network_names') { should include "network-name" }
end
This resource supports the following filter criteria: network_id
and network_name
. Any of these may be used with where
, as a block or as a method.
network_ids
- an array of google_compute_network identifier integersnetwork_names
- an array of google_compute_network name strings
Ensure the Compute Engine API is enabled for the project where the resource is located.