Use Cases
Common Use Cases
- Infrastructure provisioning
- Environment management
- Drift detection
- Cost estimation before apply
Before You Begin
Prerequisites
- AWS account with programmatic access
- Terraform CLI installed
- S3 bucket for state storage
- Understanding of IaC concepts
Walkthrough
Step-by-Step Guide
1
Configure Terraform Backend
Set up Terraform with an S3 backend for remote state and DynamoDB for state locking.
2
Connect AWS MCP Server
Configure with IAM credentials that have permissions for the resources you'll manage.
3
Plan Changes
Run Terraform plan to preview what will change before applying.
async function planInfra(workspace) {
const plan = await terraform.plan({ workspace });
const summary = `${plan.add} to add, ${plan.change} to change, ${plan.destroy} to destroy`;
await slack.sendMessage({ channel: "#infra", text: `📋 Terraform Plan (${workspace}):\n${summary}` });
return plan;
}4
Apply with Approval
Require human approval in Slack before applying infrastructure changes.
5
Verify Resources
After apply, use AWS MCP Server to verify resources were created correctly.
async function verifyResources(expectedResources) {
for (const resource of expectedResources) {
const exists = await aws.describeResource({ type: resource.type, id: resource.id });
if (!exists) throw new Error(`Resource not found: ${resource.type}/${resource.id}`);
}
}Examples
Code Examples
typescript
Drift Detection
async function detectDrift(workspace) {
const plan = await terraform.plan({ workspace, detailedExitcode: true });
if (plan.hasChanges) {
await slack.sendMessage({
channel: "#infra-alerts",
text: `⚠️ Infrastructure drift detected in ${workspace}:\n${plan.changes.map(c => `- ${c.address}: ${c.action}`).join("\n")}`
});
}
}Help
Troubleshooting
How do I handle state conflicts?+
What if apply fails halfway?+
Quick Info
DifficultyAdvanced
Time Estimate2 hours
Tools
Terraform MCP ServerAWS MCP Server