Manage IaCM
Configure Terraform workspaces, drift detection, change approval workflows, and cost estimation in Harness Infrastructure as Code Management.
Instructions
Step 1: Establish Scope
Confirm the user's org, project, cloud provider, and environments.
Call MCP tool: harness_list
Parameters:
resource_type: "project"
org_id: "<organization>"
Step 2: Identify the IaCM Task
Determine which workflow the user needs:
- Workspace and State Management -- Workspace structure, remote state, RBAC, module registry
- Drift Detection -- Continuous drift scanning with remediation workflows
- Change Approval Workflows -- Risk-based approval tiers for infrastructure changes
- Cost Estimation -- Pre-deployment cost impact analysis using Infracost
Step 3: Configure Workspaces and State Management
Gather from the user:
- Cloud provider (AWS, GCP, Azure, multi-cloud)
- Environments to manage (dev, staging, prod)
- Workspace naming convention (e.g., {project}-{env}-{region})
- State backend preference (S3+DynamoDB, GCS+Firestore, Azure Blob, Harness built-in)
Design workspace structure:
- One workspace per environment per account
- Remote state backend with encryption at rest and state locking
- State backup with versioning and configurable retention
- RBAC: Developer=plan only, Senior Dev=plan+apply to dev, Team Lead=staging, DevOps=all with prod approval
Configure module registry:
- Semantic versioning for modules
- Security scanning before module publication (Checkov, tfsec, Terrascan)
- Approval workflow for new module versions
Step 4: Set Up Drift Detection
Gather from the user:
- Environments to monitor
- Scan frequency (hourly, every 6 hours, daily)
- Resources to exclude from drift scanning
Configure drift detection:
- Compare actual cloud resources against Terraform state on schedule
- Detect additions, deletions, and modifications outside Terraform control
- Classify drift by severity: critical (security group changes, IAM), warning (tags, descriptions), info (metadata)
Remediation workflows:
- Auto-remediate low-risk drift (tag corrections, description updates)
- Alert and create ticket for medium-risk drift
- Page on-call for critical drift (security-related changes)
Step 5: Design Change Approval Workflows
Gather risk categories from the user:
- Low risk (e.g., tag changes, scaling adjustments) -- auto-apply after peer review
- Medium risk (e.g., new resources, config changes) -- team lead approval
- High risk (e.g., security groups, IAM, database changes) -- security team + CAB approval
- Emergency (break-glass) -- post-implementation review required
Call MCP tool: harness_create
Parameters:
resource_type: "pipeline"
org_id: "<organization>"
project_id: "<project>"
body:
pipeline:
name: "terraform-change-approval"
identifier: "terraform_change_approval"
stages:
- stage:
name: Plan
type: CI
spec:
# terraform plan + output change summary
- stage:
name: Cost Estimate
type: CI
spec:
# infracost diff
- stage:
name: Approval
type: Approval
spec:
# risk-based approval routing
- stage:
name: Apply
type: CI
spec:
# terraform apply
Step 6: Estimate Infrastructure Costs
When asked for cost estimation:
- Identify the workspace and pending Terraform changes (PR or plan output)
- Run Infracost analysis on the plan
Present a cost report with:
- Current monthly cost vs. projected monthly cost
- Per-resource cost breakdown for new/modified resources
- Cost optimization recommendations (right-sizing, reserved instances)
- Budget impact assessment
Examples
- "Set up Terraform workspaces for our AWS environments" -- Configure workspace structure with state management and RBAC
- "Enable drift detection for production infrastructure" -- Set up scheduled scanning with severity classification and remediation
- "Create an approval workflow for infrastructure changes" -- Design risk-based approval tiers with security review for high-risk changes
- "How much will this Terraform change cost?" -- Run Infracost analysis and present cost impact report
- "Configure our Terraform module registry" -- Set up versioned module registry with security scanning
Performance Notes
- Workspace naming conventions should be established early -- renaming workspaces requires state migration.
- Drift detection scans should avoid peak hours to minimize API rate limit conflicts.
- Cost estimation accuracy depends on Infracost having pricing data for all resource types in use.
- Change approval workflows should include a break-glass path for emergencies -- blocking all changes can be as dangerous as no controls.
Troubleshooting
State Locking Conflicts
- Check for stuck locks from failed runs -- use
terraform force-unlock cautiously
- Verify the state backend (DynamoDB, Firestore) is accessible from the runner
Drift Detection False Positives
- Exclude resources managed by auto-scaling groups or Kubernetes operators
- Add ignore rules for metadata fields that change frequently (last-modified timestamps)
- Verify the scan is running against the correct workspace/state file
Cost Estimation Missing Resources
- Infracost may not support all resource types -- check supported resource list
- Ensure the Terraform plan output includes all changed resources
- Custom modules may need explicit cost annotations
1---2name: manage-iacm3description: Manage Harness Infrastructure as Code Management (IaCM) via MCP. Configure Terraform workspaces with remote state and RBAC, set up continuous drift detection with auto-remediation, design multi-tier change approval workflows, and estimate infrastructure costs before deployment. Use when asked to manage Terraform workspaces, detect infrastructure drift, set up approval workflows for infrastructure changes, or estimate Terraform costs. Do NOT use for creating Harness infrastructure definitions (use create-infrastructure instead) or OPA policies (use create-policy instead). Trigger phrases: terraform, workspace, drift detection, infrastructure cost, IaCM, state management, change approval, terraform plan, infracost, infrastructure governance.4license: Apache-2.05---67# Manage IaCM89Configure Terraform workspaces, drift detection, change approval workflows, and cost estimation in Harness Infrastructure as Code Management.1011## Instructions1213### Step 1: Establish Scope1415Confirm the user's org, project, cloud provider, and environments.1617```18Call MCP tool: harness_list19Parameters:20 resource_type: "project"21 org_id: "<organization>"22```2324### Step 2: Identify the IaCM Task2526Determine which workflow the user needs:27281. **Workspace and State Management** -- Workspace structure, remote state, RBAC, module registry292. **Drift Detection** -- Continuous drift scanning with remediation workflows303. **Change Approval Workflows** -- Risk-based approval tiers for infrastructure changes314. **Cost Estimation** -- Pre-deployment cost impact analysis using Infracost3233### Step 3: Configure Workspaces and State Management3435Gather from the user:36- Cloud provider (AWS, GCP, Azure, multi-cloud)37- Environments to manage (dev, staging, prod)38- Workspace naming convention (e.g., {project}-{env}-{region})39- State backend preference (S3+DynamoDB, GCS+Firestore, Azure Blob, Harness built-in)4041Design workspace structure:42- One workspace per environment per account43- Remote state backend with encryption at rest and state locking44- State backup with versioning and configurable retention45- RBAC: Developer=plan only, Senior Dev=plan+apply to dev, Team Lead=staging, DevOps=all with prod approval4647Configure module registry:48- Semantic versioning for modules49- Security scanning before module publication (Checkov, tfsec, Terrascan)50- Approval workflow for new module versions5152### Step 4: Set Up Drift Detection5354Gather from the user:55- Environments to monitor56- Scan frequency (hourly, every 6 hours, daily)57- Resources to exclude from drift scanning5859Configure drift detection:60- Compare actual cloud resources against Terraform state on schedule61- Detect additions, deletions, and modifications outside Terraform control62- Classify drift by severity: critical (security group changes, IAM), warning (tags, descriptions), info (metadata)6364Remediation workflows:65- Auto-remediate low-risk drift (tag corrections, description updates)66- Alert and create ticket for medium-risk drift67- Page on-call for critical drift (security-related changes)6869### Step 5: Design Change Approval Workflows7071Gather risk categories from the user:72- Low risk (e.g., tag changes, scaling adjustments) -- auto-apply after peer review73- Medium risk (e.g., new resources, config changes) -- team lead approval74- High risk (e.g., security groups, IAM, database changes) -- security team + CAB approval75- Emergency (break-glass) -- post-implementation review required7677```78Call MCP tool: harness_create79Parameters:80 resource_type: "pipeline"81 org_id: "<organization>"82 project_id: "<project>"83 body:84 pipeline:85 name: "terraform-change-approval"86 identifier: "terraform_change_approval"87 stages:88 - stage:89 name: Plan90 type: CI91 spec:92 # terraform plan + output change summary93 - stage:94 name: Cost Estimate95 type: CI96 spec:97 # infracost diff98 - stage:99 name: Approval100 type: Approval101 spec:102 # risk-based approval routing103 - stage:104 name: Apply105 type: CI106 spec:107 # terraform apply108```109110### Step 6: Estimate Infrastructure Costs111112When asked for cost estimation:113- Identify the workspace and pending Terraform changes (PR or plan output)114- Run Infracost analysis on the plan115116Present a cost report with:117- Current monthly cost vs. projected monthly cost118- Per-resource cost breakdown for new/modified resources119- Cost optimization recommendations (right-sizing, reserved instances)120- Budget impact assessment121122## Examples123124- "Set up Terraform workspaces for our AWS environments" -- Configure workspace structure with state management and RBAC125- "Enable drift detection for production infrastructure" -- Set up scheduled scanning with severity classification and remediation126- "Create an approval workflow for infrastructure changes" -- Design risk-based approval tiers with security review for high-risk changes127- "How much will this Terraform change cost?" -- Run Infracost analysis and present cost impact report128- "Configure our Terraform module registry" -- Set up versioned module registry with security scanning129130## Performance Notes131132- Workspace naming conventions should be established early -- renaming workspaces requires state migration.133- Drift detection scans should avoid peak hours to minimize API rate limit conflicts.134- Cost estimation accuracy depends on Infracost having pricing data for all resource types in use.135- Change approval workflows should include a break-glass path for emergencies -- blocking all changes can be as dangerous as no controls.136137## Troubleshooting138139### State Locking Conflicts140- Check for stuck locks from failed runs -- use `terraform force-unlock` cautiously141- Verify the state backend (DynamoDB, Firestore) is accessible from the runner142143### Drift Detection False Positives144- Exclude resources managed by auto-scaling groups or Kubernetes operators145- Add ignore rules for metadata fields that change frequently (last-modified timestamps)146- Verify the scan is running against the correct workspace/state file147148### Cost Estimation Missing Resources149- Infracost may not support all resource types -- check supported resource list150- Ensure the Terraform plan output includes all changed resources151- Custom modules may need explicit cost annotations