- Consulting
- Training
- Partners
- About Us
x
Hello everyone, welcome back! In this article, you will learn how to write, plan, and maintain infrastructure using Terraform cloud.
Let us start with a brief about the Terraform cloud.
Terraform cloud is a self-hosted SaaS product that provides services to help teams and organizations collaborate, manage, maintain a consistent environment, and most importantly, automate the process and work as a team.
This article focuses on guiding individuals to step into the Terraform cloud. We will see how we can create a workspace and integrate it with the version control system to maintain the infra from Terraform cloud graphics.
So, let us go forward and use the Terraform Cloud.
To go further with Terraform cloud, you need to have GitHub and AWS Account.
Quickly signup and create a free account from https://app.terraform.io/signup/account. Verify the email address.
Let us create an organization to manage workspaces. Once the account is verified, you will land on the page to create an organization. Provide appropriate name and click Create Organization.
Now that we have created an organization, let us create workspaces inside them. You will land on a page to create a workspace, if not, click on a button to create a workspace inside an organization.
A workspace is where we have all the configuration files present. It is important to connect the workspace with VCS like Git, GitLab, Azure DevOps, Bit bucket. Having the source files in a version control system is in fact the recommended practice in the Software development process.
In tab 1, Select VCS (Version Control System)
In tab 2, select the VCS you want to use. Terraform Cloud provides flexibility to integrate with different version control systems like GitHub, GitLab, BitBucket, and Azure DevOps. In this demo, we are using GitHub, so select github.com.
Configure variables
Now we created our workspace and connected to the VCS. Let us plan and apply the files.
Our workspace contains two files, namely instance.tf and vars.tf. We are going to deploy an EC2 machine on AWS.
The snippet of the files is as below:
instance.tf
We are using two variables in the provider section to pass the AWS Account access key and secret key. These credentials are used to authenticate with AWS. It is not acceptable to hardcode them directly on the configuration as it is highly open to risk as it is sensitive data. Instead, we can pass as a variable.
In Terraform, we pass the sensitive data in 2 ways:
a. Using Command-line: Sensitive data is recommended to be stored in *.tfvars file that will be git ignored.
b. From Terraform Cloud: we can add a variable in a secured manner. let’s have a look at it
Now on the terraform cloud graphics, click Configure variables. In this demo, we will pass the credentials of AWS (Access key and secret key) to authenticate with users.
Click on + Add variable and provide the following details. Make sure you enable the sensitive check box.
Every operation will perform (be it Either apply or destroy). Terraform Cloud performs a plan before it. Once the Plan is completed, it asks for approval before performing the actual operation.
Now, you will notice that the Plan and Apply operation is scheduled. The terminal output is shown on the black screen.
Once Plan is successful, scroll down a bit, and it will wait for the confirmation/approval to apply the changes. Click Confirm & Apply.
Provide a message in the textbox and click on Confirm Plan.
You will see that terraform apply is happening.
On successful execution, you will see:
You can also see the state by clicking on the ‘States’ tab on the top
Verify that the resource has been created in your AWS Console
I hope that you have learned how to integrate the VCS to the Terraform cloud. We have seen how to manage the infrastructure easily from the graphics. Hope that this blog helps to get started with Terraform cloud. Follow for more updates on DevOps related information.
Drop your queries in the comments section below.
Voiced by Amazon Polly |
Shyla is an MCT and works on cloud platforms like AWS and Azure. She is certified as an Azure Administrator and works on DevOps tools like Ansible, and Terraform, to create and deploy highly available infrastructure on AWS and Azure.
Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!
Anusha Shanbhag
Dec 9, 2020
Very nice blog. Informative.
Click to Comment