title | platform |
---|---|
About the google_sql_database_instances Resource |
gcp |
Use the google_sql_database_instances
InSpec audit resource to test properties of GCP Cloud SQL Database instances.
A google_sql_database_instances
resource block collects GCP zones by project then tests that group.
describe google_sql_database_instances(project: 'chef-inspec-gcp') do
it { should exist }
end
Use this InSpec resource to enumerate IDs then test in-depth using google_sql_database_instance
.
google_sql_database_instances(project: 'chef-inspec-gcp').instance_names.each do |instance_name|
describe google_sql_database_instance(project: 'chef-inspec-gcp', database: instance_name) do
it { should exist }
its('backend_type') { should eq "SECOND_GEN" }
end
end
The following examples show how to use this InSpec audit resource.
describe google_sql_database_instances(project: 'chef-inspec-gcp') do
its('count') { should be <= 100}
end
describe google_sql_database_instances(project: 'chef-inspec-gcp') do
its('instance_zones') { should include "us-east1-b" }
end
describe google_sql_database_instances(project: 'chef-inspec-gcp') do
its('instance_regions') { should include "us-east1" }
end
describe google_sql_database_instances(project: 'chef-inspec-gcp') do
its('instance_states') { should include "RUNNABLE" }
end
google_sql_database_instances(project: 'chef-inspec-gcp').where(instance_name: /mysqldb/).instance_names.each do |instance_name|
describe google_sql_database_instance(project: 'chef-inspec-gcp', database: instance_name) do
it { should exist }
its('database_version') { should eq "MYSQL_5_7" }
end
end
This resource supports the following filter criteria: instance_name
; instance_version
; instance_region
; instance_zone
and instance_state
. Any of these may be used with where
, as a block or as a method.
instance_names
- an array of google_sql_database_instance name stringsinstance_versions
- an array of google_sql_database_instance version stringsinstance_regions
- an array of google_compute_region name stringsinstance_zones
- an array of google_sql_database_instance name stringsinstance_states
- an array of google_sql_database_instance state strings
Ensure the Cloud SQL API is enabled for the project.