Creating 100...AWS Instance using terraform within a minutes

AMARNAATH HARIAMARNAATH HARI
2 min read

🚀 Spinning Up 100 AWS EC2 Instances in Under a Minute with Terraform

Ever wondered how to launch 100 EC2 instances in under a minute, without clicking through the AWS Console like a maniac? That’s where Terraform and Infrastructure as Code (IaC) shine. Let’s break it down.


🧰 Tools of the Trade

  • AWS – Our cloud provider of choice

  • EC2 (Elastic Compute Cloud) – Virtual machines in the cloud

  • Terraform – IaC tool by HashiCorp for provisioning cloud infrastructure

  • AWS CLI (optional) – For setup and credential configuration

  • ⚙️ Step 1: Set Up Terraform for AWS

    Install Terraform and configure your AWS credentials locally (or use an IAM role if you're deploying from an EC2 instance or CI/CD pipeline).

      aws configure
    

    Make sure you’ve got the necessary permissions: ec2:RunInstances, ec2:DescribeInstances, etc.

  • 🏗️ Step 2: Terraform Configuration – Create 100 Instances

    Here’s a simple Terraform file (main.tf) that will launch 100 EC2 instances using a count meta-argument:

      provider "aws" {
        region = "us-east-1"
      }
    
      resource "aws_instance" "bulk_launch" {
        count         = 100
        ami           = "ami-0c02fb55956c7d316"  # Amazon Linux 2 AMI (example)
        instance_type = "t2.micro"
    
        tags = {
          Name = "TerraformInstance-${count.index}"
        }
      }
    

    You can adjust the instance_type and ami ID based on your needs and limits.

    ⚠️ Note: Make sure your EC2 quota (vCPU, instances per region) allows launching 100 instances. You might need to request a service quota increase from AWS beforehand.

    🚀 Step 3: Initialize and Deploy

      terraform init
      terraform apply -auto-approve
    

    Terraform will provision 100 EC2 instances in parallel using its graph-based execution model, dramatically speeding up deployment.


    💰 Cost Awareness

    Even t2.micro instances can add up. Keep an eye on your usage via AWS Cost Explorer or use budget alerts to stay safe.

  • 🧼 Clean Up

    When you're done:

      terraform destroy -auto-approve
    
0
Subscribe to my newsletter

Read articles from AMARNAATH HARI directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

AMARNAATH HARI
AMARNAATH HARI