{"id":7435,"date":"2020-12-03T13:07:42","date_gmt":"2020-12-03T13:07:42","guid":{"rendered":"https:\/\/blog.cloudthat.com\/?p=7435"},"modified":"2024-06-25T11:10:02","modified_gmt":"2024-06-25T11:10:02","slug":"manage-infrastructure-on-aws-using-terraform-cloud-for-free","status":"publish","type":"blog","link":"https:\/\/www.cloudthat.com\/resources\/blog\/step-by-step-guide-to-manage-infrastructure-on-aws-using-terraform-cloud-for-free","title":{"rendered":"Step-by-Step Guide to Manage Infrastructure on AWS using Terraform Cloud for FREE"},"content":{"rendered":"<p style=\"text-align: left;\">Hello everyone, welcome back! In this article, you will learn how to write, plan, and maintain infrastructure using Terraform cloud.<\/p>\n<p style=\"text-align: left;\">Let us start with a brief about the\u00a0<strong>Terraform cloud.<\/strong><\/p>\n<p style=\"text-align: left;\"><strong>Terraform cloud<\/strong> 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.<\/p>\n<p style=\"text-align: left;\">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.<\/p>\n<p style=\"text-align: left;\">So, let us go forward and use the Terraform Cloud.<\/p>\n<h2 style=\"text-align: left;\"><strong>Prerequisites:<\/strong><\/h2>\n<p style=\"text-align: left;\">To go further with Terraform cloud, you need to have GitHub and AWS Account.<\/p>\n<ul style=\"text-align: left;\">\n<li>GitHub repository with Terraform configuration files. If you don&#8217;t have files, fork the repo\u00a0<span style=\"text-decoration: underline;\"><a href=\"https:\/\/github.com\/shylajohn\/Terraform-Cloud.git\">https:\/\/github.com\/shylajohn\/Terraform-Cloud.git<\/a><\/span><\/li>\n<li>AWS account as we are going to provision resources on AWS. You can Signup here \u00a0<span style=\"text-decoration: underline;\"><a href=\"http:\/\/console.aws.amazon.com\/\">http:\/\/console.aws.amazon.com\/\u00a0<\/a><\/span><br \/>\n<h2><strong><br \/>\n1. Sign<\/strong><strong><strong> up and create an Organization:<\/strong><\/strong><\/h2>\n<p><strong>Quickly\u00a0signup and create a free account from\u00a0<\/strong><span style=\"text-decoration: underline;\"><a href=\"https:\/\/app.terraform.io\/signup\/account\">https:\/\/app.terraform.io\/signup\/account<\/a>.<\/span><strong> Verify the email address.\u00a0\u00a0<\/strong><\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/159.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7525\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/159.png\" alt=\"1\" width=\"1316\" height=\"609\" \/><\/a><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/157.png\"><br \/>\n<\/a><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/227.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7542\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/227.png\" alt=\"2\" width=\"1358\" height=\"361\" \/><\/a><\/p>\n<p>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\u00a0<strong>Create Organization<\/strong>.<br \/>\n<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/322.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7543\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/322.png\" alt=\"3\" width=\"1309\" height=\"544\" \/><\/a><\/p>\n<h2><strong>2. Create a Workspace:<u><br \/>\n<\/u><\/strong><\/h2>\n<p>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.<\/p>\n<p>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.<br \/>\nIn<strong> tab 1,<\/strong> Select <strong>VCS (Version Control System)<\/strong><br \/>\n<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/411.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7544\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/411.png\" alt=\"4\" width=\"961\" height=\"541\" \/><\/a><\/p>\n<p>In <strong>tab 2,<\/strong> 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.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/57.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7545\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/57.png\" alt=\"5\" width=\"911\" height=\"511\" \/><\/a><\/p>\n<ul>\n<li>Once you click Github.com, a new window will popup. Sign in to your Github account from there. Perform the verification and install Terraform on Git.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul>\n<li style=\"text-align: left;\">Now, we have the Github account connected with Terraform cloud.<br \/>\nIn <strong>tab 3<\/strong> choose the repository.\u00a0<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/69.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7546\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/69.png\" alt=\"6\" width=\"861\" height=\"466\" \/><\/a>In <strong>tab 4,<\/strong> Provide the name for the workspace and click the\u00a0<strong>Create Workspace\u00a0<\/strong>button. Once the workspace is created, you will see a success message in a popup.\u00a0<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/710.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7547\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/710.png\" alt=\"7\" width=\"839\" height=\"415\" \/><\/a><\/li>\n<\/ul>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/813.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-7548 aligncenter\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/813.png\" alt=\"8\" width=\"398\" height=\"90\" \/><\/a><\/p>\n<h2><strong>3. Plan and Apply the changes:<\/strong><\/h2>\n<\/li>\n<\/ul>\n<p><strong>Configure variables <\/strong><\/p>\n<p><strong>Now<\/strong>\u00a0we created our workspace and connected to the VCS. Let us plan and apply the files.<\/p>\n<p>Our workspace contains two files, namely\u00a0<strong>in<em>stance.tf<\/em><\/strong>\u00a0and<strong><em>\u00a0vars.tf.\u00a0<\/em><\/strong>We are going to deploy an EC2 machine on AWS.<\/p>\n<p>The snippet of the files is as below:<\/p>\n<p><strong>instance.tf<br \/>\n<\/strong><\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/912.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7549\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/912.png\" alt=\"9\" width=\"507\" height=\"262\" \/><\/a><br \/>\n<strong>vars.tf<br \/>\n<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/109.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7550\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/109.png\" alt=\"10\" width=\"300\" height=\"45\" \/><\/a><br \/>\n<\/strong><\/p>\n<p>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.<\/p>\n<p>In Terraform, we pass the sensitive data in 2 ways:<\/p>\n<p><strong>a.<\/strong>\u00a0<span style=\"font-size: 13px;\"><strong>Using Command-line<\/strong>: Sensitive data is recommended to be stored in\u00a0<\/span><strong style=\"font-size: 13px;\">*.tfvars\u00a0<\/strong><span style=\"font-size: 13px;\">file that will be git ignored.<br \/>\n<\/span><strong>b.<\/strong> <strong>From Terraform Cloud:<\/strong> we can add a variable in a secured manner. let&#8217;s have a look at it<\/p>\n<p>Now on the terraform cloud graphics, click\u00a0<strong>Configure variables<\/strong>. In this demo, we will pass the credentials of AWS (<em>Access key and secret key<\/em>) to authenticate with users.<\/p>\n<p>Click on <strong>+<\/strong>\u00a0<strong>Add variable<\/strong>\u00a0and provide the following details. Make sure you enable the sensitive check box.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Table.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7621\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Table.png\" alt=\"Table\" width=\"422\" height=\"85\" \/><\/a><\/p>\n<ul style=\"text-align: left;\">\n<li>Once variables are added, it should look like this:<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/1118.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7551\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/1118.png\" alt=\"11\" width=\"1194\" height=\"293\" \/><\/a>Apply the files.\n<ul>\n<li>Click on\u00a0<strong>Queue<\/strong><strong>\u00a0plan to<\/strong>\u00a0plan and apply the workspace. Provide the reason and click\u00a0<strong>Queue plan.<\/strong><\/li>\n<\/ul>\n<p>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.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/1314.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7554\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/1314.png\" alt=\"13\" width=\"621\" height=\"303\" \/><\/a><\/p>\n<p>Now, you will notice that the <strong>Plan<\/strong> and <strong>Apply<\/strong> operation is scheduled. The terminal output is shown on the black screen.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/1414.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7555\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/1414.png\" alt=\"14\" width=\"1234\" height=\"309\" \/><\/a><br \/>\nOnce Plan is successful, scroll down a bit, and it will wait for the confirmation\/approval to apply the changes. Click\u00a0<strong>Confirm &amp; Apply.<br \/>\n<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/1510.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7556\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/1510.png\" alt=\"15\" width=\"1262\" height=\"200\" \/><\/a><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/158.png\"><br \/>\n<\/a><\/strong><br \/>\nProvide a message in the textbox and click on Confirm Plan.<br \/>\n<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/165.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7557\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/165.png\" alt=\"15\" width=\"1211\" height=\"334\" \/><\/a><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/164.png\"><br \/>\n<\/a>You will see that terraform apply is happening.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/175.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7558\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/175.png\" alt=\"17\" width=\"1225\" height=\"506\" \/><\/a><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/174.png\"><br \/>\n<\/a>On successful execution, you will see:<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/184.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7559\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/184.png\" alt=\"18\" width=\"1320\" height=\"317\" \/><\/a><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/183.png\"><br \/>\n<\/a>You can also see the state by clicking on the &#8216;States&#8217; tab on the top<br \/>\n<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/194.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7560\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/194.png\" alt=\"19\" width=\"1269\" height=\"296\" \/><\/a><\/p>\n<p>Verify that the resource has been created in your AWS Console<br \/>\n<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/205.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7561\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/205.png\" alt=\"20\" width=\"1088\" height=\"238\" \/><\/a><\/p>\n<h2><strong>4. Terminate the resources<br \/>\n<\/strong><\/h2>\n<ul>\n<li>On the settings tab, click on <strong><strong><strong>Destruction and Deletion<br \/>\n<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/2111.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7562\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/2111.png\" alt=\"21\" width=\"381\" height=\"443\" \/><\/a><br \/>\n<\/strong><\/strong><\/strong>\u00a0Now, click on <strong>Queue destroy plan.<\/strong><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/228.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7563\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/228.png\" alt=\"22\" width=\"802\" height=\"468\" \/><\/a><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/226.png\"><br \/>\n<\/a>Provide the Workspace name and click on <strong>Queue Destroy plan<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/234.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7564\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/234.png\" alt=\"23\" width=\"639\" height=\"405\" \/><\/a><\/strong><\/li>\n<li>You will notice that the queue is scheduled. The deletion queue has two stages. Plan and apply (to delete the infra)<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/242.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7565\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/242.png\" alt=\"24\" width=\"647\" height=\"306\" \/><\/a><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/253.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7566\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/253.png\" alt=\"24\" width=\"1154\" height=\"269\" \/><\/a><br \/>\nApprove to start the delete operation<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/262.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7567\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/262.png\" alt=\"25\" width=\"637\" height=\"206\" \/><\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<ol style=\"text-align: left;\">\n<li style=\"list-style-type: none;\">\n<ul>\n<li>Once completed, check the run tab to check the status.<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/272.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7568\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/272.png\" alt=\"27\" width=\"642\" height=\"294\" \/><\/a><\/li>\n<li>Check the AWS console to verify that the resources are no longer active.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3 style=\"text-align: left;\"><strong>Conclusion<\/strong>:<\/h3>\n<p style=\"text-align: left;\">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.<\/p>\n<p style=\"text-align: left;\">Drop your queries in the comments section below.<\/p>\n","protected":false},"author":234,"featured_media":8067,"parent":0,"comment_status":"open","ping_status":"open","template":"","blog_category":[3606,3607,3624],"user_email":"shylaj@cloudthat.com","published_by":"324","primary-authors":"","secondary-authors":"","acf":[],"_links":{"self":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/7435"}],"collection":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog"}],"about":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/types\/blog"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/users\/234"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/comments?post=7435"}],"version-history":[{"count":1,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/7435\/revisions"}],"predecessor-version":[{"id":41167,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/7435\/revisions\/41167"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/media?parent=7435"}],"wp:term":[{"taxonomy":"blog_category","embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog_category?post=7435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}