Build a CICD pipeline using Gitlab, Terraform and Aws.
In this article we will explore on the reusable CICD pipeline for any resoure that can be provisioned on AWS cloud. In this Article we will build the pipeline for aws S3 storage service and enabling and disabling its lifecycle configuration.
Source code repo :
Note :
please change bucket name in variable .the code will work for you.
Jaffarterraform786/Gitlab-CicD-s3 (github.com)
Procedure:
- Structure of S3 module:
S3 is a global service. A bucket is a region-specific service.
S3 lifecycle use case:
Let's say we have a newspaper website; they are hosting it on S3. when the news is flash news or fresh news, they need to access the data immediately. if news become old, they need to move data from one storage class to other storage class. this use case we will be implementing through S3 lifecycle rules and storage classes with CICD pipeline.
S3 Storage classes:
In our pipeline script when we enable s3 lifecycle rules the data will move from S3 Standard to Glacier .
we will creating the following resources in the pipeline.
- S3 Bucket.
- Enable logs
- Enable server-side Encryption.
- Enable Lifecycle Rules.
- Enable ACL
- Enable Versioning
CICD Configurations:
GitLab offers a location for online code storage and capabilities for issue tracking and CI/CD.
What is CICD :
“A continuous integration and continuous deployment (CI/CD) pipeline is a series of steps that must be performed in order to deliver a new version of software. CI/CD pipelines are a practice focused on improving software delivery throughout the software development life cycle via automation.”
Creating a Fresh project:
Goto project and create a new project
create a new repository and upload the files.
Source code is available in below repository.
Jaffarterraform786/Gitlab-CicD-s3 (github.com)
Gitlab Runner:
1. GitLab Runner is open-source and written in Go.
2. GitLab Runner is an application that works with GitLab CI/CD to run jobs in a pipeline.
3. GitLab Runner can also run inside a Docker container or be deployed into a Kubernetes cluster.
Shared runners:
Shared runners are available to every project in a GitLab instance.
Specific Runners :
Use specific runners when you want to use runners for specific projects. For example, when you have:
- Jobs with specific requirements, like a deploy job that requires credentials.
- Projects with a lot of CI activity that can benefit from being separate from other runners.
Configuring Environment variables:
Goto Settings ……………..>> Variables …….
CICD pipeline stages :
- Checkov :
- Init
- validate
- plan
- Apply
- Destroy.
Checkov stage :
Checkov is a static code analysis tool for scanning infrastructure as code (IaC) files for misconfigurations that may lead to security or compliance problems.
Checkov helps to detect violations and naming rules errors for the infrastructure if it is not defined as per the company naming standards .
we are allowing failure for this stage so that even the stage fails the next stages will execute.
Init & validate & plan stage :
In init stage it downloads the plugins and in valiadte stage it checks for synatax errors and in plan stage it shoiws the reaources to be provisioned.
we are saving the plan in a file by name planfile.
In the show stage we will be viewing the resources plan file .and in apply stage we are adding a manual interfer for provisioning the resources.
the final CICD pipeline to be run now..
go to
CICD in deployments …..> pipelines