All Posts

generate terraform from description

Generate Terraform Code from Plain English Descriptions (AI-Powered IaC)

How to use AI to generate Terraform code from natural language descriptions — covering the prompt-to-IaC workflow, what AI handles today, and how to structure your infrastructure descriptions for maximum accuracy.

March 6, 202612 min readBy Sudarshan

Generate Terraform Code from Plain English Descriptions (AI-Powered IaC)

Writing Terraform from scratch for a new system looks something like this:

Day 1: VPC, subnets, routing tables, internet gateway, NAT gateway.
Day 2: Security groups, ALB, target groups, ECS cluster, task definitions.
Day 3: RDS, ElastiCache, S3, CloudFront, IAM roles, policies, instance profiles.
Day 4: Review, fix errors, debug state file issues, argue about module structure.

Four days of infrastructure work before you've written a single line of application logic.

The promise of AI-powered IaC is to generate Terraform from a description — compressing days of manual work into minutes of intelligent automation. This post explains what's real today, what's still in progress, and how to structure your infrastructure descriptions to get the most accurate output.


What Is Infrastructure as Code (IaC)?

Infrastructure as Code treats your cloud configuration like software — version-controlled, reviewable, repeatable. Instead of clicking through the AWS console, you write declarative configuration files that define what resources should exist.

Terraform is the most widely used IaC tool. A Terraform file describing an S3 bucket looks like:

resource "aws_s3_bucket" "static_assets" {
  bucket = "myapp-static-assets-prod"

  tags = {
    Environment = "production"
    ManagedBy   = "terraform"
  }
}

resource "aws_s3_bucket_versioning" "static_assets" {
  bucket = aws_s3_bucket.static_assets.id
  versioning_configuration {
    status = "Enabled"
  }
}

resource "aws_s3_bucket_server_side_encryption_configuration" "static_assets" {
  bucket = aws_s3_bucket.static_assets.id
  rule {
    apply_server_side_encryption_by_default {
      sse_algorithm = "AES256"
    }
  }
}

Notice that even "just an S3 bucket" is actually 3 resources (bucket, versioning, encryption) — and this doesn't include the bucket policy, CORS configuration, or lifecycle rules you'll likely need.

This verbosity is why generating Terraform from description is such a high-leverage capability.


What AI Handles Well Today

1. Architectural Blueprint Generation

The hardest part of writing Terraform isn't the syntax — it's knowing what to write. Which instance type? Which database engine version? What's the correct CIDR block for this subnet? How many replicas?

AI architecture tools like SudarshanAI solve this layer first — they take your plain English description and produce a complete, decision-resolved architectural specification. Instead of starting with a blank .tf file, you start with:

Compute: ECS Fargate, 4 tasks, 2 vCPU / 4GB RAM, auto-scaling on CPU > 70%
Database: RDS PostgreSQL 15, db.r6g.xlarge, Multi-AZ, 500GB gp3 storage
Cache: ElastiCache Redis 7, cache.r6g.large, 2 read replicas
Network: VPC 10.0.0.0/16, 2 public subnets, 2 private subnets, NAT Gateway x2
CDN: CloudFront with S3 origin, TTL 86400

That specification maps almost 1:1 to Terraform resource types. The cognitive work — the architectural decisions — is done. The Terraform is largely transcription at that point.

2. Security Configuration Generation

AI is particularly useful for generating IAM policies with least-privilege scoping. This is tedious to write manually:

resource "aws_iam_role_policy" "ecs_task_policy" {
  name = "ecs-task-s3-policy"
  role = aws_iam_role.ecs_task_role.id

  policy = jsonencode({
    Version = "2012-10-17"
    Statement = [
      {
        Effect = "Allow"
        Action = [
          "s3:GetObject",
          "s3:PutObject",
          "s3:DeleteObject"
        ]
        Resource = "arn:aws:s3:::myapp-static-assets-prod/*"
      },
      {
        Effect = "Allow"
        Action = [
          "s3:ListBucket"
        ]
        Resource = "arn:aws:s3:::myapp-static-assets-prod"
      }
    ]
  })
}

An AI that understands your architecture knows which S3 actions your ECS tasks need and can generate this policy correctly.


The Manual vs. AI-Assisted IaC Workflow

Traditional Manual Workflow

Requirements → Architecture decision (2+ days) → Write Terraform (3-5 days) 
→ Code review (1 day) → Fix mistakes → Apply in staging → Debug → Apply in prod

