Skip to content

DevSecOpsSamples/eks-terraform

Repository files navigation

EKS sample project with Terraform

Build Quality Gate Status Lines of Code

eks-terraform

Step 1: VPC

Deploy a new VPC:

cd 01-vpc
terraform init
terraform plan
terraform apply

01-vpc/main.tf

Step 2: EKS cluster and nodegroup

Update vpc_id and subnet_ids with VPC module output.

Deploy a new EKS cluster and nodegroup:

cd ../02-eks
terraform init
terraform plan
terraform apply

02-eks/main.tf

Step 3: Update kubectl context

Step 4: Build the SpringBoot Ping API

Build and push to ECR:

cd ../app
./buiid.sh

04-app/build.sh

Step 5: Deploy the API

Create a YAML file for K8s Deployment, Service, HorizontalPodAutoscaler, and Ingress using a template file.

sed -e "s|<account-id>|${ACCOUNT_ID}|g" ping-api-template.yaml | sed -e "s|<region>|${REGION}|g" > ping-api.yaml
cat ping-api.yaml
kubectl apply -f ping-api.yaml

04-app/ping-api-template.yaml

Cleanup

cd 02-eks
terraform destroy

cd ../01-vpc
terraform destroy

find . -name ".terraform" -exec rm -rf {} \;
find . -name "terraform.tfstate" -exec rm -rf {} \;
find . -name ".terraform.lock.hcl" -exec rm -rf {} \;

Reference