sparse-intern-71089
09/18/2023, 9:18 PMbillowy-army-68599
billowy-army-68599
dependsOn
to the component when it’s instantiated should created a dependency on the component itselfbillowy-army-68599
calm-cat-43230
09/19/2023, 2:10 AMcalm-cat-43230
09/19/2023, 2:12 AMdependsOn
through to each child (there’s one child in the code snippet above), then the child does not appear to have any dependency, direct or transient, on the dependsOn
used to instantiate the component resource (in this case, dbClusterInstances
).calm-cat-43230
09/19/2023, 2:14 AMdependsOn
plumbing, a state export
shows the parent relationship but doesn’t show anything in dependencies — not to the dbClusterInstances
or to the parent class. Is this parent-class dependency implicit? I put the plumbing in there originally because I noticed these child resources being created before dbClusterInstances
was completed, but I thought that having a parent dependent on a resource should have been enough. So I must be missing something here. Thanks again!billowy-army-68599
parent
on the child resourcesbillowy-army-68599
this.admin = new postgresql.Role(
`${dbName}-postgres-admin-role`,
{
login: true,
name: adminUserName,
password: adminUserPassword,
},
{ parent, this },
);
calm-cat-43230
09/19/2023, 1:26 PMopts
as the named param parent
, which is happening in line 24 (I thought — note that line 13 is what sets the local parent
to this
). It seems like your example {parent, this}
would instead send this
as a named param this
, which doesn’t exist from what I can see in the CustomResourceOptions
interface. Thanks for your help, here.billowy-army-68599
calm-cat-43230
09/19/2023, 8:16 PMparent
is a local you do not need to do parent: parent
— parent
alone will suffice (so-called “shorthand property names”). So I believe the code above is equivalent to { parent: this }
.billowy-army-68599
this.admin = new postgresql.Role(
`${dbName}-postgres-admin-role`,
{
login: true,
name: adminUserName,
password: adminUserPassword,
},
{ dependsOn, parent },
);
Does not know it is a member of a component at all. It just knows that it dependsOn
the component.
Parenting a resource in Pulumi is a specific thing. It tells Pulumi to let all resources inherit the resource options from the thing it’s parenting to, including dependsOn
billowy-army-68599
// Component class
export class PostgresDb extends pulumi.ComponentResource {
db: postgresql.Database;
admin: postgresql.Role;
constructor(
name: string,
args: PostgresDbArgs,
opts?: pulumi.ComponentResourceOptions,
) {
super('mynamespace:aws:PostgresDb', name, args, opts);
const parent = this;
const dependsOn = opts?.dependsOn;
const { dbName, adminUserName, adminUserPassword } = args;
this.admin = new postgresql.Role(
`${dbName}-postgres-admin-role`,
{
login: true,
name: adminUserName,
password: adminUserPassword,
},
{ parent: this },
);
// ...
}
}
const MySvcDb = new PostgresDb(
'my-svc-postgres-db',
{
dbName: 'my-svc',
adminUserName: '...',
adminUserPassword: '...',
},
{
parent: this
},
It’ll likely solve your issuecalm-cat-43230
09/19/2023, 8:24 PMparent: this
to the opts
for the component resource initializer as well (i.e. also to new PostgresDb()
, not just the children of the component like new postgresql.Role()
) — presumably that would make the component’s parent the…. stack? I haven’t seen this use of parent
before.billowy-army-68599
billowy-army-68599
billowy-army-68599
calm-cat-43230
09/19/2023, 8:35 PMparent
associated with its state, but no dependencies
at all:
"parent": "urn:pulumi:(stack)::cda::mynamespace:PostgresDb::my-svc-postgres-db",
billowy-army-68599
calm-cat-43230
09/19/2023, 8:37 PMbillowy-army-68599
calm-cat-43230
09/19/2023, 8:37 PMcalm-cat-43230
09/19/2023, 8:39 PMopts
to the following the state is updated with the dependencies passed into the component resource opts
:
"dependencies": [
"urn:pulumi:(stack)::cda::aws:rds/clusterInstance:ClusterInstance::rdsClusterPostgresInstance-0"
],
billowy-army-68599
// Component class
export class PostgresDb extends pulumi.ComponentResource {
db: postgresql.Database;
admin: postgresql.Role;
constructor(
name: string,
args: PostgresDbArgs,
opts?: pulumi.ComponentResourceOptions,
) {
super('mynamespace:aws:PostgresDb', name, args, opts);
const parent = this;
const dependsOn = opts?.dependsOn;
const { dbName, adminUserName, adminUserPassword } = args;
this.admin = new postgresql.Role(
`${dbName}-postgres-admin-role`,
{
login: true,
name: adminUserName,
password: adminUserPassword,
},
{ parent: this },
);
// ...
}
}
And you instantate it like this
const MySvcDb = new PostgresDb(
'my-svc-postgres-db',
{
dbName: 'my-svc',
adminUserName: '...',
adminUserPassword: '...',
},
{
dependsOn: someOtherResources
},
Everything in the PostgresDb
class should depend on someOtherResources
is there somrthing else you need?calm-cat-43230
09/19/2023, 8:40 PMcalm-cat-43230
09/19/2023, 8:40 PMsomeOtherResources
.billowy-army-68599
calm-cat-43230
09/19/2023, 9:05 PMpulumi stack export
, and finding the resource in the file, looking at its dependencies
property. It’s not present on children; when I explicitly plumb through the opts.dependsOn
to the children it shows up.billowy-army-68599
billowy-army-68599
calm-cat-43230
09/19/2023, 9:08 PMdependsOn
resources that were provided to the parent.
That’s a hard thing to reproduce quickly (it involves spinning up new RDSes). I can revert the explicit piping then and see if it reintroduces the problem or not! 🙂
Thanks for sticking with this thread, much appreciated. I’m not sure if the documentation can be improved in this respect — it’s a little vague on that parent page what should happen and how the state doesn’t show this implicit dependency. I appreciate your help in clarifying!