Had a question similar to: <https://pulumi-communi...
# general
e
Had a question similar to: https://pulumi-community.slack.com/archives/C84L4E3N1/p1572604898043200?thread_ts=1572604898.043200 where I would like to assign tags to all aws resources that are created through Pulumi. Started down the path of doing this:
Copy code
runtime.registerStackTransformation(args => {
    return {
        ...args,
        props: {
            ...args.props,
            tags: {
                owner: "stewartnoll"
            }
        }
    }
});
but ran into the problem pointed out in the question's thread where not all aws resources support a tag resulting in a failure at
pulumi up
. Followed up by moving to a more explicit approach that sets tags on those things I specifically care about:
Copy code
runtime.registerStackTransformation(args => {
    if (args.type === 'aws:lambda/function:Function' || args.type === '<ANOTHER TYPE HERE>') {
        return {
            ...args,
            props: {
                ...args.props,
                tags: {
                    owner: "stewartnoll"
                }
            }
        }
    }
    return undefined;
});
Although this has the benefit of reducing cognitive load on future devs adding functions to the stack, there's still the issue of adding a different resource to the stack that supports tags but isn't captured in the condition. If this were dot net I'd use reflection to map
args.type
to the dot net Type and check if the Type has the property
Tags
which would cover all resource types (including those that haven't been created by aws yet). I've been Googling a bunch on how to do something similar in TypeScript but haven't had any luck. Does anyone know of a way to do this or a better approach?