- Learnwithdevopsengineer
- Posts
- AI Wrote My Terraform Code for AWS S3 โ And It Actually Works! ๐คโจ
AI Wrote My Terraform Code for AWS S3 โ And It Actually Works! ๐คโจ
This isn't a demo. It's working Terraform

Written 90% by AI. Deployed 100% on AWS
๐ 1-Minute Recap
What happens when you let AI write Terraform for real cloud infrastructure?
โ GPT/Mistral generated a working AWS S3 module
โ Terraform
init
,plan
,apply
all succeededโ S3 bucket deployed with versioning
โ ๏ธ Missing: encryption, IAM, lifecycle rules, logging
๐ฅ Full source code + prompt inside.
๐ Who This Is For
You deploy infrastructure using Terraform, AWS, or Azure
Youโre exploring how AI can accelerate DevOps
Youโre curious what works โ and what breaks โ when AI writes your IaC
๐ ๏ธ The Setup: GPT Writes Terraform
I asked GPT/Mistral to generate:
"A clean Terraform module to create an AWS S3 bucket with versioning, variables, and outputs."
It generated this:
๐ ai-terraform-s3-demo/
โโโ main.tf # S3 resource with versioning
โโโ variables.tf # Type-safe variables
โโโ outputs.tf # Bucket name output
I ran:
terraform init terraform plan terraform apply
And it worked perfectly.
๐ Whatโs Missing for Production
AI got 80% right โ but hereโs what youโll still need to add:
โ Encryption โ no SSE config
โ IAM permissions โ no access policies
โ Lifecycle rules โ for cleanup or archival
โ Logging โ no access logging to another bucket
๐ Bottom line: AI is great for scaffolding, but you still own security and compliance.
๐ My Prompting Tips
Want to replicate this?
๐ก Prompt structure I used:
โWrite a Terraform module that creates an AWS S3 bucket with versioning. Include main.tf
, variables.tf
, and outputs.tf
. Use clean naming.โ
๐ง Pro Tip: Be specific with resource, features, and structure โ GPT handles infra better with clear constraints.
๐ฏ Why This Matters
This isn't just a cool AI trick. Itโs a workflow shift.
Saves 30โ60 minutes of manual Terraform writing
Great for prototyping infrastructure modules
Makes onboarding junior engineers faster
And now you have a story to share:
โTell me about a time you used AI in a DevOps projectโฆโ
Now youโve got an answer.
๐ฅ Get the Code + Prompt
Want to see the full AI-generated code and prompt I used?
๐ Subscribe to the newsletter and Iโll send you the repo.
๐ฃ What Should I AI-Generate Next?
Reply and tell me what infra module to generate next:
๐ฆ Azure Blob?
๐ฉ GCP Cloud Storage?
๐จ IAM Roles?
Iโll feature the best replies + generate it live in the next issue.
๐ Help Me Reach More DevOps Engineers
If this helped you:
Forward to your team
Tag @learnwithdevopsengineer
Letโs make DevOps faster, smarter, and AI-powered โ together.
๐ฅ YouTube: @learnwithdevopsengineer
๐ฐ Newsletter Archive: beehiiv.com
#Terraform #AIDevOps #GPT #AWS #CloudEngineering #InfrastructureAsCode