Terraform Cloud: CI/CD Tool To Check Your Build.
1. What is Terraform Cloud?
2. Prerequisets.
3. Let’s Get Started
1. What is Terraform Cloud?
Write
Create new infrastructure using Hcl, or manage existing infrastructure that you’ve already written using Terraform Open Source. You can also leverage hundreds of providers and thousands of pre-written modules in the Terraform Registry.
Compose
Workspaces provide an environment for a collection of infrastructure. They store variables, state files, credentials, and secrets. Connect a workspace to a Terraform configuration stored locally, in version control, or uploaded via an API. Then, connect that workspace to the cloud services where you would like infrastructure to be provisioned.
Plan
Terraform Cloud provides a plan for infrastructure changes before every run. It can calculate costs for this plan, and cross check it with any policy as code your security and compliance teams create using sentinel.
Provision & Manage
Instead of relying on your team’s local machines to execute runs, provision and manage infrastructure reliably and securely with Terraform cloud’s run environment . Integrate Terraform Cloud into your existing CI/CD pipeline and other tools you already use.
2. Prerequisites.
Note: This project focuses on gaining an understanding of how CI/CD tools work.
3. Let’s Get Started.
- Begin by forking over repo here from Github.
- You will need to change the key pair in the “compute” module to yours.
- Navigate to Terraform Cloud and select New Workspace.
- Next step is to choose workflow. Click version control workflow.
- Next, choose Github as your version control provider.
- Choose week-20-project-1 as seen highlighted below.
- Click create workspace.
Workspace
Let’s understand what a workspace is briefly before we move on. Terraform Cloud manages infrastructure collections with workspaces instead of directories. A workspace contains everything Terraform needs to manage a given collection of infrastructure, and separate workspaces function like completely separate working directories.
Configuring our variables.
We’ll now need to configure our variables.
- Click configure variables.
- Lets’s add a variable.
- key = access_ip
- value = 0.0.0.0/0
- click Save variable.
Configure Environmental Variables.
You will need to add four variables here.
- Add your AWS_ACCESS_KEY_ID. Mark as sensitive.
- Add your AWS_SECRET_ACCESS_KEY. Mark as sensitive
- Add your AWS_DEFAULT_REGION.
- Add CONFIRM_DESTROY. Set to 1 as value. This is for cleaning up our environment after the demo.
- Under actions, click on start new plan.
- Type test 1 when asked for reason for starting new plan
- Click Start plan.
Terraform Cloud will now start a plan of action.
- Click on confirm plan and add a comment.
Terraform Cloud has now provisioned our infrastructure.
We can also view our infrastructure via the AWS Console.
Above we have three instances running. One for our bastion host and two for our database.
We also have a load balancer.
We also have an AutoScaling group set up for our bastion host and an AutoScaling group set up for our database instances.
Here, in our outputs, we have the dns from the our application load balancer.
- Copy and past the address in a new window in your browser to verify it works.
Below is our webpage from our ALB.
Summary.
We have built a secure, highly available, highly scalable AWS environment using terraform modules to deploy this while using Terraform Cloud as a CI/CD tool to check our build.
Go ahead and destroy your environment upon completion of this demo.