Synopsis
Execute a Terraform plan on Harness servers using remote execution. This command uploads your local Terraform code, executes it remotely using the configured default pipeline, and streams logs back to your terminal in real-time.Description
Theplan command performs a Terraform plan operation remotely:
- Fetches workspace configuration from Harness
- Packages your local Terraform code based on workspace folder path settings
- Uploads the code to Harness with SHA-256 checksum verification
- Triggers the default pipeline configured for plan operations
- Streams execution logs in real-time
- Shows the pipeline execution URL for tracking in the Harness UI
The plan runs on Harness infrastructure, not locally. This means you don’t need Terraform installed on your machine.
Flags
Required Flags
Workspace identifier to execute the plan in. The workspace must exist in the specified organization and project.
Optional Flags
Organization identifier. If not specified, uses the organization from your global configuration (set via
--org flag or config file).Project identifier. If not specified, uses the project from your global configuration (set via
--project flag or config file).Resource targets to plan. Can be specified multiple times. Corresponds to Terraform’s
-target flag. Use this to limit the plan to specific resources.Variable replacements in
key=value format. Can be specified multiple times. These are passed as custom arguments to the Terraform execution.Global Flags
See Global Flags for flags available to all commands, including:--api-url- API base URL--token- Authentication token--account- Account identifier--org- Organization identifier (can be overridden by--org-id)--project- Project identifier (can be overridden by--project-id)--format- Output format--verbose/-v- Enable verbose logging
Examples
Basic Plan Execution
- Use organization and project from your saved configuration
- Upload code based on workspace’s repository path
- Stream logs to your terminal
Plan with Specific Organization and Project
Plan Specific Resources
-target aws_instance.web_server -target aws_lb.main to Terraform.
Plan with Variable Replacements
Plan with Verbose Logging
Workflow Details
1. Workspace Validation
The command first fetches workspace details:- Repository path (determines what code to upload)
- Default pipelines (which pipeline to execute)
- Terraform version and provider configuration
2. Default Pipeline Selection
The command looks for a default pipeline in this order:- Workspace-level
planpipeline - Project-level
planpipeline
3. Source Code Packaging
Based on the workspace’srepository_path configuration:
If repository path is configured (e.g., terraform/aws):
You’ll be prompted to confirm before upload:
4. Upload and Execution
- Zipped using the same format as HashiCorp’s slug package
- Uploaded with SHA-256 checksum verification
- Stored securely on Harness servers
5. Log Streaming
- Shows stages and steps as they execute
- For running steps: streams logs in real-time via SSE
- For completed steps: fetches and displays logs immediately
- Continues until pipeline completes
Logs are formatted with level, timestamp, and message for easy reading.
6. Interruption Handling
PressCtrl+C to interrupt:
- Stop streaming logs
- Clean up resources
- Exit gracefully
Remote Execution Details
Architecture
When you runhc iacm plan:
-
Client Side (your machine):
- Packages source code
- Uploads to Harness
- Streams logs
-
Harness Side (remote):
- Receives and stores code
- Triggers pipeline execution
- Runs Terraform on secure infrastructure
- Streams logs back to client
Security
- Source code is transmitted over HTTPS
- SHA-256 checksum verifies integrity
- Authentication token required for all operations
- Separate log service token for streaming
- Code is isolated per execution
Pipeline Integration
The remote execution:- Uses the default pipeline configured in your workspace
- Can access workspace environment variables
- Runs with workspace’s Terraform version
- Has access to workspace’s provider credentials
- Stores state according to workspace configuration
Troubleshooting
Error: workspace-id is required
Error: workspace-id is required
The
--workspace-id flag is mandatory. Provide the identifier of the workspace to execute the plan in:Error: The workspace has no configured default pipeline
Error: The workspace has no configured default pipeline
Configure a default pipeline for plan operations:
- Go to your workspace settings in Harness UI
- Navigate to Default Pipelines section
- Set a pipeline for “plan” operations
Error: The folder path configured in the workspace does not exist
Error: The folder path configured in the workspace does not exist
The workspace’s Option 2: Update the workspace’s repository path in Harness UI
repository_path doesn’t exist in your current directory:Option 1: Navigate to the correct directoryError: Not logged in. Please run 'hc auth login' first
Error: Not logged in. Please run 'hc auth login' first
You need to authenticate with Harness:Or provide credentials via flags:
Error: Failed to get log token
Error: Failed to get log token
The log service token retrieval failed. This can happen if:
- Your authentication token has expired
- You don’t have permission to access log service
- There’s a network connectivity issue
Pipeline execution not starting after 5 seconds
Pipeline execution not starting after 5 seconds
The pipeline didn’t start within the expected time. Possible causes:
- Harness is experiencing high load
- Pipeline is queued behind other executions
- Pipeline configuration has errors
Logs not streaming
Logs not streaming
If logs aren’t appearing:
- Check the pipeline execution URL in Harness UI to verify it’s running
- Verify your network allows SSE connections
- Try running with
--verboseto see detailed connection info - Check if your firewall blocks the log service endpoint
Exit Codes
0- Plan completed successfully1- Error occurred (authentication, network, API error, etc.)
The exit code reflects whether the CLI operation succeeded, not whether Terraform found changes. Check the plan output and pipeline execution URL for Terraform results.
See Also
- IACM Overview - Overview of IACM commands
- Global Flags - Flags available to all commands
- Authentication - Setting up authentication