{"id":4198,"date":"2021-02-10T06:37:14","date_gmt":"2021-02-10T06:37:14","guid":{"rendered":"https:\/\/linuxways.net\/?p=4198"},"modified":"2021-02-10T07:11:20","modified_gmt":"2021-02-10T07:11:20","slug":"how-to-install-terraform-on-ubuntu-18-04-20-04-lts","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-install-terraform-on-ubuntu-18-04-20-04-lts\/","title":{"rendered":"How to Install Terraform on Ubuntu 18.04\/20.04 LTS"},"content":{"rendered":"<p>Created and maintained by Hashicorp, <a href=\"https:\/\/www.terraform.io\/\">Terraform <\/a>is an open-source utility tool that is popularly regarded as Infrastructure As A Code. It allows users to easily build and provision cloud resources such as virtual machines on various popular cloud platforms such as Google Cloud and AWS. Let\u2019s now install Terraform. This guide works on both Ubuntu 18.04 (Bionic Beaver) and Ubuntu 20.04 (Focal Fossa).<\/p>\n<h2><strong>Download and Install Terraform<\/strong><\/h2>\n<p>Firstly, we need to download the Terraform compressed file from Terraform\u2019s download page. Terraform 0.14.6 is the most recent version by the time of publishing this tutorial.<\/p>\n<p>To download Terraform, use the wget command to grab the Linux installation zipped file<\/p>\n<pre><strong>$ sudo wget https:\/\/releases.hashicorp.com\/terraform\/0.14.6\/terraform_0.14.6_linux_amd64.zip<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"811\" height=\"344\" class=\"wp-image-4199\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-94.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-94.png 811w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-94-300x127.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-94-768x326.png 768w\" sizes=\"auto, (max-width: 811px) 100vw, 811px\" \/><\/strong><\/p>\n<p>Once the download is complete, confirm that the zipped file exists using the <strong>ls <\/strong>command as shown.<\/p>\n<pre><strong>$ ls | grep terraform<\/strong><\/pre>\n<p>Next, unzip the file to the <strong>\/usr\/local\/bin<\/strong> path where non-system programs are usually located.<\/p>\n<pre><strong>$ sudo unzip terraform_0.14.6_linux_amd64.zip -d \/usr\/local\/bin<\/strong><\/pre>\n<p>Once uncompressed, the installation of Terraform is complete. To verify the version of Terraform installed issue the command\u201d<\/p>\n<pre><strong>$ terraform version<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"808\" height=\"135\" class=\"wp-image-4202\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-96.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-96.png 808w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-96-300x50.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-96-768x128.png 768w\" sizes=\"auto, (max-width: 808px) 100vw, 808px\" \/><\/strong><\/p>\n<p>Perfect! Let\u2019s now see Terraform in action. We are going to demonstrate how we can use Terraform to provision an ec2 instance on AWS cloud platform<\/p>\n<h2><strong>Use Terraform to launch an EC2 instance on AWS <\/strong><\/h2>\n<p>As we mentioned earlier, Terraform can be used to deploy on-premise and cloud resources on popular cloud platforms such as AWS and Google cloud to mention a few.<\/p>\n<p>To start off, we are going to create a separate directory for our AWS project and navigate into it.<\/p>\n<pre><strong>$ mkdir aws &amp;&amp; cd aws<\/strong><\/pre>\n<p>We will create a Terraform configuration file bearing a <strong>.tf<\/strong> extension.<\/p>\n<pre><strong>$ sudo vim config.tf<\/strong><\/pre>\n<p>Now, here comes the most important part. We are going to define details about our cloud provide &#8211; In this case AWS.<\/p>\n<ol>\n<li>Cloud provider&#8217;s name &#8211; In this case, AWS.<\/li>\n<li><strong>Access key &amp; secret keys<\/strong> &#8211; These are encrypted keys that provide access to our AWS resources<\/li>\n<li><strong>Region<\/strong> &#8211; the location where the cloud infrastructure will be provisioned. In our case, this will be in us-east-2<\/li>\n<li><strong>ami<\/strong> &#8211; This is a unique ID required to deploy an EC2 instance.<\/li>\n<\/ol>\n<p>Copy and paste the following content<\/p>\n<pre><strong>#Specify the access &amp; secret keys and region<\/strong>\n\n<strong>provider \"aws\" {<\/strong>\n\n<strong>access_key = \"Your-own-access-key\"<\/strong>\n\n<strong>secret_key = \"Your-own-secret-key\"<\/strong>\n\n<strong>region = \"us-east-2\"<\/strong>\n\n<strong>}<\/strong>\n\n<strong>#Specify details of the ec2 instance <\/strong>\n\n<strong>resource \"aws_instance\" \"instance1\" {<\/strong>\n\n<strong>ami = \"ami-0dd9f0e7df0f0a138\"<\/strong>\n\n<strong>instance_type = \"t2.micro\"<\/strong>\n\n<strong>tags = {<\/strong>\n\n<strong>Name = \"ubuntu-20.04\"<\/strong>\n\n<strong>}<\/strong>\n\n<strong>}<\/strong>\n\n<\/pre>\n<p>To start working with Terraform and running command, we are going to initialize it as shown.<\/p>\n<pre><strong>$ terraform init<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"806\" height=\"387\" class=\"wp-image-4204\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-98.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-98.png 806w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-98-300x144.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-98-768x369.png 768w\" sizes=\"auto, (max-width: 806px) 100vw, 806px\" \/><\/strong><\/p>\n<p>To perform a simulation of how the command will run, invoke the <strong>terraform plan <\/strong>command as shown. Note that this is only a simulation that is meant to see how the whole thing will play out.<\/p>\n<pre><strong>$ terraform plan<\/strong><\/pre>\n<p>Finally, to provision the ec2 instance, run:<\/p>\n<pre><strong>$ terraform apply<\/strong><\/pre>\n<p>A flurry of information will be printed on the terminal displaying the various actions that will be performed by Terraform as shown.<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"811\" height=\"411\" class=\"wp-image-4206\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-100.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-100.png 811w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-100-300x152.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-100-768x389.png 768w\" sizes=\"auto, (max-width: 811px) 100vw, 811px\" \/><\/strong><\/p>\n<p>When prompted whether to proceed with the execution of the actions, simply type \u2018<strong>Yes<\/strong>\u2019 and hit ENTER.<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"724\" height=\"185\" class=\"wp-image-4208\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-102.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-102.png 724w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-102-300x77.png 300w\" sizes=\"auto, (max-width: 724px) 100vw, 724px\" \/><\/strong><\/p>\n<p>Within a few seconds, the creation of your ec2 instance will be complete and if all went well you should get the output below.<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"806\" height=\"295\" class=\"wp-image-4210\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-104.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-104.png 806w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-104-300x110.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-104-768x281.png 768w\" sizes=\"auto, (max-width: 806px) 100vw, 806px\" \/><\/strong><\/p>\n<p>And just to sure that your instance was created, head over to our AWS account and navigate to the EC2 instances Below is a screenshot of the newly created ec2 instance.<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"1145\" height=\"380\" class=\"wp-image-4212\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-106.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-106.png 1145w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-106-300x100.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-106-1024x340.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-106-768x255.png 768w\" sizes=\"auto, (max-width: 1145px) 100vw, 1145px\" \/><\/strong><\/p>\n<p>This draws the curtains on this guide. We have walked you through the installation of Terraform and demonstrated its effectiveness in provisioning cloud resources.<\/p>","protected":false},"excerpt":{"rendered":"<p>Created and maintained by Hashicorp, Terraform is an open-source utility tool that is popularly regarded as Infrastructure As A Code. It allows users to easily build and provision&hellip;<\/p>","protected":false},"author":36,"featured_media":4215,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-4198","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/4198","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/36"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=4198"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/4198\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/4215"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=4198"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=4198"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=4198"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}