GoodMirek
GoodMirek

Reputation: 222

Programmaticaly tagging stack in Pulumi

I would like to programmatically add a tag to a Pulumi stack. Specifically, I want to add a tag named environment with value equal to a name of the Pulumi stack.
E.g. if name of the Pulumi stack is staging, I would like to add a tag environment with value staging to the stack. I will then use the tag environment for grouping all the staging stacks in Pulumi console.

I know that it is possible to tag Pulumi stacks using Pulumi CLI, as described in Pulumi CLI doc. However, I would like to add the tags to Pulumi stack programmatically, from the code defining the stack. I know I can access the name of the current stack via variable Deployment.Instance.StackName, but cannot find how to assign a tag to the current stack.

I use the current version of Pulumi, which is 3.5.1. Is there any way?

Upvotes: 1

Views: 557

Answers (1)

iWahbe
iWahbe

Reputation: 28

To tag a pulumi stack as part of running the program, use the Pulumi Service provider. The resource you want is StackTag.

Upvotes: 1

Related Questions