Creating workspaces using Terraform Cloud
Hello, readers. Today we will see the creation of workspaces, which exist in Terraform cloud, and which can further help in maintaining multiple clouds infrastructure.
Let's look into Terraform Cloud briefly.
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.
So, let's start now!
There are two prerequisites for the process, a GitHub and an AWS Account.
- GitHub repository with Terraform configuration files. If you don’t have files, fork the repo https://github.com/tithichoudhary/My-Terraform-Cloud1
- AWS account as we are going to provision resources on AWS. You can Signup here http://console.aws.amazon.com/
1. Sign Up and Create an Organization
Let us create an organization to manage workspaces. Once the account is verified, you will land on the page to create an organization. Provide an appropriate name and click Create Organization.
2. Create a Workspace:
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 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.
Once you click Github.com, a new window will pop up. Sign in to your Github account from there. Perform the verification and install Terraform on Git.
Now, we have the Github account connected with Terraform cloud.
In tab 3 choose the repository. In tab 4, Provide the name for the workspace and click the Create Workspace button. Once the workspace is created, you will see a success message in a popup.
3. Plan and Apply the changes:
Configure variables
Now we created our workspace and connected it 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.
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.
Apply the files.
Click on Queue plan to plan and apply the workspace. Provide the reason and click Queue plan.
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:
Thanks for reading!




Comments
Post a Comment