Hello! I'm using TS SDK and docker stack for the local environment. I can deploy an instance of the ...
b
Hello! I'm using TS SDK and docker stack for the local environment. I can deploy an instance of the postgresql and want to test the postgresql.Provider to create Grant resource. For some reason, Provider is created, but Grant resource is constantly failing with different variation of connection errors. I tried to connect by hostname and by IP of the created container. The code snippet is pretty simple:
Copy code
import * 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:
Copy code
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?