Using this Terraform configuration you can automatically provision following resources:
-
Create a service account which will be used to access Cloud SQL instances via IAM authentication.
-
Assign Cloud SQL Client, and Cloud SQL Instance User roles to the service account.
-
Create Cloud SQL instances for PostgreSQL 15, MySQL 8, and SQL Server 2019.
-
Create IAM users for PostgreSQL and MySQL instances.
-
Install Terraform
brew install terraform
-
Authenticate to Google Cloud
Make sure that your user has sufficient roles to create resource mentioned in the first paragraph.
gcloud auth application-default login
-
Populate Terraform variables with your own values
cp example.tfvars value.tfvars vim value.tfvars
-
Provision infrastructure with Terraform
terraform init terraform apply --var-file value.tfvars
-
Generate
.env
file for a SQL instance that you want to useterraform output -raw mysql_env > ../.env terraform output -raw postgres_env > ../.env terraform output -raw sqlserver_env > ../.env