{"id":61764,"date":"2022-04-08T14:00:00","date_gmt":"2022-04-08T18:00:00","guid":{"rendered":"https:\/\/jumpcloud.com\/?p=61764"},"modified":"2024-08-14T17:24:01","modified_gmt":"2024-08-14T21:24:01","slug":"how-to-launch-amazon-linux-ec2-instance-terraform","status":"publish","type":"post","link":"https:\/\/jumpcloud.com\/blog\/how-to-launch-amazon-linux-ec2-instance-terraform","title":{"rendered":"How to Launch an Amazon Linux EC2 Instance Using Terraform"},"content":{"rendered":"\n
Jump to Tutorial<\/a><\/p>\n\n\n\n Cloud computing has revolutionized the way organizations deploy and manage resources, and provides numerous benefits to businesses of all sizes. These benefits include:<\/p>\n\n\n\n The advancement of cloud computing has gone hand in hand with transformational technologies that aim to boost the efficiency and speed of deploying and managing resources. One of these technologies is Infrastructure as Code (IaC).<\/p>\n\n\n\n IaC is the practice of deploying, managing, and provisioning resources using configuration files instead of using interactive graphical tools or manual hardware configuration. Simply put, it is the management of your infrastructure using code that provides a blueprint for the desired state of the resources.<\/p>\n\n\n\n Before IaC, operation teams would manually make configuration changes to their infrastructure, which was a tedious and time-consuming task often peppered with inconsistencies and errors.<\/p>\n\n\n\n IaC provides consistency and error reduction in the deployment and management of resources. In addition, it increases the speed of deployment, eliminates configuration drift, and reduces the costs that come with manual deployment.<\/p>\n\n\n\n One of the most popular IaC utilities is Terraform<\/a>. Developed by HashiCorp, Terraform is an open source IaC utility that uses a declarative configuration language known as HashiCorp Configuration Language (HCL) to manage or deploy hundreds of cloud resources. <\/p>\n\n\n\n Terraform takes away a huge chunk of deploying resources from developers who only need to run a few commands to have their resources ready. It also forms a critical part of DevOps and CI\/CD implementation<\/a>.<\/p>\n\n\n\n In this guide, you will learn how to deploy an EC2 instance using Terraform.<\/p>\n\n\n\n To realize the power of Terraform in deploying resources, the first step is to install it. Follow the steps outlined below for your operating system. <\/p>\n\n\n\n Note that although the apt-key is deprecated<\/a>, as of the publishing of this tutorial, these instructions are provided by HashiCorp<\/a> and will still work.<\/p>\n\n\n\n First, add the HashiCorp GPG key.<\/p>\n\n\n\n Next, add the HashiCorp repository.<\/p>\n\n\n\n Once the repository is added, update the package lists to notify your system about the newly added repository and then install Terraform using the APT package manager.<\/p>\n\n\n\n If you are running a modern Red Hat distribution such as RHEL 8, CentOS 8 and 9, Rocky Linux, or AlmaLinux, follow the steps shown.<\/p>\n\n\n\n Install the prerequisite packages:<\/p>\n\n\n\n Next, add the HashiCorp repository<\/p>\n\n\n\n Lastly, install Terraform using the DNF package manager.<\/p>\n\n\n\n Install the prerequisite packages first.<\/p>\n\n\n\n Next, add the HashiCorp repository.<\/p>\n\n\n\n And finally, install Terraform using the DNF package manager.<\/p>\n\n\n\n When the installation of Terraform is complete, verify the version installed as follows.<\/p>\n\n\n\n From the output, you can clearly see the latest version of Terraform is installed.<\/p>\n\n\n\n\n
Step 1: Install Terraform on Linux<\/strong><\/h2>\n\n\n\n
For Debian\/Ubuntu<\/h3>\n\n\n\n
$ curl -fsSL https:\/\/apt.releases.hashicorp.com\/gpg | sudo apt-key add –<\/code><\/p>\n\n\n\n
$ sudo apt-add-repository “deb [arch=amd64] https:\/\/apt.releases.hashicorp.com $(lsb_release -cs) main”<\/code><\/p>\n\n\n\n
$ sudo apt-get update && sudo apt-get install terraform -y<\/code><\/p>\n\n\n\n
For CentOS and RHEL 8\/Rocky Linux and AlmaLinux<\/h3>\n\n\n\n
$ sudo yum clean all<\/code><\/p>\n\n\n\n
$ sudo yum update<\/code><\/p>\n\n\n\n
$ sudo yum install -y yum-utils<\/code><\/p>\n\n\n\n
$ sudo yum-config-manager –add-repo https:\/\/rpm.releases.hashicorp.com\/RHEL\/hashicorp.repo<\/code><\/p>\n\n\n\n
$ sudo dnf install terraform -y<\/code><\/p>\n\n\n\n
For Fedora<\/h3>\n\n\n\n
$ sudo dnf install -y dnf-plugins-core<\/code><\/p>\n\n\n\n
$ sudo dnf config-manager –add-repo https:\/\/rpm.releases.hashicorp.com\/fedora\/hashicorp.repo<\/code><\/p>\n\n\n\n
$ sudo dnf install terraform -y<\/code><\/p>\n\n\n\n
$ terraform version<\/code><\/p>\n\n\n\n