<?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 Ajinkya Bhabal on Medium]]></title>
        <description><![CDATA[Stories by Ajinkya Bhabal on Medium]]></description>
        <link>https://medium.com/@bhabalajinkya?source=rss-bba14091c643------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Vwy-y27I35vPmQD6MVTCUw.jpeg</url>
            <title>Stories by Ajinkya Bhabal on Medium</title>
            <link>https://medium.com/@bhabalajinkya?source=rss-bba14091c643------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 04:22:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bhabalajinkya/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[Scaling down Google Kubernetes cluster to zero during off-peak hours]]></title>
            <link>https://bhabalajinkya.medium.com/scaling-down-google-kubernetes-cluster-to-zero-during-off-peak-hours-4281b464d14e?source=rss-bba14091c643------2</link>
            <guid isPermaLink="false">https://medium.com/p/4281b464d14e</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[cost-optimization]]></category>
            <dc:creator><![CDATA[Ajinkya Bhabal]]></dc:creator>
            <pubDate>Mon, 03 Apr 2023 11:56:48 GMT</pubDate>
            <atom:updated>2023-04-04T10:24:35.925Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/769/1*WCusEN3aY22oqSr5i860kQ.jpeg" /></figure><h4><strong>Introduction</strong></h4><p>This step-by-step guide helps you to scale down GKE clusters in an off-hour to zero for cost optimization. It will be helpful in enterprises for developers and the Ops team who want to scale up GKE Clusters before the spike arrive and scale it down again at night and on weekends to save money.</p><p>It is recommended to use in development or testing environments only.</p><p>We will be using the following google cloud resources to achieve this</p><ol><li>Cloud Scheduler</li><li>Cloud Run</li><li>Artifact Registry</li></ol><p>In this architecture, We have implemented Cloud run jobs that only run their tasks and exit when finished. Using Cloud scheduler to schedule the cloud run jobs at a certain interval in the time of day.</p><p>There will be two jobs running, First in the morning at 9 AM to scale up the GKE cluster and at the end of the day at 8 PM to scale down the GKE cluster to zero. Also, it will be running from Monday to Friday only accordingly cron job can be written.</p><p>Let’s start with the implementation in Google Cloud.</p><p>First, Enable services (Cloud Run, Cloud Scheduler) and Create a Service account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t2QnVYF7A3Mm4mMkYXq8rw.png" /></figure><p>Setup permissions on SA for cloud run to invoke the jobs and pull the latest image from the Artifact registry and resize the Kubernetes cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5OJ8jdb_dN7G5cYKo1KkuQ.png" /></figure><p>Create Artifact Repository where we will store scale down and up docker images.</p><ul><li>Repository for GKE Scale down docker Image</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TPNSDRM9ISAqRPoCxK01Kg.png" /></figure><p>Use following commands if you want to push docker images to Google Artifact registry.</p><p>Here’s the bash script used for scaling down the GKE cluster.</p><p>The following bash script will check all GKE clusters with the prefix ‘test’ in a name and will scale down all node pools to zero within those clusters.</p><blockquote><strong>Note</strong>: When autoscaling is turned on, Script will not scale the cluster to zero. After validating your scaling work, make sure to turn off the autoscaling.</blockquote><pre>#!/bin/bash<br><br>CLOUD_RUN_TASK_INDEX=${CLOUD_RUN_TASK_INDEX:=0}<br>CLOUD_RUN_TASK_ATTEMPT=${CLOUD_RUN_TASK_ATTEMPT:=0}<br><br>echo &quot;Starting Task #${CLOUD_RUN_TASK_INDEX}, Attempt #${CLOUD_RUN_TASK_ATTEMPT}...&quot;<br><br>echo &quot;Scaling down test gke cluster instances&quot;<br><br>for CLUSTER_NAME in  $(gcloud container clusters list --format=&quot;value(name)&quot; --filter=&quot;name~test*&quot;)<br>do<br>    for NP_NAME in $(gcloud container node-pools list --cluster=$CLUSTER_NAME --format=&quot;value(name)&quot; --zone=asia-south1-a)<br>    do<br>        gcloud container clusters resize $CLUSTER_NAME --node-pool $NP_NAME --num-nodes 0 --zone=asia-south1-a --quiet<br>    done<br>done<br><br>retVal=$?<br>if [[ $retVal -eq 0 ]] <br>then<br>    echo &quot;Completed Task # ${CLOUD_RUN_TASK_INDEX}.&quot;<br>else<br>    echo &quot;Task #${CLOUD_RUN_TASK_INDEX}, Attempt #${CLOUD_RUN_TASK_ATTEMPT} failed.&quot;<br>fi</pre><p>Next will create Dockerfile to run above bash script.</p><pre>FROM google/cloud-sdk:latest<br><br># Execute following commands in the folder /gke_scripts<br>WORKDIR /gke_scripts<br><br># Copy over the script to the /gke_scripts folder<br>COPY scale_down.sh .<br><br># Just in case the script doesn&#39;t have the executable permissions set<br>RUN chmod +x ./scale_down.sh<br><br># Run the script when starting the container<br>CMD [ &quot;./scale_down.sh&quot; ]   </pre><p>We will run following commands to push docker image to Artifact repository.</p><blockquote>gcloud auth configure-docker asia-south1-docker.pkg.dev</blockquote><blockquote>docker build -t scdown .</blockquote><blockquote>docker tag scdown asia-south1-docker.pkg.dev/flawless-helper-376817/gke-sc-d/v0.0.1</blockquote><blockquote>docker push asia-south1-docker.pkg.dev/flawless-helper-376817/gke-sc-d/v0.0.1</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k0UuewFtJ05rK1siIztLWA.png" /></figure><p>Now we will create Cloud run job with above container image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MkXqHYxq6Dp_lon_PSY1-A.png" /></figure><p>We will be creating job in asia-south1(Mumbai) region.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-IZYte9IpQJcK00LZBNXfA.png" /></figure><p>In the Security section, We have to provide previously created Service account name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9Wkjcm_SxH89eskcXmX-AA.png" /></figure><p>Finally, We are Setting up scheduler to execute the job on cloud run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9tXRJ7oC0Cx82x6_WocBKg.png" /></figure><p>We have set the following trigger URL in the cloud scheduler to invoke the cloud run.</p><blockquote><a href="https://asia-south1-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/flawless-helper-376817/jobs/gke-scale-down-v1:run">https://asia-south1-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/flawless-helper-376817/jobs/gke-scale-down-v1:run</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mv2rl3szCVIQD10ebS6zRA.png" /></figure><p>For authentication OAuth configured with previously created Service account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vsfUrbn2qFYIT_JoHUssrA.png" /></figure><p>Now after the scheduler triggers the cloud run will get the following result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V2IgYBPxX7JqYR-0ubqFLw.png" /></figure><p>In the logs of the Cloud run job, we can see that cluster has been resized successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qDbjo11UmbVZtON7N7iq0w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*69Unui1WZH_E9nDCeRkTDQ.png" /></figure><p>GKE cluster has been scaled to zero nodes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YBITi7Aq5EC2XSUFaaDhtQ.png" /></figure><p><strong>Conclusion:</strong></p><p>Here we have learned, that using this simple implementation we can reduce the cost of a Google Kubernetes Engine cluster in dev/test environment.</p><p>If you’d like to read more about IaaC tools, Kubernetes topics, Just let me know in the comments. Thanks for reading!</p><p><strong>Ref link -</strong></p><p><a href="https://codelabs.developers.google.com/cloud-run-jobs-and-cloud-scheduler#0">Triggering Cloud Run Jobs with Cloud Scheduler | Google Codelabs</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4281b464d14e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Teleport: Securely authenticating to Kubernetes clusters with MFA]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://faun.pub/teleport-securely-authenticating-to-k8s-clusters-with-mfa-42a4d1aad440?source=rss-bba14091c643------2"><img src="https://cdn-images-1.medium.com/max/2312/1*RAHmolC--zbpMi7JiTH3Gg.png" width="2312"></a></p><p class="medium-feed-snippet">Introduction</p><p class="medium-feed-link"><a href="https://faun.pub/teleport-securely-authenticating-to-k8s-clusters-with-mfa-42a4d1aad440?source=rss-bba14091c643------2">Continue reading on FAUN.dev()  »</a></p></div>]]></description>
            <link>https://faun.pub/teleport-securely-authenticating-to-k8s-clusters-with-mfa-42a4d1aad440?source=rss-bba14091c643------2</link>
            <guid isPermaLink="false">https://medium.com/p/42a4d1aad440</guid>
            <category><![CDATA[compliance]]></category>
            <category><![CDATA[teleport]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[cloud-security]]></category>
            <dc:creator><![CDATA[Ajinkya Bhabal]]></dc:creator>
            <pubDate>Mon, 01 Aug 2022 05:03:20 GMT</pubDate>
            <atom:updated>2022-08-03T03:38:43.081Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[kpt — Packaging tool for Kubernetes workload]]></title>
            <link>https://blog.searce.com/kpt-packaging-tool-for-kubernetes-workload-9a065888dec1?source=rss-bba14091c643------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a065888dec1</guid>
            <category><![CDATA[gitops]]></category>
            <category><![CDATA[gke]]></category>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[cloud]]></category>
            <dc:creator><![CDATA[Ajinkya Bhabal]]></dc:creator>
            <pubDate>Sun, 24 Jul 2022 11:04:53 GMT</pubDate>
            <atom:updated>2022-07-29T17:40:45.511Z</atom:updated>
            <content:encoded><![CDATA[<h3>kpt — Packaging tool for Kubernetes workload</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*Zdavwu79rcCP2ZCtY0jPtA.jpeg" /></figure><h3>What is kpt?</h3><p>kpt is a package manager for k8s alternative to our traditional helm charts built by Google. kpt lets you reuse and share package across all environments. We can perform operations like Package k8s configs, pull those from GitHub, with a single command update all files in the package, and again update the latest files in GitHub.</p><p>Let’s see it in action</p><p><strong>Installation of kpt tool</strong></p><pre>mkdir -p ~/bin<br>curl -L https://github.com/GoogleContainerTools/kpt/releases/download/v1.0.0-beta.1/kpt_linux_amd64 --output ~/bin/kpt &amp;&amp; chmod u+x ~/bin/kpt<br>export PATH=${HOME}/bin:${PATH}</pre><p>First, we have written a sample Nginx deployment and service and stored it on GitHub.</p><p><a href="https://github.com/ajinkya101/kpt-demo-repo">GitHub - ajinkya101/kpt-demo-repo</a></p><pre># fetch nginx application sub-directory<br>kpt pkg get <a href="https://github.com/ajinkya101/kpt-demo-repo.git/Packages/Nginx">https://github.com/ajinkya101/kpt-demo-repo.git/Packages/Nginx</a></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I_I-D82JTTgKq60CxHVp9g.png" /></figure><p>To examine the package contents run</p><pre>kpt pkg tree Nginx</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z3oUzWrkTcUwEwHoxyaczw.png" /></figure><p>We will be now using kpt functions to modify configurations across all files.</p><ol><li>Set Labels</li></ol><pre>kpt fn eval --image gcr.io/kpt-fn/set-labels:v0.1.5 -- env=dev</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7O8FpIGudtb4tX_h1nyPbA.jpeg" /></figure><p>Now we can check the Nginx deployment and service file for changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2GcR9pnaEpiMKVW1zX8SSw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EOTB9Z3g7Pfxg4HCFZEShA.png" /></figure><p>2. Set Namespace</p><p>Let’s say the current config is getting deployed in the default Namespace and as per best practice application should be deployed in its dedicated namespace. So rather than manually modifying all files to insert namespace details. We can run just a single command kpt will add the namespace in all files.</p><pre>kpt fn eval --image gcr.io/kpt-fn/set-namespace:v0.1 -- namespace=nginx-deploy</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uw7qc2NVtFm5RXcrSoXHZw.png" /></figure><p>Now we can check the Nginx deployment and service file for changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JXqzOJkAlr169w3xwo487A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7jcXFM7Di7hBevuQ2r-7_A.png" /></figure><p>Till now we have imperatively executed kpt functions, but also we do have an option to provide in a declarative manner with pipeline file.</p><p>In the following example, I have added one new label, so kpt will check all files and then find out one label is present and another need to be added.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ee16b2ffef1cce313b31b884abb2d65/href">https://medium.com/media/8ee16b2ffef1cce313b31b884abb2d65/href</a></iframe><p>To execute the pipeline, we need to run the following command.</p><pre>kpt fn render Nginx</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YmFJ4OWZ8DZC6qkzIUTw1Q.png" /></figure><p>So this is how kpt file looks when we download the Nginx package.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/737/1*EuaWhPHfIYiWeZ0T2xnryg.png" /></figure><p>So after performing the required changes we will be pushing updated content on the remote repository.</p><p>Now we initialize package for the deployment</p><pre>kpt live init Nginx</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*Brv1tbxdFiI5eJr08eez2A.png" /></figure><p>Applied the configuration to our GKE cluster.</p><pre>kpt live apply Nginx</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*Pg8LdEgpR8laAqWpcoMt2g.png" /></figure><p>Here we can see the latest tags has been applied.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ujl3P0DXSiXzO1bMn3pn8g.png" /></figure><p>To view the status of all k8s resources</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*lTRz2nbB8bN12p8VB30gXQ.png" /></figure><p>Here we are using Pure ‘Yaml’ to describe and operate Kubernetes files. In my future article, I would be briefing about how we can adopt the tool in our GitOps-based architecture.</p><p>If you’d like to read more about IaaC tools, Kubernetes topics, Just let me know in the comments. Thanks for reading!</p><p>You can connect me on #LinkedIn</p><p><a href="https://www.linkedin.com/in/ajinkya-bhabal/">Ajinkya Bhabal ☁ - Mumbai, Maharashtra, India | Professional Profile | LinkedIn</a></p><p>Ref links —</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FG5_iJaqThmk%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DG5_iJaqThmk&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FG5_iJaqThmk%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/b47b849d7a588cf110a17ff1ba809654/href">https://medium.com/media/b47b849d7a588cf110a17ff1ba809654/href</a></iframe><p><a href="https://github.com/GoogleContainerTools/kpt">GitHub - GoogleContainerTools/kpt: Automate Kubernetes Configuration Editing</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a065888dec1" width="1" height="1" alt=""><hr><p><a href="https://blog.searce.com/kpt-packaging-tool-for-kubernetes-workload-9a065888dec1">kpt — Packaging tool for Kubernetes workload</a> was originally published in <a href="https://blog.searce.com/">Searce</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Send Azure Infrastructure Alerts to Microsoft Teams!]]></title>
            <link>https://faun.pub/send-azure-infrastructure-alerts-to-microsoft-teams-2bbe09f7073d?source=rss-bba14091c643------2</link>
            <guid isPermaLink="false">https://medium.com/p/2bbe09f7073d</guid>
            <category><![CDATA[arm-templates]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[alerts]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[monitoring]]></category>
            <dc:creator><![CDATA[Ajinkya Bhabal]]></dc:creator>
            <pubDate>Sun, 15 May 2022 08:55:14 GMT</pubDate>
            <atom:updated>2022-05-16T13:04:48.867Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i4UqthSVfBro3a1DGJwAkg.jpeg" /></figure><h3><strong>Introduction</strong></h3><p>Today, we’ll be looking at how to get Azure alerts in the Microsoft teams channel, which will help us reduce email overload and provide a centralized location where all team members can watch alerts and take action according to them.</p><p>Here we’ll be using the Logic app to post a message in the Teams channel, as it contains a built-in Microsoft teams Connector and with it’s consumption based capability we would have the pay-per-use model.</p><p>In the following scenario, I have taken the Azure Redis resource on which alerts have been configured.</p><p>Let’s Understand the Azure Redis Alert configuration and its components.</p><ul><li>First, we have defined the base resource of the Azure logic app.</li><li>Then the Workflow configuration is specified in ARM Template and the reason is it’s still a complex configuration in terraform and even if the API Connection resource was released recently, It&#39;s very difficult to work within the logic app structure.</li><li>The best thing is with help of “<em>azurerm_resource_group_template_deployment” </em>Resource Terraform manages the ARM deployed resources also.</li><li>Creating a New Action Group where Logic app callback URL is configured in Webhook.</li><li>Following alerts have been configured<br>- Azure Redis CPU Usage Threshold reaches above 90%<br>- Azure Redis Memory Usage Threshold reaches above 90%<br>- Azure Logic App Runs failed</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4825ca6f289de9abf81aa5adc67b07e1/href">https://medium.com/media/4825ca6f289de9abf81aa5adc67b07e1/href</a></iframe><p>Now let&#39;s take a look at the Workflow configuration which is written in the ARM Template.</p><ul><li>First, API Connection for Teams has been configured. Here I have created one account in the Office admin portal with access to the Microsoft teams app that will post messages as the service account. After deploying Resources we have to manually authenticate with that account.</li><li>The Default HTTP Trigger has been configured, The Callback URL generated from which will be utilized by the Alert Action group to notify the logic app about the alert triggered.</li><li>With this, our logic app can parse, consume and pass along the data from the HTTP request through the trigger into our workflow.</li><li>From the result of the above trigger, we will check whether the alert status has been activated or not. Based on that condition would be set up.</li><li>Then in the If section we will add the “Post a Message in teams chat” action and write a custom message about the triggered alert with all of it’s detail and in a similar way else section will add the “Post a Message in teams chat” action and write a custom message about the alert resolved.</li><li>From the terraform we will provide input for Microsoft Teams Id and Microsoft Teams Channel Id.<br>- To get the above values we need to go to “Get a link to the team”.<br>- e.g. <strong><em>Microsoft Teams Channel ID</em></strong> — 19%3aKsrELenmjB3PYM6jgWbk9nu5J_e191NOoZoIC9vwHbk1%40thread.tacv2<br>- <strong><em>Microsoft Teams ID</em></strong> — groupId=4dbebb37-c017–4483-aa8b-26d4a01b4de8</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a01a33108f16c6646dce322ba0682e39/href">https://medium.com/media/a01a33108f16c6646dce322ba0682e39/href</a></iframe><p>Complete Terraform Code available here —</p><p><a href="https://github.com/ajinkya101/infra-alerts-teams">GitHub - ajinkya101/infra-alerts-teams</a></p><p>To perform a stress test on Redis Instance “Redis-benchmark” tool is used here.</p><p>To test things out, I have reduced the threshold value to 5% to quickly get an alert from the Redis instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xPs8CxQMte2j8jTCyXbJLw.png" /></figure><p>Now we will start the stress test on the Redis instance with the following command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yzQSstM29RfpSRq9nN3yXA.png" /></figure><p>The alert is triggered for CPU usage, let’s take a look at it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qzTCdqbd5y9_61Fi7YWESg.png" /></figure><p>On our Microsoft Teams channel, we will get a notification about alert triggered for Azure Redis Resource.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IJgqwAjJEAisX2vLbdhINQ.jpeg" /></figure><p>After successfully remediation action is performed on the instance we will get notified about the alert has been resolved.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zQbnfZIF8_Azdjh_A6OJbg.jpeg" /></figure><p>If you’d like to read more about IaaC tools and Azure Cloud topics, Just let me know in the comments. <strong>Thanks for reading!</strong></p><p>You can connect me on #LinkedIn</p><p><a href="https://www.linkedin.com/in/ajinkya-bhabal/">Ajinkya Bhabal ☁ - Mumbai, Maharashtra, India | Professional Profile | LinkedIn</a></p><figure><a href="https://faun.to/bP1m5"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BCiLLad3dvZLwBa-B5cAVQ.png" /></a></figure><p>Join FAUN: <a href="https://faun.to/i9Pt9"><strong>Website</strong></a><strong> </strong>💻<strong>|</strong><a href="https://faun.dev/podcast"><strong>Podcast</strong></a><strong> </strong>🎙️<strong>|</strong><a href="https://twitter.com/joinfaun"><strong>Twitter</strong></a><strong> </strong>🐦<strong>|</strong><a href="https://www.facebook.com/faun.dev/"><strong>Facebook</strong></a><strong> </strong>👥<strong>|</strong><a href="https://instagram.com/fauncommunity/"><strong>Instagram</strong></a><strong> </strong>📷|<a href="https://www.facebook.com/groups/364904580892967/"><strong>Facebook Group</strong></a><strong> </strong>🗣️<strong>|</strong><a href="https://www.linkedin.com/company/faundev"><strong>Linkedin Group</strong></a><strong> </strong>💬<strong>|</strong> <a href="https://faun.dev/chat"><strong>Slack</strong></a> 📱<strong>|</strong><a href="https://thechief.io/"><strong>Cloud Native</strong> <strong>News</strong></a><strong> </strong>📰<strong>|</strong><a href="https://linktr.ee/faun.dev/"><strong>More</strong></a><strong>.</strong></p><p><strong>If this post was helpful, please click the clap 👏 button below a few times to show your support for the author 👇</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2bbe09f7073d" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/send-azure-infrastructure-alerts-to-microsoft-teams-2bbe09f7073d">Send Azure Infrastructure Alerts to Microsoft Teams!</a> was originally published in <a href="https://faun.pub/">FAUN.dev() 🐾</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Refactor Terraform Repository to Modular structure]]></title>
            <link>https://faun.pub/refactor-terraform-repository-to-modular-structure-eaac70f2130d?source=rss-bba14091c643------2</link>
            <guid isPermaLink="false">https://medium.com/p/eaac70f2130d</guid>
            <category><![CDATA[modules]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[enterprise]]></category>
            <dc:creator><![CDATA[Ajinkya Bhabal]]></dc:creator>
            <pubDate>Sun, 13 Feb 2022 13:02:05 GMT</pubDate>
            <atom:updated>2022-02-18T11:12:36.441Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lewnp-1toselOdia.jpg" /><figcaption>Image Credits: Cloudzero</figcaption></figure><h3>Introduction</h3><p>Most of the organizations when they start working on terraform to build cloud resources, they usually go with the traditional approach. Where all resource configurations are specified in a single directory. So with the traditional monolithic approach, it becomes very difficult to manage the codebase as it grows. As per best practice given by HashiCorp for production workloads terraform reusable modular structure should be used to build infrastructure.</p><p>Now there are two ways from which code can be refactored into DRY modules.</p><p><strong>1. Terraform state mv command</strong></p><p>Let’s understand the first approach, With the state mv command we will be making changes in terraform state file to move resource block to the modular structure.</p><p>e.g.</p><blockquote>terraform state mv packet_device.worker module.worker.packet_device.worker</blockquote><p>When your workload running in production through CI/CD pipeline you don’t want to make changes manually by running the state mv command to refactor the code, A small mistake can lead to losing track of terraform managed resources, which can eventually compromise the security of our operations. So we have to be very careful while making changes to the state file.</p><p><strong>2. Moved block</strong></p><p>Now let’s talk about the Second approach, Moved block feature recently released with terraform v1.1 will also be used for refactoring the terraform code.</p><p>Terraform has brought one of the best features to refactor the code by simply providing <strong>Moved block</strong> in your code where we can easily move from the traditional single directory structure to the DRY Module structure.</p><p>Let me give you an example,</p><p>Here we have deployed a single Azure resource group containing one virtual network and one subnet in it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b25a0c4ab2bf6ee7d81278f41f5e037a/href">https://medium.com/media/b25a0c4ab2bf6ee7d81278f41f5e037a/href</a></iframe><p>Now we want to move it to the following modular structure.</p><pre>¦  +-- RG</pre><pre>¦  ¦ +-- main.tf</pre><pre>¦  ¦ +-- output.tf</pre><pre>¦  ¦ +-- variables.tf</pre><pre>¦  +-- VNET</pre><pre>¦  ¦ +-- main.tf</pre><pre>¦  ¦ +-- output.tf</pre><pre>¦  ¦ +-- variables.tf</pre><pre>+-- main.tf</pre><pre>+-- output.tf</pre><pre>+-- variables.tf</pre><pre>+-- README.md</pre><p>We will prepare the Modular terraform code with the same configuration along with “Moved Block”. Now we need to comment out all existing code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/096072c321f3718420ae02ec304a14d0/href">https://medium.com/media/096072c321f3718420ae02ec304a14d0/href</a></iframe><p>When we run again the terraform plan command will see no changes are required.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O-6vBq8JrpFQ11qj2RWbpQ.jpeg" /></figure><p>After verifying we can run terraform apply command and state file will be updated with modular resource configurations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lDHXiZp9a6zkg7HZqx8PeQ.jpeg" /></figure><p>With state list command we can see the updated information in the state file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0IrrQZ09t7RIozD0TA4VSg.png" /></figure><p>Now the best thing is after migrating to the modular structure, we can remove the Moved block and existing terraform code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ba_XoO_Zd-DMBZXGCA-0Fg.jpeg" /></figure><p><strong>Conclusion</strong></p><p>Here we learn that even if the organization does not follow core best practices of Terraform, they can still walk towards achieving an efficient and consistent result in the future. If you have any feedback or suggestions you can ask in the comments.</p><blockquote><em>Full code is available on github :-</em><a href="https://github.com/ajinkya101/tf-move.git"><em> </em>github.com/ajinkya101/tf-move.git</a></blockquote><p>You can connect me @<a href="https://www.linkedin.com/in/ajinkya-bhabal/">Ajinkya Bhabal | LinkedIn</a></p><p><strong>Reference links</strong></p><ul><li><a href="https://www.hashicorp.com/blog/structuring-hashicorp-terraform-configuration-for-production">Structuring HashiCorp Terraform Configuration for Production</a></li><li><a href="https://www.terraform.io/language/modules/develop/refactoring">Refactoring | Terraform by HashiCorp</a></li></ul><figure><a href="https://faun.to/bP1m5"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BCiLLad3dvZLwBa-B5cAVQ.png" /></a></figure><p>Join FAUN: <a href="https://faun.to/i9Pt9"><strong>Website</strong></a><strong> </strong>💻<strong>|</strong><a href="https://faun.dev/podcast"><strong>Podcast</strong></a><strong> </strong>🎙️<strong>|</strong><a href="https://twitter.com/joinfaun"><strong>Twitter</strong></a><strong> </strong>🐦<strong>|</strong><a href="https://www.facebook.com/faun.dev/"><strong>Facebook</strong></a><strong> </strong>👥<strong>|</strong><a href="https://instagram.com/fauncommunity/"><strong>Instagram</strong></a><strong> </strong>📷|<a href="https://www.facebook.com/groups/364904580892967/"><strong>Facebook Group</strong></a><strong> </strong>🗣️<strong>|</strong><a href="https://www.linkedin.com/company/faundev"><strong>Linkedin Group</strong></a><strong> </strong>💬<strong>|</strong> <a href="https://faun.dev/chat"><strong>Slack</strong></a> 📱<strong>|</strong><a href="https://thechief.io/"><strong>Cloud Native</strong> <strong>News</strong></a><strong> </strong>📰<strong>|</strong><a href="https://linktr.ee/faun.dev/"><strong>More</strong></a><strong>.</strong></p><p><strong>If this post was helpful, please click the clap 👏 button below a few times to show your support for the author 👇</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eaac70f2130d" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/refactor-terraform-repository-to-modular-structure-eaac70f2130d">Refactor Terraform Repository to Modular structure</a> was originally published in <a href="https://faun.pub/">FAUN.dev() 🐾</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Infracost : Cost estimates for the IaC Resources in Azure]]></title>
            <link>https://faun.pub/infracost-cost-estimates-for-the-iac-resources-in-azure-e840ab556d12?source=rss-bba14091c643------2</link>
            <guid isPermaLink="false">https://medium.com/p/e840ab556d12</guid>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[microsoft]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[cost]]></category>
            <dc:creator><![CDATA[Ajinkya Bhabal]]></dc:creator>
            <pubDate>Wed, 30 Jun 2021 08:26:38 GMT</pubDate>
            <atom:updated>2022-03-01T11:15:45.752Z</atom:updated>
            <content:encoded><![CDATA[<h3>Infracost : Cost estimates of the IaC Resources for Azure</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yfVf8PK1XDivHW7m.png" /><figcaption>Credits: Infracost</figcaption></figure><h3>Introduction</h3><p>As we are moving forward to automate the infrastructure deployment, Terraform has become the top choice among the DevOps and Software Engineers as an IaC tool. There are so many Continuous Integration/Continuous Deployment tools available in the Market for Automate Infrastructure deployment. Some of them are Azure DevOps, Jenkins, Atlantis, GitHub Action, GitLab, Circle CI.</p><p>The common workflow of Infrastructure as code deployment is after following the IaC best practices, the code will be stored in VCS and Code review operation will be done by the other Contributors, then it will be deployed in the public cloud. So the Contributors have to find cost estimates of the Infrastructure through external estimates tool, which involves lots of manual work.</p><p>So to avoid this Terraform has been providing cloud cost estimates feature in its paid plan.</p><p>A few days ago, I found this Awesome open-source tool named “<strong>Infracost</strong>” which supports over 140 resources, and the best thing is it works perfectly with the Terragrunt.</p><p>To get a basic introduction of the “<strong>Infracost” </strong>tool and a quick walkthrough of the CLI Tool, Please visit the below reference.</p><p><a href="https://www.infracost.io/docs/">Get started | Infracost</a></p><p>In this article, I will demonstrate a tutorial of “<strong>Infracost” </strong>integration with the two CI/CD Tools.</p><h3>1. Infra Cost Estimation Review with Atlantis</h3><blockquote>Atlantis is Terraform Pull Request Automation Tool.</blockquote><p>Here we will try out “<strong>Infracost” </strong>tool in the Atlantis Configured GitHub used for Terraform Deployment.</p><p>First, take a quick look at the Customized Atlantis Docker Image for the “<strong>Infracost”</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d40cf5e31b13ebc198dec11240fc826/href">https://medium.com/media/3d40cf5e31b13ebc198dec11240fc826/href</a></iframe><p>The above Atlantis Container Image contains the following elements,</p><ol><li>Install Azure CLI Tool.</li><li>Install Terraform v0.15.5 Package.</li><li>Install Infracost Tool.</li><li>Configure and Start Atlantis Server</li></ol><p>Next, Configure Repo Level repos.yaml file which allows us to instruct Atlantis on the structure of your repo and set custom workflows.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb1114c606f5c83e1ca533adf17c589a/href">https://medium.com/media/cb1114c606f5c83e1ca533adf17c589a/href</a></iframe><p>Now you can deploy this container image in Azure Kuberenetes Service and exposed with Load balancer Service mapping default Atlantis Port 4141 to 80.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4n7p4J_8PPWX4U70bLL7sQ.jpeg" /></figure><p>Now we will create Pull request for Terraform Deployment, as you can see from below image Atlantis plan command is commented. So behind the scenes it runs the Terraform Plan command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f7t9uVHiyM2f6hdRtgvREw.jpeg" /></figure><p>At the end of Plan output we can see the Cost estimates calculated by the Infracost tool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1eabBRFMVol2kwuHWFLsoQ.jpeg" /></figure><p>Before deploying the resources we can set the approval gates, this feature is already provided by the Atlantis.</p><p><a href="https://www.runatlantis.io/docs/apply-requirements.html#supported-requirements">Apply Requirements | Atlantis</a></p><p>Next we will perform Atlantis Apply operation and all the Azure Resources will be deployed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uUQjcqwGlY3UfCsbDwqOJg.jpeg" /></figure><p>After the Apply Operation completes the pull request will automatically merged with the Master Branch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9IJX1kgM_-NlY5qdIWTC5g.jpeg" /></figure><p>In the Azure Portal, We can see the Deployed Resource.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uGFC7-5SqsUlqzQ3no6iYg.jpeg" /></figure><h3>2. Infra Cost Estimation Review with GitHub Actions</h3><blockquote>GitHub Actions is CI/CD tool used for Build, Test and Deploy your code from GitHub.</blockquote><p>Let’s Start with the configuring GitHub Actions Pipeline yml file for customizing the workflow of Terraform along with “<strong>Infracost”</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd6c7cba2609cdc7473362994cbf932d/href">https://medium.com/media/cd6c7cba2609cdc7473362994cbf932d/href</a></iframe><p>We will be using GitHub Secrets to Store our Azure Authentication Credentials and Infracost API Key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D4Q8o9tpaviNP-TJK6meFA.jpeg" /></figure><p>After configuring GitHub Actions we will create pull request where other contributors can check resource deployment along with Cost estimates using Infracost.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZJd-OooygKFxzlOg7_oyJg.jpeg" /></figure><p>Here we can see the Infracost has sent the Cost estimates of all azure terraform resources in the comment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cTvnGd0suB5DK0iKc_S3zg.jpeg" /></figure><p>Here also we set the approval using branch protection rule, where atleast one reviewer is needed to approve the Resource deployment.</p><p><a href="https://docs.github.com/en/github/administering-a-repository/defining-the-mergeability-of-pull-requests/managing-a-branch-protection-rule">Managing a branch protection rule</a></p><p>Then we will Merge the pull request to the main branch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UB7M_2Tr00aJO0_PGrDqwA.jpeg" /></figure><p>In the pipeline configuration file, we have set the condition about when we merge the Pull request to the main branch, then Terraform Apply command will be executed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*joO5DOlkVDiVNtEwlFt0LQ.jpeg" /></figure><p>Finally we can see the deployed resource in Azure Portal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VF5DI17uKjxxpfwTbvsTEw.jpeg" /></figure><p>It’s always great to learn and explore something new, in IaC there are still so many blockades that we need to solve to get higher efficiency in the automation process.</p><p>If you’d like to read more about IaaC Tools or Popular Terraform wrappers, Just let me know in the comments. <strong>Thanks for reading!</strong></p><figure><a href="https://faun.to/bP1m5"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BCiLLad3dvZLwBa-B5cAVQ.png" /></a></figure><p>Join FAUN: <a href="https://faun.to/i9Pt9"><strong>Website</strong></a><strong> </strong>💻<strong>|</strong><a href="https://faun.dev/podcast"><strong>Podcast</strong></a><strong> </strong>🎙️<strong>|</strong><a href="https://twitter.com/joinfaun"><strong>Twitter</strong></a><strong> </strong>🐦<strong>|</strong><a href="https://www.facebook.com/faun.dev/"><strong>Facebook</strong></a><strong> </strong>👥<strong>|</strong><a href="https://instagram.com/fauncommunity/"><strong>Instagram</strong></a><strong> </strong>📷|<a href="https://www.facebook.com/groups/364904580892967/"><strong>Facebook Group</strong></a><strong> </strong>🗣️<strong>|</strong><a href="https://www.linkedin.com/company/faundev"><strong>Linkedin Group</strong></a><strong> </strong>💬<strong>|</strong> <a href="https://faun.dev/chat"><strong>Slack</strong></a> 📱<strong>|</strong><a href="https://thechief.io/"><strong>Cloud Native</strong> <strong>News</strong></a><strong> </strong>📰<strong>|</strong><a href="https://linktr.ee/faun.dev/"><strong>More</strong></a><strong>.</strong></p><p><strong>If this post was helpful, please click the clap 👏 button below a few times to show your support for the author 👇</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e840ab556d12" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/infracost-cost-estimates-for-the-iac-resources-in-azure-e840ab556d12">Infracost : Cost estimates for the IaC Resources in Azure</a> was originally published in <a href="https://faun.pub/">FAUN.dev() 🐾</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Terratag: Manage your cloud resource tags efficiently across terraform modules in Azure]]></title>
            <link>https://bhabalajinkya.medium.com/terratag-manage-your-cloud-resource-tags-efficiently-across-terraform-modules-in-azure-9d187b263f53?source=rss-bba14091c643------2</link>
            <guid isPermaLink="false">https://medium.com/p/9d187b263f53</guid>
            <category><![CDATA[terraform-modules]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[tag]]></category>
            <category><![CDATA[terratag]]></category>
            <dc:creator><![CDATA[Ajinkya Bhabal]]></dc:creator>
            <pubDate>Sun, 11 Apr 2021 12:06:59 GMT</pubDate>
            <atom:updated>2021-04-12T03:40:14.000Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wIoJeR12nYuVD59I3RX31Q.png" /><figcaption>Credit: Damian Flynn</figcaption></figure><h3>Introduction</h3><h4>What is Terratag ?</h4><p>It is a CLI tool that will help you to apply tags across all of the Terraform files.</p><p>The best thing is you can use this tool for all popular public cloud providers like Azure, AWS, GCP.</p><p>To begin with, for those who want to have foundational knowledge about this CLI tool, please visit the below article.</p><p><a href="https://link.medium.com/XfLqAUDxmfb">We&#39;re Open sourcing Terratag to Make Multi-cloud Resource Tagging Easier</a></p><blockquote>Note: It is assumed that you have prior knowledge of terraform.</blockquote><p><strong>Installation of Terratag :-</strong></p><p>As from the official website you can install the CLI tool for both Linux and windows.</p><p>I have downloaded the Terratag binary for windows and store it in the folder, which was already added in the system environment variable.</p><p><a href="https://github.com/env0/terratag/releases">Releases · env0/terratag</a></p><p>Now here, I will demonstrate the use of Terratag in modular structure in Azure terraform. First, let’s take a look at the tf files hierarchy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qWEyQh8bjjOAJ17YPjrxfg.jpeg" /></figure><p>From above we can see that 3 modules have been created. Which are resource group, network, and network security group module. “Terraform file which contains code is only added in the above structure.”</p><p>In this scenario, we are applying tags to all cloud resources at the Root level module.</p><blockquote>One question that can arise in someone’s mind is why do we need this, the answer is when you are dealing with 4–5 modules, it’s no big deal to manage tags. But when we have 15–20 modules or more modules will be added in the future at that point automatic tag assignment will be heaven to us.</blockquote><p>Before going for implementation let’s just take a quick look at the code.</p><p>The following module describes the resource group resource.</p><pre># modules/resource_group/main.tf<br>#-------------------------<br># Create a resource group<br>#-------------------------<br>resource &quot;azurerm_resource_group&quot; &quot;rg&quot; {<br>  name     = &quot;DEV-RG01&quot;<br>  location = &quot;East US&quot;<br>}</pre><p>The following module describes the network security group resource.</p><pre># modules/network_security_group/main.tf<br>#-------------------------------------------------------<br># network security group configuration is specified here.<br>#-------------------------------------------------------<br>resource &quot;azurerm_network_security_group&quot; &quot;nsg1&quot; {<br>  name                = &quot;NetworkSecurityGroup1&quot; <br>  location            = &quot;East US&quot;               <br>  resource_group_name = &quot;DEV-RG01&quot;              </pre><pre>security rule {<br>    name                       = &quot;port_80&quot;<br>    priority                   = 100<br>    direction                  = &quot;Inbound&quot;<br>    access                     = &quot;Allow&quot;<br>    protocol                   = &quot;Tcp&quot;<br>    source_port_range          = &quot;*&quot;<br>    destination_port_range     = &quot;80&quot;<br>    source_address_prefix      = &quot;*&quot;<br>    destination_address_prefix = &quot;*&quot;<br>  }<br>}</pre><p>The following module describes the virtual network resource.</p><pre># modules/virtual_network/main.tf<br>#-------------------------------------------------<br># virtual network configuration is specified here.<br>#--------------------------------------------------<br>resource &quot;azurerm_virtual_network&quot; &quot;vnet&quot; {<br>  name                = &quot;prod-vnet1&quot;<br>  address_space       = [&quot;10.30.0.0/16&quot;]<br>  location            = &quot;East US&quot;<br>  resource_group_name = &quot;DEV-RG01&quot;<br>}</pre><pre>resource &quot;azurerm_subnet&quot; &quot;internal&quot; {<br>  name                 = &quot;internal_subnet&quot;<br>  address_prefixes     = [&quot;10.30.2.0/24&quot;]<br>  resource_group_name  = &quot;DEV-RG01&quot;<br>  virtual_network_name = azurerm_virtual_network.vnet.name<br>}</pre><pre>resource &quot;azurerm_subnet_network_security_group_association&quot; &quot;nsga1&quot; {<br>  subnet_id                 = azurerm_subnet.internal.id <br>  network_security_group_id = var.nsg_id             <br>  depends on                = [azurerm_subnet.internal]  <br>}</pre><p>First step is to perform terraform init operation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1IsDDq5DLNmBbl_kL4Jhsg.jpeg" /></figure><p>After performing initialization all provider schema and child modules will be pulled. Now we will run the terratag command to apply tags across all child modules.</p><pre>terratag -tags=&#39;{&quot;ENV&quot;: &quot;DEV&quot;}&#39; -rename=false</pre><ul><li>-tags = tags, as valid JSON Format.</li><li>-rename=false — Instead of replacing all files named &lt;original_name&gt;.tf with &lt;original_name&gt;.terratag.tf, here flag will keep the original filename.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j5yn3rKcoXMYunk-fCrb0g.jpeg" /></figure><p>before going any further let’s see what’s happening behind the scenes after running terratag. You will notice here locals are used for tagging all resources and our original tf file is backup with .bak extension.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CXyn8Xc0AaFB_YDLFmQ2Iw.jpeg" /></figure><p>Now tags are added to all child modules, next, we will perform a dry run with terraform plan command and deploy the resources into azure with terraform apply command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YPGqvBlsD1Z81twbI9de-A.jpeg" /></figure><p>Final, we can check in the Azure portal to verify tags added to all resources.</p><ol><li>Resource Group Resource</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jDrFBJGBvgC7WiFm2c_qjg.jpeg" /></figure><p>2. Network Security Group Resource</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BJ5Zj6GMUhVPNIw84ACa7g.jpeg" /></figure><p>3. Virtual Network Resource</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E2GrV_yk8nykzs1PrDlVEQ.jpeg" /></figure><p>Full GitHub repo of above code is available below:-</p><p><a href="https://github.com/ajinkya101/terratag-demo-az-modules">ajinkya101/terratag-demo-az-modules</a></p><p>It’s always great to learn and explore something new, in IaaC there are still so many blockades that we need to solve to get higher efficiency in the automation process.</p><p>If you’d like to read more about IaaC Tools or Popular Terraform wrappers, Just let me know in the comments. <strong>Thanks for reading!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9d187b263f53" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Azure Bicep: Private Communication Between Azure Resources]]></title>
            <link>https://bhabalajinkya.medium.com/azure-bicep-private-communication-between-azure-resources-f4a17c171cfb?source=rss-bba14091c643------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4a17c171cfb</guid>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[microsoft]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[iaac]]></category>
            <category><![CDATA[bicep]]></category>
            <dc:creator><![CDATA[Ajinkya Bhabal]]></dc:creator>
            <pubDate>Mon, 22 Mar 2021 03:48:59 GMT</pubDate>
            <atom:updated>2021-03-22T03:48:59.385Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QHfQSyvrlL2VQD6nW4wN0Q.jpeg" /><figcaption>Use Private Endpoint for Azure Storage</figcaption></figure><h3>Introduction</h3><p>Nowadays most companies want their cloud resources to privately communicate with each other without going over the internet. Today we will focus on Microsoft Azure solutions.</p><p>The two of the services provided by azure to achieve this goal are,</p><ol><li>Private Endpoints</li><li>Service Endpoints</li></ol><p>In the above services, data will travel through the Microsoft Backbone Network.</p><p>So this article will cover making private the internet-facing public services like e.g. SQL Database, Storage Account, Web apps in Azure. The great thing is it can be access across different Virtual networks and from a Hybrid connected data center also.</p><p>The solution which I have given is based on an Azure storage account. There are different ways to deploy resources in Azure, here we have chosen the new approach Azure Bicep.</p><h3>Part 1 — Private Endpoints</h3><p>The private endpoint helps us to establish secure communication between resources running on a virtual network and storage account. All traffic will traverses over the VNET and Microsoft backbone network only. The private endpoint uses an IP address from the VNET address space for our storage account service. Besides resources from the on-premises network which are connected through VPN or ExpressRoute also get access to the storage service.</p><p>Now let’s begin with the actual implementation of the private endpoint with Azure bicep.</p><p>First Start Configuring the Virtual network for the private endpoint.</p><pre>// All Parameters required for Network Deployment is given here.<br>param location string = resourceGroup().location</pre><pre>// All Variables required for Network Deployment is given here.<br>var virtualNetworkName = &#39;VNET01&#39;<br>var addressPrefix = &#39;10.50.0.0/16&#39;<br>var subnetName = &#39;Subnet01&#39;<br>var subnetPrefix = &#39;10.50.1.0/24&#39;</pre><pre>resource vn &#39;Microsoft.Network/virtualNetworks@2020-06-01&#39; = {<br>  name: virtualNetworkName<br>  location: location<br>  properties: {<br>    addressSpace: {<br>      addressPrefixes: [<br>        addressPrefix<br>      ]<br>    }<br>    subnets: [<br>      {<br>        name: subnetName<br>        properties: {<br>          addressPrefix: subnetPrefix<br>          privateEndpointNetworkPolicies: &#39;Disabled&#39;<br>          privateLinkServiceNetworkPolicies: &#39;Enabled&#39;<br>        }<br>      }<br>    ]<br>  }<br>}</pre><p>The thing to notice here is Private Endpoint Network Policies are disabled because Network Security Group are not supported for private endpoint resource. Next Source IP address for private link service is automatically selected.</p><blockquote>Note: This setting only applies to the Private endpoint resource.</blockquote><p>In the second step Storage Account resource is configured.</p><pre>// All Parameters required for Network Deployment is given here.<br>param location string = resourceGroup().location<br>param storageAccountName string = &#39;store38291&#39;<br>param sku_name string = &#39;Standard_LRS&#39;</pre><pre>resource stg &#39;Microsoft.Storage/storageAccounts@2019-06-01&#39; =  {<br>  name: storageAccountName<br>  location: location<br>  sku: {<br>    name: sku_name<br>    tier: &#39;Standard&#39;<br>  }<br>  kind: &#39;StorageV2&#39;<br>  properties: {<br>    accessTier: &#39;Hot&#39;<br>    networkAcls: {<br>      bypass: &#39;None&#39;<br>      defaultAction: &#39;Deny&#39;<br>    }<br>  }<br>}</pre><p>The point to note here is in Network ACL’s we have disabled everything, so only private endpoint resource will be attached to it.</p><p>In the third step, we will create a Private Endpoint resource along with its configuration.</p><pre>// All Parameters required for Network Deployment is given here.<br>param location string = resourceGroup().location</pre><pre>// All Variables required for Network Deployment is given here.<br>var subnetName = &#39;Subnet01&#39;<br>var subnetRef = &#39;${vn.id}/subnets/${subnetName}&#39;</pre><pre>resource privateEndpoint &#39;Microsoft.Network/privateEndpoints@2020-06-01&#39; = {<br>  name: &#39;PrivateEndpoint1&#39;<br>  location: location<br>  properties: {<br>    subnet: {<br>      id: subnetRef<br>    }<br>    privateLinkServiceConnections: [<br>      {<br>        properties: {<br>          privateLinkServiceId: stg.id<br>          groupIds: [<br>            &#39;blob&#39;<br>          ]<br>        }<br>        name: &#39;PrivateEndpoint1&#39;<br>      }<br>    ]<br>  }<br>}</pre><p>Following three things on which we need to be focused on for the configuration,</p><p>i. Subnet ID</p><p>ii. Storage Account ID</p><p>iii. Type of Service or Sub Resource — Blob</p><pre>resource privateDnsZones &#39;Microsoft.Network/privateDnsZones@2018-09-01&#39; = {<br>  name: &#39;privatelink.blob.core.windows.net&#39;<br>  location: &#39;global&#39;<br>  properties: {}<br>}</pre><pre>resource privateDnsZoneLink &#39;Microsoft.Network/privateDnsZones/virtualNetworkLinks@2018-09-01&#39; = {<br>  name: &#39;${privateDnsZones.name}/${privateDnsZones.name}-link&#39;<br>  location: &#39;global&#39;<br>  properties: {<br>    registrationEnabled: false<br>    virtualNetwork: {<br>      id: vn.id<br>    }<br>  }<br>}</pre><pre>resource privateDnsZoneGroup &#39;Microsoft.Network/privateEndpoints/privateDnsZoneGroups@2020-06-01&#39; = {<br>  name: &#39;${privateEndpoint.name}/dnsgroupname&#39;<br>  properties: {<br>    privateDnsZoneConfigs: [<br>      {<br>        name: &#39;config1&#39;<br>        properties: {<br>          privateDnsZoneId: privateDnsZones.id<br>        }<br>      }<br>    ]<br>  }<br>}</pre><p>After setting up the private endpoint, Next will be Private DNS Zones using which DNS resolution will be performed to reach to the storage account service.</p><p>There’s a strict requirement from Microsoft azure to use “privatelink.blob.core.windows.net” DNS zone name for blob services.</p><blockquote>In the DNS Zones Linking Virtual Network is Key element because after linking only connected resource can reach the storage service.</blockquote><p>Now let’s deploy these resources in our environment. The Bicep file has been compiled here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pLikDoKH5VnV-_FPQfsKnA.jpeg" /></figure><p>After Generating ARM Template resources are deployed through it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KHOEsCLdBJjZHkcJWFf6Cg.jpeg" /></figure><p>Take a look at all deployed resources in the portal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9UHe4NYEdcrHkq025X2wZw.jpeg" /></figure><p>Check for Network Interface Card deployment in the VNET.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WyGYyCAKb69_pvvVtjTTBA.jpeg" /></figure><p>The most important thing to check now here is configured private endpoint in the storage account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_R7f0Gy6vQoA1s1ItnrJcQ.jpeg" /></figure><p>After checking connection, let’s see the configuration of the Private endpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cZ_C8ou5x5QwdyNvdPm2Eg.jpeg" /></figure><p>Next is DNS Configuration where we will see the important configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LSTozecCft94xWXiQKBIHg.jpeg" /></figure><p>In the DNS Zone we can see A Record is automatically added for Storage URL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OoJJvuDMB10TGBONJjihnQ.jpeg" /></figure><p>Last, But very important Linking of an Virtual Network to the Private DNS Zone.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iGRmQ6nCwjPQi8k4DsR0SQ.jpeg" /></figure><h3>Part 2 — Service Endpoints</h3><p>The Virtual Network’s Service endpoint communication also done securely over Azure Backbone Network to Internet facing public services. The big difference here is critical Azure Resources can only accessed through connected virtual network subnets.</p><p>Lets begin with Azure bicep based configuration, first resource will be Azure Virtual Network.</p><pre>// All Variables required for Network Deployment is given here.<br>var subnetName = &#39;SP_Subnet01&#39;<br>var subnetRef = &#39;${vn.id}/subnets/${subnetName}&#39;</pre><pre>resource vn &#39;Microsoft.Network/virtualNetworks@2020-06-01&#39; = {<br>  name: &#39;SP_VNET01&#39;<br>  location: resourceGroup().location<br>  properties: {<br>    addressSpace: {<br>      addressPrefixes: [<br>        &#39;10.60.0.0/16&#39;<br>      ]<br>    }<br>    subnets: [<br>      {<br>        name: subnetName<br>        properties: {<br>          addressPrefix: &#39;10.60.1.0/24&#39;<br>          serviceEndpoints: [<br>            {<br>              service: &#39;Microsoft.Storage&#39;<br>            }<br>          ]<br>        }<br>      }<br>    ]<br>  }<br>}</pre><blockquote>The Key thing to notice here is, “Microsoft.Storage” service is enabled in the Service endpoint section so Storages can configured for Service Endpoints.</blockquote><p>The Second resource storage account will be configured,</p><pre>// All Variables required for Network Deployment is given here.<br>var subnetName = &#39;SP_Subnet01&#39;<br>var subnetRef = &#39;${vn.id}/subnets/${subnetName}&#39;</pre><pre>resource stg &#39;Microsoft.Storage/storageAccounts@2019-06-01&#39; =  {<br>  name: &#39;store38291&#39;<br>  location: resourceGroup().location<br>  sku: {<br>    name: &#39;Standard_LRS&#39;<br>    tier: &#39;Standard&#39;<br>  }<br>  kind: &#39;StorageV2&#39;<br>  properties: {<br>    accessTier: &#39;Hot&#39;<br>    networkAcls: {<br>      bypass: &#39;None&#39;<br>      virtualNetworkRules: [<br>        {<br>          id: subnetRef<br>          action: &#39;Allow&#39;<br>        }<br>      ]<br>      defaultAction: &#39;Deny&#39;<br>    }<br>  }<br>}</pre><p>Here in the Storage Network Access control policy, Subnet ID is provided. So that only resources in that subnet can access storage accounts.</p><p>It’s time to run this bicep code now, First we create resource group and then build the bicep file for deployment.</p><pre>Bicep build .\main.bicep</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ae-1K91VK8NTz6mV_SuXHQ.jpeg" /></figure><p>After build ARM Template has been generated from which we will start the deployment.</p><pre>New-AzResourceGroupDeployment -TemplateFile &quot;./main.json&quot; -ResourceGroupName &quot;SE-RG01&quot; -Confirm -Mode &quot;Complete&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M_jlJw8HnLLW4pFjZ1rQpw.jpeg" /></figure><p>After deployment let’s take a look at the Networking of Storage account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0R_06lgceFzcCGO5R-wCIg.jpeg" /></figure><h3>Conclusion</h3><p>As Cloud is becoming popular day by day, Security is the most important aspect that people often do not care mostly. The thing which we need to remember is its shared responsibility. Hope you like this session on secure communication between azure resources. Don’t wait, just get start along with me. If you have any feedback or suggestions you can ask in the comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4a17c171cfb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tutorial: Deploying Azure Resources in Multiple Resource Groups with Azure Bicep Language]]></title>
            <link>https://bhabalajinkya.medium.com/tutorial-deploying-azure-resources-in-multiple-resource-groups-with-azure-bicep-language-2881e1c8a109?source=rss-bba14091c643------2</link>
            <guid isPermaLink="false">https://medium.com/p/2881e1c8a109</guid>
            <dc:creator><![CDATA[Ajinkya Bhabal]]></dc:creator>
            <pubDate>Sun, 14 Mar 2021 12:15:50 GMT</pubDate>
            <atom:updated>2021-03-17T08:55:30.475Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wTXXDbwFyfKI0WWWnUElVw.jpeg" /></figure><h3><strong>Introduction</strong></h3><p>What is Azure Bicep?</p><p>Bicep is a Domain Specific Language (DSL) for deploying Azure resources declaratively. It’s evolved version of Azure ARM templates, with some additional great benefits. It simplifies the authoring experience in IaaC with a cleaner syntax, improved type safety, and better support for modularity and code re-use.</p><p>Here in Bicep we still create ARM template after building the code and through which deployment is done.</p><p>Those who are already familiar with IaaC 3rd party tool like eg. Terraform can easily get along with me. Now the reason for trying this tool is obviously it’s azure native service.</p><p>As I have been working on Terraform for long time, I feel that terraform lags behind when bringing new features and updates on cloud services, at the end it’s an open source tool it takes lot’s of effort to bring latest feature. I got fond of terraform because it provide some of the features like e.g. Multi-cloud, Dry runs, Module reusability, Easy to understand language, Data sources that no other tool can provide efficiently in that category.</p><p>For this tutorial, We will deploy lifecycle of virtual machine along with it’s resources. So here first resource group will contain Network Resources and second resource group will contain Virtual Machine Resources.</p><h4>Tools Used in this Tutorial:</h4><p>· Microsoft Visual Studio Code</p><p>· Powershell 7</p><p>· Bicep</p><p>· Azure Az Powershell Module</p><p>Now let’s get started with the initial configuration.</p><blockquote>Microsoft Azure has created wonderful Visual studio extension for Bicep, with built-in Intellisense! Make sure to add it.</blockquote><blockquote><a href="https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-bicep">Bicep — Visual Studio Marketplace</a></blockquote><p>Now we need our PowerShell to be Authenticated with an Azure.</p><pre>Connect-AzAccount</pre><p>First take a look at our network resources module.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/87fb0d41fbc8a77b2edc10007ecefc46/href">https://medium.com/media/87fb0d41fbc8a77b2edc10007ecefc46/href</a></iframe><p>Here Network Security Group with 3389 Inbound rule and Virtual Network with Single Subnet is created, also NSG is attached to Subnet. To learn more about code visit bicep official repository.</p><p>Second will be Virtual Machine resources Module:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2466b23da2d6db3d256b325e85696907/href">https://medium.com/media/2466b23da2d6db3d256b325e85696907/href</a></iframe><p>Here we will create Public IP Address, Network Interface and Windows 2016 Datacenter Server resource. To learn more about code visit bicep official repository.</p><p>Now challenge comes, where we will be deploying resources in multiple resource group and subnet id need to be passed to the Network Interface of Virtual Machine.</p><p>I have used Reusability feature i.e. Modules in Bicep.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f714ffd9c29b80528aa8b647ab2f2b58/href">https://medium.com/media/f714ffd9c29b80528aa8b647ab2f2b58/href</a></iframe><blockquote>The solution for our challenge is we have passed virtual network resource object in output and use in another Virtual Machine Module where we add NIC to that Subnet.</blockquote><p>The last file will be parameters, it’s the same as ARM Template parameter file in JSON format.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a5c7fc0dde6026632c5219d2e0b5775a/href">https://medium.com/media/a5c7fc0dde6026632c5219d2e0b5775a/href</a></iframe><p>Now let’s deploy resources into an Azure.</p><p>First we will create two resource groups through PowerShell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QMj3smNGv6XybeObGF8XpA.jpeg" /></figure><p>We will perform Bicep build in which ARM template will be generated for resource deployment. With Native ARM template deployment command resources will be created.</p><pre>bicep build .\main.bicep</pre><pre>New-AzResourceGroupDeployment -TemplateFile &quot;./main.json&quot; -ResourceGroupName &quot;RG1&quot; -TemplateParameterFile &quot;./parameters.json&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*25YvfDQxXvv2n8QI-MDtwQ.jpeg" /></figure><p>Let’s take a look at the Azure Portal to check successful deployment.</p><p>Resource Group 1 Deployments:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zkEk1SsPKnMR3KPHeOATiw.jpeg" /></figure><p>Resource Group 2 Deployments:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nPKMEps5rYF2_Kn22VkgoA.jpeg" /></figure><blockquote>The overcoming multi resource group deployment was big challenge because, in PowerShell or CLI Command you have option to pass single resource group name in parameter and scope option in bicep is still under development.</blockquote><p>As we have now came to an end, share your experience with me in the comments and suggest me what other feature or topic in IaaC should i cover next. Thank you.</p><blockquote>Full code is available on github :- <a href="https://github.com/ajinkya101/bicep-multi-rg">ajinkya101/bicep-multi-rg (github.com)</a></blockquote><p>You can connect me @<a href="https://www.linkedin.com/in/ajinkya-bhabal/">Ajinkya Bhabal | LinkedIn</a></p><p>Reference:</p><p><a href="https://github.com/Azure/bicep">GitHub - Azure/bicep: Bicep is a declarative language for describing and deploying Azure resources</a></p><p>Copyrights <strong>©</strong>2021 | All rights reserved by Ajinkya Ravindra Bhabal</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2881e1c8a109" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>