1. How to find Pulumi stack's initial deployment date?

    TypeScript

    Pulumi does not natively support retrieving the initial deployment date of a stack. However, you can implement a workaround by storing the deployment date as a custom stack tag when you first create the stack.

    Here's a program that demonstrates how to add a custom tag to a Pulumi stack. This program sets the current timestamp as a custom tag named "DeploymentDate".

    import * as pulumi from "@pulumi/pulumi"; // Get the current stack const stack = pulumi.StackReference.get(pulumi.getStack()); // Set the deployment date as a stack tag, but only if it doesn't exist yet if (!stack.tags.apply(tags => tags.hasOwnProperty("DeploymentDate"))) { pulumi.log.info(`Setting DeploymentDate for the first time`); // Get the current time const now = new Date(); // Set the stack tag pulumi.Config.set("DeploymentDate", JSON.stringify(now)); } else { pulumi.log.info(`DeploymentDate is already set`); }

    To retrieve this tag and its value later, you could use pulumi.StackReference:

    import * as pulumi from "@pulumi/pulumi"; // Get the current stack const stack = pulumi.StackReference.get(pulumi.getStack()); // Get the deployment date from the stack tags const deploymentDate = stack.tags.apply(tags => tags["DeploymentDate"]); // Print the deployment date deploymentDate.apply(date => { if (date) pulumi.log.info(`This stack was first deployed on ${date}`); else pulumi.log.info(`Could not find the initial deployment date of this stack`); });

    Please note that this solution would only work for future stacks where you implemented this mechanism, not existing stacks.