How do I create a PostgreSQL extension with Pulumi?
In this tutorial, we will create a PostgreSQL extension using Pulumi. We will define a PostgreSQL database and then add an extension to it. This example will use the postgresql
Pulumi provider to manage the PostgreSQL resources.
Key Points
- We will create a PostgreSQL database.
- We will add an extension to the PostgreSQL database.
- We will use the
postgresql
Pulumi provider.
Below is the TypeScript code to accomplish this:
import * as pulumi from "@pulumi/pulumi";
import * as postgresql from "@pulumi/postgresql";
// Define the PostgreSQL provider
const pgProvider = new postgresql.Provider("pg", {
host: "your-postgresql-host",
port: 5432,
username: "your-username",
password: "your-password",
database: "your-database",
});
// Create a PostgreSQL database
const database = new postgresql.Database("mydatabase", {
name: "mydatabase",
owner: "your-username",
}, { provider: pgProvider });
// Create a PostgreSQL extension
const extension = new postgresql.Extension("myextension", {
name: "pgcrypto",
database: database.name,
}, { provider: pgProvider });
// Export the database name and extension name
export const dbName = database.name;
export const extensionName = extension.name;
Summary
In this tutorial, we created a PostgreSQL database and added an extension to it using Pulumi. We used the postgresql
Pulumi provider to manage the PostgreSQL resources. This setup allows you to manage your PostgreSQL infrastructure as code, making it easy to automate and replicate.
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.