{"id":57339,"date":"2023-05-11T13:22:54","date_gmt":"2023-05-11T07:52:54","guid":{"rendered":"https:\/\/www.tothenew.com\/blog\/?p=57339"},"modified":"2023-09-06T14:01:39","modified_gmt":"2023-09-06T08:31:39","slug":"implementing-terraform-for-azure-cloud","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/implementing-terraform-for-azure-cloud\/","title":{"rendered":"Implementing Terraform for Azure Cloud"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">In today&#8217;s digital world, everything is moving towards automation, including cloud computing.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Microsoft Azure is one example of a public cloud computing service. All hardware, software, and other supporting infrastructure within the public cloud is owned and managed by the cloud provider. Here you can access these services and manage your account using a web browser.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Terraform lets you set up your cloud infrastructure setup into IaaC. If you&#8217;ve used Microsoft Azure before, you&#8217;ll know that configuring your infrastructure through the Microsoft Azure Portal (the Web UI) is far from ideal. Terraform enables you to use Infrastructure as Code rather than manually executing the steps in the Microsoft Azure Portal.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We must install Terraform in our infrastructure and must follow a few steps:<\/span><\/p>\n<ol>\n<li><span style=\"font-weight: 400;\"> Setup Terraform<\/span><\/li>\n<li><span style=\"font-weight: 400;\"> Check the installation<\/span><\/li>\n<li><span style=\"font-weight: 400;\"> Download and install the Azure CLI tool.<\/span><\/li>\n<li><span style=\"font-weight: 400;\"> Use the Azure CLI to authenticate.<\/span><\/li>\n<\/ol>\n<h3><br style=\"font-weight: 400;\" \/><b>Install Terraform<\/b><\/h3>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">RHEL Installation<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Windows Installation<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Ubuntu Installation<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Mac Installation<\/span><\/li>\n<\/ol>\n<h3><b>RHEL Installation<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">To install Terraform on Redhat, we need to follow the steps mentioned below<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0 \u00a0a. Install yum-config-manager to manage your repositories.<\/span><\/p>\n<pre><i><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 $ sudo yum install -y yum-utils<\/span><\/i><\/pre>\n<p><span style=\"font-weight: 400;\">\u00a0 b. Yum-config-manager command will be Used to add the official HashiCorp Linux repository.<\/span><\/p>\n<pre><i><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 $ sudo yum-config-manager --add-repo \r\n        https:\/\/rpm.releases.hashicorp.com\/RHEL\/hashicorp.repo<\/span><\/i><\/pre>\n<p><span style=\"font-weight: 400;\">\u00a0 c. Install Terraform from the new repository.<\/span><\/p>\n<pre><i><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 $ sudo yum -y install terraform<\/span><\/i><\/pre>\n<h3><b>Ubuntu Installation<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">To install Terraform in Ubuntu, the steps are almost the same, but you need to ensure that the curl package, gnupg, software-properties-common, and your system should be up to date.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Now follow the steps<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0a. To update your system<\/span><\/p>\n<pre><i><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0$ sudo apt-get update<\/span><\/i><\/pre>\n<p><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0b. To install gnupg and software properties common<\/span><\/p>\n<pre><i><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0$\u00a0 sudo apt install\u00a0 software-properties-common gnupg2 curl<\/span><\/i><\/pre>\n<p><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0c. running the command: first add Terraform&#8217;s gpg key to Ubuntux<\/span><\/p>\n<pre><i><span style=\"font-weight: 400;\">  \u00a0 \u00a0 \u00a0 \u00a0$\u00a0 curl https:\/\/apt.releases.hashicorp.com\/gpg | gpg --dearmor &gt; hashicorp.gpg<\/span><\/i>\r\n<i><span style=\"font-weight: 400;\">  \u00a0 \u00a0 \u00a0 \u00a0$ sudo install -o root -g root -m 644 hashicorp.gpg \/etc\/apt\/trusted.gpg.d\/<\/span><\/i><\/pre>\n<p><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0d. Now, with the key imported, add Hashicorp repository to your Ubuntu system:<\/span><\/p>\n<pre><i><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 $ sudo apt-add-repository \"deb [arch=$(dpkg --print-architecture)] \r\n        https:\/\/apt.releases.hashicorp.com $(lsb_release -cs) main\"<\/span><\/i><\/pre>\n<p><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0e. To install Terraform<\/span><\/p>\n<pre><i><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 $ sudo apt install terraform<\/span><\/i><\/pre>\n<h3><b>Windows Installation<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">To install Windows, we have the option to install it from an executable file of terraform, which is available over the internet.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">But we need to <\/span><span style=\"font-weight: 400;\">configure environment variables for Terraform in windows<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Open and goto <\/span><span style=\"font-weight: 400;\">This PC(MyComputer)\u2014&gt;properties \u2014&gt;advanced system settings\u2013&gt;environment variables\u2014&gt;system variables\u2014&gt;path\u2013edit\u2013&gt;new<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-57335 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/Screenshot-2023-05-07-at-10.33.25-AM.png\" alt=\"\" width=\"792\" height=\"860\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/Screenshot-2023-05-07-at-10.33.25-AM.png 792w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/Screenshot-2023-05-07-at-10.33.25-AM-276x300.png 276w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/Screenshot-2023-05-07-at-10.33.25-AM-768x834.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/Screenshot-2023-05-07-at-10.33.25-AM-624x678.png 624w\" sizes=\"(max-width: 792px) 100vw, 792px\" \/><\/span><\/p>\n<p><span style=\"font-weight: 400;\">Edit System Variable, add terraform path<\/span><\/p>\n<p><br style=\"font-weight: 400;\" \/><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-57336 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/Screenshot-2023-05-07-at-10.34.39-AM-716x1024.png\" alt=\"\" width=\"625\" height=\"894\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/Screenshot-2023-05-07-at-10.34.39-AM-716x1024.png 716w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/Screenshot-2023-05-07-at-10.34.39-AM-210x300.png 210w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/Screenshot-2023-05-07-at-10.34.39-AM-768x1098.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/Screenshot-2023-05-07-at-10.34.39-AM-624x892.png 624w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/Screenshot-2023-05-07-at-10.34.39-AM.png 814w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Click on OK and Apply to save changes.<\/span><\/p>\n<h4><strong>Manual Installation on Windows using Powershell and chocolatey<\/strong><\/h4>\n<pre><i><span style=\"font-weight: 400;\">$ Choco Install terraform<\/span><\/i><\/pre>\n<p><br style=\"font-weight: 400;\" \/><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-57337 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/Screenshot-2023-05-07-at-10.37.04-AM-1024x646.png\" alt=\"\" width=\"625\" height=\"394\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/Screenshot-2023-05-07-at-10.37.04-AM-1024x646.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/Screenshot-2023-05-07-at-10.37.04-AM-300x189.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/Screenshot-2023-05-07-at-10.37.04-AM-768x485.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/Screenshot-2023-05-07-at-10.37.04-AM-624x394.png 624w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/Screenshot-2023-05-07-at-10.37.04-AM.png 1268w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<h3><b>Macintosh Installation<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0a. First of all, we need to install the HashiCorp tap, a repository of all our Homebrew packages.<\/span><\/p>\n<pre><i><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0$ brew tap hashicorp\/tap<\/span><\/i><\/pre>\n<p><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0b. Now, install Terraform with hashicorp\/tap\/terraform<\/span><\/p>\n<pre><i><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0$ brew install hashicorp\/tap\/terraform<\/span><\/i><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-57338 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/Screenshot-2023-05-07-at-10.39.28-AM-1024x575.png\" alt=\"\" width=\"625\" height=\"351\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/Screenshot-2023-05-07-at-10.39.28-AM-1024x575.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/Screenshot-2023-05-07-at-10.39.28-AM-300x168.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/Screenshot-2023-05-07-at-10.39.28-AM-768x431.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/Screenshot-2023-05-07-at-10.39.28-AM-624x350.png 624w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/Screenshot-2023-05-07-at-10.39.28-AM.png 1226w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0d. To update to the latest version of Terraform on the system,<\/span><\/p>\n<pre><i><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0$ brew update<\/span><\/i><\/pre>\n<p><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0e. Now run the <\/span><span style=\"font-weight: 400;\">upgrade<\/span><span style=\"font-weight: 400;\"> command to download and use the latest Terraform version.<\/span><\/p>\n<pre><i><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0$ brew upgrade hashicorp\/tap\/terraform<\/span><\/i><\/pre>\n<h3><b>Verify the installation<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">By starting a new terminal session and listing Terraform&#8217;s available subcommands, you can confirm that the installation was successful.<\/span><\/p>\n<pre><i><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0$ terraform -help<\/span><\/i><\/pre>\n<h3><b>Install the Azure CLI tool<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">We need to install the Azure CLI tool for Windows and Macintosh systems so open cmd or terminal and follow the below-mentioned steps.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Install the Azure CLI on <\/span><b>Windows Cmd prompt<\/b><span style=\"font-weight: 400;\"> using run as administrator<\/span><\/p>\n<pre><i><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0$ Invoke-WebRequest -Uri https:\/\/aka.ms\/installazurecliwindows -OutFile .\\AzureCLI.msi; \r\nStart-Process msiexec.exe -Wait -ArgumentList '\/I AzureCLI.msi \/quiet'; rm .\\AzureCLI.msi<\/span><\/i><\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Install the <\/span><a href=\"https:\/\/formulae.brew.sh\/formula\/azure-cli\"><span style=\"font-weight: 400;\">Azure CLI formula<\/span><\/a><span style=\"font-weight: 400;\"> from the <\/span><b>Macintosh terminal<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n<pre><i><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0$ brew update &amp;&amp; brew install azure-cli<\/span><\/i><\/pre>\n<p><span style=\"font-weight: 400;\">Installation on <\/span><b>Ubuntu Terminal<\/b><\/p>\n<pre><i><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0$ curl -sL https:\/\/aka.ms\/InstallAzureCLIDeb | sudo bash<\/span><\/i><\/pre>\n<h3><b>Authenticate using the Azure CLI<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Now to get started, we must authenticate to the Azure portal using the credentials to create infrastructure.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0a. Open your terminal or cmd prompt, and use the Azure CLI tool to set up your account permissions locally.<\/span><\/p>\n<pre><i><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 $ az login<\/span><\/i><\/pre>\n<p><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 b. Now, the browser window will prompt, and you need to enter our Azure login credentials. Once the authentication is successful, our terminal will display the subscription information.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Once the above steps are completed, we are ready to perform the Azure automation.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0c. Now go to your Azure portal and Find the subscription ID for the account you want to use. Once we have the account subscription ID, set the account with the Azure CLI.<\/span><\/p>\n<pre><i><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 $ az account set --subscription \"Azure-subscription-id\"<\/span><\/i><\/pre>\n<p><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0d.Now we need to authenticate our terraform by creating a service principle in the Azure AD. A Service Principal is an application within Azure Active Directory with the authentication tokens Terraform needs to perform actions on our behalf.\u00a0<\/span><\/p>\n<pre><i><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 $ az ad sp create-for-rbac --role=\"Contributor\" --scopes=\"\/subscriptions\/&lt;SUBSCRIPTION_ID&gt;\"<\/span><\/i><\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">This is the same for new resources being added to Terraform code, as well as existing resources being imported.<\/span><\/p>\n<div class=\"ap-custom-wrapper\"><\/div><!--ap-custom-wrapper-->","protected":false},"excerpt":{"rendered":"<p>In today&#8217;s digital world, everything is moving towards automation, including cloud computing. Microsoft Azure is one example of a public cloud computing service. All hardware, software, and other supporting infrastructure within the public cloud is owned and managed by the cloud provider. Here you can access these services and manage your account using a web [&hellip;]<\/p>\n","protected":false},"author":1562,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":4},"categories":[1818,4308,2348],"tags":[5216],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/57339"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/1562"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=57339"}],"version-history":[{"count":2,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/57339\/revisions"}],"predecessor-version":[{"id":58340,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/57339\/revisions\/58340"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=57339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=57339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=57339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}