Today in my #30DaysOfTerraform challenge, I explored two key areas:
I scaled a web server cluster using count
in Terraform to spin up multiple EC2 instances based on demand.
resource "aws_instance" "web" {
count = var.instance_count
ami = var.ami_id
instance_type = var.instance_type
...
}
I deployed an Application Load Balancer (ALB) to distribute traffic across my cluster, increasing availability and resilience.
I learned how Terraform uses a terraform.tfstate
file to track infrastructure. When I deleted an instance manually from AWS, Terraform tried to recreate it — showing the importance of not manually changing cloud resources outside of Terraform.
Block | Description | Example |
---|---|---|
resource |
Declares infrastructure (e.g., EC2, VPC) | resource "aws_instance" "web" {...} |
variable |
Inputs to parametrize configurations | variable "instance_type" {...} |
output |
Returns useful values | output "web_ip" {...} |
provider |
Specifies the provider (e.g., AWS) | provider "aws" {...} |
module |
Reusable group of resources | module "web_cluster" {...} |
Always let Terraform manage your infrastructure to avoid state drift. Manual changes to resources should be avoided!
#30DaysOfTerraform #IaC #DevOps #AWS #Terraform