Table of Contents

Class TagManager

Namespace
Amazon.CDK
Assembly
Amazon.CDK.dll

TagManager facilitates a common implementation of tagging for Constructs.

public class TagManager : DeputyBase
Inheritance
TagManager

Examples

using Amazon.CDK;


            class MyConstruct : Resource, ITaggable
            {
                public readonly void Tags = new TagManager(TagType.KEY_VALUE, "Whatever::The::Type");

                public MyConstruct(Construct scope, string id) : base(scope, id)
                {

                    new CfnResource(this, "Resource", new CfnResourceProps {
                        Type = "Whatever::The::Type",
                        Properties = new Dictionary<string, object> {
                            // ...
                            { "Tags", Tags.RenderedTags }
                        }
                    });
                }
            }

Remarks

Normally, you do not need to use this class, as the CloudFormation specification will indicate which resources are taggable. However, sometimes you will need this to make custom resources taggable. Used tagManager.renderedTags to obtain a value that will resolve to the tags at synthesis time.

Constructors

TagManager(TagType, string, object?, ITagManagerOptions?)

public TagManager(TagType tagType, string resourceTypeName, object? tagStructure = null, ITagManagerOptions? options = null)

Parameters

tagType TagType
resourceTypeName string
tagStructure object
options ITagManagerOptions

Properties

RenderedTags

A lazy value that represents the rendered tags at synthesis time.

public virtual IResolvable RenderedTags { get; }

Property Value

IResolvable

Remarks

If you need to make a custom construct taggable, use the value of this property to pass to the tags property of the underlying construct.

TagPropertyName

The property name for tag values.

public virtual string TagPropertyName { get; }

Property Value

string

Remarks

Normally this is tags but some resources choose a different name. Cognito UserPool uses UserPoolTags

Methods

ApplyTagAspectHere(string[]?, string[]?)

Determine if the aspect applies here.

public virtual bool ApplyTagAspectHere(string[]? include = null, string[]? exclude = null)

Parameters

include string[]
exclude string[]

Returns

bool

Remarks

Looks at the include and exclude resourceTypeName arrays to determine if the aspect applies here

HasTags()

Returns true if there are any tags defined.

public virtual bool HasTags()

Returns

bool

IsTaggable(object)

Check whether the given construct is Taggable.

public static bool IsTaggable(object construct)

Parameters

construct object

Returns

bool

RemoveTag(string, double)

Removes the specified tag from the array if it exists.

public virtual void RemoveTag(string key, double priority)

Parameters

key string

The tag to remove.

priority double

The priority of the remove operation.

RenderTags()

Renders tags into the proper format based on TagType.

public virtual object RenderTags()

Returns

object

Remarks

This method will eagerly render the tags currently applied. In most cases, you should be using tagManager.renderedTags instead, which will return a Lazy value that will resolve to the correct tags at synthesis time.

SetTag(string, string, double?, bool?)

Adds the specified tag to the array of tags.

public virtual void SetTag(string key, string value, double? priority = null, bool? applyToLaunchedInstances = null)

Parameters

key string
value string
priority double?
applyToLaunchedInstances bool?

TagValues()

Render the tags in a readable format.

public virtual IDictionary<string, string> TagValues()

Returns

IDictionary<string, string>