-replace flag into Terraform Cloud runs by using workspace environment variables.
Overview of the Terraform Cloud Workspace
You have multiple workspaces—DevOps, AWS MyApp Dev, Prod, and Staging—all linked to their respective Git branches. The screenshot below shows the Terraform Cloud dashboard with workspace names, run statuses, linked repositories, and last update times.
Configuring Terraform CLI for Terraform Cloud
Even with a VCS-connected workspace, you can runterraform init and terraform plan locally by pointing your CLI to Terraform Cloud:
clumsy_bird repo and checking out the development branch (tied to the MyApp Dev workspace), initialize and plan:
Local
plan and init commands work because Terraform Cloud is acting as your remote backend.Local Apply Is Blocked for VCS-Connected Workspaces
Attemptingterraform apply on a VCS-connected workspace will result in an error:
Terraform Cloud disallows local
apply on VCS workspaces. All changes must flow through your Git repository.Using -replace to Recreate Specific Resources
Terraform’s -replace flag lets you target explicit resources for recreation:
apply is blocked, we’ll inject these flags into Terraform Cloud runs.
Injecting CLI Arguments via Environment Variables
Terraform Cloud lets you define environment variables for each run phase. We’ll configureTF_CLI_ARGS_plan and TF_CLI_ARGS_apply to include -replace.
- In the Terraform Cloud UI, open the MyApp Dev workspace.
- Navigate to Variables → Environment Variables.
- Add the following entries:
| Variable Name | Value | Purpose |
|---|---|---|
| TF_CLI_ARGS_plan | -replace=aws_instance.clumsy_bird -input=false | Automatically replace the instance during plan |
| TF_CLI_ARGS_apply | -replace=aws_instance.clumsy_bird -auto-approve -input=false | Bypass approval and replace on apply |


Triggering the Terraform Cloud Run
Now, start a new run from the Terraform Cloud UI. During Plan and Apply, Terraform Cloud automatically applies your-replace flags:


Conclusion
By usingTF_CLI_ARGS_plan and TF_CLI_ARGS_apply environment variables in Terraform Cloud, you can inject CLI flags (such as -replace) into runs on VCS-connected workspaces. This method lets you force resource replacement without altering your Terraform configuration or committing changes to Git.