Terraform module prompt for infrastructure as code

Generate a clean, reusable Terraform module from plain requirements, with variables, outputs, tagging, security defaults and a usage example.

Published
Works with
ChatGPT, Claude and Gemini
Level
Advanced
By
GoodAIPromt editorial team

Writing Terraform from scratch means remembering resource arguments, wiring variables and outputs, and not forgetting security basics such as encryption and least-privilege access. This Terraform module prompt turns a plain-language description of the infrastructure you need into a structured, reusable module with sensible defaults, comments and a usage example, and points out what you should review before running terraform apply.

The prompt

Act as a senior DevOps engineer. Write a reusable Terraform module.

Cloud provider and region: 
Terraform and provider versions: 
What the module should create: 
Environments: 
Naming and tagging rules: 
Security requirements: 
State backend: 

Provide:
1. File structure (main.tf, variables.tf, outputs.tf, versions.tf, README.md).
2. Full code for each file with comments explaining non-obvious choices.
3. Variables with types, descriptions, validation rules and safe defaults; no hard-coded secrets.
4. Outputs other modules will need.
5. A root-module usage example for dev and prod.
6. Security defaults applied (encryption, blocked public access, least-privilege IAM) and anything I must decide myself.
7. Commands to run: init, fmt, validate, plan, and what to check in the plan output.
8. Rough cost drivers to watch.

Use only resources and arguments that exist in the stated provider version; if unsure about an argument, say so instead of guessing.

0 of 7 blanks filled

How to use it

  1. Pin your provider version in the prompt so the code matches your setup.
  2. Run terraform validate and plan and read the plan carefully before applying.
  3. Test in a dev account first, never straight in production.

Tips

  • Ask for a tflint or checkov configuration to catch issues automatically.
  • Keep secrets in a secrets manager and reference them; never put them in variables files.

Frequently asked questions

What does this prompt do?

Generate a clean, reusable Terraform module from plain requirements, with variables, outputs, tagging, security defaults and a usage example.

Which AI tools does it work with?

It is written for ChatGPT, Claude and Gemini. It also works in other AI tools that accept text prompts, with small changes.

What do I need to fill in?

7 blanks: e.g. aws eu-west-1 / gcp / azure; e.g. terraform >= 1.6, aws provider ~> 5.0; e.g. a private s3 bucket with versioning and lifecycle rules / a vpc with public and private subnets / a container service behind a load balancer; dev / staging / prod differences; conventions; encryption, public access, iam, logging; and more. Click each blue blank on the page, type your details and press Copy prompt.

Is this prompt free to use?

Yes. You can copy and use it for personal and commercial work.

terraforminfrastructure as codedevopscloud

More prompts for ChatGPT, Claude, Gemini.