Cloud Config supports many Google Cloud services. The complete list of supported services can be found at https://cloud.google.com/config-connector/docs/reference/overview.
We will create a Cloud Storage bucket using Config Connector as a sample resource.
Config Connector describes each resource well and provides some sample YAML code:
Figure 7.31 – Config Connector sample YAML code
The code to create a Cloud Storage bucket looks like this:
apiVersion: storage.cnrm.cloud.google.com/v1beta1
kind: StorageBucket
metadata:
annotations:
cnrm.cloud.google.com/force-destroy: “false”
labels:
label-one: “value-one”
name: wmarusiak-cc-bucket
spec:
lifecycleRule:
– action:
type: Delete
condition:
age: 7
versioning:
enabled: true
uniformBucketLevelAccess: true
To create a resource, we need to save the code as a YAML file and apply it using the following command:
kubectl apply -f YOUR_FILENAME.YAML
After a moment, resource creation will be completed:
Figure 7.32 – Cloud Storage bucket created by Config Connector
We can edit the previous YAML file to change the Cloud Storage bucket configuration. Let’s add additional labels and an additional life cycle rule:
apiVersion: storage.cnrm.cloud.google.com/v1beta1
kind: StorageBucket
metadata:
annotations:
cnrm.cloud.google.com/force-destroy: “false”
labels:
label-one: “value-one”
label-two: “value-two”
name: wmarusiak-cc-bucket
spec:
lifecycleRule:
– action:
storageClass: NEARLINE
type: SetStorageClass
condition:
age: 7
– action:
type: Delete
condition:
age: 365
versioning:
enabled: true
uniformBucketLevelAccess: true
We must apply the file using the same command that we used previously:
Figure 7.33 – An additional life cycle rule has been added to the bucket
We can also see that an additional label was added to the bucket configuration:
Figure 7.34 – An additional label has been added to the bucket
After changing the resource, we can remove it. We can do this using kubectl delete –namespace CC_NAMESPACE -f your_resource.YAML. In our case, the command will be kubectl delete –namespace config-connector -f config-connector-cloud-storage.yaml.
To confirm that the Cloud Storage bucket was deleted, we can check the logs in Logs Explorer:
Figure 7.35 – Confirming that the Cloud Storage bucket has been deleted in Logs Explorer
Config Connector allows us to easily create and manage Google Cloud resources in a Kubernetes way. The following section focuses on managing Google Cloud resources using Terraform.
In Chapter 2 we briefly touched upon Terraform as part of the possible ways to manage Google Cloud resources. This book and its content focus on the Google Cloud Associate Cloud Engineer certification. We will briefly touch upon Terraform as one of the ways to deploy IaC. Many blog articles and books describe Terraform and other Hashicorp products in much greater detail; we recommend checking them out if you wish to use Terraform as your IaC deployment tool.
Fortunately for us, Cloud Shell includes Terraform as one of the base tools. Terraform is a tool that can be installed on many platforms, such as macOS, Windows, Linux, and many others. To install Terraform on your operating system, go to https://developer.hashicorp.com/terraform/downloads, which contains guides on various operating systems.