Generating Terraform infrastructure
Draft reviewable Terraform modules with sane variables, outputs and remote state — then validate before anything touches an account.
IntermediateCOMMUNITY ANALYSISTerraformOpenTofuCloud
Prompt
Write a Terraform module for {resource}. Use variables for every environment-specific value, provide outputs, tag all resources, and include a README with a usage example. Do not hardcode credentials or region. Target Terraform >= 1.6.Problem
Infrastructure code is written under deadline and reviewed lightly, which is how drift and open security groups happen.
Scenario
A team needs a repeatable module for a service's networking and storage footprint.
Architecture
- Module + example directory
- Remote state with locking
- Plan-only CI on pull requests
Why Bob?
Module scaffolding, variable plumbing and README examples are mechanical. Human judgement stays on the network and IAM design.
Prompt
Substitute {resource} with the concrete infrastructure you need.Bob Workflow
- Ask clarifying questions about provider and region strategy
- Emit module, variables, outputs and example
- Explain each IAM permission requested
Generated Result
A module that passes `terraform validate` and `tflint`, with an example that plans cleanly.
Validation
- `terraform validate`
- `tflint` and `checkov`
- Plan against a sandbox account
Security
Review every IAM policy by hand. Generated policies trend towards wildcards.
Lessons Learned
- Always ask for a README example — it exposes bad variable design immediately
- Never let generated code run `apply` unattended
Resources
- Terraform module registry conventions