brash-kilobyte-32523
07/25/2024, 11:03 AMimport * as pulumi from "@pulumi/pulumi";
import * as docker from "@pulumi/docker";
import * as postgresql from "@pulumi/postgresql";
const network = new docker.Network("identus-stack", {
ipamConfigs: [{
subnet: "172.18.0.0/16",
}],
driver: "bridge", // You can choose other drivers like "overlay", "host", etc.
attachable: true,
checkDuplicate: true
});
// Create a Docker container running PostgreSQL
const postgresContainer = new docker.Container("postgresContainer", {
image: "postgres:16",
ports: [{
internal: 5432,
external: 5432,
}],
envs: [
"POSTGRES_DB=agent",
"POSTGRES_USER=postgres",
"POSTGRES_PASSWORD=postgres",
],
hostname: "postgres-agent",
publishAllPorts: true,
rm: true, // Remove the container when stopped
healthcheck: {
tests: ["CMD", "pg_isready", "-U", "postgres"],
interval: "30s",
timeout: "10s",
retries: 5,
},
networksAdvanced: [
{
name: network.name,
ipv4Address: "172.18.0.2",
}
],
}, {dependsOn: network});
const containerIp = pulumi.output(postgresContainer.networksAdvanced).apply(networks => {
const networkInfo = networks && networks[0];
return networkInfo ? networkInfo.ipv4Address : undefined;
});
containerIp.apply(ip => {
console.log(`Postgres Container IP: ${ip}`);
});
const pgProvider = new postgresql.Provider("pgProvider", {
host: postgresContainer.hostname, //containerIp.apply(ip => ip as string),
port: 5432,
username: "postgres",
password: "postgres",
databaseUsername: "postgres",
database: "agent",
superuser: true
}, {dependsOn: [postgresContainer], parent: postgresContainer});
const agentDbApplicationUser = new postgresql.Role("agentApplicationUser", {
name: "agent-application-user",
password: "postgres",
login: true,
}, {provider: pgProvider, dependsOn: pgProvider, parent: pgProvider});
const agentDbApplicationUserPrivileges = new postgresql.Grant("agentApplicationUserPrivileges", {
role: agentDbApplicationUser.name,
database: "agent",
objectType: "table",
privileges: ["SELECT", "INSERT", "UPDATE", "DELETE"],
}, {provider: pgProvider, dependsOn: pgProvider, parent: pgProvider});
export const containerId = postgresContainer.id;
export const containerName = postgresContainer.name;
I wonder, are there examples of initializing the Provider and Grant resources using postgredsql package.
Error example:
Diagnostics:
postgresql:index:Role (agentApplicationUser):
error: sdk-v2/provider2.go:385: sdk.helper_schema: Error connecting to PostgreSQL server postgres-agent (scheme: postgres): dial tcp: lookup XXXX-agent: no such host: provider=postgresql@3.11.3
error: 1 error occurred:
* Error connecting to PostgreSQL server postgres-agent (scheme: postgres): dial tcp: lookup XXXX-agent: no such host
pulumi:pulumi:Stack (docker-dev):
Postgres Container Port: 5432
Postgres Container IP: 172.18.0.2
error: update failed
Could somebody help me with this issue?No matter how you like to participate in developer communities, Pulumi wants to meet you there. If you want to meet other Pulumi users to share use-cases and best practices, contribute code or documentation, see us at an event, or just tell a story about something cool you did with Pulumi, you are part of our community.
Powered by