DEV Community

Oluwademilade Oyekanmi
Oluwademilade Oyekanmi

Posted on

Automating the Provisioning of AWS EKS Cluster Using Terraform and CircleCI

What is CircleCI?

CircleCI is one of the potent tools used for continuous integration and continuous deployment (CI/CD), for those who are unfamiliar. With the aid of CI/CD, a group of ideas, methods, and tools, consumers can receive software updates of any kind in a quick, effective, repeatable, and secure manner.

In the link below, I was able to go into great detail about CI/CD, including what it is, why it is important, and various CI/CD tools.

Jenkins vs CircleCI

What is Terraform?

Terraform is a provisioning management tool that enables infrastructure automation for provisioning, compliance, and management of any cloud, datacenter, and service.

Allocating resources from a cloud service provider to a client is known as cloud provisioning. It specifies how a client acquires resources and cloud services from a supplier, making it a crucial part of cloud computing. It may also be described as the process of automating the management of cloud computing service installation, configuration, and management.

What's Needed

For this tutorial you'll need the following

  1. An AWS account
  2. An access key and secret access key file
  3. An Integrated Development Environment (IDE) of your choice.
  4. A GitHub account
  5. A CircleCI account. You can sign up for a CircleCI account using your GitHub account if you don't already have one.

Step 1: Clone this repository

https://github.com/MsOluwademilade/learn-terraform-eks-circleci

Step 2: Review the CircleCI configuration file

The CircleCI configuration (which was gotten from here) will complete four jobs during the process of automating the Terraform workflow.

1. The “plan-apply” Job:
The image "hashicorp/terraform: light," which, according to HashiCorp, includes a Terraform binary, will be used by this job. The "terraform init" command and the checkout procedures are carried out by this task. A file named "tfapply" will also be created by executing the "terraform plan -out" command.

Image description

2. The “apply” Job:
The "attach_workspace" step in the apply job loads the previously persisted workspace in the "plan" job, according to HashiCorp's description of this task. The "apply" job will execute the "terraform apply" command, which we created in the previous step, to run "tfapply."

Image description

3. The “plan-destroy” Job:
A strategy to destroy the distributed infrastructure is generated by this job.

Image description

4. The “destroy” Job:
The strategy to destroy the infrastructure is carried out in this step of the procedure.

NB: Users are advised by HashiCorp to monitor the "plan-destroy" and "destroy" tasks carefully while they are in operation. Users will be expected to keep tabs on the status of each job despite the possibility of interruptions.

Workflow

The final element of this CircleCI setup is the workflow. It coordinates the sequencing and specifications for each pipeline task. According to HashiCorp, the "plan_approve_apply" workflow follows a sequential process that creates applications for each stage along the way. Therefore, the prior job must have run successfully in order for the current job to run.

Step Three: Set up the project in CircleCI

Since our GitHub and CircleCI accounts are connected, you can already see the forked repository displayed under "Projects." Choose the blue "Set Up Project" button to move to the following page when attempting this project.

Image description

Select "Fastest" on the subsequent screen, then press the "Start Building" button.

Image description

CircleCI will try to execute the jobs inside the pipelines right away, but it will fail. That outcome happened as a consequence of the absence of two essential components for a smooth operation. To continue with our project, we must input our AWS Access Key ID and AWS Secret Access Key in the "Environment Variables" screen and save them.

Use AWS_ACCESS_KEY_ID as the name and enter the value for the Access Key ID. Use AWS_SECRET_ACCESS_KEY as the name and enter the value for the Secret Access Key.

Image description

The name of the project that is currently in focus, the pipeline's job statuses, the workflow, the repo branch/commit, and settings are all shown on the accompanying screen by CircleCI. Start the project.

Step Four: Destroy your resources

Image description

In a later article, I'll decsribe how to access the deployed resources.

Top comments (0)