Hello all, I stumbled upon a weird issue with tagg...
# python
i
Hello all, I stumbled upon a weird issue with tagging resources. I am running a stack transformation which tags all of the resources created, like this:
Copy code
def transformation(args: ResourceTransformationArgs):
    new_props = args.props
    new_props["tags"] = {"blah1": "blah2"}
    return ResourceTransformationResult(props=new_props, opts=args.opts)

pulumi.runtime.stack.register_stack_transformation(transformation)
The issue here is that pulumi throws this error
Copy code
Diagnostics:
  github:index:RepositoryEnvironment (repo-env):
    error: github:index/repositoryEnvironment:RepositoryEnvironment resource 'repo-env' has a problem: Invalid or unknown key. Examine values at 'repo-env.tags'.
during the creation of a simple GitHub repository environment (code below):
Copy code
repo_env=github.RepositoryEnvironment(
    resource_name="repo-env",
    environment="dev",
    repository=ams_repo.name,
    can_admins_bypass=True,
)
If I remove the stack transformation, the deployment goes on normally. Any idea on what I am doing wrong? Google is not helping and the less I have to say about Pulumi "AI" the better. Thanks in advance.
d
Not all resources take tags. What's the usecase?
i
Had to take a call and din't finish writing. The GitHub repository resource (and most other GitHub resources) does not has any tags. My question is - is there any way to omit them from the stack transformation?
I tried the protected flag, the ignoreChanges and a few other.
d
You can conditionally apply your transformation based on the resource type. Take a look at
args.type_
Is this for auto-tagging aws resources by any chance?
i
I am auto-tagging azure and github resources in this case
from docs here: https://www.pulumi.com/docs/concepts/options/transformations/#no-typed-args-classes I should include some sort of filter (if clause) in the example above to filter out Github resources
If I understood you correctly?
d
Yes. I'm not aware of any github resources that support
tags
, so you should be able to do
if not args.type_.startswith("github:")
i
Thank you. Off to the salt mines.