Skip to main content
Glama

terraform_validate

Validate Terraform configuration and check formatting to ensure infrastructure code follows best practices before deployment.

Instructions

Validate Terraform configuration and check formatting

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
directoryYesDirectory containing Terraform files

Implementation Reference

  • The implementation of the terraform_validate tool, which executes `terraform validate` and `terraform fmt -check` commands.
    export async function terraformValidate(args: Record<string, unknown>): Promise<string> {
      const directory = args.directory as string;
      if (!directory) throw new Error("Terraform directory is required");
    
      const lines: string[] = [];
    
      // Validate
      try {
        const { stdout } = await execFileAsync("terraform", ["validate", "-json"], {
          cwd: directory,
          timeout: 30000,
        });
        const result = JSON.parse(stdout);
        if (result.valid) {
          lines.push("Validation: PASSED");
        } else {
          lines.push("Validation: FAILED");
          for (const diag of result.diagnostics || []) {
            lines.push(`  ${diag.severity}: ${diag.summary}`);
            if (diag.detail) lines.push(`    ${diag.detail}`);
          }
        }
      } catch (error: any) {
        lines.push(`Validation error: ${error.stderr || error.message}`);
      }
    
      // Format check
      try {
        const { stdout } = await execFileAsync("terraform", ["fmt", "-check", "-diff"], {
          cwd: directory,
          timeout: 30000,
        });
        if (stdout.trim()) {
          lines.push("", "Formatting issues:", stdout);
        } else {
          lines.push("", "Formatting: OK");
        }
      } catch (error: any) {
        if (error.stdout?.trim()) {
          lines.push("", "Formatting issues:", error.stdout);
        } else {
          lines.push("", `Format check error: ${error.message}`);
        }
      }
    
      return lines.join("\n");
    }
  • Registration of the `terraform_validate` tool including its name, description, and input schema.
    {
      name: "terraform_validate",
      description: "Validate Terraform configuration and check formatting",
      inputSchema: {
        type: "object" as const,
        properties: {
          directory: { type: "string", description: "Directory containing Terraform files" },
        },
        required: ["directory"],
      },
    },
  • The dispatch logic within `handleTerraformTool` that routes calls to the `terraform_validate` tool to its handler function.
    case "terraform_validate": return terraformValidate(a);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. While 'validate' and 'check formatting' imply a read-only analysis operation, it doesn't specify whether this tool makes any changes, what permissions are required, whether it's safe to run repeatedly, what happens with invalid configurations, or what the output format looks like. For a tool with zero annotation coverage, this leaves significant behavioral questions unanswered.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise with just two verb phrases that directly convey the core functionality. Every word earns its place, and the structure is front-loaded with the essential information. There's no wasted text or unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's purpose (configuration validation), lack of annotations, and absence of an output schema, the description is insufficiently complete. It doesn't explain what constitutes successful validation versus errors, what specific checks are performed, or what format results are returned in. For a validation tool with no structured output documentation, the description should provide more context about expected outcomes.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100% with the single 'directory' parameter fully documented in the schema. The description doesn't add any parameter-specific information beyond what's already in the schema, but with complete schema coverage, the baseline score of 3 is appropriate as the schema handles the parameter documentation adequately.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verbs ('validate', 'check formatting') and resource ('Terraform configuration'), making it immediately understandable. However, it doesn't explicitly differentiate from sibling tools like terraform_plan or terraform_state_list, which also work with Terraform configurations but serve different purposes.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. There are several Terraform-related sibling tools (terraform_plan, terraform_output, terraform_state_list, terraform_state_show), but the description doesn't indicate whether this should be used before planning, after changes, or in what specific validation context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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