title | platform |
---|---|
About the google_container_clusters Resource |
gcp |
Use the google_container_clusters
InSpec audit resource to test properties of all, or a filtered group of, GCP container clusters for a project in a particular google_compute_zone
.
A google_container_clusters
resource block collects GCP clusters by project and zone, then tests that group.
describe google_container_clusters(project: 'chef-inspec-gcp', zone: 'europe-west2-a') do
it { should exist }
end
Use this InSpec resource to enumerate IDs then test in-depth using google_container_cluster
.
google_container_clusters(project: 'chef-inspec-gcp', zone: 'europe-west2-a').cluster_names.each do |cluster_name|
describe google_container_cluster(project: 'chef-inspec-gcp', zone: 'europe-west2-a', name: cluster_name) do
it { should exist }
end
end
The following examples show how to use this InSpec audit resource.
Test that there are no more than a specified number of clusters available for the project in a particular zone
describe google_container_clusters(project: 'chef-inspec-gcp', zone: 'europe-west2-a') do
its('count') { should be <= 5}
end
describe google_container_clusters(project: 'chef-inspec-gcp', zone: 'europe-west2-a') do
its('cluster_names') { should include "my-cluster" }
end
describe google_container_clusters(project: 'chef-inspec-gcp', zone: 'europe-west2-a') do
its('cluster_statuses') { should_not include "STOPPING" }
end
google_container_clusters(project: gcp_project_id).where(cluster_name: /^kube/).cluster_names.each do |cluster_name|
describe google_container_cluster(project: 'chef-inspec-gcp', zone: 'europe-west2-a', name: cluster_name) do
it { should exist }
its('status') { should eq 'RUNNING' }
end
end
This resource supports the following filter criteria: cluster_name
, cluster_subnetwork
, and cluster_status
. Any of these may be used with where
, as a block or as a method.
cluster_names
- an array of google_container_cluster name stringscluster_subnetworks
- an array of google_compute_subnetwork name stringscluster_statuses
- an array of google_container_cluster status strings
Ensure the Kubernetes Engine API is enabled for the project where the resource is located.