Thread
#general
    b

    broad-island-71889

    4 months ago
    Hi guys, we have a transformation defined on stack level that registers common tags for AWS resources (similar to the one described here). The only problem with it is that if we use same resource in another project(below), it rewrites the tags
    bucket = aws.s3.Bucket.get(
        f"{name}-some-bucket", id=f"bucket-created-in-another-program")
    )
    I was wondering if there is a way to filter auto-tagging by the operation, i.e. if it’s only reading resources, then do not apply the transformation.
    aws:s3/bucket:Bucket: (read)
    Current implementation:
    # registerAutoTags registers a global stack transformation that merges a set
    # of tags with whatever was also explicitly added to the resource definition.
    def register_auto_tags(auto_tags):
        pulumi.runtime.register_stack_transformation(lambda args: auto_tag(args, auto_tags))
    
    
    # auto_tag applies the given tags to the resource properties if applicable.
    def auto_tag(args, auto_tags):
        if is_taggable(args.type_):
            args.props["tags"] = {**auto_tags, **(args.props["tags"] or {})}
            return pulumi.ResourceTransformationResult(args.props, args.opts)
    w

    white-balloon-205

    4 months ago
    I'm not certain off the top of my head - but it's possible that the resource options property on the args has an
    id
    property set only in the case of read. If so you may be able to use that to decide whether to apply the transformation?