Skip to content
Open

Dev #21

Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
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('Manual Approval') {
steps {
input message: "Review plan for folder '${env.TF_DIR}'. Proceed with ${params.ACTION}?", ok: 'Proceed'
}
}

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
}
}
}
1 change: 0 additions & 1 deletion eks-install/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ terraform {
bucket = "demo-terraform-eks-state-s3-bucket"
key = "terraform.tfstate"
region = "us-west-2"
dynamodb_table = "terraform-eks-state-locks"
encrypt = true
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Restore Terraform state locking or remove the unused lock table.

eks-install/backend/main.tf still provisions aws_dynamodb_table.terraform_locks, but this backend no longer references it. Unless another locking mechanism is configured, concurrent Jenkins runs can update the same state without coordination, risking state corruption. Re-add dynamodb_table = "terraform-eks-state-locks" or complete an explicit migration to the intended locking mechanism.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@eks-install/main.tf` around lines 12 - 14, Update the Terraform backend
configuration in eks-install/backend/main.tf to reference the existing
terraform_locks DynamoDB table via dynamodb_table = "terraform-eks-state-locks",
restoring state locking for concurrent runs; alternatively, remove the unused
aws_dynamodb_table.terraform_locks resource only if an explicit migration to
another locking mechanism is completed.

}
Expand Down
8 changes: 4 additions & 4 deletions eks-install/variables.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
variable "region" {
description = "AWS region"
type = string
default = "us-west-2"
default = "ap-south-1"
}

variable "vpc_cidr" {
Expand All @@ -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" {
Expand Down Expand Up @@ -53,10 +53,10 @@ 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
}
Expand Down