Terraform (AWS) Generator — Free Online Tool

Generate Terraform HCL configuration for AWS, Azure, GCP. EC2, S3, VPC, Lambda, Kubernetes. Infrastructure as Code (IaC) templates. Copy-paste ready.

Use this free online Terraform (AWS) Generator directly in your browser. No signup required, no data leaves your device. Part of Utilier — a collection of 133+ developer utilities.

What is Terraform Configuration Generator (AWS, Azure, GCP)?

Terraform configuration generator creates Infrastructure as Code (IaC) templates in HashiCorp Configuration Language (HCL) for AWS, Azure, Google Cloud Platform (GCP), and other cloud providers. Select resource type (EC2 instance, S3 bucket, VPC, Lambda function, Kubernetes cluster, RDS database) and configure options (region, instance type, tags, network settings). Tool generates Terraform HCL code ready to run with terraform apply. Includes: provider configuration (AWS credentials, Azure subscription), resource definitions (aws_instance, azurerm_virtual_machine, google_compute_instance), variables (parameterize configs), outputs (resource IDs, IPs), and modules (reusable components). Useful for learning Terraform, deploying cloud infrastructure, or automating cloud resource management.

  • Multi-cloud support: AWS (EC2, S3, VPC, Lambda, RDS), Azure (Virtual Machines, Storage, AKS), GCP (Compute Engine, Cloud Storage, GKE). Unified syntax across clouds.
  • Resource templates: Pre-configured resources: EC2 instance (with security group, key pair), S3 bucket (versioning, encryption), VPC (subnets, internet gateway), Lambda (function code, IAM role), RDS (database, backup).
  • Variables and outputs: Parameterize configs with variables (var.region, var.instance_type). Export outputs (instance IP, bucket ARN) for reference in other modules.
  • Best practices: Includes tags (Name, Environment, Terraform=true), remote backend (S3 state storage), encryption (S3 server-side encryption), IAM roles (least privilege).
  • Copy-paste ready: Generate main.tf, variables.tf, outputs.tf. Copy to project directory, run terraform init && terraform plan && terraform apply.

Why use Terraform?

Writing Terraform configuration manually is time-consuming and error-prone (syntax errors, missing dependencies, security misconfigurations). This tool generates production-ready configs.

  • Avoid syntax errors: HCL syntax is strict (indentation, brackets, commas). Tool validates syntax and generates correct HCL. No more 'unexpected token' errors.
  • Learn Terraform: See how to define resources (aws_instance, azurerm_virtual_machine), use variables (var.region), and configure providers (AWS credentials). Great for beginners.
  • Save time: No need to search Terraform docs for resource attributes or examples. Tool generates configs instantly based on your needs.
  • Infrastructure as Code (IaC): Manage cloud resources with code (version control, code review, automation). No manual clicking in AWS console. Terraform applies changes programmatically.
  • Multi-cloud portability: Similar syntax for AWS, Azure, GCP. Learn once, deploy anywhere. Easier to migrate between clouds or use multi-cloud (AWS + GCP).
  • Best practices built-in: Tool adds tags (Name, Environment), encryption (S3 SSE), IAM roles (least privilege), remote state (S3 backend). Security and organization by default.

When to use Terraform

Use whenever you need to deploy or manage cloud infrastructure with Terraform.

  • Deploying AWS EC2 instances (web servers, app servers, bastion hosts) with security groups.
  • Creating S3 buckets (static websites, file storage, backups) with encryption and versioning.
  • Setting up VPCs (subnets, route tables, internet gateways) for network isolation.
  • Deploying Lambda functions (serverless APIs, event processing) with IAM roles.
  • Provisioning RDS databases (PostgreSQL, MySQL) with backups and multi-AZ.
  • Creating Kubernetes clusters (EKS, AKS, GKE) for container orchestration.
  • Learning Terraform syntax and Infrastructure as Code (IaC) principles.

