1. Answers
  2. Configure a GCP SQL Database Instance using Pulumi

How do I configure a GCP SQL database instance using Pulumi?

In this guide, we will configure a Google Cloud SQL database instance using Pulumi in TypeScript. We will create a SQL database instance with the necessary settings and configurations.

import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

// Define the settings for the SQL database instance
const dbInstance = new gcp.sql.DatabaseInstance("dbInstance", {
    name: "my-db-instance",
    region: "us-central1",
    databaseVersion: "MYSQL_8_0",
    settings: {
        tier: "db-f1-micro",
        backupConfiguration: {
            enabled: true,
            startTime: "01:00",
        },
        ipConfiguration: {
            ipv4Enabled: true,
            authorizedNetworks: [{
                name: "office-network",
                value: "203.0.113.0/24",
            }],
        },
        availabilityType: "ZONAL",
        maintenanceWindow: {
            day: 7, // Sunday
            hour: 3, // 3 AM
        },
    },
});

// Export the connection name of the database instance
export const connectionName = dbInstance.connectionName;

Key Points

  • We used the gcp.sql.DatabaseInstance resource to create a Google Cloud SQL database instance.
  • The settings block includes configurations like the machine type (tier), backup configuration, IP configuration, and maintenance window.
  • The ipConfiguration allows for enabling IPv4 and specifying authorized networks.
  • The backupConfiguration ensures that backups are enabled and scheduled to start at 1 AM.
  • The connectionName of the database instance is exported for use in other parts of your infrastructure.

Summary

We configured a Google Cloud SQL database instance using Pulumi in TypeScript. The configuration included setting the database version, machine type, backup settings, IP configuration, and maintenance window. This setup helps ensure your database instance is properly configured and ready for use.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up