A Pulumi package for creating and managing pgedge cloud resources.
Project description
pgEdge Pulumi Provider
The official Pulumi provider for pgEdge Cloud, designed to simplify the management of pgEdge Cloud resources using infrastructure as code.
- Documentation: pgEdge Pulumi Docs
- Website: pgEdge
- Discuss: GitHub Issues
Prerequisites
Before you begin, ensure you have the following tools installed:
- Pulumi CLI
- Go (version 1.18 or later)
- pulumictl
- golangci-lint
- Node.js (Active LTS or maintenance version, we recommend using nvm to manage Node.js installations)
- Yarn
- TypeScript
Installation
To use this provider, you need to have Pulumi installed. If you haven't already, you can install Pulumi here.
Go
go get github.com/pgEdge/pulumi-pgedge/sdk/go/pgedge
Node.js
npm install @pgEdge/pulumi-pgedge
Configuration
Before using the provider, you need to configure your pgEdge credentials. Set the following environment variables:
export PGEDGE_CLIENT_ID="your-client-id"
export PGEDGE_CLIENT_SECRET="your-client-secret"
These credentials authenticate the Pulumi provider with your pgEdge Cloud account.
Getting Started
Creating a New Pulumi Project
- Create a new directory for your project:
mkdir pgedge-pulumi-project && cd pgedge-pulumi-project
- Initialize a new Pulumi project:
pulumi new typescript
Follow the prompts to set up your project.
- Install the pgEdge provider:
npm install @pgedge/pulumi-pgedge
- Update your
Pulumi.yamlfile to include the pgEdge provider:
name: pgedge-pulumi-project
runtime: nodejs
description: A new Pulumi project using pgEdge
plugins:
providers:
- name: pgedge
path: ./node_modules/@pgEdge/pulumi-pgedge
Writing Your Pulumi Program
Replace the contents of index.ts with the following:
import * as pulumi from "@pulumi/pulumi";
import * as pgedge from "@pgEdge/pulumi-pgedge";
// Create an SSH Key
const sshKey = new pgedge.SSHKey("exampleSSHKey", {
name: "example",
publicKey: "ssh-ed25519 AAAAC3NzaC1lZsdw877237ICXfT63i04t5fvvlGesddwed21VG7DkyxvyXbYQNhKP/rSeLY user@example.com",
});
// Create a Cloud Account
const cloudAccount = new pgedge.CloudAccount("exampleCloudAccount", {
name: "my-aws-account",
type: "aws",
description: "My AWS Cloud Account",
credentials: {
role_arn: "arn:aws:iam::21112529deae39:role/pgedge-135232c",
},
}, {
dependsOn: [sshKey]
});
// Create a Backup Store
const backupStore = new pgedge.BackupStore("exampleBackupStore", {
name: "example",
cloudAccountId: cloudAccount.id,
region: "us-west-2",
}, {
dependsOn: [cloudAccount]
});
// Create a Cluster
const cluster = new pgedge.Cluster("exampleCluster", {
name: "example",
cloudAccountId: cloudAccount.id,
regions: ["us-west-2", "us-east-1", "eu-central-1"],
nodeLocation: "public",
sshKeyId: sshKey.id,
backupStoreIds: [backupStore.id],
nodes: [
{
name: "n1",
region: "us-west-2",
instanceType: "r6g.medium",
volumeSize: 100,
volumeType: "gp2",
},
{
name: "n2",
region: "us-east-1",
instanceType: "r6g.medium",
volumeSize: 100,
volumeType: "gp2",
},
{
name: "n3",
region: "eu-central-1",
instanceType: "r6g.medium",
volumeSize: 100,
volumeType: "gp2",
},
],
networks: [
{
region: "us-west-2",
cidr: "10.1.0.0/16",
publicSubnets: ["10.1.0.0/24"],
// privateSubnets: ["10.1.0.0/24"],
},
{
region: "us-east-1",
cidr: "10.2.0.0/16",
publicSubnets: ["10.2.0.0/24"],
// privateSubnets: ["10.2.0.0/24"],
},
{
region: "eu-central-1",
cidr: "10.3.0.0/16",
publicSubnets: ["10.3.0.0/24"],
// privateSubnets: ["10.3.0.0/24"],
},
],
firewallRules: [
{
name: "postgres",
port: 5432,
sources: ["123.456.789.0/32"],
},
],
}, {
dependsOn: [sshKey, cloudAccount, backupStore]
});
// Create a Database
const database = new pgedge.Database("exampleDatabase", {
name: "example",
clusterId: cluster.id,
options: [
"autoddl:enabled",
"install:northwind",
"rest:enabled",
],
extensions: {
autoManage: true,
requesteds: [
"postgis",
],
},
nodes: {
n1: {
name: "n1",
},
n2: {
name: "n2",
},
n3: {
name: "n3",
},
},
backups: {
provider: "pgbackrest",
configs: [
{
id: "default",
schedules: [
{
id: "daily-full-backup",
cronExpression: "0 1 * * *",
type: "full",
},
{
id: "hourly-incr-backup",
cronExpression: "0 * * * ?",
type: "incr",
},
]
},
]
},
}, {
dependsOn: [cluster]
});
// Export resource IDs
export const sshKeyId = sshKey.id;
export const cloudAccountId = cloudAccount.id;
export const backupStoreId = backupStore.id;
export const clusterId = cluster.id;
export const clusterStatus = cluster.status;
export const clusterCreatedAt = cluster.createdAt;
export const databaseId = database.id;
export const databaseStatus = database.status;
// Optional: Log outputs
pulumi.all([
sshKeyId,
cloudAccountId,
backupStoreId,
clusterId,
clusterStatus,
clusterCreatedAt,
databaseId,
databaseStatus
]).apply(([
sshId,
accountId,
backupId,
cId,
cStatus,
cCreatedAt,
dbId,
dbStatus
]) => {
console.log({
sshKeyId: sshId,
cloudAccountId: accountId,
backupStoreId: backupId,
clusterId: cId,
clusterStatus: cStatus,
clusterCreatedAt: cCreatedAt,
databaseId: dbId,
databaseStatus: dbStatus
});
});
Deploying Your Infrastructure
To deploy your infrastructure:
- Set up your pgEdge credentials as environment variables.
- Run the following command:
pulumi up
Review the changes and confirm the deployment.
Updating Resources
Updating a Database
To update a database, you can modify properties such as options, extensions, or nodes. Here's an example of adding a new extension and removing a node. (Make sure to update one property at a time):
const database = new pgedge.Database("exampleDatabase", {
// ... other properties ...
options: [
"install:northwind",
"rest:enabled",
"autoddl:enabled",
"cloudwatch_metrics:enabled", // New option
],
extensions: {
autoManage: true,
requesteds: [
"postgis",
"vector", // New extension
],
},
nodes: {
n1: {
name: "n1",
},
n3: {
name: "n3",
},
},
// ... other properties ...
});
Updating a Cluster
To update an existing cluster, such as adding or removing nodes, you can modify the nodes, regions, and networks arrays in your Pulumi program. Here's an example of removing a node:
const cluster = new pgedge.Cluster("exampleCluster", {
// ... other properties ...
nodes: [
{
name: "n1",
region: "us-west-2",
instanceType: "r6g.medium",
volumeSize: 100,
volumeType: "gp2",
},
{
name: "n3",
region: "eu-central-1",
instanceType: "r6g.medium",
volumeSize: 100,
volumeType: "gp2",
},
],
regions: ["us-west-2", "eu-central-1"],
networks: [
{
region: "us-west-2",
cidr: "10.1.0.0/16",
publicSubnets: ["10.1.0.0/24"],
// privateSubnets: ["10.1.0.0/24"],
},
{
region: "eu-central-1",
cidr: "10.3.0.0/16",
publicSubnets: ["10.3.0.0/24"],
// privateSubnets: ["10.3.0.0/24"],
},
],
// ... other properties ...
});
After making these changes, run pulumi up to apply the updates to your infrastructure.
You can find more examples in the examples directory.
Contributing
We welcome contributions from the community. Please review our contribution guidelines for more information on how to get started.
License
This project is licensed under the Apache License. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pgedge_pulumi_pgedge-0.0.0.tar.gz.
File metadata
- Download URL: pgedge_pulumi_pgedge-0.0.0.tar.gz
- Upload date:
- Size: 34.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63c3b3294723664bcbc9b4839b043b1f3c3a904b1e2ed9f8d6f5b50a00bc4f9d
|
|
| MD5 |
9b9226f1711e89981f9266c86fe7d332
|
|
| BLAKE2b-256 |
e6d6868b222f93984da948fd18baf4e7443c9c13d763cc3aade6ca0ca34201db
|
File details
Details for the file pgEdge_pulumi_pgedge-0.0.0-py3-none-any.whl.
File metadata
- Download URL: pgEdge_pulumi_pgedge-0.0.0-py3-none-any.whl
- Upload date:
- Size: 43.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62469e2651fedbad65b97d6cdb088bf3ac61b29b03b89ff863cae3c772a96a00
|
|
| MD5 |
6b274f1c10a803389022381e5828f675
|
|
| BLAKE2b-256 |
408accd3a773414764c803fdd454c1f74ef9f35794a023d9ad8c47f50c3e4d1c
|