Skip to content

Resource: awsEc2Tag

Manages an individual EC2 resource tag. This resource should only be used in cases where EC2 resources are created outside Terraform (e.g., AMIs), being shared via Resource Access Manager (RAM), or implicitly created by other means (e.g., Transit Gateway VPN Attachments).

\~> NOTE: This tagging resource should not be combined with the Terraform resource for managing the parent resource. For example, using awsVpc and awsEc2Tag to manage tags of the same VPC will cause a perpetual difference where the awsVpc resource will try to remove the tag being added by the awsEc2Tag 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 awsCustomerGatewayExample = new aws.customerGateway.CustomerGateway(
  this,
  "example",
  {
    bgpAsn: 65000,
    ipAddress: "172.0.0.1",
    type: "ipsec.1",
  }
);
const awsEc2TransitGatewayExample = new aws.ec2TransitGateway.Ec2TransitGateway(
  this,
  "example_1",
  {}
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsEc2TransitGatewayExample.overrideLogicalId("example");
const awsVpnConnectionExample = new aws.vpnConnection.VpnConnection(
  this,
  "example_2",
  {
    customerGatewayId: awsCustomerGatewayExample.id,
    transitGatewayId: awsEc2TransitGatewayExample.id,
    type: awsCustomerGatewayExample.type,
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsVpnConnectionExample.overrideLogicalId("example");
const awsEc2TagExample = new aws.ec2Tag.Ec2Tag(this, "example_3", {
  key: "Name",
  resourceId: awsVpnConnectionExample.transitGatewayAttachmentId,
  value: "Hello World",
});
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsEc2TagExample.overrideLogicalId("example");

Argument Reference

The following arguments are supported:

  • resourceId - (Required) The ID of the EC2 resource to manage the tag for.
  • key - (Required) The tag name.
  • value - (Required) The value of the tag.

Attributes Reference

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

  • id - EC2 resource identifier and key, separated by a comma (,)

Import

awsEc2Tag can be imported by using the EC2 resource identifier and key, separated by a comma (,), e.g.,

$ terraform import aws_ec2_tag.example tgw-attach-1234567890abcdef,Name