Hello there, I have had an issue for months dealin...
# google-cloud
b
Hello there, I have had an issue for months dealing with
gcp.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.
b
can you share your code?
b
The code is very easy:
Copy code
import * 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}`,
    );
  }
}
b
there’s no dependency between the database and user, add a
dependsOn
so that the user gets created after the database: https://www.pulumi.com/docs/intro/concepts/resources/options/dependson/
b
I tried using the depenbdsOn but nothing changed, consider by official doc, seems necessary to use the deletion policy abandon if there are other objects (users i.e.) belonging to the database because the GCP API cannot perform the delete. For me is unbelievable to have su a limitation
b
There’s not much we can do about the Google cloud API limitations
b
So are you confirming that I cannot delete databases and I have to leave it there for manual deletion?
b
I can’t confirm that, it’s a Google cloud limitation. If the dependon didn’t help
b
OK, I just want some official pulumi answer on how to properly create and delete those resources via pulumi.