{"id":8040,"date":"2020-08-10T12:33:20","date_gmt":"2020-08-10T12:33:20","guid":{"rendered":"https:\/\/cloudkul.com\/blog\/?p=8040"},"modified":"2020-08-10T12:44:32","modified_gmt":"2020-08-10T12:44:32","slug":"how-to-install-terraform-on-ubuntu-18-04","status":"publish","type":"post","link":"https:\/\/cloudkul.com\/blog\/how-to-install-terraform-on-ubuntu-18-04\/","title":{"rendered":"How to Install Terraform on Ubuntu 18.04"},"content":{"rendered":"\n<p>In this blog, we will learn about how to install terraform on ubuntu 18.04. Along with some useful commands of terraform. As well as to learn more about terraform <a rel=\"noreferrer noopener\" href=\"https:\/\/cloudkul.com\/blog\/introduction-to-terraform\/\" target=\"_blank\">click<\/a>.<\/p>\n\n\n\n<h4 class=\"has-text-align-left wp-block-heading\">Prerequisites<\/h4>\n\n\n\n<ul><li>Ubuntu 18.04<\/li><li>Root privileges<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What we will do?<\/h2>\n\n\n\n<ul><li>Download Terraform<\/li><li>Setup Terraform<\/li><li>Run Basic commands of Terraform<\/li><li>Conclusion<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Download Terraform<\/h3>\n\n\n\n<p><a href=\"https:\/\/cloudkul.com\/blog\/introduction-to-terraform\/\" target=\"_blank\" rel=\"noreferrer noopener\">Terraform<\/a> uses HashiCorp Configuration Language (HCL) to manage environments of Operators and Infrastructure teams. To download open ternimal with root privileges and enter commands.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt update\nsudo apt install -y zip\nsudo wget https:\/\/releases.hashicorp.com\/terraform\/0.12.29\/terraform_0.12.29_linux_amd64.zip<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"108\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2020\/08\/terraform-download-3-1024x108.png\" alt=\"\" class=\"wp-image-8060\" \/><\/figure>\n\n\n\n<p>Now unzip the downloaded terraform file in folder. Use any name for folder, in my case it is terraform.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mkdir ~\/terraform\ncd ~\/terraform\nunzip ~\/terraform_0.12.29_linux_amd64.zip<\/pre>\n\n\n\n<p>By this commands the terraform file in unzip under terraform folder.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Setup Terraform<\/h3>\n\n\n\n<p>Now to setup terraform so that we can use terraform from any path in terminal.<\/p>\n\n\n\n<p>Check for the hidden file in home directory &#8220;~&#8221; of linux by command and open profile by any editor.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ls -al\nsudo nano ~\/.profile<\/pre>\n\n\n\n<p>And now export the path of terraform folder in .profile file. At last of .profile file enter the line. In my case path is &#8220;~\/terraform&#8221;.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">export PATH=\"$PATH:~\/terraform\"<\/pre>\n\n\n\n<p>Now save the file with &#8220;<em>ctrl+x&#8221; <\/em>to exit, <em>&#8220;y&#8221;<\/em> to save and press <em>&#8220;enter&#8221;<\/em>.<\/p>\n\n\n\n<p>Now this will not automatically update the path for current session to do this run command.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">source ~\/.profile<\/pre>\n\n\n\n<p>By this command it will update path in environment variable and we can use terraform from any location of terminal.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"607\" height=\"206\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2020\/08\/terraform-profile-1.png\" alt=\"\" class=\"wp-image-8056\" \/><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Run basic Commands of Terraform<\/h3>\n\n\n\n<p>There are so many <a rel=\"noreferrer noopener\" href=\"https:\/\/www.terraform.io\/docs\/commands\/index.html\" target=\"_blank\">commands<\/a> in terraform we can discuss about some.<\/p>\n\n\n\n<ul><li>Initialization<\/li><li>Plan and Apply<\/li><li>Formatting and Validation<\/li><li>State and Graph<\/li><li>Destroy<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Initialization<\/h4>\n\n\n\n<p>It is the first command to run any new configuration, and also use to check an existing configuration from version control is <strong><em>\u201cterraform init\u201d<\/em><\/strong>.<br>Terraform use to support hundreds of infrastructure and service provider, it uses a plugin-based architecture. The command <strong><em>\u201cterraform init\u201d<\/em><\/strong> is use to downloads and installs providers used in the configuration. <\/p>\n\n\n\n<p>As we see when we build the infrastructure.<\/p>\n\n\n\n<p>In our example <strong><em>\u201cterraform init\u201d<\/em><\/strong> is use to downloads the AWS provider and also installs some hidden sub directories of the current working directory.<br>By this command the version of plugin was installed.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"898\" height=\"440\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2020\/08\/terraform-init.png\" alt=\"\" class=\"wp-image-8057\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Plan and Apply<\/h4>\n\n\n\n<p>Use <strong><em>\u201cterraform apply\u201d<\/em><\/strong> within the same directory in which we save .tf file. <\/p>\n\n\n\n<p>From terraform 0.11 and above versions we don\u2019t required <strong><em>\u201cterraform plan\u201d<\/em><\/strong> for showcase of execution plan before applying it.<\/p>\n\n\n\n<p>With the help of <strong><em>\u201cterraform apply\u201d<\/em><\/strong> it will first show execution plan and then ask to build the infrastructure or not.<\/p>\n\n\n\n<p>In our example we are building EC2 instance. Along with this it wrote some data in <strong><em>\u201cterraform.tsftate\u201d<\/em><\/strong> file. This file is very important because it keeps track of the Ids of created resources so that Terraform knows what it is managing.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"534\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2020\/08\/terraform-apply.png\" alt=\"\" class=\"wp-image-8061\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Formatting and Validation<\/h4>\n\n\n\n<p>We use <strong><em>\u201cterraform fmt\u201d<\/em><\/strong> when different teams are use to write the files and modules. With the use of <strong><em>\u201cterraform fmt\u201d<\/em><\/strong> it enables standardization which is use to updates configurations automatically in the current directory.<\/p>\n\n\n\n<p>With the help of <strong><em>\u201cterraform validate\u201d<\/em><\/strong> we will use to check and report errors within modules, attribute names, and value types.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"928\" height=\"34\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2020\/08\/terraform-validate.png\" alt=\"\" class=\"wp-image-8064\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">State and Graph<\/h4>\n\n\n\n<p>With the help of <strong><em>&#8220;terraform state&#8221;<\/em><\/strong> we manage advance state terraform has build in command called <strong><em>\u201cterraform state\u201d<\/em><\/strong>. To modify the state file by finding resources in the <strong><em>terraform.tfstate<\/em><\/strong> file with <strong><em>\u201cterraform state list\u201d<\/em><\/strong>.<\/p>\n\n\n\n<p>To see visual representation of either a configuration or execution plan we use command <strong><em>&#8220;terraform graph&#8221;<\/em><\/strong>. The output of this command <strong><em>&#8220;terraform graph&#8221;<\/em><\/strong> is in the <strong>DOT <\/strong>format. Which can be used by GraphViz to generate charts.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"281\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2020\/08\/terraform-grapg-1024x281.png\" alt=\"\" class=\"wp-image-8065\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Destroy<\/h4>\n\n\n\n<p>Now to destroy all the resources of terraform directory we use <strong><em>\u201cterraform destroy\u201d<\/em><\/strong>. <\/p>\n\n\n\n<p>With the help of \u201c-\u201d in the execution plan it will show the resources which gone to be destroyed after completion of process. <\/p>\n\n\n\n<p>To complete write \u201cyes\u201d for confirmation.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"968\" height=\"84\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2020\/08\/terraform-destroy.png\" alt=\"\" class=\"wp-image-8069\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n\n\n\n<p>With the help of installation steps you can easily install terraform in your ubuntu 18.04 machine.  And with the help of this commands you can easily start with terraform. This all commands are important as well as very useful commands of terraform.<\/p>\n\n\n\n<p><strong>In case of any help or query, please<\/strong>\u00a0<a href=\"https:\/\/cloudkul.com\/contact\/\"><strong>contact<\/strong><\/a>\u00a0<strong>us or raise a<\/strong>\u00a0<strong><a href=\"https:\/\/webkul.uvdesk.com\/en\/customer\/create-ticket\/\">ticket<\/a>.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog, we will learn about how to install terraform on ubuntu 18.04. Along <a class=\"text-primary\" title=\"read more\" href=\"https:\/\/cloudkul.com\/blog\/how-to-install-terraform-on-ubuntu-18-04\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":33,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[32,2],"tags":[16,412,418,416,417],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Install Terraform on Ubuntu 18.04 - Cloudkul cloud - Cloudkul<\/title>\n<meta name=\"description\" content=\"Terraform uses HashiCorp Configuration Language (HCL) to manage environments of Operators and Infrastructure teams. To install terraform in ubuntu 18.04....\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cloudkul.com\/blog\/how-to-install-terraform-on-ubuntu-18-04\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Install Terraform on Ubuntu 18.04 - Cloudkul cloud - Cloudkul\" \/>\n<meta property=\"og:description\" content=\"Terraform uses HashiCorp Configuration Language (HCL) to manage environments of Operators and Infrastructure teams. To install terraform in ubuntu 18.04....\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudkul.com\/blog\/how-to-install-terraform-on-ubuntu-18-04\/\" \/>\n<meta property=\"og:site_name\" content=\"Cloudkul\" \/>\n<meta property=\"article:published_time\" content=\"2020-08-10T12:33:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-08-10T12:44:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2020\/08\/terraform-download-3-1024x108.png\" \/>\n<meta name=\"author\" content=\"Siddharth Chouradiya\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cloudkul.com\/blog\/how-to-install-terraform-on-ubuntu-18-04\/\",\"url\":\"https:\/\/cloudkul.com\/blog\/how-to-install-terraform-on-ubuntu-18-04\/\",\"name\":\"How to Install Terraform on Ubuntu 18.04 - Cloudkul cloud - Cloudkul\",\"isPartOf\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/#website\"},\"datePublished\":\"2020-08-10T12:33:20+00:00\",\"dateModified\":\"2020-08-10T12:44:32+00:00\",\"author\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/9303394e1ef74da24b7bb4ac81e88706\"},\"description\":\"Terraform uses HashiCorp Configuration Language (HCL) to manage environments of Operators and Infrastructure teams. To install terraform in ubuntu 18.04....\",\"breadcrumb\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/how-to-install-terraform-on-ubuntu-18-04\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cloudkul.com\/blog\/how-to-install-terraform-on-ubuntu-18-04\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cloudkul.com\/blog\/how-to-install-terraform-on-ubuntu-18-04\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cloudkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Install Terraform on Ubuntu 18.04\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#website\",\"url\":\"https:\/\/cloudkul.com\/blog\/\",\"name\":\"Cloudkul\",\"description\":\"Host your eCommerce Store on AWS with Optimized Performance\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/cloudkul.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/9303394e1ef74da24b7bb4ac81e88706\",\"name\":\"Siddharth Chouradiya\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/73437ba66ba4fee2da26aebcba96530e?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/73437ba66ba4fee2da26aebcba96530e?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g\",\"caption\":\"Siddharth Chouradiya\"},\"url\":\"https:\/\/cloudkul.com\/blog\/author\/siddharthchouradiya-cloud360\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Install Terraform on Ubuntu 18.04 - Cloudkul cloud - Cloudkul","description":"Terraform uses HashiCorp Configuration Language (HCL) to manage environments of Operators and Infrastructure teams. To install terraform in ubuntu 18.04....","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/cloudkul.com\/blog\/how-to-install-terraform-on-ubuntu-18-04\/","og_locale":"en_US","og_type":"article","og_title":"How to Install Terraform on Ubuntu 18.04 - Cloudkul cloud - Cloudkul","og_description":"Terraform uses HashiCorp Configuration Language (HCL) to manage environments of Operators and Infrastructure teams. To install terraform in ubuntu 18.04....","og_url":"https:\/\/cloudkul.com\/blog\/how-to-install-terraform-on-ubuntu-18-04\/","og_site_name":"Cloudkul","article_published_time":"2020-08-10T12:33:20+00:00","article_modified_time":"2020-08-10T12:44:32+00:00","og_image":[{"url":"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2020\/08\/terraform-download-3-1024x108.png"}],"author":"Siddharth Chouradiya","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/cloudkul.com\/blog\/how-to-install-terraform-on-ubuntu-18-04\/","url":"https:\/\/cloudkul.com\/blog\/how-to-install-terraform-on-ubuntu-18-04\/","name":"How to Install Terraform on Ubuntu 18.04 - Cloudkul cloud - Cloudkul","isPartOf":{"@id":"https:\/\/cloudkul.com\/blog\/#website"},"datePublished":"2020-08-10T12:33:20+00:00","dateModified":"2020-08-10T12:44:32+00:00","author":{"@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/9303394e1ef74da24b7bb4ac81e88706"},"description":"Terraform uses HashiCorp Configuration Language (HCL) to manage environments of Operators and Infrastructure teams. To install terraform in ubuntu 18.04....","breadcrumb":{"@id":"https:\/\/cloudkul.com\/blog\/how-to-install-terraform-on-ubuntu-18-04\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudkul.com\/blog\/how-to-install-terraform-on-ubuntu-18-04\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/cloudkul.com\/blog\/how-to-install-terraform-on-ubuntu-18-04\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Install Terraform on Ubuntu 18.04"}]},{"@type":"WebSite","@id":"https:\/\/cloudkul.com\/blog\/#website","url":"https:\/\/cloudkul.com\/blog\/","name":"Cloudkul","description":"Host your eCommerce Store on AWS with Optimized Performance","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cloudkul.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/9303394e1ef74da24b7bb4ac81e88706","name":"Siddharth Chouradiya","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/73437ba66ba4fee2da26aebcba96530e?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/73437ba66ba4fee2da26aebcba96530e?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g","caption":"Siddharth Chouradiya"},"url":"https:\/\/cloudkul.com\/blog\/author\/siddharthchouradiya-cloud360\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/8040"}],"collection":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/users\/33"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/comments?post=8040"}],"version-history":[{"count":23,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/8040\/revisions"}],"predecessor-version":[{"id":8074,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/8040\/revisions\/8074"}],"wp:attachment":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/media?parent=8040"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/categories?post=8040"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/tags?post=8040"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}