diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..8e234bf1 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,64 @@ +pipeline { + agent any + tools { + terraform 'terraform-latest' // Must match the name you set in Manage Jenkins -> Tools + } + + parameters { + choice(name: 'ACTION', choices: ['apply', 'destroy'], description: 'Choose whether to apply or destroy the Terraform EKS module') + } + + environment { + TF_DIR = 'eks-install' + AWS_DEFAULT_REGION = 'ap-south-1' + + // This pulls the two "Secret text" credentials you already created in Jenkins + // using the exact IDs shown in your screenshot ('accesskey' and 'secretaccesskey') + AWS_ACCESS_KEY_ID = credentials('accesskey') + AWS_SECRET_ACCESS_KEY = credentials('secretaccesskey') + } + + stages { + stage('Checkout Code') { + steps { + checkout scm + } + } + + stage('Terraform Init') { + steps { + dir("${env.TF_DIR}") { + sh 'terraform init' + } + } + } + + stage('Terraform Plan') { + steps { + dir("${env.TF_DIR}") { + sh "terraform plan ${params.ACTION == 'destroy' ? '-destroy' : ''} -out=tfplan" + } + } + } + + stage('Terraform Execute') { + steps { + dir("${env.TF_DIR}") { + script { + if (params.ACTION == 'apply') { + sh 'terraform apply -auto-approve tfplan' + } else if (params.ACTION == 'destroy') { + sh 'terraform apply -destroy -auto-approve' + } + } + } + } + } + } + + post { + always { + cleanWs() // Cleans up workspace after execution + } + } +} diff --git a/eks-install/main.tf b/eks-install/main.tf index 3abe1f3d..95b07fb9 100644 --- a/eks-install/main.tf +++ b/eks-install/main.tf @@ -7,11 +7,10 @@ terraform { } backend "s3" { - bucket = "demo-terraform-eks-state-s3-bucket" + bucket = "demo-terraform-eks-state-s3-buckethojabhai" key = "terraform.tfstate" - region = "us-west-2" - dynamodb_table = "terraform-eks-state-locks" - encrypt = true + region = "ap-south-1" + use_lockfile = true } } diff --git a/eks-install/variables.tf b/eks-install/variables.tf index 1d32e287..d02fe1e3 100644 --- a/eks-install/variables.tf +++ b/eks-install/variables.tf @@ -1,7 +1,7 @@ variable "region" { description = "AWS region" type = string - default = "us-west-2" + default = "ap-south-1" } variable "vpc_cidr" { @@ -13,7 +13,7 @@ variable "vpc_cidr" { variable "availability_zones" { description = "Availability zones" type = list(string) - default = ["us-west-2a", "us-west-2b", "us-west-2c"] + default = ["ap-south-1a", "ap-south-1b", "ap-south-1c"] } variable "private_subnet_cidrs" { @@ -37,7 +37,7 @@ variable "cluster_name" { variable "cluster_version" { description = "Kubernetes version" type = string - default = "1.30" + default = "1.31" } variable "node_groups" { @@ -53,13 +53,13 @@ variable "node_groups" { })) default = { general = { - instance_types = ["t3.medium"] + instance_types = ["c7i-flex.large"] capacity_type = "ON_DEMAND" scaling_config = { - desired_size = 2 + desired_size = 1 max_size = 4 min_size = 1 } } } -} \ No newline at end of file +}