How do I build a GCP SQL database instance with Pulumi?
In this guide, we will demonstrate how to create a SQL database instance on Google Cloud using Pulumi. We will define a SQL instance and a database within that instance. This setup is useful for applications that require a managed relational database service.
Key Points:
- We will create a SQL instance using Google Cloud SQL.
- We will then create a database within this SQL instance.
- The Pulumi program will be written in TypeScript.
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
// Define a Google Cloud SQL instance
const sqlInstance = new gcp.sql.DatabaseInstance("sqlInstance", {
name: "my-sql-instance",
databaseVersion: "MYSQL_8_0",
region: "us-central1",
settings: {
tier: "db-f1-micro",
backupConfiguration: {
enabled: true,
},
ipConfiguration: {
ipv4Enabled: true,
},
},
});
// Define a database within the SQL instance
const sqlDatabase = new gcp.sql.Database("sqlDatabase", {
name: "mydatabase",
instance: sqlInstance.name,
charset: "utf8",
collation: "utf8_general_ci",
});
// Export the instance connection name
export const instanceConnectionName = sqlInstance.connectionName;
Summary:
In this guide, we created a Google Cloud SQL instance and a database within that instance using Pulumi. This setup can be used to provide a managed SQL database for your applications.
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.