Overview
Harness IACM (Infrastructure as Code Management) provides:- Remote execution of Terraform plans on Harness infrastructure
- Local code upload from your development environment
- Real-time log streaming to monitor execution progress
- Workspace management with configured pipelines
- Variable replacement and resource targeting
- Graceful interruption handling
How It Works
Configure Workspace
Create a workspace in Harness IACM with:
- Default pipeline for plan execution
- Repository path configuration
- Terraform version settings
Quick Start
Command Reference
Basic Usage
With Options
Command Options
Workspace identifier in Harness IACM
Organization identifier (defaults to global config)
Project identifier (defaults to global config)
Resource targets to plan (can be specified multiple times)
Variable replacements in
key=value format (can be specified multiple times)Workspace Configuration
Default Pipeline
Each workspace must have a default pipeline configured for plan operations. The CLI uses this pipeline for remote execution.The default pipeline can be configured at workspace level or project level. Workspace-level pipelines take precedence.
- Plan operation: Terraform init → Terraform plan
- Infrastructure stage: Defines execution environment
- Terraform steps: Run Terraform commands
Repository Path
The workspace can specify a folder path within your repository:- No folder path configured: Uploads current directory
- Folder path configured:
- If current directory ends with folder path → uploads parent directory
- If folder path exists as subdirectory → uploads current directory
- Otherwise → error
Advanced Usage
Resource Targeting
Target specific resources for planning:-target flags to Terraform, limiting the plan to specified resources and their dependencies.
Example output:
Variable Replacement
Override Terraform variables during plan:-replace flags to Terraform, replacing specific variables for this execution.
Use cases:
- Testing different configurations
- Environment-specific values
- Feature flag toggling
- Temporary overrides
Organization and Project Scope
Override default org/project settings:If not specified, org and project IDs are read from global CLI configuration set via
hc config command.Execution Workflow
Step-by-Step Process
1. Fetch Workspace Information
1. Fetch Workspace Information
The CLI retrieves workspace details:
- Default pipeline configuration
- Repository path settings
- Terraform version
- Authentication requirements
2. Validate Directory Structure
2. Validate Directory Structure
The CLI determines what directory to upload based on:
- Current working directory
- Workspace folder path configuration
- Repository structure
3. User Confirmation
3. User Confirmation
You confirm the upload before proceeding:Respond with
y or yes to continue, any other input cancels.4. Zip Source Code
4. Zip Source Code
The CLI packages your directory:
- Respects
.gitignorepatterns - Excludes
.gitdirectory - Compresses for efficient upload
5. Create Remote Execution
5. Create Remote Execution
The CLI creates an execution record in Harness:
- Allocates execution ID
- Prepares upload endpoint
- Configures custom arguments (targets, replacements)
6. Upload Source Code
6. Upload Source Code
The packaged code is uploaded to Harness:
- Uses multipart upload for large files
- Shows upload progress
- Verifies successful transfer
7. Trigger Pipeline
7. Trigger Pipeline
The CLI triggers the workspace’s default pipeline:
- Starts pipeline execution
- Returns execution URL
- Begins log streaming
8. Stream Logs
8. Stream Logs
Execution logs stream to your terminal:
- Follows stage progression
- Shows each step’s output
- Updates in real-time
- Handles stage transitions
Log Streaming Details
The CLI implements intelligent log streaming: Stage Walking:- Polls pipeline execution every 3 seconds
- Discovers active stages in execution graph
- Transitions between stages automatically
- Tracks visited stages to avoid duplication
- Polls stage execution every 1 second
- Identifies active steps within current stage
- Fetches logs for running and completed steps
- Ignores internal orchestration steps
- For running steps: Uses tail API for streaming
- For completed steps: Uses blob API for full logs
- Handles log key extraction from execution nodes
- Manages concurrent log streams for parallel steps
Examples
Basic Plan Execution
Plan with Specific Targets
Plan changes to specific resources:Plan with Variable Overrides
Test configuration with different variables:Multi-Environment Workflow
CI/CD Integration
GitHub Actions
.github/workflows/terraform-plan.yml
GitLab CI
.gitlab-ci.yml
Interrupting Execution
Gracefully stop execution withCtrl+C:
- Stops log streaming immediately
- Cancels context for all operations
- Closes API connections
- Note: Remote execution may continue on server
- Use the Harness UI to abort the pipeline
- Or wait for execution to complete
Troubleshooting
Workspace Not Found
Workspace Not Found
Error:
failed to get workspace: workspace not foundSolutions:- Verify workspace ID is correct
- Check org and project IDs are set correctly
- Ensure you have access to the workspace
- List workspaces in Harness UI to find correct ID
No Default Pipeline
No Default Pipeline
Error:
The workspace has no configured default pipelineSolutions:- Configure default pipeline in workspace settings
- Set plan operation pipeline at workspace or project level
- Ensure pipeline has correct Terraform steps
- Verify pipeline is active and not deleted
Folder Path Not Found
Folder Path Not Found
Error:
The folder path configured in the workspace terraform does not existSolutions:- Check workspace folder path configuration
- Run command from correct directory
- Verify repository structure matches configuration
- Update workspace folder path if moved
Upload Failures
Upload Failures
Error:
failed to upload source codeSolutions:- Check network connectivity
- Verify API key has upload permissions
- Ensure zip file size is within limits
- Try reducing directory size (remove node_modules, etc.)
Log Streaming Stops
Log Streaming Stops
Symptom: Logs stop streaming mid-executionSolutions:
- Check network connection
- Refresh log token if expired
- View logs in Harness UI as fallback
- Restart command to resume streaming
Authentication Errors
Authentication Errors
Error:
401 Unauthorized or failed to get log tokenSolutions:- Verify API key is valid:
hc config get api-key - Check account ID is correct:
hc config get account-id - Regenerate API key in Harness UI
- Ensure service account has IACM permissions
Best Practices
Use .gitignore
Ensure
.gitignore excludes:.terraform/directory*.tfstatefiles.terraform.lock.hcl- Secrets and credentials
Confirm Before Upload
Always review:
- Directory being uploaded
- Files included in zip
- Workspace configuration
- Repository path alignment
n if anything looks wrong.Start with Small Directories
For first-time usage:
- Test with small Terraform projects
- Verify workspace configuration
- Check log streaming works
- Then scale to larger projects
Monitor in Harness UI
While CLI streams logs:
- Open pipeline URL in browser
- Watch execution graph
- Review detailed step logs
- Access plan output files
Use Workspaces Per Environment
Create separate workspaces:
dev-workspacefor developmentstaging-workspacefor stagingprod-workspacefor production
Set Org/Project in Config
Configure once:Avoid repeating in every command.
Integrate with CI/CD
Automate plan execution:
- Run on pull requests
- Comment results on PRs
- Gate merges on clean plans
- Track plan history
Handle Interruptions
If you interrupt:
- Check Harness UI for execution status
- Cancel pipeline if needed
- Rerun if necessary
- Don’t assume it stopped
Limitations
- Plan only: Currently supports plan operations, not apply
- No input prompts: Terraform configurations requiring interactive input will fail
- Limited variable override: Uses replace flags, doesn’t support
.tfvarsfiles - No local execution: All plans run remotely on Harness infrastructure
- Pipeline dependency: Requires pre-configured default pipeline
Next Steps
Configure Workspaces
Set up IACM workspaces in Harness
IACM Commands
View all IACM command options