terraform_state_list
List all resources in Terraform state to manage infrastructure configurations and track deployed components.
Instructions
List all resources in the Terraform state
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| directory | Yes | Directory containing Terraform files |
Implementation Reference
- src/tools/terraform/state.ts:6-21 (handler)The handler function that executes 'terraform state list' in the specified directory.
export async function terraformStateList(args: Record<string, unknown>): Promise<string> { const directory = args.directory as string; if (!directory) throw new Error("Terraform directory is required"); try { const { stdout } = await execFileAsync("terraform", ["state", "list"], { cwd: directory, timeout: 30000, }); const resources = stdout.trim().split("\n").filter(Boolean); if (resources.length === 0) return "No resources in Terraform state."; return `Terraform state resources (${resources.length}):\n\n${resources.join("\n")}`; } catch (error: any) { throw new Error(`Terraform state list failed: ${error.stderr || error.message}`); } } - src/tools/terraform/index.ts:19-29 (schema)The input schema definition for the terraform_state_list tool.
{ name: "terraform_state_list", description: "List all resources in the Terraform state", inputSchema: { type: "object" as const, properties: { directory: { type: "string", description: "Directory containing Terraform files" }, }, required: ["directory"], }, }, - src/tools/terraform/index.ts:75-75 (registration)Registration logic mapping the tool name to its handler function within the tool router.
case "terraform_state_list": return terraformStateList(a);