Hello everyone, welcome back! This article will teach you how to plan, write, and maintain Terraform cloud infrastructure.
Let’s start by briefly describing Terraform cloud.
Terraform cloud is a SaaS product that can be self-hosted and provides services to help organizations and teams collaborate, manage, maintain a consistent atmosphere, and most importantly, automate the process so they can work together as a team.
This article will help you to get into Terraform cloud. We will show you how to create a workspace, and integrate it with the version management system to maintain the Terraform cloud graphics infra.
Let’s move on and use Terraform Cloud.
Terraform cloud requires you to have a GitHub or AWS account in order to move forward.
Terraform configuration files are available in the GitHub repository. If you don’t have files, fork the repo https://github.com/shylajohn/Terraform-Cloud.git
AWS account, as we will be providing resources on AWS. You can Signup here http://console.aws.amazon.com/ 1. Register now to create an Organization
Quickly signup and create a free account from https://app.terraform.io/signup/account. Verify your email address.
Let’s create an organization to manage workspaces. After your account has been verified, you will be able to create an organisation. Click Create Organization and enter the appropriate name.
2. Create a Workspace
Let’s create workspaces within the organization we have just created. If you don’t see a page that allows you to create a workspace within an organization, click on the button to create one.
A workspace is the place where all configuration files are stored. It is important that the workspace be connected to VCS such as Git, GitLab and Azure DevOps. In fact, it is a best practice to have the source files in a version management system during the Software development process. Click tab 1 and select VCS (Version Control System).
Tab 2 allows you to select the VCS that you wish to use. Terraform Cloud allows you to integrate with different version control systems such as BitBucket and GitLab. This demo uses GitHub. Please select github.com.
A new window will open when you click Github.com. From there, sign in to your Github Account. After completing the verification, Terraform can be installed on Git.
We now have the Terraform cloud account linked to Github. Click tab 3 to choose the repository. Tab 4: Enter the name of the workspace and click on the Create Workspace button. After the workspace has been created, you will receive a popup with a success message.
3. Plan and apply the changes:
Now, we have created our workspace and connected it to the VCS. Let’s plan and apply the files.
Our workspace has two files: instance.tf, and vars.tf. We will deploy an EC2 server on AWS.
Below is a snippet from the files:
To pass the AWS Account Access Key and Secret Key, we are using two variables in our provider section. These credentials are used for authentication with AWS. These credentials cannot be hardcoded directly on the configuration. This is because it exposes sensitive data to risk. We can instead pass them as variables.
Terraform transmits sensitive data in two ways:
a. Command-line: Sensitive data should be stored in *.tfvars files that will be git ignored. We can add a variable to Terraform Cloud in a secure manner. Let’s take a look at it
Click Configure variables on the Terraform cloud graphics. To authenticate with users, we will pass the credentials for AWS (Access key & secret key) in this demo.
Click on + Add Variable and enter the following information. Make sure to enable the sensitive checkbox
After variables have been added, it should look something like this:Apply files. Click on Queue plan plan to plan and then apply the workspace. Click Queue plan and enter the reason.
Every operation will be successful.