This message was deleted.
# general
s
This message was deleted.
b
Hi @great-postman-59271 What does your autotagging code look like for Azure?
g
i was basically trying to run the same code as from the link, and just adding the name of the azure resource under that taggable list of resources
i know its a pretty basic attempt, but i figured since the tags property was the same, it might work directly 🙂
m
Hi @great-postman-59271, I'm not sure what language you are using but in c# I am using reflection to see if a type supports tags using the following
Copy code
static bool IsTaggable(Resource resource)
{
    try{
        string name = resource.GetType().GetProperty("Tags")!.Name;
        return true;
    }
    catch(NullReferenceException ex)
    {
        return false;
    }
}
I call this using
Copy code
static ResourceTransformation RegisterAutoTags(Dictionary<string, string> autoTags) {
    return args => {
        if (IsTaggable(args.Resource)) {
            // Use reflection to look up the Tags property and merge the auto-tags.
            var tagp = args.Args.GetType().GetProperty("Tags");
            var tags = (InputMap<string>)tagp?.GetValue(args.Args, null)! ?? new InputMap<string>();
            foreach (var tag in autoTags) {
                tags[tag.Key] = tag.Value;
            }
            tagp?.SetValue(args.Args, tags, null);
            return new ResourceTransformationResult(args.Args, args.Options);
        }
        return null;
    };
}
The above works with Azure but I haven't tried AWS