aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
147 lines (146 loc) • 4.79 kB
TypeScript
import { TagType } from './cfn-resource';
import { IResolvable } from './resolvable';
/**
* Interface to implement tags.
*/
export interface ITaggable {
/**
* TagManager to set, remove and format tags
*/
readonly tags: TagManager;
}
/**
* Modernized version of ITaggable
*
* `ITaggable` has a problem: for a number of L1 resources, we failed to generate
* `tags: TagManager`, and generated `tags: CfnSomeResource.TagProperty[]` instead.
*
* To mark these resources as taggable, we need to put the `TagManager` in a new property
* whose name is unlikely to conflict with any existing properties. Hence, a new interface
* for that purpose. All future resources will implement `ITaggableV2`.
*/
export interface ITaggableV2 {
/**
* TagManager to set, remove and format tags
*/
readonly cdkTagManager: TagManager;
}
/**
* Options to configure TagManager behavior
*/
export interface TagManagerOptions {
/**
* The name of the property in CloudFormation for these tags
*
* Normally this is `tags`, but Cognito UserPool uses UserPoolTags
*
* @default "tags"
*/
readonly tagPropertyName?: string;
}
/**
* 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.
*
* @example
* 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,
* },
* });
* }
* }
*
*/
export declare class TagManager {
/**
* Check whether the given construct is Taggable
*/
static isTaggable(construct: any): construct is ITaggable;
/**
* Check whether the given construct is ITaggableV2
*/
static isTaggableV2(construct: any): construct is ITaggableV2;
/**
* Return the TagManager associated with the given construct, if any
*/
static of(construct: any): TagManager | undefined;
/**
* The property name for tag values
*
* Normally this is `tags` but some resources choose a different name. Cognito
* UserPool uses UserPoolTags
*/
readonly tagPropertyName: string;
/**
* 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.
*/
readonly renderedTags: IResolvable;
private readonly tags;
private dynamicTags?;
private readonly priorities;
private readonly tagFormatter;
private readonly resourceTypeName;
private readonly externalTagPriority;
private readonly didHaveInitialTags;
constructor(tagType: TagType, resourceTypeName: string, initialTags?: any, options?: TagManagerOptions);
/**
* Adds the specified tag to the array of tags
*
*/
setTag(key: string, value: string, priority?: number, applyToLaunchedInstances?: boolean): void;
/**
* Removes the specified tag from the array if it exists
*
* @param key The tag to remove
* @param priority The priority of the remove operation
*/
removeTag(key: string, priority: number): void;
/**
* 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.
*/
renderTags(combineWithTags?: any): any;
/**
* Render the tags in a readable format
*/
tagValues(): Record<string, string>;
/**
* Determine if the aspect applies here
*
* Looks at the include and exclude resourceTypeName arrays to determine if
* the aspect applies here
*/
applyTagAspectHere(include?: string[], exclude?: string[]): boolean;
/**
* Returns true if there are any tags defined
*/
hasTags(): boolean;
private _setTag;
private get sortedTags();
/**
* Parse external tags.
*
* Set the parseable ones into this tag manager. Save the rest (tokens, lazies) in `this.dynamicTags`.
*/
private parseExternalTags;
}