berenddeboer / cdk-rds-sql

A CDK construct that allows creating roles and databases an on Aurora Serverless Postgresql cluster.
Apache License 2.0
23 stars 11 forks source link

Create Role for Database docs #32

Open stephanpelikan opened 2 months ago

stephanpelikan commented 2 months ago

I try to create a database and a dedicated user for it and facing different errors:

  1. Missleading docs: Docs says a parameter database or databaseName is necessary. So I guess I have to create the database first. On the other hand one can specify owner as a database's property. The javascript docs says I can create a role without database:

    /**
     * Optional database this user is expected to use.
     *
     * If the database exists, connect privileges are granted.
     *
     * Specify none of `database` or `databaseName` or only one of them.
     *
     * @default no connection to any database is granted
     */
    readonly database?: IDatabase;
    /**
     * Optional database name this user is expected to use.
     *
     * If the database exists, connect privileges are granted.
     *
     * Specify none of `database` or `databaseName` or only one of them.
     *
     * @default no connection to any database is granted
     */
    readonly databaseName?: string;

    But doing so gives me the error: Specify either database or databaseName.

  2. I found only this code working:

    const identityPostgresqlDatabaseName = 'identity';
    const identityPostgresqlDatabase = new Database(this, "IdentityPostgresqlDatabase", {
      provider: props.rdsStack.postgreSqlProvider,
      databaseName: identityPostgresqlDatabaseName,
    });
    
    const identityPostgresqlRole = new Role(props.rdsStack, 'IdentityPostgresqlRole', {
      provider: props.rdsStack.postgreSqlProvider,
      roleName: identityPostgresqlDatabaseName,
      database: identityPostgresqlDatabase,
    });

    I would prefer to create the role first and pass it to the database as an owner.

berenddeboer commented 2 months ago

I think that's possibly a mistake, could you try to make the condition such that allowing both to be empty is valid too? Let me know if that actually works (I think it should).

stephanpelikan commented 2 months ago

could you try to make the condition such that allowing both to be empty is valid too

Sorry, I'm not sure about what you mean. Do you mean to fork cdk-rds-sql, remove the test causing the error Specify either database or databaseName and retrying my stack? You think that this test that is causing the error is something that can be removed without causing further problems.

berenddeboer commented 2 months ago

Yes, you could try that. Or simply change the compiled .js file in your node_modules directory and see if this works for you.