Voiced by Amazon Polly
Terraform Cloud is HashiCorp’s managed service offering. It removes the need for unnecessary tooling and documentation for practitioners, teams, and organizations to use Terraform in production. Deliver infrastructure in a remote environment that is optimized for the Terraform workflow. Terraform Cloud is a SAAS. HashiCorp co-founder and CTO Mitchell Hashimoto give a short whiteboard illustration of Terraform Cloud—a new service from HashiCorp that removes the hassle of managing Terraform state files across multiple teams, while also providing a centralized change history and policy governance.
Here I am going to show you how CICD works on terraform cloud with Google provider.
Steps to Create a free Terraform Cloud account
Create an account
If you have a HashiCorp Cloud Platform (HCP) account, use your HCP account credentials to log in to Terraform Cloud and go to the next step. If you already have a Terraform Cloud account, go to the further step.
For the creation of terraform cloud account, visit https://app.terraform.io/signup/account URL and follow the steps to create a free Terraform Cloud account.
- When you sign up, you will get an email asking you to confirm your email address.
- Validate your email address before moving on. When you tick the link to confirm your email address, the Terraform Cloud UI will ask which setup workflow you would like to use. Here, Select the Start from scratch option
A Simple Guide to Setup Ansible Tower in GCP VM
- Virtual Machine
- Ansible Tower
Steps to Create an Organization
The next screen will prompt you to create a new organization.
Creating organizations of up to 5 users is free, and the members you add to the organization will be able to cooperate on your workspaces and share private modules and providers.
- Click Create organization. Later, will create and use a workspace within your new Terraform Cloud organization.
- Now that you have created an account and organization, you are ready to authenticate and begin using Terraform Cloud.
VCS Driven (Use VCS driven workflow)
Before using VCS driven workflow, we need to create one repository in a GitHub account, here I am going to show step by step process.
Step 1 – Create one repository in GitHub.
Step 2 – Fill up all the necessary fields and create a repo.
Step 3 – Once the GitHub repository is created, just copy the URL of that repo.
Step 4 – Let’s create some folder inside that repo after cloning and create some files into it and get it commit to the repo.
Step 5 – Then you can push it to GitHub and refresh your GitHub account and be able to see that folder came inside it.
Step 6 – Quickly go to terraform cloud account and follow the step-by-step method for creating VCS driven.
- Go to provider and click on Add VCS provider.
- Go to GitHub option and choose custom GitHub.
- For setup of the provider, you need to click on register a new OAuth application.
- New page will come, you just need to fill in the necessary field and copy paste application name and authorization callback URL from the previous page and register the application.
- Now you need to copy the Client ID and client secrets after generating a new client secret and paste it in the provider section and connect to continue.
- You have successfully created a VCS provider for VCS driven workflow.
Steps to Create a Workspace
Step 1 – Let’s create a Workspace by following the step-by-step method by choosing the VCS workflow.
Step 2 – After creating a workspace, Now I am going to add terraform files to my GitHub repo and when we upload the terraform files automatically it will run. Here I am taking GCP as a cloud provider.
Step 3 –Configure the variables.
Step 4 – Before configuring variables, we have to create a service account in the GCP console and use those credentials in the environment variable section.
Steps to set up Google Cloud (GCP) credentials in Terraform Cloud
- Authenticate to GCP
- Set up Google Cloud Service Account
- Download your JSON key file
In Terraform documentation for GCP providers, the authentication is done by pointing to the location of the JSON key file which is not a suitable approach for Terraform Cloud.
2. Having the following example code, we will create a variable named gcp-creds.
Then, we create Terraform variable in Terraform Cloud named gcp-creds and we populate the content of the JSON key file as its value.
Note: Please don’t forget to set up the variable as sensitive.
3. You can also enter the contents of the service account key file by an environment variable. All you have to do is (follow the below steps)
- Select variables in the environment variable section, Click add variable
- Set GOOGLE_CREDENTIALS as the key
- Open the service account key file, copy the contents, then paste the content into the value field and mark the environment variable as sensitive, click on save variable.
4. After setting terraform variables create some terraform files inside a simple repository, you can use visual studio code for creating terraform files and just push it to GitHub
Steps to Run Terraform
- Now you quickly have to specify the terraform variables in terraform cloud console.
- Now run the terraform cloud by clicking on action.
After running, just confirm and apply, it will create the VM as per the terraform script.
CICD in Terraform Cloud Console
Step 1 – Go to settings -> Click Version control->Enable Automatic speculative plans->click update VCS settings.
Step 2 – Now Let us do changes to the terraform script and commit to the GitHub repo, then back to Terraform cloud console.
You can now see the plan will automatically run and all you need to confirm and apply. Once you are done with the lab, destroy the resource by clicking action.
I hope that you have acquired knowledge of how to integrate the VCS into the Terraform cloud. Here, we have noticed how to manage the infrastructure easily from the graphics. Hope that this blog helps to get started with Terraform cloud and google providers.
CloudThat is also the official AWS (Amazon Web Services) Advanced Consulting Partner and Training partner and Microsoft gold partner, helping people develop knowledge of the cloud and help their businesses aim for higher goals using best in industry cloud computing practices and expertise. We are on a mission to build a robust cloud computing ecosystem by disseminating knowledge on technological intricacies within the cloud space. Our blogs, webinars, case studies, and white papers enable all the stakeholders in the cloud computing sphere.
Drop a query if you have any questions regarding VCS, Terraform, GCP and I will get back to you quickly.
1. What are the features of Terraform Cloud & Terraform Cloud plans?
ANS: – In Terraform Cloud platform it provisions infrastructure, both in demand and in response to various events. Dissimilar to a general-purpose continuous integration (CI) system, it is greatly integrated with Terraform’s workflows and data, which accept it to make Terraform significantly more easy and more high-powered.
2. Is Terraform Cloud free?
ANS: – Terraform Cloud supplies infrastructure automation as a service and is free to begin, also can upgrade to a paid option.
WRITTEN BY Minhaj Kadri
Minhaj is a Research Associate-DevOps in CloudThat and a certified professional on AWS. She has demonstrated a history of architecting highly secure, scalable, fault-tolerant, cost-effective infrastructure on multi-cloud platforms AWS, Azure, and GCP.