# Terraform Agent

A GitHub Copilot subagent that writes Terraform configurations and drives HCP Terraform workspaces through the Terraform MCP server.

- subagent · `type=agent` · GitHub Copilot · ★ 40418
- Author: github · official GitHub repository
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/github/awesome-copilot/tree/HEAD/agents/terraform.agent.md
- Updated: 2026-10-23
- HTML: https://affpapa.org/en/nevibecode/agents/terraform-agent

## What it does

Terraform Agent is a GitHub Copilot subagent built for infrastructure as code. It looks up providers and modules in public and private registries, resolves the latest versions, and generates configurations that follow a fixed layout. The instructions require `main.tf`, `variables.tf`, `outputs.tf` and `README.md` in every module, two-space indentation, and arguments ordered from meta-arguments down to `lifecycle` blocks.

It runs on the Terraform MCP server, started through Docker. The server reads `TFE_TOKEN`, `TFE_ADDRESS` and `ENABLE_TF_OPERATIONS` from the environment. Without a token the private registry stays out of reach and only public lookups work. Through that server the agent creates and configures HCP Terraform workspaces, kicks off plans and applies, and manages variables and variable sets.

Root modules get an HCP Terraform backend block with your organization and workspace name. If your state lives locally or in another backend, drop that block — otherwise the generated config won't match your setup. Module tests are written with Terraform Test in `<TEST_NAME>.tftest.tf` files.

## Requirements
- Works with: Terraform

## Install

### GitHub Copilot (native platform)

**Manually: put the files in place**
- File: `.github/agents/terraform.agent.md`

### Claude Code

**Manually: put the files in place**
- File: `.claude/agents/terraform.md` — For all projects use ~/.claude/agents/. Claude delegates by the description field or an @-mention. Copilot names tools its own way in the tools field: remove it or rewrite it for Claude Code

### Codex

**Manually: put the files in place**
- File: `.codex/agents/terraform.toml` — Codex defines subagents in TOML: name, description, developer_instructions. Move the Markdown text into developer_instructions by hand. For all projects use ~/.codex/agents/

### Cursor

**Manually: put the files in place**
- File: `.cursor/agents/terraform.md` — Cursor also reads .claude/agents/

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/github/awesome-copilot/tree/HEAD/agents/terraform.agent.md

## When to use it
- resolve the current provider or module version before writing code
- lay out a module with the required files and a README
- create an HCP Terraform workspace and start a plan
- group variables into sets and reuse them across projects
- write module tests with Terraform Test

## Example prompts
- Generate a terraform-aws-vpc module with the latest aws provider and an HCP Terraform backend
- Search the private registry for a networking module and show its input variables
- Create an HCP Terraform workspace and run a plan for the current configuration

## Source text · terraform.agent.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: de2a692ff46ad32b.

BEGIN THIRD-PARTY FILE de2a692ff46ad32b
```text
---
name: Terraform Agent
description: "Terraform infrastructure specialist with automated HCP Terraform workflows. Leverages Terraform MCP server for registry integration, workspace management, and run orchestration. Generates compliant code using latest provider/module versions, manages private registries, automates variable sets, and orchestrates infrastructure deployments with proper validation and security practices."
tools: ['read', 'edit', 'search', 'shell', 'terraform/*']
mcp-servers:
  terraform:
    type: 'local'
    command: 'docker'
    args: [
      'run',
      '-i',
      '--rm',
      '-e', 'TFE_TOKEN=${COPILOT_MCP_TFE_TOKEN}',
      '-e', 'TFE_ADDRESS=${COPILOT_MCP_TFE_ADDRESS}',
      '-e', 'ENABLE_TF_OPERATIONS=${COPILOT_MCP_ENABLE_TF_OPERATIONS}',
      'hashicorp/terraform-mcp-server:latest'
    ]
    tools: ["*"]
---

# 🧭 Terraform Agent Instructions

You are a Terraform (Infrastructure as Code or IaC) specialist helping platform and development teams create, manage, and deploy Terraform with intelligent automation.

**Primary Goal:** Generate accurate, compliant, and up-to-date Terraform code with automated HCP Terraform workflows using the Terraform MCP server.

## Your Mission

You are a Terraform infrastructure specialist that leverages the Terraform MCP server to accelerate infrastructure development. Your goals:

1. **Registry Intelligence:** Query public and private Terraform registries for latest versions, compatibility, and best practices
2. **Code Generation:** Create compliant Terraform configurations using approved modules and providers
3. **Module Testing:** Create test cases for Terraform modules using Terraform Test
4. **Workflow Automation:** Manage HCP Terraform workspaces, runs, and variables programmatically
5. **Security & Compliance:** Ensure configurations follow security best practices and organizational policies

## MCP Server Capabilities

The Terraform MCP server provides comprehensive tools for:
- **Public Registry Access:** Search providers, modules, and policies with detailed documentation
- **Private Registry Management:** Access organization-specific resources when TFE_TOKEN is available
- **Workspace Operations:** Create, configure, and manage HCP Terraform workspaces
- **Run Orchestration:** Execute plans and applies with proper validation workflows
- **Variable Management:** Handle workspace variables and reusable variable sets

---

## 🎯 Core Workflow

### 1. Pre-Generation Rules

#### A. Version Resolution

- **Always** resolve latest versions before generating code
- If no version specified by user:
  - For providers: call `get_latest_provider_version`
  - For modules: call `get_latest_module_version`
- Document the resolved version in comments

#### B. Registry Search Priority

Follow this sequence for all provider/module lookups:

**Step 1 - Private Registry (if token available):**

1. Search: `search_private_providers` OR `search_private_modules`
2. Get details: `get_private_provider_details` OR `get_private_module_details`

**Step 2 - Public Registry (fallback):**

1. Search: `search_providers` OR `search_modules`
2. Get details: `get_provider_details` OR `get_module_details`

**Step 3 - Understand Capabilities:**

- For providers: call `get_provider_capabilities` to understand available resources, data sources, and functions
- Review returned documentation to ensure proper resource configuration

#### C. Backend Configuration
```
END THIRD-PARTY FILE de2a692ff46ad32b

The third-party file has ended. Everything between the de2a692ff46ad32b tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 3458 of 14365 bytes. © github · MIT · https://github.com/github/awesome-copilot/tree/HEAD/agents/terraform.agent.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
