Scenario
User's workspace is configured with a VCS connection in Terraform Cloud (this could be Terraform Enterprise as well since they both allow this feature).
The user connects to the remote backend for via the CLI. Below is an sample of a basic remote connection configuration backend.tf file. Additional examples are found with the backend doc.
terraform {
backend "remote" {
hostname = "app.terraform.io"
organization = "company"
workspaces {
name = "my-app-prod"
}
}
}
In this example terraform init
would be executed from the commandline to establish connection to the remote backend.
Problem
When a user executes aterraform apply
from the command line interface the following error is returned:
Error: Apply not allowed for workspace with a VCS connection
A workspace that is connected to a VCS requires the VCS-driven workflow to ensure that the VCS remains the single source of truth
Cause
The error is by design and it's the correct response. Terraform Cloud/Enterprise does not allow a command-line driven terraform apply
from the remote backend when a workspace is VCS connected in a VCS driven workflow. See the snippet below as a reference from remote applies doc
Important: You cannot run remote applies in workspaces that are linked to a VCS repository, since the repository serves as the workspace’s source of truth. To apply changes in a VCS-linked workspace, merge your changes to the designated branch.
Solutions:
When a workspace is configured with a VCS connection, the configuration from the VCS connection is the only one that can be applied. When a terraform plan
is executed from the command-line, the local configuration is pushed to the TFE workspace where theterraform apply
takes place.
- A
terraform apply
from the command-line using terraform is possible, but the VCS connection must be removed. - Use alternative run workflows such as CLI driven or API run workflows driven types that can be a consideration to execute runs within Terraform Cloud.
Additional Information
- For additional assistance please contact HashiCorp Support to request additional assistance.