This repo is having Terraform script that automates the creation of an Amazon Elastic Kubernetes Service (EKS) cluster and RDS instance on AWS. The script covers the following key components:
-
AWS Configuration in Terraform:
- Ensure you have an AWS account and have created an IAM user with administrator permissions.
- Generate the Access Key ID and Secret Access Key for this IAM user.
-
Jenkins Integration with AWS:
- Add the IAM user's Access Key ID and Secret Access Key as Jenkins credentials.
- In the Jenkinsfile, set these credentials as environment variables.
Example Jenkinsfile snippet:
pipeline { agent any environment { AWS_ACCESS_KEY_ID=credentials('aws_access_key') AWS_SECRET_ACCESS_KEY=credentials('aws_access_key_value') } }
-
Terraform State Management:
- The Terraform state file is stored in an S3 bucket for better collaboration and consistency across your team.
- Ensure that you have configured the AWS provider with the necessary credentials.
Example Terraform Configuration:
terraform { backend "s3" { bucket = "terraform-statefile-s3-aws" key = "state/eks-cluster.tfstate" region = "us-east-2" } }
-
EKS cluster creation
- EKS Cluster:
- VPC and 2 public subnets are created for the EKS cluster.
- IAM roles are created and attached to the the
AmazonEKSClusterPolicy
. - The EKS cluster is created utilizing the specified IAM roles and VPC.
- Node Group:
- EKS Cluster:
-
RDS Instance creation
- Creating an AWS RDS instance with Terraform involves setting up a VPC, two public subnets in different zones, and a database subnet group.
- The RDS instance, specifically for MySQL, is configured using Terraform, defining details like instance ID, username, and password.
- Additionally, a security group is established to permit all required incoming connections, ensuring accessibility to the RDS instance.
- Setup Terraform:
- Install Terraform locally
- Terraform steps :
-
Terraform init -- This initiates the download of required providers.
-
Terraform plan -- This command reveals the anticipated resources that will be created.
-
terraform apply -- This command parameterized within the pipeline, can be chosen to be executed or skipped, It results in the creation of resources in AWS.
-
Terraform destroy -- This command, which can be customized in the pipeline, lets you decide whether to run it or not. If executed, it starts cleaning up resources.