Set up and maintain an ElastiCache Redis instance on Amazon Linux using Terraform for infrastructure as code (IaC) automation.
Description: Installed Terraform on an Amazon Linux EC2 instance to manage and automate AWS infrastructure.
Commands:
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
sudo yum -y install terraform
Description: Created a Terraform configuration file to define the AWS provider, ElastiCache subnet group, and Redis cluster. Ensured the configurations matched the actual AWS environment.
File: main.tf
provider "aws" {
region = "us-east-2" // Ensure the region matches your subnet's AZ
}
resource "aws_elasticache_subnet_group" "example" {
name = "redis-subnet-group"
subnet_ids = ["subnet-0b313bf9dfbc70934"] // Your actual subnet ID
}
resource "aws_elasticache_cluster" "example" {
cluster_id = "syed-redis-cluster"
engine = "redis"
node_type = "cache.t3.micro" // Adjust as needed
num_cache_nodes = 1
parameter_group_name = "default.redis6.x"
subnet_group_name = aws_elasticache_subnet_group.example.name
security_group_ids = ["sg-0b8875bcfc87fc22b"] // Your security group ID
port = 6379
engine_version = "6.x"
tags = {
Name = "SyedRedisCluster"
}
}
Description: Initialized the Terraform working directory and applied the configuration to provision the ElastiCache Redis instance on AWS.
Commands:
-
Initialize Terraform
terraform init
-
Apply the Terraform Configuration
terraform apply
- Confirmed by typing
yes
to apply the configuration.
- Confirmed by typing
Description: Verified the successful creation and deployment of the ElastiCache Redis cluster.
Verification Steps:
- Checked the AWS Management Console under the ElastiCache section to ensure the Redis cluster was created successfully.
Description: Connected to the Redis cluster using the Redis CLI from the EC2 instance to ensure connectivity and functionality.
Steps:
-
Install Redis CLI
sudo yum install redis
-
Connect to Redis
redis-cli -h <redis-endpoint> -p 6379 -a <password>
Successfully set up and maintained an ElastiCache Redis instance on Amazon Linux using Terraform. This project showcased the use of infrastructure as code (IaC) to automate and manage AWS resources, ensuring reproducibility and scalability.