How to use Terraform

Select cloud provider and resource type, configure options, generate HCL.

  1. Choose cloud provider: Select AWS, Azure, or GCP. Different resources and syntax for each provider.
  2. Select resource type: AWS: EC2, S3, VPC, Lambda, RDS, EKS. Azure: Virtual Machine, Storage, AKS. GCP: Compute Engine, Cloud Storage, GKE.
  3. Configure resource settings: Set region (us-east-1, eastus, us-central1), instance type (t3.micro, Standard_B2s, e2-micro), tags (Name, Environment), network settings.
  4. Add provider configuration: AWS: region, credentials (access_key, secret_key, or IAM role). Azure: subscription_id, tenant_id. GCP: project_id, credentials_file.
  5. Set variables (optional): Parameterize configs: var.region, var.instance_type. Edit variables.tf to change values without modifying main.tf.
  6. Generate Terraform files: Click Generate to get main.tf (resource definitions), variables.tf (input variables), outputs.tf (exported values), provider.tf (provider config).
  7. Run Terraform commands: Save files to directory. Run: terraform init (install providers), terraform plan (preview changes), terraform apply (create resources). Confirm with 'yes'.

Key features

  • Multi-cloud support: AWS, Azure, GCP. Unified syntax (HCL) across clouds. Learn once, deploy anywhere.
  • Resource templates: EC2, S3, VPC, Lambda, RDS, Kubernetes (EKS, AKS, GKE). Pre-configured with best practices.
  • Variables and outputs: Parameterize with variables (var.region). Export outputs (instance_ip, bucket_arn) for reuse.
  • Provider configuration: AWS credentials (access_key, secret_key, or IAM role), Azure subscription, GCP project. Secure credential management.
  • Tags and metadata: Auto-add tags: Name, Environment, Terraform=true. Helps organization and cost tracking.
  • Security best practices: S3 encryption (SSE-S3, SSE-KMS), IAM roles (least privilege), VPC security groups (restrict traffic).
  • Copy-paste ready: Generate main.tf, variables.tf, outputs.tf, provider.tf. Copy to project, run terraform apply.

Common use cases

  • Deploy EC2 instance (AWS): AWS EC2 t3.micro in us-east-1. Security group allows SSH (port 22) and HTTP (port 80). Key pair for SSH access. Output: instance public IP.
  • Create S3 bucket (AWS): S3 bucket with versioning, server-side encryption (SSE-S3), public access blocked. Tags: Name=my-bucket, Environment=production.
  • Setup VPC (AWS): VPC with 2 subnets (public, private), internet gateway (public subnet), route tables. Enable DNS hostnames. Output: VPC ID, subnet IDs.
  • Deploy Lambda function (AWS): Lambda function (Node.js, Python) with IAM role, environment variables, CloudWatch Logs. Trigger: API Gateway or S3 event.
  • Provision RDS database (AWS): RDS PostgreSQL 13 (db.t3.micro), multi-AZ for high availability, automated backups (7 days), encryption at rest.
  • Create Kubernetes cluster (EKS): AWS EKS cluster with managed node group (3 nodes, t3.medium), IAM roles for pods, VPC CNI plugin. Output: cluster endpoint, kubeconfig.

Examples

Terraform configuration examples.

AWS EC2 instance (Ubuntu)

Provider: AWS, Resource: EC2, AMI: Ubuntu 22.04, Instance: t3.micro, Region: us-east-1
resource "aws_instance" "web" { ami = "ami-0c55b159cbfafe1f0" instance_type = "t3.micro" tags = { Name = "web-server" }
}
output "instance_ip" { value = aws_instance.web.public_ip
}

Creates EC2 instance. Output: public IP. Run: terraform apply, then terraform output instance_ip to get IP.

AWS S3 bucket (encrypted, versioned)

