Scenario
Need to add tags AWS subnets that were created outside of Terraform.
Solution
- You can tag subnets using the aws_ec2_tag resource.
resource "aws_ec2_tag" "example" {
for_each = toset(data.aws_subnets.example.ids)
resource_id = each.value
key = "example_key"
value = "example value"
}
**Note: If you use default_tags
in the provider, it's going to clash with this resource.
- To query existing subnets, the aws_subnets data source can be used