brash-hairdresser-60389
01/13/2023, 12:37 AMgcp.sql.Database
and gcp.sql.User
(using Postgres)
In my pulumi script, I use to create in order:
1. The gcp.sql.User
2. the gcp.sql.Database
This works fine until I try to destroy the stack, I have always the issue the User cannot be deleted because there’s a reference (the database).
I tried to change the order of creation Database first, then User, but this doesn’t bind the user correctly to the database.
I’ve seen there’s the need in such a case to set up the deletionPolicy: 'ABANDON'
on the Database, but in doing so, the Database is not deleted, and then if I try to recreate the database, it fails because it already exists.
It is possible there is no way to manage these GCP resources correctly using Pulumi? I can’t believe I have to delete it manually.
Thank you for any answer.billowy-army-68599
brash-hairdresser-60389
01/13/2023, 11:20 PMimport * as gcp from '@pulumi/gcp';
import * as pulumi from '@pulumi/pulumi';
import { ManagedDatabaseInfo } from '../schema';
export class AppDatabaseManaged extends pulumi.ComponentResource {
public readonly uri: pulumi.Output<string>;
constructor(args: ManagedDatabaseInfo, opts?: pulumi.ResourceOptions) {
super('sys:app:Database-managed', args.name, args, opts);
const user = new gcp.sql.User(
`${args.name}-user`,
{
instance: 'app-dev',
name: args.user.name,
password: args.user.password,
project: args.project,
},
{
parent: this,
customTimeouts: { create: '45s', update: '45s', delete: '45s' },
},
);
const db = new gcp.sql.Database(
`${args.name}-pgdatabase`,
{
instance: 'app-dev',
name: args.name,
project: args.project,
},
{
parent: this,
customTimeouts: { create: '45s', update: '45s', delete: '45s' },
},
);
this.uri = pulumi.output(
pulumi.interpolate`postgresql://${user.name}:${user.password}@${args.publicIpAddress}:5432/${db.name}`,
);
}
}
billowy-army-68599
dependsOn
so that the user gets created after the database:
https://www.pulumi.com/docs/intro/concepts/resources/options/dependson/brash-hairdresser-60389
01/13/2023, 11:33 PMbillowy-army-68599
brash-hairdresser-60389
01/13/2023, 11:41 PMbillowy-army-68599
brash-hairdresser-60389
01/13/2023, 11:47 PM