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.

Related rules

Angular 20 Copilot instructions

Copilot instructions for Angular 20 apps using standalone components, signals, and the new control flow.

GitHub CopilotAngular

Code review Copilot instructions

Copilot instructions focused on pull request review: what to flag, severity labels, and how to word comments.

GitHub CopilotAgent workflows

C# / .NET Copilot path instructions

Path-specific Copilot instructions for C# files on .NET 10: nullable types, async, records, and logging.

GitHub Copilot.NET / ASP.NET Core

Dockerfile Copilot path instructions

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

GitHub CopilotDocker

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.