Total time from requirements to first terraform apply: 1-2 weeks
Risk of missing resources: High (human memory)
Risk of insecure default configs: High (easy to miss encryption flags, public access blocks)

AI-Assisted Workflow

Requirements → AI architecture generation (60 seconds) → Review blueprint (30 min)
→ Transcribe to Terraform (2-4 hours) → Code review (30 min) → Apply

Total time from requirements to first terraform apply: ~1 day
Risk of missing resources: Low (AI generates complete specifications)
Risk of insecure default configs: Lower (AI includes security recommendations)

The time savings calculation:

PhaseManualAI-AssistedTime Saved
Architecture decisions2-3 days1 hour~90%
Terraform authoring3-5 days2-4 hours~80%
Security review4-8 hours1-2 hours~70%
Total6-9 days~1 day~85%

How To Structure Your Infrastructure Description

The quality of AI-generated architecture (and by extension, the quality of Terraform you derive from it) depends directly on the quality of your description. Here's the template I use:

SYSTEM: [What the application does in one sentence]

SCALE:
- Peak QPS/RPS: [number]
- Concurrent users: [number]  
- Data volume: [GB/TB]

STACK:
- Backend: [language and framework]
- Database: [preferred type or leave for AI to decide]
- Cache: [yes/no and use case]

CONSTRAINTS:
- Regions: [primary and failover]
- Budget: [$X/month]
- Compliance: [HIPAA/PCI-DSS/SOC2 or none]

SPECIFIC REQUIREMENTS:
- [any non-negotiable architectural requirement]

Example:

SYSTEM: Real-time collaborative document editor (like Notion)

SCALE:
- Peak QPS: 5,000
- Concurrent users: 50,000 (50k WebSocket connections)
- Data volume: 2TB documents

STACK:
- Backend: Node.js + Express
- Database: PostgreSQL (documents) + Redis (real-time sync)
- Cache: Yes — operational transforms, user presence

CONSTRAINTS:
- Regions: AWS us-east-1 primary, eu-west-1 failover
- Budget: $6,000/month
- Compliance: SOC2 Type II required

SPECIFIC REQUIREMENTS:
- WebSocket connections must be persistent (stateful load balancing)
- All document data must be encrypted at rest and in transit
- PITR (point-in-time recovery) for database required

From this description, you can derive a Terraform specification that covers:

  • NLB instead of ALB (sticky sessions for WebSockets)
  • EKS with session affinity instead of ECS (better for stateful connections)
  • Aurora PostgreSQL with PITR enabled
  • ElastiCache Redis with cluster mode for 50k connection state
  • TLS everywhere with ACM certificates
  • KMS key for database encryption

What's Coming: Direct Terraform Export

SudarshanAI currently generates the architectural blueprint layer — the complete specification that answers all architectural questions. This is the hardest part — the part where you need to know that 50,000 WebSocket connections requires NLB + session affinity, not ALB.

Direct Terraform export from the blueprint is in development. The blueprint already contains every decision that Terraform needs — compute type, instance size, database config, networking, IAM roles — so the translation is mostly mechanical at that point.

Until Terraform export ships, the current workflow is: use SudarshanAI to make all architectural decisions, then write Terraform against that specification. You've eliminated the research and decision-making phase — the most time-consuming part.


Practical Starting Points

Here are three sample prompts to try:

Simple API backend:

Node.js REST API, 500 QPS peak, PostgreSQL 100GB, Redis cache, 
AWS us-east-1, $500/month budget.

ML inference pipeline:

Python FastAPI serving PyTorch models, 200 req/s inference, 
GPU inference required, model registry in S3, Redis for 
request deduplication. AWS, $3,000/month.

Multi-region e-commerce:

E-commerce platform, 10,000 QPS peak, PostgreSQL global tables,
Redis sessions, Stripe payments (PCI-DSS required), 
AWS us-east-1 + eu-west-1, $8,000/month.

Each of these produces a complete architectural specification you can directly transcribe to Terraform — or use as the architectural ground truth for your IaC review.


Try It Free

Try SudarshanAI Free

Turn any infrastructure idea into a production-ready blueprint in 60 seconds. No signup, no credit card.

Generate Your Blueprint →
Generate Terraform Code from Plain English Descriptions (AI-Powered IaC) | SudarshanAI | SudarshanAI