Class: AWSCDK::TagManager

Inherits:
Jsii::Object
  • Object
show all
Defined in:
tag_manager.rb

Overview

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.

Examples:

class MyConstruct < AWSCDK::Resource
  include AWSCDK::ITaggable
  attr_reader :tags

  def initialize(scope, id)
    super(scope, id)

    AWSCDK::CfnResource.new(self, "Resource", {
        type: "Whatever::The::Type",
        properties: {
            # ...
            Tags: @tags.rendered_tags,
        },
    })
  end
end

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag_type, resource_type_name, initial_tags = nil, options = nil) ⇒ TagManager

Returns a new instance of TagManager.

Parameters:



35
36
37
38
39
40
41
42
# File 'tag_manager.rb', line 35

def initialize(tag_type, resource_type_name, initial_tags = nil, options = nil)
  options = options.is_a?(Hash) ? ::AWSCDK::TagManagerOptions.new(**options.transform_keys(&:to_sym)) : options
  Jsii::Type.check_type(tag_type, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5UYWdUeXBlIn0=")), "tagType")
  Jsii::Type.check_type(resource_type_name, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "resourceTypeName")
  Jsii::Type.check_type(initial_tags, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJhbnkifQ==")), "initialTags") unless initial_tags.nil?
  Jsii::Type.check_type(options, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5UYWdNYW5hZ2VyT3B0aW9ucyJ9")), "options") unless options.nil?
  Jsii::Object.instance_method(:initialize).bind(self).call(tag_type, resource_type_name, initial_tags, options)
end

Class Method Details

.is_taggable(construct) ⇒ Boolean

Check whether the given construct is Taggable.

Parameters:

  • construct (Object)

Returns:

  • (Boolean)


61
62
63
64
# File 'tag_manager.rb', line 61

def self.is_taggable(construct)
  Jsii::Type.check_type(construct, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJhbnkifQ==")), "construct")
  Jsii::Kernel.instance.call_static("aws-cdk-lib.TagManager", "isTaggable", [construct])
end

.is_taggable_v2(construct) ⇒ Boolean

Check whether the given construct is ITaggableV2.

Parameters:

  • construct (Object)

Returns:

  • (Boolean)


70
71
72
73
# File 'tag_manager.rb', line 70

def self.is_taggable_v2(construct)
  Jsii::Type.check_type(construct, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJhbnkifQ==")), "construct")
  Jsii::Kernel.instance.call_static("aws-cdk-lib.TagManager", "isTaggableV2", [construct])
end

.jsii_overridable_methodsObject



44
45
46
47
48
49
50
51
52
53
54
55
# File 'tag_manager.rb', line 44

def self.jsii_overridable_methods
  {
    :rendered_tags => { kind: :property, name: "renderedTags", is_optional: false },
    :tag_property_name => { kind: :property, name: "tagPropertyName", is_optional: false },
    :apply_tag_aspect_here => { kind: :method, name: "applyTagAspectHere", is_optional: false },
    :has_tags => { kind: :method, name: "hasTags", is_optional: false },
    :remove_tag => { kind: :method, name: "removeTag", is_optional: false },
    :render_tags => { kind: :method, name: "renderTags", is_optional: false },
    :set_tag => { kind: :method, name: "setTag", is_optional: false },
    :tag_values => { kind: :method, name: "tagValues", is_optional: false },
  }
end

.of(construct) ⇒ AWSCDK::TagManager?

Return the TagManager associated with the given construct, if any.

Parameters:

  • construct (Object)

Returns:

  • (AWSCDK::TagManager, nil)


79
80
81
82
# File 'tag_manager.rb', line 79

def self.of(construct)
  Jsii::Type.check_type(construct, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJhbnkifQ==")), "construct")
  Jsii::Kernel.instance.call_static("aws-cdk-lib.TagManager", "of", [construct])
end

Instance Method Details

#apply_tag_aspect_here(include = nil, exclude = nil) ⇒ Boolean

Determine if the aspect applies here.

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

Parameters:

  • include (Array<String>, nil) (defaults to: nil)
  • exclude (Array<String>, nil) (defaults to: nil)

Returns:

  • (Boolean)


112
113
114
115
116
# File 'tag_manager.rb', line 112

def apply_tag_aspect_here(include = nil, exclude = nil)
  Jsii::Type.check_type(include, JSON.parse(Base64.strict_decode64("eyJjb2xsZWN0aW9uIjp7ImVsZW1lbnR0eXBlIjp7InByaW1pdGl2ZSI6InN0cmluZyJ9LCJraW5kIjoiYXJyYXkifX0=")), "include") unless include.nil?
  Jsii::Type.check_type(exclude, JSON.parse(Base64.strict_decode64("eyJjb2xsZWN0aW9uIjp7ImVsZW1lbnR0eXBlIjp7InByaW1pdGl2ZSI6InN0cmluZyJ9LCJraW5kIjoiYXJyYXkifX0=")), "exclude") unless exclude.nil?
  jsii_call_method("applyTagAspectHere", [include, exclude])
end

#has_tagsBoolean

Returns true if there are any tags defined.

Returns:

  • (Boolean)


121
122
123
# File 'tag_manager.rb', line 121

def has_tags()
  jsii_call_method("hasTags", [])
end

#remove_tag(key, priority) ⇒ void

This method returns an undefined value.

Removes the specified tag from the array if it exists.

Parameters:

  • key (String)

    The tag to remove.

  • priority (Numeric)

    The priority of the remove operation.



130
131
132
133
134
# File 'tag_manager.rb', line 130

def remove_tag(key, priority)
  Jsii::Type.check_type(key, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "key")
  Jsii::Type.check_type(priority, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJudW1iZXIifQ==")), "priority")
  jsii_call_method("removeTag", [key, priority])
end

#render_tags(combine_with_tags = nil) ⇒ Object

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.

Parameters:

  • combine_with_tags (Object, nil) (defaults to: nil)

Returns:

  • (Object)


145
146
147
148
# File 'tag_manager.rb', line 145

def render_tags(combine_with_tags = nil)
  Jsii::Type.check_type(combine_with_tags, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJhbnkifQ==")), "combineWithTags") unless combine_with_tags.nil?
  jsii_call_method("renderTags", [combine_with_tags])
end

#rendered_tagsAWSCDK::IResolvable

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.

Returns:



90
91
92
# File 'tag_manager.rb', line 90

def rendered_tags()
  jsii_get_property("renderedTags")
end

#set_tag(key, value, priority = nil, apply_to_launched_instances = nil) ⇒ void

This method returns an undefined value.

Adds the specified tag to the array of tags.

Parameters:

  • key (String)
  • value (String)
  • priority (Numeric, nil) (defaults to: nil)
  • apply_to_launched_instances (Boolean, nil) (defaults to: nil)


157
158
159
160
161
162
163
# File 'tag_manager.rb', line 157

def set_tag(key, value, priority = nil, apply_to_launched_instances = nil)
  Jsii::Type.check_type(key, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "key")
  Jsii::Type.check_type(value, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "value")
  Jsii::Type.check_type(priority, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJudW1iZXIifQ==")), "priority") unless priority.nil?
  Jsii::Type.check_type(apply_to_launched_instances, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJib29sZWFuIn0=")), "applyToLaunchedInstances") unless apply_to_launched_instances.nil?
  jsii_call_method("setTag", [key, value, priority, apply_to_launched_instances])
end

#tag_property_nameString

The property name for tag values.

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

Returns:

  • (String)


100
101
102
# File 'tag_manager.rb', line 100

def tag_property_name()
  jsii_get_property("tagPropertyName")
end

#tag_valuesHash{String => String}

Render the tags in a readable format.

Returns:

  • (Hash{String => String})


168
169
170
# File 'tag_manager.rb', line 168

def tag_values()
  jsii_call_method("tagValues", [])
end