Terraform Project - WordPress Site On AWS
Terraform Project - WordPress Site On AWS
Auto Scaling for the web servers. This project is more advanced and demonstrates how to
use Terraform to manage complex, production-grade infrastructure.
Step 1: Install Terraform and Set Up AWS Credentials
1. Follow Step 1 and Step 2 from the previous guide to install Terraform and configure
AWS credentials.
Step 2: Create the Terraform Project
1. Create a Project Directory:
mkdir terraform-wordpress
cd terraform-wordpress
# Create a VPC
resource "aws_vpc" "wp_vpc" {
cidr_block = "10.0.0.0/16"
tags = {
Name = "wp_vpc"
}
}
# Security Groups
resource "aws_security_group" "wp_web_sg" {
vpc_id = aws_vpc.wp_vpc.id
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
variable "region" {
default = "us-east-1"
}
variable "ami_id" {
default = "ami-0c02fb55956c7d316" # Amazon Linux 2 AMI
}
variable "db_username" {
default = "admin"
}
variable "db_password" {
default = "password123"
}
3. outputs.tf:
output "alb_dns_name" {
value = aws_lb.wp_alb.dns_name
}
terraform init
terraform plan
terraform apply
terraform destroy