GitLab | Simple CICD Pipeline Project to Deploy AWS Infrastructure using Terraform!

Project Overview

Goal

The primary objective of this project is to deploy a ec2 instance in a secure single-tier architecture using IAC code (Terraform) through Gitlab CI pipeline.

Pre-Requisites

Before starting the deployment, ensure you have the following:

  • Sign up for an Amazon Web Services (AWS) Free Tier account.

  • Create IAM role with EC2 and s3 full admin role access

  • Get aws access key and secret key

  • Gitlab Account and Repository

Folder structure

Deployment

  • Create new bucket in s3 and add bucket name in backend.tf file
terraform {
  backend "s3" {
   bucket = "aws-ec2-creation-tfstate"
   region="us-east-1"
   key="terrform.tfstate"
}
  }
  • Add aws access key and secret key in GitLab repository environment variable setting> CICD> variable

  • Create GitLab account token from below path and add in environment variable setting > access tokens> project access tokens> add token

  • Create .gitlab-ci.yml file and write pipeline code as mentioned in file

  • Commit the changes to main branch

Validation

  • check the aws account and verify ec2 and s3 created

  • Ensure ec2 accessible from outside of aws

AWS Single Tier architecture Diagram

The complete CICD pipeline code is available in GitLab repo .

0
Subscribe to my newsletter

Read articles from Ilayaraja Veerakalai directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ilayaraja Veerakalai
Ilayaraja Veerakalai

DevOps Engineer with a strong background in Configuration Management and support roles, skilled in tools like AWS, Docker, Kubernetes, Terraform, and Ansible. I focus on automating processes, improving system performance, and making networks scalable and secure in cloud environments.