Skip to content

Resource: awsAutoscalingGroupTag

Manages an individual Autoscaling Group (ASG) tag. This resource should only be used in cases where ASGs are created outside Terraform (e.g., ASGs implicitly created by EKS Node Groups).

\~> NOTE: This tagging resource should not be combined with the Terraform resource for managing the parent resource. For example, using awsAutoscalingGroup and awsAutoscalingGroupTag to manage tags of the same ASG will cause a perpetual difference where the awsAutoscalingGroup resource will try to remove the tag being added by the awsAutoscalingGroupTag resource.

\~> NOTE: This tagging resource does not use the provider ignoreTags configuration.

Example 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";
const awsEksNodeGroupExample = new aws.eksNodeGroup.EksNodeGroup(
  this,
  "example",
  {
    clusterName: "example",
    nodeGroupName: "example",
  }
);
const awsAutoscalingGroupTagExample =
  new aws.autoscalingGroupTag.AutoscalingGroupTagA(this, "example_1", {
    autoscalingGroupName: "${each.value}",
    tag: {
      key: "k8s.io/cluster-autoscaler/node-template/label/eks.amazonaws.com/capacityType",
      propagateAtLaunch: false,
      value: "SPOT",
    },
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsAutoscalingGroupTagExample.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.*/
awsAutoscalingGroupTagExample.addOverride(
  "for_each",
  `\${toset(
    [for asg in flatten(
      [for resources in ${awsEksNodeGroupExample.resources} : resources.autoscaling_groups]
    ) : asg.name]
  )}`
);

Argument Reference

The following arguments are supported:

  • autoscalingGroupName - (Required) Name of the Autoscaling Group to apply the tag to.
  • tag - (Required) Tag to create. The tag block is documented below.

The tag block supports the following arguments:

  • key - (Required) Tag name.
  • value - (Required) Tag value.
  • propagateAtLaunch - (Required) Whether to propagate the tags to instances launched by the ASG.

Attributes Reference

In addition to all arguments above, the following attributes are exported:

  • id - ASG name and key, separated by a comma (,)

Import

awsAutoscalingGroupTag can be imported by using the ASG name and key, separated by a comma (,), e.g.,

$ terraform import aws_autoscaling_group_tag.example asg-example,k8s.io/cluster-autoscaler/node-template/label/eks.amazonaws.com/capacityType