Resolving "Can't set variables when applying a saved plan" error with TF_CLI_ARGS
Last updated: September 16, 2025
If you're encountering the error "Can't set variables when applying a saved plan" when using the TF_CLI_ARGS environment variable to pass a tfvars file, this is likely due to how the environment variable is being applied to different Terraform commands.
The Problem
When you set TF_CLI_ARGS without a command qualifier, Terraform applies those arguments to all subcommands. This can cause conflicts when:
The arguments are passed to commands that don't support them (like
workspace)The arguments conflict with the command's operation (like
applywith a saved plan)
The Solution
Instead of using the generic TF_CLI_ARGS, use command-specific environment variables. For passing tfvars files, use:
TF_CLI_ARGS_plan
This ensures that the variable arguments are only applied to the terraform plan command, avoiding conflicts when applying the saved plan.
Example
Instead of:
export TF_CLI_ARGS="-var-file=my-variables.tfvars"Use:
export TF_CLI_ARGS_plan="-var-file=my-variables.tfvars"This way, the tfvars file will be included when creating the plan, but won't cause conflicts when applying the saved plan file.