terraform_plan
Preview infrastructure changes safely before applying them with Terraform. This read-only tool analyzes your configuration to show what modifications would occur.
Instructions
Run terraform plan to preview infrastructure changes (read-only, safe)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| directory | Yes | Directory containing Terraform files |
Implementation Reference
- src/tools/terraform/plan.ts:6-19 (handler)The implementation of the `terraform_plan` tool logic, which executes `terraform plan` using `child_process`.
export async function terraformPlan(args: Record<string, unknown>): Promise<string> { const directory = args.directory as string; if (!directory) throw new Error("Terraform directory is required"); try { const { stdout, stderr } = await execFileAsync("terraform", ["plan", "-no-color", "-input=false"], { cwd: directory, timeout: 120000, }); return `Terraform plan for '${directory}':\n\n${stdout}${stderr ? `\nWarnings:\n${stderr}` : ""}`; } catch (error: any) { throw new Error(`Terraform plan failed: ${error.stderr || error.message}`); } } - src/tools/terraform/index.ts:8-18 (schema)Registration of the `terraform_plan` tool, including its name, description, and input schema.
{ name: "terraform_plan", description: "Run terraform plan to preview infrastructure changes (read-only, safe)", inputSchema: { type: "object" as const, properties: { directory: { type: "string", description: "Directory containing Terraform files" }, }, required: ["directory"], }, }, - src/tools/terraform/index.ts:68-81 (handler)The handler function that routes calls to `terraform_plan` to the appropriate implementation.
export async function handleTerraformTool( name: string, args: Record<string, unknown> | undefined ): Promise<string> { const a = args || {}; switch (name) { case "terraform_plan": return terraformPlan(a); case "terraform_state_list": return terraformStateList(a); case "terraform_state_show": return terraformStateShow(a); case "terraform_output": return terraformOutput(a); case "terraform_validate": return terraformValidate(a); default: throw new Error(`Unknown Terraform tool: ${name}`); } }