# TagManager

TagManager facilitates a common implementation of tagging for Constructs.

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.

- Source: [`core/lib/tag-manager.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/core/lib/tag-manager.ts#L303)
- Type last changed: v2.81.0 · 25 May 2023

## Example

```ts
class MyConstruct extends Resource implements ITaggable {
  public readonly tags = new TagManager(TagType.KEY_VALUE, 'Whatever::The::Type');

  constructor(scope: Construct, id: string) {
    super(scope, id);

    new CfnResource(this, 'Resource', {
      type: 'Whatever::The::Type',
      properties: {
        // ...
        Tags: this.tags.renderedTags,
      },
    });
  }
}
```

## Initializer

```ts
new TagManager(tagType: TagType, resourceTypeName: string, initialTags?: any, options?: TagManagerOptions)
```

## Properties

- `renderedTags`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) — A lazy value that represents the rendered tags at synthesis time.

  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`: string — The property name for tag values.

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

## Methods

- `applyTagAspectHere(include?: string[], exclude?: string[]): boolean` — Determine if the aspect applies here.

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

- `hasTags(): boolean` — Returns true if there are any tags defined.

- `isTaggable(construct: any): boolean` (static) — Check whether the given construct is Taggable.

- `isTaggableV2(construct: any): boolean` (static) — Check whether the given construct is ITaggableV2.

- `of(construct: any): TagManager // chainable` (static) — Return the TagManager associated with the given construct, if any.

- `removeTag(key: string, priority: number): void` — Removes the specified tag from the array if it exists.

  **Parameters**

  - `key` — The tag to remove.
  - `priority` — The priority of the remove operation.

- `renderTags(combineWithTags?: any): any` — Renders tags into the proper format based on TagType.

  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(key: string, value: string, priority?: number, applyToLaunchedInstances?: boolean): void` — Adds the specified tag to the array of tags.

- `tagValues(): { [key: string]: string }` — Render the tags in a readable format.
