CLI-driven runs with HCP Terraform allow you to execute Terraform operations from your local command line while leveraging HCP Terraform's powerful backend features for state management, collaboration, and governance.
When using CLI-driven runs, you configure your Terraform project to use HCP Terr…CLI-driven runs with HCP Terraform allow you to execute Terraform operations from your local command line while leveraging HCP Terraform's powerful backend features for state management, collaboration, and governance.
When using CLI-driven runs, you configure your Terraform project to use HCP Terraform as a remote backend. This is accomplished by adding a cloud block or backend configuration in your Terraform configuration files. Once configured, commands like 'terraform plan' and 'terraform apply' are executed through HCP Terraform's infrastructure rather than on your local machine.
The workflow begins when you run Terraform commands locally. Your CLI sends the configuration to HCP Terraform, which then performs the actual execution in a secure, isolated environment. The output streams back to your terminal in real-time, providing a familiar experience while benefiting from centralized execution.
Key benefits of CLI-driven runs include:
1. **Centralized State Management**: State files are stored securely in HCP Terraform, enabling team collaboration and preventing state file conflicts.
2. **Consistent Environment**: Operations run in HCP Terraform's controlled environment, ensuring consistency across team members regardless of their local setups.
3. **Policy Enforcement**: Sentinel policies and cost estimation can be applied to all runs, maintaining governance standards.
4. **Audit Trail**: All operations are logged in HCP Terraform, providing visibility into who made changes and when.
5. **Secure Variable Storage**: Sensitive variables are stored encrypted in HCP Terraform rather than locally.
To enable CLI-driven runs, set the execution mode to 'remote' or 'cloud' in your workspace settings. You must authenticate using 'terraform login' to establish credentials.
This approach combines the convenience of local development with enterprise-grade features, making it ideal for teams transitioning from local Terraform usage to a more collaborative, governed workflow while maintaining familiar command-line interactions.
CLI-Driven Runs with HCP Terraform: Complete Guide
Why CLI-Driven Runs Matter
CLI-driven runs are essential for teams transitioning from local Terraform workflows to HCP Terraform (formerly Terraform Cloud). They allow you to maintain familiar command-line habits while gaining the benefits of remote state management, collaboration features, and policy enforcement. This hybrid approach bridges local development with centralized infrastructure management.
What Are CLI-Driven Runs?
CLI-driven runs enable you to trigger Terraform operations on HCP Terraform using your local terminal. Instead of running terraform plan and terraform apply locally, these commands are sent to HCP Terraform for remote execution. Your local CLI acts as a trigger, while the actual execution happens in HCP Terraform's managed environment.
How CLI-Driven Runs Work
1. Configuration Setup: Add a cloud block to your Terraform configuration specifying your organization and workspace.
2. Authentication: Run terraform login to authenticate with HCP Terraform and store your API token locally.
3. Initialization: Execute terraform init to connect your local directory to the remote workspace.
4. Triggering Runs: When you run terraform plan or terraform apply, the operation is queued and executed remotely on HCP Terraform.
5. Output Streaming: Results stream back to your terminal in real-time, providing the same feedback as local execution.
- CLI-Driven: Runs triggered from local terminal, best for development and testing - VCS-Driven: Runs triggered by version control commits, best for production pipelines
Important Features
- State is stored remotely in HCP Terraform - Sentinel policies still apply to CLI-triggered runs - Variables can be set in the workspace or passed via CLI - Run history is recorded in HCP Terraform - Team permissions and access controls remain enforced
Exam Tips: Answering Questions on CLI-Driven Runs
1. Remember the cloud block: Questions often test whether you know the correct configuration syntax. The cloud block replaced the older remote backend.
2. Authentication method: Know that terraform login creates and stores an API token in your credentials file.
3. Execution location: Always remember that with CLI-driven runs, execution happens remotely on HCP Terraform, not on your local machine.
4. State management: State is managed remotely when using CLI-driven workflows. Local state files are not created.
5. Policy enforcement: Sentinel policies and run tasks execute during CLI-driven runs, just as they would with VCS-driven runs.
6. Variable precedence: Understand that workspace variables in HCP Terraform can be overridden by CLI flags like -var.
7. Workspace modes: CLI-driven workflows work with both named workspaces and tag-based workspace selection.
8. Common exam scenarios: Questions may present situations where you need to choose between CLI-driven and VCS-driven approaches based on team requirements.
9. Local execution mode: Be aware that workspaces can be configured for local execution, where only state is remote but operations run locally.
10. Speculative plans: CLI-driven runs can produce speculative plans that do not appear in the workspace run queue when using certain flags.