https://pulumi.com logo
Title
k

kind-room-82948

12/20/2022, 6:45 PM
Whenever I do an export of an object created from a custom made pulumi.ComponentResource, preview will always show changes on that output. Has anyone run into this and found a way around it? I'm attempting to have the ComponentResource class attributes be outputs but I don't want it to always show diffs
Diffs themselves show no actual changes to class attributes, so I'm guessing there is some other part of ComponentResource that is changing that it doesn't show
l

little-cartoon-10569

12/20/2022, 7:29 PM
That's not something Are the exported properties Outputs? Or just primitives?
k

kind-room-82948

12/20/2022, 7:30 PM
Mix of pulumi.output<strings> and strings
l

little-cartoon-10569

12/20/2022, 7:30 PM
Nothing is occurring. Can you create a snippet example?
k

kind-room-82948

12/20/2022, 7:31 PM
~ firebaseComponent    : {
        firebaseDatabaseName: "removed"
        firebaseDatabaseUrl : "removed"
        urn                 : "removed"
    }
Output diff looks something like this
With no actual planned changes
l

little-cartoon-10569

12/20/2022, 7:32 PM
Can you show how those properties are set, and how the exports are done? You can use the Text Snippet feature in the + menu
k

kind-room-82948

12/20/2022, 7:33 PM
export (cut off the inputs):
export const firebaseComponent = new FirebaseComponent('firebase', {
class definition
export class FirebaseComponent extends pulumi.ComponentResource {
    public readonly firebaseDatabaseUrl: pulumi.Output<string>;
    public readonly firebaseDatabaseName: pulumi.Output<string>;

    constructor(name: string, props: FirebaseInterface, opts?: pulumi.ComponentResourceOptions) {

....

        const firebaseDatabase = new GoogleFirebaseInstanceResource(firebaseDatabaseName, {
            gcpProjectNumber: props.projectNumber,
            location: props.firebaseRegion,
            databaseId: firebaseDatabaseName,
        }, {
            parent: this,
            dependsOn: [firebaseProject],
        });

        this.firebaseDatabaseName = firebaseDatabase.id;
l

little-cartoon-10569

12/20/2022, 7:34 PM
Ah. You're exporting an object, not a primitive / output. That's the expected result.
Export just the properties you want exported, and it'll hide them when they don't change.
k

kind-room-82948

12/20/2022, 7:35 PM
so I'd need to make a new object of the attributes of the class instead of just exporting the class object?
l

little-cartoon-10569

12/20/2022, 7:35 PM
No. Exporting a class does nothing from Pulumi's point of view. Only data (objects / primitives / outputs) are relevant.
If it's feasible, you should consider exporting only the properties.
Like this:
const firebaseComponent = new FirebaseComponent( ...);
eporrt const firebaseDatabaseUrl = firebaseComponent.firebaseDatabaseUrl;
k

kind-room-82948

12/20/2022, 7:37 PM
we've got downstream stacks already depending on the attributes (
firebaseComponent.firebaseDatabaseName
for example) so in order to not break functionality I'd have to still make an object, but understood
thanks
l

little-cartoon-10569

12/20/2022, 7:38 PM
You can create the object on the other side. You can export the values individually.
That said, you can export the object as-is, there is no non-cosmetic downside.
In one of the projects I work on, every stack exports only a single object. All the relevant properties of all the resources are grouped into a single exported object. It's weird, and I don't recommend it, but it works.
k

kind-room-82948

12/20/2022, 7:39 PM
Yeah was just hoping to find something like an ignoreChanges I could use to ignore whatever hidden attribute is changing, but I'll just make new ones to export so we don't have to change downstream too
l

little-cartoon-10569

12/20/2022, 7:40 PM
You could try ignoreChanges. It's an opt.
I don't think it'll do anything for exports.
k

kind-room-82948

12/20/2022, 7:43 PM
makes sense
well I've got a workaround that should work, appreciate the help
will stick to single string outputs going forward 🙂