Provisioning the database
Note
The code for this section is in the chap06/database
directory in the GitHub repository of this book.
In the previous chapter, we provisioned a Cloud SQL instance to demonstrate the use of a remote state. We will now provision a complete database along with a user and password. Following good security practices, we use Google Cloud Secret Manager to securely store the passwords to retrieve them in the application layer.
Note
While Google Cloud Secret Manager stores the secret in an encrypted fashion, the secret remains in plaintext in the Terraform state file, so take extra care to protect the state file from unwarranted access.
So, first, we generate the root and user password using the random_password
Terraform resource. Next, we store the generated passwords in the secret manager. We need to use two resources each – google_secret_manager_secret
to provision the secret and google_secret_manager_secret_version
to store the actual...