<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by KARTIKEYA JAIN on Medium]]></title>
        <description><![CDATA[Stories by KARTIKEYA JAIN on Medium]]></description>
        <link>https://medium.com/@kartikeya47jain?source=rss-391d2735c0e6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*zCW4UGqzBSfwGXzphfLV6Q.png</url>
            <title>Stories by KARTIKEYA JAIN on Medium</title>
            <link>https://medium.com/@kartikeya47jain?source=rss-391d2735c0e6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 21:34:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kartikeya47jain/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Mastering Terraform on Azure: A Step-by-Step Guide for Beginners]]></title>
            <link>https://medium.com/@kartikeya47jain/mastering-terraform-on-azure-a-step-by-step-guide-for-beginners-d07caa0ea172?source=rss-391d2735c0e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/d07caa0ea172</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[KARTIKEYA JAIN]]></dc:creator>
            <pubDate>Thu, 09 Jan 2025 04:08:34 GMT</pubDate>
            <atom:updated>2025-01-12T05:21:35.944Z</atom:updated>
            <content:encoded><![CDATA[<h4>Understanding Terraform Configuration Blocks with hands-on Azure Deployment</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*7PZyo2buoEqLkhfhzRfXoQ.gif" /><figcaption>Created by <a href="https://tenor.com/en-GB/users/gamerrazor">GamerRazor</a><strong> </strong>on <a href="https://tenor.com/">Tenor</a></figcaption></figure><p><strong>Table of Content</strong><br>· <a href="#a4c9">Recap</a><br>· <a href="#2967">Prerequisites for the deployment</a><br>· <a href="#8e25">Overview</a><br>· <a href="#aa61">Phase One (Laying the Groundwork for Terraform)</a><br> ∘ <a href="#d07e">Terraform Block</a><br> ∘ <a href="#7825">Local Name</a><br> ∘ <a href="#954b">Source</a><br> ∘ <a href="#838d">Version</a><br> ∘ <a href="#0922">Provider Block</a><br> ∘ <a href="#d515">Resource Block</a><br> ∘ <a href="#0bc5">Implementation</a><br>· <a href="#dee4">Phase Two (What We Deployed and Why It Matters)</a><br>· <a href="#f706">Phase Three (Bringing Your Terraform Project to Life)</a><br>· <a href="#2099">Conclusion</a></p><h3>Recap</h3><p>Let us start with a quick recap. In the <a href="https://medium.com/@kartikeya47jain/a-journey-from-click-to-code-4a96c8a8309b">Previous Episode,</a> we saw how the author introduced Terraform, an Infrastructure as Code (IaC) tool, explaining its benefits, functionality, and basic commands for automating and managing cloud infrastructure. Let’s see what he has kept in his teaching arsenal this time 😄.</p><blockquote><strong>Author’s Note</strong></blockquote><blockquote>Hi guys, I wish you all a very Happy New Year. Man, time flies so fast. It looks like yesterday when I explained to you about Terraform, and in a blink of time, here I am writing an entirely new blog in a completely different year 😬.</blockquote><h3>Prerequisites for the deployment</h3><ol><li><a href="https://learn.microsoft.com/en-us/cli/azure/install-azure-cli">Azure account setup</a></li><li><a href="https://code.visualstudio.com/download">VS Code or preferred IDE</a></li><li><a href="https://dev.to/annysah/step-by-step-guide-to-installing-terraform-on-windows-m2e">Terraform installation</a></li></ol><h3>Overview</h3><p>So, most of us have gone through an education where Theory prevailed over Practical Implementation, where every time we saw Practicality saying: “<em>Et tu, Brute?</em>”</p><p>But don’t worry, I won’t allow my Julius to say the same to me 😅.</p><p>This time, I will dive deep into the Scripting part of writing a basic <strong>Terraform Configuration</strong> for Azure.</p><blockquote><strong>Terraform Configuration</strong> is an umbrella term used for all the Scripts used to create an Infrastructure.</blockquote><p>You need not worry if you have no prior knowledge of Azure. I have structured the blog into three Phases. In <strong>Phase One</strong>, I will explain the Scripts and their functionality. In <strong>Phase Two</strong>, I will give you an overview of what I deployed in Azure, also explaining the use and meaning of those resources. In <strong>Phase Three</strong>, I will share the Scripts used to deploy the Architecture.</p><blockquote>I want to make it clear that we will be going with basic Scripting. I won’t be covering how to use Modules and variables. Let us keep those topics for another day.</blockquote><p>Let us begin 😎</p><h3>Phase One (Laying the Groundwork for Terraform)</h3><figure><img alt="Basic Structure of the Directory" src="https://cdn-images-1.medium.com/max/125/1*F7X1W52iDjnjcP65rNwVew.png" /><figcaption>Fig-1: Terraform Configuration</figcaption></figure><p>Generally, a single executable Terraform Script must contain:</p><ol><li><a href="https://developer.hashicorp.com/terraform/language/terraform">Terraform Block</a></li><li><a href="https://developer.hashicorp.com/terraform/language/providers">Provider</a></li><li><a href="https://developer.hashicorp.com/terraform/language/resources/syntax">Resource Block</a></li></ol><blockquote>Do follow the chronology when writing your code inside a single script.</blockquote><p>Referring to <strong>Fig-1:</strong></p><ol><li>Provider.tf contains <strong>Terraform Block </strong>&amp; <strong>Provider</strong></li><li>RG_Main.tf, VNet_Main.tf and Subnet_Main.tf contains <strong>Resource Block</strong></li></ol><p>Let us start diving deep into the workings of every component.</p><h4><strong>Terraform Block</strong></h4><figure><img alt="Basic architecture of a Terraform Block" src="https://cdn-images-1.medium.com/max/340/1*lyTnJmapsoyA86ESZ-k3_g.png" /><figcaption>Fig-2: Basic structure of a <strong>Terraform Block</strong></figcaption></figure><p>A Terraform Block acts as the backbone of the entire Project. Terraform Block contains <strong>settings </strong>and <strong>providers </strong>used to Provision the Infrastructure.</p><p>So, if we consider a real-world scenario, we can say that <strong>Terraform Block </strong>is like a young kid who tells his/her father (<strong>Terraform</strong>) which bike (along with the model) (<strong>required_providers</strong>) he/she wants when his/her father gets ready to buy him/her one.</p><p>(PS: I wish convincing Parents in real life was so easy the way Terraform Block does🥲).</p><p>Technically speaking, the <strong><em>required_providers</em> </strong>block serves as the point that describes Terraform all the Provider Configuration utilized in the Project, as demonstrated by the previous example.</p><blockquote>We can <strong>initialize multiple providers </strong>inside the <strong><em>required_providers</em></strong> block.</blockquote><p>A <strong><em>required_providers</em></strong><em> </em>block contains:</p><ol><li><strong>Local name</strong></li><li><strong>A source location</strong></li><li><strong>A version constraint</strong></li></ol><figure><img alt="Basic architecture of a required_providers Block" src="https://cdn-images-1.medium.com/max/607/1*_NQI4rqRbH0p3il_Ktky2Q.png" /><figcaption>Fig-3: Basic structure of a <strong>required_providers Block</strong></figcaption></figure><p>Let us start by knowing what role each component of the <strong><em>required_providers </em></strong>Block plays:</p><h4><strong><em>Local Name</em></strong></h4><p>Let us talk about the concept of pet names. When a person gets a pet name, that person only allows dear ones to call him/her by that name. In the same way, we can say that a <strong>Local Name </strong>is like a pet name given to <strong>Providers. </strong>The modules inside the Directory (containing Provider Script) use the Local Name to refer to the Provider.</p><h4><strong><em>Source</em></strong></h4><p>As the name suggests, the source acts as a Global Identifier, allowing Terraform to<strong> Find and Download</strong> the <strong>desired Provider </strong>over the Internet.</p><p>A typical Source follows the following Syntax: <strong><em>[&lt;HOSTNAME&gt;/]&lt;NAMESPACE&gt;/&lt;TYPE&gt;</em></strong>. Generally, we <strong>prefer </strong>writing <em>&lt;NAMESPACE&gt;/&lt;TYPE&gt;</em>.</p><blockquote><strong>Fully Qualified Address </strong>is the name given to refer to a source that contains all three components (Hostname, Namespace and Type).</blockquote><p>Speaking about each option inside the Syntax:</p><ol><li><strong>Hostname: </strong>It is an Optional value. We generally do not provide Hostname value. By default, Terraform assumes it to be <strong>registry.terraform.io</strong></li><li><strong>Namespace: </strong>In the case of <strong>Provider Block, </strong>Namespace<strong> </strong>refers to the Organizations name that has published the Provider.</li><li><strong>Type: </strong>When it comes to<strong> Provider Blocks</strong>, Type serves as the Provider’s name used to call the Provider from the Namespace Registry that contains it.</li></ol><blockquote><strong><em>Note: Local Name </em></strong><em>and </em><strong><em>Source </em></strong><em>act as Unique Identifiers for a Provider. </em>The main distinction is that the <strong>Local Name</strong> identifies the Provider at the local level (inside the Directory). On the other hand, the<strong> source</strong> enables Terraform to locate the Provider via Terraform Registry.</blockquote><h4><strong><em>Version</em></strong></h4><p>You might think that “version” just means the version of the Provider used by Terraform. Yes, that is right, but it is only a half-truth. Let us know everything (PS: Let’s bake the truth well 😉).</p><blockquote><strong>Semantic Versioning (A gist about versioning)</strong></blockquote><blockquote>Semantic Versioning or <strong>SemVer </strong>is a common way to label software versions.</blockquote><blockquote>A SemVer follows the format of <strong>Major.Minor.Patch. </strong>Say we have software with <strong>version X.Y.Z. </strong>In that software:</blockquote><blockquote><strong>X</strong> is the <strong>Major Version</strong>. The Major Version value defines the changes that cause the API to break.</blockquote><blockquote><strong>Y</strong> is the <strong>Minor Version. </strong>The Minor<strong> </strong>Version value defines small updates that <em>do not break</em> the API.</blockquote><blockquote><strong>Z</strong> acts as the <strong>Patch Version </strong>that defines the Bug Fixes.</blockquote><blockquote>Note: While changes made as add-ons are generally not considered breaking changes, <a href="https://nordicapis.com/what-are-breaking-changes-and-how-do-you-avoid-them/">breaking an API</a> in software refers to altering or removing the existing portion of an API.</blockquote><p><strong>How Does Terraform Handle Versions? 🧐</strong></p><p>Terraform provides two ways of versioning with the help of:</p><ol><li><strong>~&gt; </strong>Operator <strong>specifies</strong> both Major and Minor Versions, allowing only Patches to get updated. <br>Say we have ~&gt;3.1.0; we can refer to it as X.Y.0 where the X and Y coordinates get fixed. Changes are only visible in the <strong>last </strong>position.</li><li><strong>&gt;= </strong>Operator <strong>allows</strong> us to specify only the <strong>minimum versions</strong>. By using the<strong> &gt;= </strong>operator, the version can be automatically updated as needed. <br>Suppose we have &gt;=1.0.0; Terraform may automatically make it 2.1.0.<br>We use this technique only if we want our module to work with newer versions (of the provider) and if it (module) does not rely on specific features or bug patches associated with any version (of the provider).</li></ol><p>Now, before moving further, let us see the practical comparison between the two so that the theory gets cleared 🧑‍🏫:</p><figure><img alt="Functioning of ~&gt; operator" src="https://cdn-images-1.medium.com/max/826/1*MUkjnrGce9_Ap3jnKquh7w.png" /><figcaption>Fig-4: Using <strong>~&gt; </strong>operator</figcaption></figure><p><strong>terraform init </strong>shows that the <strong>~&gt;</strong> operator used constraint and initialized 3.0.2 version, implying that only the<strong> Patch Version alters</strong>, whereas the Major and Minor Versions stay unchanged.</p><figure><img alt="Functioning of &gt;= operator" src="https://cdn-images-1.medium.com/max/758/1*x_OUxI171BwbWSlKDWWnuA.png" /><figcaption>Fig-5: Using <strong>&gt;= </strong>operator</figcaption></figure><p>When we run <strong>terraform init</strong>, we can see that the &gt;= operator used the constraint to inform Terraform of the <strong>minimum </strong>necessary version. Terraform initialized version <strong>4.14.0</strong>, which is higher than the Constraint Version.</p><p>I know this might seem a bit scary, but don’t worry, we’ve covered the most difficult and time-consuming aspect; the remaining section consists of a few simple steps to set things up and get going ☺️.</p><h4><strong>Provider Block</strong></h4><p>We use a Provider Block to configure the Provider (as in to define how the Provider shall work). Every Provider has its own set of settings that must be configured in order for its Provider Block to function.</p><figure><img alt="Basic architecture of a Provider Block" src="https://cdn-images-1.medium.com/max/373/1*Sp0zcaYL1CXhmlhkvTnmVA.png" /><figcaption>Fig-6: Basic structure of a Provider Block</figcaption></figure><h4><strong>Resource Block</strong></h4><figure><img alt="Fig-7: Basic Architecture of a Resource Block" src="https://cdn-images-1.medium.com/max/588/1*3QgG1-Owlyq3-7VelC9ttw.png" /><figcaption>Fig-7: Basic Structure of a Resource Block</figcaption></figure><p>Resource Blocks allow us to define the components that will be deployed within our infrastructure. A Resource Block holds arguments for configuring the settings of a Resource.</p><p>A resource block consists of two components:</p><ol><li><strong>Resource Type: </strong>A Resource Type identifies the type of Resource deployed in the Cloud Environment.</li><li><strong>Resource Name:</strong> A Resource Name is a <strong>Unique Name </strong>assigned to a specific resource type. Other Resource Blocks use the <strong>Resource Name </strong>to refer to a particular resource in the script.</li></ol><blockquote>The Resource Type and Resource Name combine to generate a <strong>Unique ID </strong>for the Resource. In <strong>Figure 6</strong>, the <strong>Unique ID</strong> = <em>azurerm_resource_group.RG</em>.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*iaT94mGcPrLQoOIn2LxhVw.gif" /><figcaption>Created by <a href="https://tenor.com/en-GB/users/bigglar">bigglar</a> on <a href="https://tenor.com/">Tenor</a></figcaption></figure><p>Phew 😮‍💨, here we complete all the basic things of Phase One that we shall know before implementing our infrastructure. Now let’s start with the good part, <strong>Implementation</strong> part of Phase One😁</p><h4>Implementation</h4><blockquote>Note: In the subsequent phases, I will not discuss the working of each command that is utilized. All of the commands that are used have been explained in my previous document (click on <a href="https://medium.com/@kartikeya47jain/a-journey-from-click-to-code-4a96c8a8309b">here</a> to access it).</blockquote><p><strong>Step 1: </strong>Launch VS Code and create a directory. Create all the scripts in that directory. Open a terminal in that directory and sign in to Azure. (Use <strong>az login</strong> to access your Azure account).</p><figure><img alt="Way to Login to Azure Account" src="https://cdn-images-1.medium.com/max/715/1*liknzJo2RGwvmJatzFvlgQ.png" /><figcaption>Fig-8: Login to Azure Account</figcaption></figure><p><strong>Step 2:</strong> Perform <strong>terraform init</strong></p><figure><img alt=".terraform and .terraform.lock.hcl gets created" src="https://cdn-images-1.medium.com/max/161/1*Dd5klzVaf46cq3gcV6WK8w.png" /><figcaption>Fig-9: <strong>.terraform</strong> and <strong>.terraform.lock.hcl</strong> gets created</figcaption></figure><blockquote><strong>Note: </strong>This <strong>.terraform </strong>acts like a folder used to manage cached Provider Plugins, record last known backend Configuration and record which workspace is currently active, etc.</blockquote><p><strong>Step 3: </strong>Perform <strong>terraform fmt</strong></p><p><strong>Step 4: </strong>Perform <strong>terraform refresh</strong></p><figure><img alt="terraform.tfstate gets created and .terraform.tfstate.lock.info can be seen" src="https://cdn-images-1.medium.com/max/192/1*hFafuViZUr7Lrvx-0jngEw.png" /><figcaption>Fig-10: <strong>terraform.tfstate </strong>and <strong>.terraform.tfstate.lock.info </strong>gets created</figcaption></figure><p><strong>Step 5: </strong>Perform <strong>terraform plan</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*qjIHa1Pe-v9yKGniv7G1Dg.png" /><figcaption>Fig-11: A proper Blueprint of the Infrastructure gets created</figcaption></figure><blockquote>Note: It should be noted that the terraform plan command also creates the <strong>terraform.tfstate </strong>file and <strong>terraform.tfstate.lock.info</strong>. But they are visible for a brief moment only.</blockquote><blockquote>To permanently view the<strong> terraform.tfstate</strong> file, use either the <strong>terraform refresh</strong> or <strong>terraform apply</strong> commands.</blockquote><p><strong>Step 6: </strong>Perform <strong>terraform apply</strong></p><figure><img alt="terraform.tfstate file gets created" src="https://cdn-images-1.medium.com/max/201/1*ZoiZapAmRbTB_ojYY2iYGQ.png" /><figcaption>Fig-12: <strong>terraform.tfstate </strong>file gets created</figcaption></figure><figure><img alt="Infrastructure deployed" src="https://cdn-images-1.medium.com/max/1024/1*OIryoG73wNO0FvfISSl0sQ.png" /><figcaption>Fig-13: Infrastructure deployed</figcaption></figure><blockquote>Use <strong>terraform apply –auto-approve </strong>when executing terraform apply to avoid repeatedly typing yes.</blockquote><blockquote>If you run <strong>terraform apply</strong> again after modifying the scripts (e.g., increasing a resource group), you will see the creation of a <strong>terraform.tfstate.backup </strong>file</blockquote><figure><img alt="Infrastructure deployed on the Azure Portal" src="https://cdn-images-1.medium.com/max/1024/1*V0RdTekAIG4dPw37ynOGNg.png" /><figcaption>Fig-14: Infrastructure deployed on the Azure Portal</figcaption></figure><blockquote><strong>Note: </strong>terraform apply command also creates the <strong>terraform.tfstate </strong>file and <strong>terraform.tfstate.lock.info</strong></blockquote><p><strong>Step 7: </strong>Perform <strong>terraform show</strong></p><p><strong>Step 8: </strong>Perform <strong>terraform destroy</strong></p><figure><img alt="terraform.tfstate.backup gets created" src="https://cdn-images-1.medium.com/max/198/1*eL8F7mL3K2N6l0BRa_OEaQ.png" /><figcaption>Fig-15: <strong>terraform.tfstate.backup </strong>gets created</figcaption></figure><h3><strong>Phase Two (</strong>What We Deployed and Why It Matters)</h3><p>All major learning about IaC has been finished. But, as they say, learning never ends. Therefore, before ending. Let us know what infrastructure we deployed using Terraform.</p><figure><img alt="Network Architecture" src="https://cdn-images-1.medium.com/max/500/1*hyQaS1ej-xPiN4w_dqU3DA.png" /><figcaption>Fig-16: Network Architecture</figcaption></figure><p>We deployed the Network Architecture in <strong>Fig-15</strong> with the Terraform Configuration discussed in this article.</p><p>Instead of getting into technical language, I’ll give you a very brief overview of what the architecture in Fig-15 implies.</p><p>Let us take an example:</p><p>Assume you are a <strong>Pahadi </strong>(a broad term used in India to describe people who reside in cities on or near mountains) from Uttarakhand. Furthermore, say you live in <strong>Mussoorie</strong>, Uttarakhand. Say your <strong>house </strong>address is X/Y near Library Chowk, and <strong>you </strong>live there.</p><p>This entire example describes the physical space that you occupy in the universe. Imagine a world beyond physical touch, accessible via the Internet.</p><p>If we start comparing, on a very superficial level, we can say that:</p><ol><li><strong>Resource Group</strong> <strong>= Pahadi from Uttarakhand<br></strong>In technical words, it means that all resources relevant to a specific project can be combined into a single Resource Group.</li><li><strong>Mussoorie = Virtual Network<br></strong>In technical words, this means that all resources, such as virtual machines, must be present within the virtual network.</li><li><strong>House = Subnet</strong> <br>In technical terms, even if all the Pahadi are from Mussoorie, this does not imply that they all reside together; a subnet is analogous to a house, hosting many resources together.</li><li><strong>You = Azure Resource<br></strong>In technical terms, we create a virtual network and a subnet to provide a resting place for resources like virtual computers.</li></ol><h3><strong>Phase Three (</strong>Bringing Your Terraform Project to Life)</h3><p><strong>Provider.tf File</strong></p><pre># Azure Provider Block<br>terraform {<br>  required_providers {<br>    azurerm = {<br>      source  = &quot;hashicorp/azurerm&quot;<br>      version = &quot;~&gt;3.0.0&quot;<br>    }<br>  }<br>}<br># Configure the Microsoft Azure Provider<br>provider &quot;azurerm&quot; {<br>  features {}<br>}</pre><p><strong>RG_Main.tf</strong></p><pre>resource &quot;azurerm_resource_group&quot; &quot;RG&quot; {<br>  name     = var.RG_Name<br>  location = var.RG_Location<br>  tags     = var.Tags<br>}</pre><p><strong>RG_Var.tf</strong></p><pre>variable &quot;RG_Name&quot; {<br>  description = &quot;Name of the Resource Group&quot;<br>  type        = string<br>  default     = &quot;RG-1&quot;<br>}<br><br>variable &quot;RG_Location&quot; {<br>  description = &quot;Name of the Resource Group Location&quot;<br>  type        = string<br>  default     = &quot;Central India&quot;<br>}<br><br>variable &quot;Tags&quot; {<br>  description = &quot;Name of the Tag&quot;<br>  type        = map(string)<br>  default = {<br>    Environment = &quot;Production&quot;<br>    Department  = &quot;Cloud&quot;<br>  }<br>}</pre><p><strong>Subnet_Main.tf</strong></p><pre># Created a Subnet<br>resource &quot;azurerm_subnet&quot; &quot;Subnet&quot; {<br>  name                 = var.Subnet_Name<br>  resource_group_name  = azurerm_resource_group.RG.name<br>  virtual_network_name = azurerm_virtual_network.VNet.name<br>  address_prefixes     = [var.Subnet_Address_Space]<br>}</pre><p><strong>Subnet_Var.tf</strong></p><pre>variable &quot;Subnet_Name&quot; {<br>  description = &quot;Name of the Subnet&quot;<br>  type        = string<br>  default     = &quot;Subnet-1&quot;<br>}<br><br>variable &quot;Subnet_Address_Space&quot; {<br>  description = &quot;Address Space of the Subnet&quot;<br>  type        = string<br>  default     = &quot;10.0.0.0/26&quot;<br>}</pre><p><strong>VNet_Main.tf</strong></p><pre># Created a Virtual Network<br>resource &quot;azurerm_virtual_network&quot; &quot;VNet&quot; {<br>  name                = var.VNet_Name<br>  address_space       = [var.VNet_Address_Space]<br>  location            = azurerm_resource_group.RG.location<br>  resource_group_name = azurerm_resource_group.RG.name<br>  tags                = var.Tags<br>}</pre><p><strong>VNet_Var.tf</strong></p><pre>variable &quot;VNet_Name&quot; {<br>  description = &quot;Name of the Virtual Network&quot;<br>  type        = string<br>  default     = &quot;VNet-1&quot;<br>}<br><br>variable &quot;VNet_Address_Space&quot; {<br>  description = &quot;Address Space of Virtual Network&quot;<br>  type        = string<br>  default     = &quot;10.0.0.0/24&quot;<br>}</pre><h3><strong>Conclusion</strong></h3><blockquote>Hey there! Before we wrap things up, I want to mention that this blog post doesn’t cover how to set up Terraform and the Azure CLI. If you’d like help with that on your system, just let me know in the comments!</blockquote><p>If you have any questions or thoughts about this guide, don’t hesitate to reach out. You can drop a comment below or connect with me:</p><ul><li>Follow me on Medium for more cloud adventures</li><li>Find me on LinkedIn: <a href="https://www.linkedin.com/in/kartikeya-jain-267628220/">KARTIKEYA JAIN</a></li><li>Check out my Portfolio at <a href="https://kartikeyajain.com/">Kartikeya_Jain</a></li></ul><p>Got questions? You can reach me on Twitter <a href="https://x.com/KARTIKEYA47JAIN">@KARTIKEYA47JAIN</a> or via email at <a href="/service/mailto:kartikeya007jain@gmail.com">kartikeya007jain@gmail.com</a></p><p>That’s it for today!! We built our first Azure infrastructure using Terraform, and I hope you enjoyed this hands-on adventure as much as I did 😌.</p><p>Stay tuned for another story🤗 — plenty more exciting infrastructure adventures lay ahead!</p><p>Until then, May the Infrastructure be with You🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d07caa0ea172" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A journey from Click to Code]]></title>
            <link>https://medium.com/@kartikeya47jain/a-journey-from-click-to-code-4a96c8a8309b?source=rss-391d2735c0e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a96c8a8309b</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[KARTIKEYA JAIN]]></dc:creator>
            <pubDate>Fri, 04 Oct 2024 08:02:34 GMT</pubDate>
            <atom:updated>2024-10-04T08:02:34.811Z</atom:updated>
            <content:encoded><![CDATA[<h4>Terraform 101 : A Beginner’s Journey into Terraform</h4><figure><img alt="An illustration for “Terraform 101: A Beginner’s Journey” featuring a robot and a human character." src="https://cdn-images-1.medium.com/max/1024/1*ohW3kH0MkEMX3lLf8LAIsw.png" /><figcaption>Concept by Author, Visualized with <a href="https://www.comicsmaker.ai/">AI</a></figcaption></figure><h3>Table of Content</h3><p>· <a href="#a4c9">Introduction</a><br> ∘ <a href="#aa61">Benefits of Infrastructure as Code</a><br>· <a href="#fb6c">About Terraform</a><br>· <a href="#0bc5">What is Terraform?</a><br>· <a href="#08ff">Why Choose Terraform?</a><br>· <a href="#1a1c">How Does Terraform Work?</a><br> ∘ <a href="#6c8a">Part A (Working)</a><br> ∘ <a href="#ce7c">Part B (Detail about the Files used by Terraform)</a><br>· <a href="#7366">Basic Commands of Terraform</a><br>· <a href="#d5ba">Conclusion</a></p><h3>Introduction</h3><p>If you are working on Cloud Infrastructure, it is relaxing to deploy an infrastructure with just one click. But as we say, even being lazy is a tough task. What if you are asked to deploy a thousand copies of the same infrastructure with different names or just a slight tweak. Now clicking something for the first time might look wonderful, but clicking the same thing for the thousandth time (until and unless we are not speaking about gaming), this might cause an issue😅. This issue gave birth to the perfect solution — the Concept of <a href="https://thenewstack.io/a-brief-devops-history-the-roots-of-infrastructure-as-code/#:~:text=It%20was%20built%20by%20Mark%20Burgess%20while,he%20was%20pursuing%20a%20postdoctorate%20in%20theoretical%20physics.">Infrastructure as a Code</a> (IaC)😎.</p><figure><img alt="A Medium article draft page showing a GIF from the TV show Brooklyn Nine-Nine with the caption “MAMA MAGGLIONE”." src="https://cdn-images-1.medium.com/max/576/1*Gx-0MjIVxJKSyo_bWL7pWw.gif" /><figcaption>Created by <a href="https://tenor.com/users/samkaseiso">Samkaseiso</a> on <a href="https://tenor.com/">Tenor</a></figcaption></figure><p>In an extreme layman language, IaC means, writing a Code for our Infrastructure. Now it might look quite hard just by hearing the name but Mama Magglione (iykyk😉), it is not. Let me list out a few benefits of why you should spend your time and brain in learning this concept.</p><h4>Benefits of Infrastructure as Code</h4><blockquote>Coding is all about how efficiently you are able to Cut, Copy and Paste. And yups how good you are with Logics — Author</blockquote><ol><li><strong>Automation: </strong>As we got to know that IaC means coding. This means you just need to hustle for the first time. After your script is working perfectly (I repeat, working perfectly without any bugs🙄). You just need to use the Golden Mantra of Coding:<strong> Cut, Copy &amp; Paste </strong>🤣. In the end, your deployment:<br>a. Gets automated (automatically the deployment is happening)<br>b. You can <em>Share</em> the Script.<br>c. You can <em>Reuse</em> the Script.</li><li><strong>Support of </strong><a href="https://www.geeksforgeeks.org/version-control-systems/"><strong>Version Control</strong></a><strong>: </strong>Since IaC is supported by Version Control Systems, you can revert to your previous code. This means at least in your code you get multiple second chances of reliving from your last checkpoint (last time when you saved the code). (Wished life was also like this 🥺)</li><li><strong>Reduce Security Breaches: </strong>I have a simple ideology, you give me a gadget (or account), and I will open (or use) it to look at how it works, which might lead to its early demise. Now think what if the client gives your team their account to do the project, and you get someone with the aforementioned mentality. Mamma Mia, the ruckus that person might make is unimaginable. Therefore, IaC allows the Developer to develop the scripts of the infrastructure and hand them over to the Client without logging into their account. The Client can directly run the script in their environment. But do make sure that there is a limit to how much you can restrict a developer from entering the environment, because in a few cases, for troubleshooting, you might need to give them access.</li></ol><p>Just like this, there are many benefits of IaC; most of them have the same crux. Say we want <strong><em>Disaster Recovery</em></strong>, so this can come under the concept of Version Control. Say we want <strong><em>confidentiality</em></strong>, so this can come under the concept of Reducing Security Breaches and so on.</p><h3>About Terraform</h3><p>Now there is a cauldron of IaC platforms, to name a few: Terraform, Ansible, Chef, Puppet etc. Out of all these languages, the one that I am going to explain is Terraform.</p><p><strong>Let’s take an analogy: <br></strong>You go to a Café and try all of their Pastries. After trying them, you get to know which one suits you the most 😋. Next time, when you take your dear ones to that café, the first pastry that you want them to try is the one that you have tasted before.<br>Sole reason? Because you loved it. Simple!</p><p>Now, similarly, I have tried my hands on Terraform, Bicep and so on. Out of these, I am recommending Terraform, this means there are a few things that I liked a lot because of which I prefer this language. So do remember that it is not hard and fast that you have to use Terraform only, if you want to be Service Specific then you can use Bicep for Azure, AWS CloudFormation for AWS and so on.</p><p>So, let&#39;s discuss <strong><em>What</em></strong> Terraform is and down the lane I will tell you <strong><em>Why</em></strong> I decided to use this language and <strong><em>How </em></strong>does this language work. Let’s begin😎</p><h3>What is Terraform?</h3><figure><img alt="A meme with a confused cat peeking from behind a wall, with the text “What is Terraform?”" src="https://cdn-images-1.medium.com/max/505/1*X9aSOA3z9RJGy-9bzELrHw.gif" /><figcaption>Created by <a href="https://tenor.com/users/kwendel999">Kwendel999</a> on <a href="https://tenor.com/">Tenor</a></figcaption></figure><p>Terraform is an IaC Tool (I repeat 🔁 it is a Tool and not a language). As a Tool, IaC allows us to Automate and Manage Our Infrastructure. Terraform has its own DSL (Domain Specific Language) <strong>(1)</strong> known as HCL (Harshi Corp Configuration Language). While using Terraform, you can see features of JSON being also used in it.</p><blockquote><strong>(1)</strong>Domain Specific Language refers to Language that are dedicated for a particular Application/Domain. Languages like Python are GPL (General Purpose Programming Languages) which are used to look into wider ranges of Applications. So, in a layman language, you can say: “DSL are like Professors of a particular subject who have strong hold in their field of study. On the other hand, GPL are like Jack of All Trades.)</blockquote><h3>Why Choose Terraform?</h3><figure><img alt="A meme with a cute white cartoon character asking “Why Choose Terraform?” with “why? why? why?”" src="https://cdn-images-1.medium.com/max/576/1*KMxCpKfibJu-2lE7B0NkkQ.gif" /><figcaption>Created by <a href="https://tenor.com/users/sweetjoed">SweetJoeD</a> on <a href="https://tenor.com/">Tenor</a></figcaption></figure><ol><li>Terraform provides support to write code for multiple Cloud Service Providers. This means that Terraform is like a crossroad, allowing you to write code according to your destination.</li><li>Terraform contains Plugins, known as Terraform Provider <strong>(2)</strong>. These Providers allow Terraform to interact with different Services, making Terraform the perfect Tool to work for all sorts of Services.</li><li>Terraform is a Declarative Management Tool <strong>(3)</strong>. This means we just need to tell Terraform what we want and rest, it will take care 😼.</li></ol><p>These are a few reasons why I prefer Terraform. For me, I personally believe that Terraform is a perfect example of crossing your limits within the boundary. Being an IaC tool it is bounded by the label of Infrastructure but within this domain, with the help of Providers and state-of-the-art approaches, it keeps on crossing its limits.</p><blockquote><strong>(2)</strong>As mentioned, that Providers are Plugins. These Plugins enable Terraform to interact with the desired API (Application Package Interface)/third-party Tools/Cloud Providers. These Providers are written in Go. Terraform allows you to create your own Custom Provider. Through these custom plugins, you get the leverage of allowing Terraform to interact with any API of your choice.</blockquote><blockquote><strong>(3)</strong>Declarative Management Tool are the ones that take in use the concept of Declarative Programming Language. To simply explain what Declarative Programming Language is, we can say that it is a style of programming in which the User is more concerned about<strong> What</strong> to do rather than thinking about<strong> How</strong> to do. Whereas, on the other hand, Imperative Language is the one that <strong>describes </strong>the entire <strong>process</strong> of how things must be done (how the program needs to run). Let’s take a simple example:<br>When a car enthusiast (one who really knows his business 🙂) goes to a Mechanic. He / She tells the Mechanic <strong>What</strong> all things need to be fixed in the Car. So, for the person, he/she just conveys <strong>What</strong> all the things the Mechanic needs to do. But <strong>How </strong>the Mechanic is going to do that? That is not the concern of the Client.</blockquote><h3>How Does Terraform Work?</h3><figure><img alt="Meme featuring a Minion character with the text “HOW HOW IS THIS POSSIBLE”" src="https://cdn-images-1.medium.com/max/576/1*A2_TWdqA7AQjAH0e94D0cQ.gif" /><figcaption>Created by <a href="https://tenor.com/users/whatsjason">whatsjason</a> on <a href="https://tenor.com/">Tenor</a></figcaption></figure><p>Now, now, now; here comes the question, which has started to extinct since the Dawn of the Era of AI. <strong>How??</strong>, so far, we understood <strong>What</strong> Terraform is and <strong>Why </strong>we need it. Now, let’s start with unfolding <strong>How</strong> does this language actually work.</p><figure><img alt="A diagram showing the flow from Developer to TF-Config and State-File, through Terraform Core, to Cloud Services, with icons representing various cloud providers." src="https://cdn-images-1.medium.com/max/511/1*nf6LmC4FH628gAwcZfGcfw.png" /><figcaption>Terraform Architecture</figcaption></figure><p>The above figure shows the basic layout of Terraform. Let us dive deep into how this entire architecture works. For this, let us break down the entire workflow into two subparts:</p><ol><li><strong>Part A</strong> tells about the working</li><li><strong>Part B</strong> talks about the files which are present during the runtime and the files which remains after the execution is completed</li></ol><figure><img alt="A GIF featuring a man in a dark, industrial-looking setting, gazing intently with text overlay reading “BEGIN STAGE ONE”" src="https://cdn-images-1.medium.com/max/576/1*dsiKcozF7O7RphT_rQ_BYA.gif" /><figcaption>Created by <a href="https://tenor.com/users/yuukicyan">yuukicyan</a> on <a href="https://tenor.com/">Tenor</a></figcaption></figure><figure><img alt="Diagram showing the relationship between TF-Config, TF-State File, and cloud resources" src="https://cdn-images-1.medium.com/max/1024/1*w60NbCWwt5BRZzc263PIeg.png" /><figcaption>Fig-1</figcaption></figure><h4><strong>Part A (Working):</strong></h4><p>So basically, what happens is that we have different types of files in Terraform, each having its own significance. In the above diagram, we can see two most important Files of Terraform: <strong>TF-Config &amp; State File</strong>.</p><p>Before understanding the flow, let us know what these two files are for:</p><ol><li><strong>TF-Config</strong>: This file is basically the code that we write. Generally, Main.tf etc. files that we write at our end are considered in it.</li><li><strong>State File</strong>: This file is the most important file in Terraform. A state file can be said to be a <strong>Map File</strong>. It Maps our scripts with Real-World Resources.</li></ol><p>The above flow takes place in the below manner:</p><figure><img alt="Flowchart of Terraform configuration and state file processes" src="https://cdn-images-1.medium.com/max/348/1*9PKijJuyDcLO5WVLXaf28A.png" /><figcaption>Flow of Tf-Config and State File</figcaption></figure><figure><img alt="A meme featuring a woman with long dark hair looking upward, with text overlay reading “ON TO PHASE TWO.”" src="https://cdn-images-1.medium.com/max/576/1*l9Yv1IJAzVrUwBrUvMLadA.gif" /><figcaption>Created by <a href="https://tenor.com/users/masoncarr2244">masoncarr2244</a> on <a href="https://tenor.com/">Tenor</a></figcaption></figure><h4><strong>Part B (Detail about the Files used by Terraform):</strong></h4><p>In this part, let us dive deeper into the different files that are created during the process shown in Fig-1. Let’s see the Insider Story.</p><ol><li><strong>State File:<br></strong>It is the one with <strong>.tfstate</strong> extension.<br>The key <strong>purpose</strong> of this file is to:<br>a. Keep track of the Configurations changes.<br>b. Keep track of Infrastructure modified.<br>c. Map our Code (Virtual) to the Real World (one that we can see on the Portal).<br>d. Keep Track of our Metadata to know which resource has what dependency.<br><strong>Need</strong> of State File:<br>1) It allows Terraform to support Multiple Cloud Providers.<br>2) It allows Terraform to become Declarative<br>3) It makes Terraform both Mutable and Immutable Infrastructure:<br> 3.1) Mutable: Upgrade the existing code by modifying it.<br> 3.2) Immutable: Never Modify the code once it has been created.<br>Key <strong>points about</strong> State file:<br>a. For the very first time, it is created after we use <strong>terraform apply </strong>command.<br>b. State file supports One to One Mapping.<br><strong>Structure </strong>of the State file:<br>a. <strong><em>version</em></strong>: Version of the State File Format.<br>b. <strong><em>terraform_version</em></strong>: Version of Terraform that has created the file.<br>c. <strong><em>serial</em></strong>: It is a counter that increments after every change made in the state.<br>d. <strong><em>Lineage</em></strong>: An identity given which is unique to a state file.<br>e. <strong><em>resources</em></strong>: All the resources managed by Terraform.</li><li><strong>Tfstate.backup File:</strong><br>a. It is the backup File of <strong>State </strong>file.<br>b. It is created before any changes are made to the State File. This means if State File is at Position <strong>X</strong> then<em> tfstate.backup File</em> is at Position <strong>X-1</strong>.<br>c. It is stored in the same directory in which the State File is stored.<br>d. It is <em>overwritten</em> only when any changes are <em>made in the State File</em>.</li><li><strong>.terraform.lock.hcl:</strong><br>a. It is generated when we run <strong>terraform</strong> <strong>init.</strong><br>b. It contains the configuration of the terraform code (including all the modules) and is loaded in the terraform cache.<br>c. It <em>locks the Version</em> of the Provider Plugin that is being used in our Configuration. This means that if I am using an <strong>X Plugin</strong> then until the entire Script runs, that Plugin will be locked so that during the runtime if someone tries to change the Plugin Code, the Script doesn’t stop to return an error.</li><li><strong>.terraform.tfstate.lock.info:</strong><br>a. It is a temporary file created when Terraform applies lock on the State.<br>b. It prevents multiple users/processes from <em>modifying</em> the states simultaneously. Therefore, we can say that it <em>locks the State</em>.</li></ol><p>So, through this we get to know that Terraform uses a State File and maintains a backup of that State File. Furthermore, we learn that Terraform implements locking mechanisms not only for Plugins (dependency) but also for the State File during execution.</p><h3>Basic Commands of Terraform</h3><blockquote>“Consider this command cheat sheet your secret weapon — a little gift from me to you, because who doesn’t love a good shortcut?”</blockquote><figure><img alt="Diagram of basic Terraform commands and their flow, with a quote about command shortcuts." src="https://cdn-images-1.medium.com/max/1024/1*yPH2LX1MyjB_5bpzrOZ2GA.png" /><figcaption>Basic Flow of how the commands should be used</figcaption></figure><ol><li><strong>terraform init</strong>: It Initializes the Project and the Provider (if we have changed the provider).</li><li><strong>terraform fmt</strong>: Format the Terraform Code. (just to make the code look good 😅😑)</li><li><strong>terraform refresh:</strong> Get current State (not necessary to use this command)</li><li><strong>terraform plan:</strong> — Create an Execution Plan. I.e. Take TF-Config and State as Input and understand what needs to be done (creating a proper Plan on how the Execution should be done).</li><li><strong>terraform apply:</strong> Make actual changes to cloud</li><li><strong>terraform show: </strong>Inspect current state inside the Infra (see what all changes have been made inside the infrastructure deployed)</li><li><strong>terraform destroy:</strong> Delete everything in configuration file</li></ol><h3>Conclusion</h3><p>And <strong>that’s a wrap</strong>!! So the first part of the story ends here😌. But this is not the end, my friend, it’s just a start. As we continue this journey, remember that the world of Infrastructure as Code is vast and ever-evolving. With Terraform, you’re not just automating infrastructure; you’re crafting the future of cloud management.</p><p>Stay tuned for another story 🤗</p><p>Until then, happy coding, and may your infrastructure always be resilient and scalable! 🚀</p><blockquote>Coding is not always about What you write, it is about WHY? you write it— Author</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a96c8a8309b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>