https://pulumi.com logo
Title
e

enough-kite-69616

06/23/2020, 9:32 PM
I'm creating a PostgreSQL server on Azure then I want to configure roles and schemas on it using the
@pulumi\postgresql
package. How do I tie the roles and schemas to the server I create?
g

gentle-diamond-70147

06/24/2020, 6:49 PM
If I'm understanding your question, you would do something like this:
import * as azure from "@pulumi/azure";
import * as pg from "@pulumi/postgresql";

const resourceGroup = new azure.core.ResourceGroup("resourceGroup");

const server = new azure.sql.SqlServer("main",{});

const db = new azure.sql.Database("main",{});

const pgProvider = new pg.Provider("main",{
    username: server.administratorLogin,
    password: server.administratorLoginPassword,
    host: db.serverName,
});

const pgRole = new pg.Role("main",{
    // role args
}, {provider: pgProvider})
(pseudocode)
You need to create an explicit provider (e.g.
pg.Provider
in this case) and then pass it into the PostgreSQL specific resources in order to tie it to the specific server that you created.
e

enough-kite-69616

06/24/2020, 6:57 PM
Nice, thanks!
👍 1
Running into this:
azure:sql:Database (ground-control-db):
    error: Error issuing create/update request for SQL Database "ground-control-db" (Resource Group "RD-FoundationalServices-rg", Server "ground-control-db-server"): sql.DatabasesClient#CreateOrUpdate: Failure sending request: StatusCode=404 -- Original Error: Code="ParentResourceNotFound" Message="Can not perform requested operation on nested resource. Parent resource 'ground-control-db-server' not found."
Relevant code:
const server = new azure.postgresql.Server(name, {
        name: name + '-server',
        location: resourceGroup.location,
        resourceGroupName: resourceGroup.name,
        administratorLogin: "psqladmin",
        administratorLoginPassword: adminPassword,
        skuName: "GP_Gen5_4",
        version: "11",
        sslEnforcement: `Enabled`,
        storageProfile: {
            storageMb: 5120,
            backupRetentionDays: 7,
            autoGrow: 'Enabled',
        },
        tags: {
            "project": "mercury"
        }
    });

    const db = new azure.sql.Database(name,{
        name: name,
        resourceGroupName: resourceGroup.name,
        serverName: server.name,
    }, {
        dependsOn: server
    });
@gentle-diamond-70147 thoughts on this?
g

gentle-diamond-70147

06/25/2020, 6:23 PM
Nothing obvious jumps out at me. You might try setting
location
on the
Database
too. Maybe the "not found" error is because it's trying to reference the Server from a different region.
If you re-run the
up
, does it succeed or same error?
Sometimes these "not found" errors are due to eventual consistency type issues at the provider. Meaning Azure returned an "ok" response for the Server and then Pulumi very quickly tried to create the Database referencing it and Azure's internal database hasn't fully propagated.
e

enough-kite-69616

06/25/2020, 7:59 PM
@gentle-diamond-70147 see my posts in the main channel... Changed to a specific postgres type