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.
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.
Configure resource settings: Set region (us-east-1, eastus, us-central1), instance type (t3.micro, Standard_B2s, e2-micro), tags (Name, Environment), network settings.
Add provider configuration: AWS: region, credentials (access_key, secret_key, or IAM role). Azure: subscription_id, tenant_id. GCP: project_id, credentials_file.
Set variables (optional): Parameterize configs: var.region, var.instance_type. Edit variables.tf to change values without modifying main.tf.
Generate Terraform files: Click Generate to get main.tf (resource definitions), variables.tf (input variables), outputs.tf (exported values), provider.tf (provider config).
Run Terraform commands: Save files to directory. Run: terraform init (install providers), terraform plan (preview changes), terraform apply (create resources). Confirm with 'yes'.
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.
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.
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.
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 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).