Skip to content

Stage #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open

Stage #110

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
05cfb9d
Fixing Terraform syntax errors
NarendraSingh2003 Apr 2, 2025
ed9792d
fix error
NarendraSingh2003 Apr 2, 2025
38e0994
fix it
NarendraSingh2003 Apr 2, 2025
76048b4
fix
NarendraSingh2003 Apr 2, 2025
356d070
fix code
NarendraSingh2003 Apr 2, 2025
9d4a6f2
fix the committed
NarendraSingh2003 Apr 2, 2025
73adfb9
test
NarendraSingh2003 Apr 2, 2025
57a15b2
fix code
NarendraSingh2003 Apr 2, 2025
42033e7
Fix: Set Terraform version to 1.6.3 in GitHub Actions
NarendraSingh2003 Apr 2, 2025
1fe3ed3
fix the error
NarendraSingh2003 Apr 2, 2025
c93e9e5
fix the code
NarendraSingh2003 Apr 2, 2025
a52a19e
other error
NarendraSingh2003 Apr 2, 2025
9888b28
fixnext
NarendraSingh2003 Apr 2, 2025
09ca4e2
now done
NarendraSingh2003 Apr 3, 2025
7ef41f9
fixed
NarendraSingh2003 Apr 3, 2025
001ebe0
Formatted terraform.tf using terraform fmt
NarendraSingh2003 Apr 3, 2025
b9ee947
fix now
NarendraSingh2003 Apr 3, 2025
72a00e7
fix the code
NarendraSingh2003 Apr 3, 2025
d7f4344
run the code
NarendraSingh2003 Apr 3, 2025
9557cd1
comiit
NarendraSingh2003 Apr 3, 2025
45d2958
fix the committed
NarendraSingh2003 Apr 3, 2025
3c692a1
correct the code
NarendraSingh2003 Apr 3, 2025
c0eb02d
check the code
NarendraSingh2003 Apr 3, 2025
7e31b0d
now correct
NarendraSingh2003 Apr 3, 2025
3384705
check
NarendraSingh2003 Apr 3, 2025
74cda76
terrafrom apply
NarendraSingh2003 Apr 4, 2025
a3a6bb6
stage test
NarendraSingh2003 Apr 4, 2025
3713305
changed
NarendraSingh2003 Apr 4, 2025
5372703
correct regins
NarendraSingh2003 Apr 4, 2025
9339cfd
commit
NarendraSingh2003 Apr 4, 2025
0662dcd
correct
NarendraSingh2003 Apr 4, 2025
cd0eea4
regian
NarendraSingh2003 Apr 4, 2025
2043848
Changes
NarendraSingh2003 Apr 4, 2025
cdc3b83
correct
NarendraSingh2003 Apr 4, 2025
0a6ca2b
...
NarendraSingh2003 Apr 4, 2025
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
62 changes: 62 additions & 0 deletions .github/workflows/terrafrom.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: "Vprofile IAC"
on:
push:
branches:
- main
- stage
paths:
- terraform/**
pull_request:
branches:
- main
paths:
- terraform/**

env:
# Credentials for deployment to AWS
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# S3 bucket for the Terraform state
BUCKET_TF_STATE: ${{ secrets.BUCKET_TF_STATE}}
AWS_REGION: us-east-1 # Update this to the correct region if needed
EKS_CLUSTER: vprofile-eks

jobs:
terraform:
name: "Apply terraform code changes"
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: ./terraform

steps:
- name: Checkout source code
uses: actions/checkout@v4

- name: Setup Terraform with specified version on the runner
uses: hashicorp/setup-terraform@v2

- name: Terraform init
id: init
run: terraform init -backend-config="bucket=$BUCKET_TF_STATE"

- name: Terraform format
id: fmt
run: terraform fmt -check

- name: Terraform validate
id: validate
run: terraform validate

- name: Terraform plan
id: plan
run: terraform plan -no-color -input=false -out planfile
continue-on-error: true

- name: Terraform plan status
if: steps.plan.outcome == 'failure'
run: exit 1

- name: Update kubeconfig
run: aws eks update-kubeconfig --region $AWS_REGION --name $EKS_CLUSTER
69 changes: 62 additions & 7 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -1,16 +1,71 @@
provider "kubernetes" {
host = module.eks.cluster_endpoint
cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)
}

provider "aws" {
region = var.region
}

data "aws_availability_zones" "available" {}

locals {
cluster_name = var.clusterName
cluster_name = var.cluster_name
}

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "5.1.2"

name = local.cluster_name
cidr = "172.20.0.0/16"
azs = slice(data.aws_availability_zones.available.names, 0, 3)

private_subnets = [
"172.20.1.0/24",
"172.20.2.0/24",
"172.20.3.0/24"
]

public_subnets = [
"172.20.4.0/24",
"172.20.5.0/24",
"172.20.6.0/24"
]

enable_nat_gateway = true
single_nat_gateway = true
enable_dns_hostnames = true

public_subnet_tags = {
"kubernetes.io/cluster/${local.cluster_name}" = "shared"
"kubernetes.io/role/elb" = 1
}

private_subnet_tags = {
"kubernetes.io/cluster/${local.cluster_name}" = "shared"
"kubernetes.io/role/internal-elb" = 1
}
}

##
module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "20.8.4"

cluster_name = local.cluster_name
cluster_version = "1.29"

subnet_ids = module.vpc.private_subnets
vpc_id = module.vpc.vpc_id

enable_irsa = true

eks_managed_node_groups = {
default = {
instance_types = ["t3.medium"]
desired_size = 2
max_size = 3
min_size = 1
}
}

tags = {
Environment = "dev"
Terraform = "true"
}
}
3 changes: 3 additions & 0 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ output "cluster_security_group_id" {
description = "Security group ID for the Amazon Web Service EKS Cluster "
value = module.eks.cluster_security_group_id
}


##
14 changes: 5 additions & 9 deletions terraform/terraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,32 @@ terraform {
source = "hashicorp/aws"
version = "~> 5.25.0"
}

random = {
source = "hashicorp/random"
version = "~> 3.5.1"
}

tls = {
source = "hashicorp/tls"
version = "~> 4.0.4"
}

cloudinit = {
source = "hashicorp/cloudinit"
version = "~> 2.3.2"
}

kubernetes = {
source = "hashicorp/kubernetes"
version = "~> 2.23.0"
}
}

backend "s3" {
bucket = "gitopsterrastate"
bucket = "gitops2003"
key = "terraform.tfstate"
region = "us-east-2"
}

required_version = "~> 1.6.3"
required_version = ">=1.6.3, <=1.11.3"
}
##
##
##


######
7 changes: 5 additions & 2 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ variable "region" {
default = "us-east-2"
}

variable "clusterName" {
variable "cluster_name" {
description = "Name of the EKS cluster"
type = string
default = "kitops-eks"
default = "vprofile-eks"
}


##