Provider: AWS, Resource: S3, Bucket: my-bucket, Versioning: enabled, Encryption: SSE-S3
resource "aws_s3_bucket" "data" { bucket = "my-bucket" versioning { enabled = true } server_side_encryption_configuration { rule { apply_server_side_encryption_by_default { sse_algorithm = "AES256" } } }
}

Creates S3 bucket with versioning and encryption. Best practices: block public access, enable logging.

AWS VPC with subnets

Provider: AWS, Resource: VPC, CIDR: 10.0.0.0/16, Subnets: 10.0.1.0/24 (public), 10.0.2.0/24 (private)
resource "aws_vpc" "main" { cidr_block = "10.0.0.0/16" tags = { Name = "main-vpc" }
}
resource "aws_subnet" "public" { vpc_id = aws_vpc.main.id cidr_block = "10.0.1.0/24" tags = { Name = "public-subnet" }
}

Creates VPC and subnet. Add internet gateway, route tables for full setup. Reference vpc_id with aws_vpc.main.id.

AWS Lambda function (Python)

Provider: AWS, Resource: Lambda, Runtime: Python 3.11, Function: hello.py, Handler: index.handler
resource "aws_lambda_function" "hello" { filename = "hello.zip" function_name = "hello" role = aws_iam_role.lambda.arn handler = "index.handler" runtime = "python3.11"
}

Creates Lambda function. Requires: hello.zip (code), IAM role (execution permissions), CloudWatch Logs.

GCP Compute Engine instance

Provider: GCP, Resource: Compute Engine, Machine: e2-micro, Zone: us-central1-a, Image: Debian 11
resource "google_compute_instance" "vm" { name = "my-vm" machine_type = "e2-micro" zone = "us-central1-a" boot_disk { initialize_params { image = "debian-cloud/debian-11" } } network_interface { network = "default" }
}

Creates GCP VM. Similar syntax to AWS but different provider (google instead of aws).

Technical reference

Terraform configuration structure (HCL syntax):

