Home › Terraform › Terraform Copilot instructions

Terraform Copilot instructions

Copilot instructions for Terraform 1.x / OpenTofu infrastructure: modules, state safety, variables, and plan review.

GitHub CopilotTerraform

How to use

Save this as .github/copilot-instructions.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

.github/copilot-instructions.mdDownload  
# Terraform / OpenTofu instructions

## Commands
- `terraform fmt -recursive` · `terraform init -backend=false && terraform validate` · `tflint` · `checkov -d .` or `trivy config .` if configured.
- Only run `terraform plan` when credentials are present. Never run `apply`, `destroy`, `state rm`, `import` or `taint` unless the user explicitly asks.

## Layout
- `modules/<name>/` with `main.tf`, `variables.tf`, `outputs.tf`, `versions.tf`, `README.md`.
- `envs/<env>/` root modules call shared modules; no copy-pasted resources across envs.
- Pin `required_version` and provider versions with `~>` in `versions.tf`; commit `.terraform.lock.hcl`.

## Code rules
- Every variable has `type` and `description`; add `validation` blocks for constrained values. Mark secrets `sensitive = true`.
- Use `for_each` with maps over `count` for collections that can change, so resources aren't recreated on reorder.
- Name resources by role (`aws_s3_bucket.uploads`), not `this`/`main`, except in single-resource modules.
- Tag everything via provider `default_tags` (or the cloud's equivalent).
- Data sources instead of hard-coded IDs/ARNs.
- Encryption, private access and least-privilege IAM by default; no `0.0.0.0/0` ingress or `*` actions without a comment explaining why.
- Renaming a resource requires a `moved {}` block so state isn't destroyed.

## In PRs
Summarize the plan: resources added, changed, and especially destroyed or replaced.

More: all Terraform rules · all GitHub Copilot rules

Related rules

Dockerfile Copilot path instructions

Path-specific Copilot instructions for Dockerfiles and compose files: multi-stage builds, non-root, and pinned images.

GitHub CopilotDocker

GitHub Actions Copilot path instructions

Path-specific Copilot instructions for .github/workflows YAML: least privilege, pinned actions, and injection-safe steps.

GitHub CopilotGitHub Actions

Ansible Windsurf rules

Windsurf rules for Ansible playbooks and roles: FQCN modules, idempotency, check mode, vault secrets, and ansible-lint.

WindsurfAnsible

AWS CDK (TypeScript) CLAUDE.md

CLAUDE.md for AWS CDK v2 apps in TypeScript: constructs, least-privilege grants, snapshot tests, and safe deploys.

Claude Code (CLAUDE.md)AWS CDK

Docker & Compose AGENTS.md

AGENTS.md for containerized projects: lean multi-stage Dockerfiles, Docker Compose for local dev, and image security.

AGENTS.mdDocker

GitHub Actions workflow rules

Cursor rules for writing secure, fast GitHub Actions workflows: permissions, pinning, caching, and concurrency.

CursorGitHub Actions

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.