1. Answers
  2. Building a GCP SQL Database

How do I build a GCP SQL Database?

Overview

This guide will walk you through creating a SQL database instance in Google Cloud Platform (GCP). The setup involves:

  1. Setting up a GCP provider.
  2. Creating a GCP SQL instance.
  3. Configuring the instance with appropriate settings like version, region, tier, and more.
  4. Exporting the IP address of the instance.

We will break down each step and explain the key components required to achieve this.

Steps:

  1. Setup the GCP provider: This ensures that we are interacting with resources on the GCP.
  2. Create a SQL instance: Configure and deploy your SQL instance, including the database version and tier.
  3. Export Instance IP Address: Obtain the IP address of the SQL instance for use in other resources or connections.
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

const example = new gcp.sql.DatabaseInstance("example", {
    name: "example-instance",
    databaseVersion: "POSTGRES_13",
    region: "us-central1",
    settings: {
        tier: "db-f1-micro",
        ipConfiguration: {
            ipv4Enabled: true,
            requireSsl: false,
        },
        backupConfiguration: {
            enabled: true,
        },
        databaseFlags: [{
            name: "max_connections",
            value: "250",
        }],
    },
});
const exampleDb = new gcp.sql.Database("example_db", {
    name: "example-db",
    instance: example.name,
    charset: "UTF8",
});
export const instanceIpAddress = example.ipAddresses;

Key Points:

  • Provider Configuration: Ensures the use of your GCP project and credentials.
  • SQL Instance: Specifies the instance settings such as name, region, tier, etc.
  • Database: Creates a database within the SQL instance.
  • Output: Exports the IP address of the instance for later use.

Conclusion

This guide provided step-by-step instructions to set up a SQL database instance in GCP. You learned how to configure the provider, create a database instance, and retrieve the instance’s IP address.

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