HCL syntax
HashiCorp Configuration Language. Declarative (describe desired state, not steps). Structure: resource 'type' 'name' { attribute = value }. Example: resource 'aws_instance' 'web' { ami = 'ami-123' }.
Provider block
Configures cloud provider: provider 'aws' { region = 'us-east-1' access_key = var.aws_access_key secret_key = var.aws_secret_key }. Or use IAM role (recommended for security).
Resource block
Defines cloud resource: resource 'aws_instance' 'web' { ami = 'ami-123' instance_type = 't3.micro' tags = { Name = 'web-server' } }. Terraform creates/updates/deletes resources to match config.
Variables
Parameterize configs: variable 'region' { default = 'us-east-1' }. Reference with var.region. Allows reuse without hardcoding values. Set via terraform.tfvars or CLI.
Outputs
Export values: output 'instance_ip' { value = aws_instance.web.public_ip }. View with terraform output. Used by other modules or scripts.
Data sources
Query existing resources: data 'aws_ami' 'latest' { most_recent = true owners = ['amazon'] }. Reference with data.aws_ami.latest.id. Useful for dynamic lookups.
Modules
Reusable components: module 'vpc' { source = './modules/vpc' region = var.region }. Encapsulate resources (VPC module creates subnets, gateways, routes). DRY (Don't Repeat Yourself).
State file
Tracks current infrastructure state (terraform.tfstate). Stores resource IDs, attributes. Used to plan changes (compare desired vs current state). Store in S3 with locking (DynamoDB) for teams.
Terraform commands
terraform init (install providers), terraform plan (preview changes), terraform apply (create/update resources), terraform destroy (delete all resources), terraform output (view outputs).
Best practices
Use variables (no hardcoding), remote state (S3 backend), modules (reusable), tags (organization), version pinning (provider version), separate environments (dev, prod).

Common mistakes to avoid

Hardcoding values (region, AMI, credentials) instead of using variables

Why it happens: Hardcoded values make config non-reusable (can't use same config for dev and prod). Example: ami = 'ami-123' breaks when AMI changes or in different region. Common when copy-pasting examples.

How to avoid it: Use variables: variable 'ami' { default = 'ami-123' }. Reference with var.ami. Set via terraform.tfvars or CLI: terraform apply -var='ami=ami-456'. Makes config reusable.

Not using remote state (storing terraform.tfstate locally), causing state conflicts

Why it happens: Local state file (terraform.tfstate) doesn't sync across team members. Multiple people running terraform apply causes conflicts, overwrites, or duplicate resources. State file contains secrets (passwords, keys).

How to avoid it: Use remote backend (S3 + DynamoDB for locking): terraform { backend 's3' { bucket = 'my-terraform-state' key = 'prod/terraform.tfstate' region = 'us-east-1' dynamodb_table = 'terraform-lock' } }. Enables collaboration and locks state during apply.

Running terraform apply without terraform plan, causing unexpected changes or deletions

Why it happens: terraform apply creates/updates/deletes resources to match config. Without plan, you don't see what will change. Common mistake: deleting resource from config = Terraform deletes real resource (data loss).

How to avoid it: Always run terraform plan first. Review changes (+ = create, ~ = update, - = delete). If looks good, run terraform apply. Never apply blindly.

Not pinning provider versions, breaking configs when provider updates

Why it happens: Terraform downloads latest provider version by default. Provider updates can introduce breaking changes (deprecated attributes, renamed resources). Config breaks on next terraform init.

How to avoid it: Pin provider version: terraform { required_providers { aws = { source = 'hashicorp/aws' version = '~> 5.0' } } }. Use ~> (pessimistic constraint) to allow patch updates but not major changes.

Committing terraform.tfstate to git (exposes secrets, causes state conflicts)

Why it happens: State file contains sensitive data (passwords, API keys, resource IDs). Committing to git = exposing secrets. Also causes state conflicts when multiple people push/pull.

How to avoid it: Add terraform.tfstate to .gitignore. Use remote backend (S3) for state storage. NEVER commit state file to version control.

Frequently asked questions

What is Terraform and why use it?

Infrastructure as Code (IaC) tool. Manage cloud resources (AWS, Azure, GCP) with code instead of console clicking. Benefits: version control, automation, reproducibility, multi-cloud support.

What is the difference between terraform plan and terraform apply?

terraform plan = preview changes (dry run, shows what will be created/updated/deleted). terraform apply = execute changes (creates/updates/deletes resources). Always plan before apply.

How do I store Terraform state for a team?

Use remote backend (S3 + DynamoDB for locking): terraform { backend 's3' { bucket = 'my-state' key = 'terraform.tfstate' } }. Enables collaboration and prevents state conflicts.

What are Terraform modules?

Reusable components. Encapsulate resources (e.g., VPC module creates subnets, gateways). Call with: module 'vpc' { source = './modules/vpc' }. DRY (Don't Repeat Yourself).

How do I pass variables to Terraform?

Define: variable 'region' { default = 'us-east-1' }. Set via: terraform.tfvars (region = 'us-west-2'), CLI (terraform apply -var='region=us-west-2'), or environment variable (TF_VAR_region).

What is the difference between Terraform and CloudFormation?

Terraform = multi-cloud (AWS, Azure, GCP), HCL syntax, state file. CloudFormation = AWS only, JSON/YAML, managed by AWS. Terraform is more flexible (multi-cloud), CloudFormation is simpler (AWS-native).

How do I delete resources created by Terraform?

terraform destroy (deletes all resources). Or remove resource from config and run terraform apply (Terraform deletes removed resources). CAUTION: data loss (S3 buckets, RDS databases).

References

Privacy and availability

  • Runs entirely in your browser — zero server processing
  • No signup or account required
  • Works offline once loaded
  • Fast, lightweight, no external dependencies
  • Available as a browser extension for Chrome and Firefox