# Add Consistent Resource Tags to a Terraform Configuration

Yes. An agent adds provider default tags and module tags to your Terraform root so every AWS resource carries project, environment and owner tags, and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-resource-tags/terraform/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent clones the repository into its own cloud sandbox and reads the root module before it adds a tag anywhere. In a configuration like hashicorp-education/learn-terraform-provision-eks-cluster, `main.tf` configures the `aws` provider with only a region, then calls `terraform-aws-modules/vpc/aws` 5.8.1 with three private and three public subnets, `terraform-aws-modules/eks/aws` 20.8.5 with two managed node groups named `node-group-1` and `node-group-2` on `t3.small`, and the `iam-assumable-role-with-oidc` submodule of the IAM module 5.39.0 for the EBS CSI driver role. The only tags in the file are the `kubernetes.io/role/elb` and `kubernetes.io/role/internal-elb` subnet tags the load balancer controller needs. `terraform.tf` pins `hashicorp/aws` at `~> 5.47.0` and `required_version` at `~> 1.3`, `variables.tf` has only `region`, and `outputs.tf` exposes the cluster endpoint, security group, region and name.

It adds a `tags` local built from a new `environment` variable with a validation block that allows `dev`, `staging` and `prod`, plus `Project`, `ManagedBy = "terraform"` and an `Owner` taken from a variable the reader fills in, and gives the provider a `default_tags` block with that map. With the AWS provider at 5.x, `default_tags` reaches every taggable resource the provider creates, including the ones inside the three modules, and a resource's own `tags` merge over them rather than replacing them, so the subnet role tags stay as they are.

Provider defaults do not reach what AWS creates on its own, so the agent also passes `tags = local.tags` to the EKS module, which writes them into each managed node group's launch template tag specifications; that is how the EC2 instances, volumes and network interfaces that EKS launches for `node-group-1` and `node-group-2` get the same keys. It passes the map to the VPC and IRSA modules as well, so the plan is readable without reasoning about which path a tag took, and adds `tags` to `outputs.tf` so other configurations can reuse the map.

In the sandbox it runs `terraform init -backend=false`, which downloads the providers the lock file and `terraform.tf` pin, then `terraform fmt -check`, `terraform validate` and `tflint` with the AWS ruleset. A plan needs credentials for `aws_availability_zones` and the modules, so without them the agent stops there and says so; with read-only AWS credentials saved as secrets in a Project and the run started in that Project (`POST /o/{org}/p/{project}/sessions`), it also runs `terraform plan` and pastes the summary, where every change is an in-place update of `tags_all`, into the pull request.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add consistent AWS resource tags to this Terraform configuration. Read main.tf, terraform.tf, variables.tf and outputs.tf first. Add an environment variable with validation and an owner variable, build one tags local with Project, Environment, Owner and ManagedBy, set it as the aws provider's default_tags, and pass it as tags to the VPC, EKS and IAM modules so node group instances and volumes carry it too. Keep the existing subnet role tags. Run terraform init without a backend, terraform fmt -check, terraform validate and tflint; run terraform plan only if AWS credentials are present and paste its summary. Open a pull request that lists each file changed and which resources get their tags from the provider and which from a module.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request on its own branch that changes `main.tf`, `variables.tf` and `outputs.tf`, and `terraform.tfvars.example` if the repository has one. The description shows the `tags` local and the `default_tags` block, lists which resources are tagged through the provider and which through the EKS module's launch templates, and pastes the `terraform validate` and `tflint` output; when credentials were available it adds the plan summary showing in-place `tags_all` updates and no replacements.

The run's record keeps every command with its output, including the provider versions `terraform init` resolved, so a reviewer can check the AWS provider was in the 5.x range where `default_tags` behaves as the description says.

Before merging, a reviewer runs `terraform plan` against the real state if the run could not, confirms no resource is replaced, and decides the tag keys their cost allocation report expects, since an `Environment` key is only useful if billing activates it.

## Run it on every new Terraform repository

Start one run per root module from your own server: `POST /o/{org}/sessions` with this prompt and that repository in `resources`, one call each. `GET /o/{org}/github` lists every repository the Rush GitHub App installation reaches, so a script can find the ones with a `provider "aws"` block and no `default_tags`, and start a run for each in its own sandbox and on its own branch.

Give the key a `webhook_url` and each run posts `run.completed` with its `session_url` when the turn finishes, so the pull request links collect on your side without polling. A script over many Terraform repositories can start them all without waiting on each other: once the key's `max_concurrent` runs are in progress, 4 by default and up to 100, each further start answers `202` with `status: "queued"` and begins, oldest first, when a slot frees.

## Why run it on Rush?

Tagging looks like a one-line change and is not: provider defaults silently miss the instances a node group launches, a tag key that collides with a module's own produces a plan full of noise, and a validation block written wrong rejects the value already in state. The agent reads the real modules and their versions, puts each tag where it has to be, and validates and lints the configuration in its own sandbox before the pull request exists.

The sandbox downloads the pinned providers and keeps every command's output in the run's record, so the reviewer reads the real `validate`, `tflint` and plan results. Several root modules can be tagged at once in separate sandboxes, each ending in its own pull request.

## Frequently asked questions

### Will applying this replace any resource?

No. Tags on AWS resources are updated in place, and the plan shows each one as a `tags_all` change. The agent keeps the existing subnet role tags untouched and adds no tag to the `random_string` resource, which has none.

### Why pass tags to the modules when the provider already has default_tags?

Provider defaults apply to resources Terraform creates. EC2 instances, volumes and network interfaces behind a managed node group are launched by EKS from a launch template, so they only carry what the EKS module writes into that template's tag specifications from its `tags` input.

### Can the run prove the plan without my AWS account?

It can validate, format and lint without credentials, and the pull request says that is as far as it went. Save read-only AWS credentials as secrets in the Project that holds the repository and start the run in that Project with `POST /o/{org}/p/{project}/sessions`; the agent reads them as environment variables, runs `terraform plan` too and pastes the summary.

### What if a module already sets a tag with the same key?

A resource's own tags merge over `default_tags`, so the module's value wins for that key and the plan shows no churn. The pull request lists any such overlap it found in the module sources.

## More Terraform jobs

- [Generate Terraform Module Docs With terraform-docs and Keep Them Current in CI](https://getrush.ai/run/add-terraform-docs/terraform/)
- [Add TFLint and Format Checks to Terraform CI](https://getrush.ai/run/add-tflint-to-ci/terraform/)
- [Add Trivy Scanning to a Terraform Module's CI](https://getrush.ai/run/add-trivy-scan-to-ci/terraform/)

## The same job on other stacks

- [Tag Every Resource in an AWS CDK App from a Linear Issue](https://getrush.ai/run/add-resource-tags/aws-cdk/)
- [Tag Every Resource in a Pulumi Program](https://getrush.ai/run/add-resource-tags/pulumi/)

## More jobs like this: Hand off a long task

- [Add Response Caching to a Fiber App](https://getrush.ai/run/add-response-caching/fiber/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
