Skip to main content
Glama

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
NameRequiredDescriptionDefault
directoryYesDirectory containing Terraform files

Implementation Reference

  • 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}`);
      }
    }
  • 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"],
      },
    },
  • 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}`);
      }
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/batu-sonmez/infraclaude'

If you have feedback or need assistance with the MCP directory API, please join our Discord server