Data Source: awsDefaultTags
Use this data source to get the default tags configured on the provider.
With this data source, you can apply default tags to resources not directly managed by a Terraform resource, such as the instances underneath an Auto Scaling group or the volumes created for an EC2 instance.
Example Usage
Basic Usage
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.dataAwsDefaultTags.DataAwsDefaultTags(this, "example", {});
Dynamically Apply Default Tags to Auto Scaling Group
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.provider.AwsProvider(this, "aws", {
defaultTags: [
{
tags: {
environment: "Test",
name: "Provider Tag",
},
},
],
});
const dataAwsDefaultTagsExample = new aws.dataAwsDefaultTags.DataAwsDefaultTags(
this,
"example",
{}
);
const awsAutoscalingGroupExample = new aws.autoscalingGroup.AutoscalingGroup(
this,
"example_2",
{
tag: [],
}
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsAutoscalingGroupExample.overrideLogicalId("example");
/*In most cases loops should be handled in the programming language context and
not inside of the Terraform context. If you are looping over something external, e.g. a variable or a file input
you should consider using a for loop. If you are looping over something only known to Terraform, e.g. a result of a data source
you need to keep this like it is.*/
awsAutoscalingGroupExample.addOverride("tag", {
for_each: dataAwsDefaultTagsExample.tags,
content: [
{
key: "${tag.key}",
propagate_at_launch: true,
value: "${tag.value}",
},
],
});
Argument Reference
This data source has no arguments.
Attributes Reference
In addition to all arguments above, the following attributes are exported:
tags
- Blocks of default tags set on the provider. See details below.
tags
key
- Key name of the tag (i.e.,tags.#Key
).value
- Value of the tag (i.e.,tags.#Value
).