<?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 Ravi Sharma on Medium]]></title>
        <description><![CDATA[Stories by Ravi Sharma on Medium]]></description>
        <link>https://medium.com/@ravisharma0527?source=rss-38dc9877a6c0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*2-Srx-_0qySZtY5Z</url>
            <title>Stories by Ravi Sharma on Medium</title>
            <link>https://medium.com/@ravisharma0527?source=rss-38dc9877a6c0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 05:07:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ravisharma0527/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[ Automate Cloud Infrastructure Cost Estimation with Infracost and GitHub Actions ]]></title>
            <link>https://medium.com/@ravisharma0527/automate-cloud-infrastructure-cost-estimation-with-infracost-and-github-actions-d2f6a287e713?source=rss-38dc9877a6c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/d2f6a287e713</guid>
            <dc:creator><![CDATA[Ravi Sharma]]></dc:creator>
            <pubDate>Sat, 28 Jun 2025 05:59:35 GMT</pubDate>
            <atom:updated>2025-06-28T05:59:35.184Z</atom:updated>
            <content:encoded><![CDATA[<h3>🌐 Introduction</h3><p>In the previous blog post, <a href="https://medium.com/@ravisharma0527/cost-estimation-with-infracost-terraform-382928c32285"><strong>Cost Estimation with Infracost — Terraform</strong></a>, we explored how to estimate costs when provisioning cloud deployments using Terraform. We demonstrated the use of the <strong>Infracost CLI tool</strong> to calculate costs effectively.</p><p>In this blog, we take it a step further by automating cost calculations via the <strong>CI/CD process</strong>. With automation, DevOps and SRE teams can determine cost changes <strong>before deploying resources</strong> to the cloud. This speeds up the deployment process and eliminates the need for manual CLI operations.</p><h3>🔄 Trigger Cost Estimation for Pull Requests</h3><h3>🛠️ GitHub Actions Workflow</h3><p>To automate cost estimation, we use <strong>GitHub Actions</strong>. The workflow is triggered whenever a pull request is created. This ensures that cost changes are calculated and displayed before merging changes into the main branch.</p><h3>🔑 Secure Your Infracost API Key</h3><p>Store your <strong>Infracost API key</strong> securely in <strong>GitHub Secrets</strong>. This key is used to authenticate the pipeline during execution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*9bz9nmz2_Q6344jFeXZFKQ.png" /></figure><h3>📋 Steps to Automate Infracost</h3><h3>1️⃣ Create a Workflow File</h3><p>Create a file named infracost.yaml in the workflows directory of your repository. Below is the sample workflow configuration:</p><pre># Infracost runs on pull requests (PR) and posts PR comments.<br># If you use Infracost Cloud, Infracost also runs on main/master branch pushes so the dashboard is updated.<br># The GitHub Action docs (https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows) describe other trigger options.<br>on:<br>    pull_request:<br>      types: [opened, synchronize, closed]<br>    push:<br>      branches:<br>        - main<br>        - master<br>  <br>env:<br>    # If you use private modules you&#39;ll need this env variable to use<br>    # the same ssh-agent socket value across all jobs &amp; steps.<br>    SSH_AUTH_SOCK: /tmp/ssh_agent.sock<br>jobs:<br>    # This stage runs the Infracost CLI and posts PR comments.<br>    # It also updates PR comments when the PR is updated (synchronize event).<br>    infracost-pull-request-checks:<br>      name: Infracost Pull Request Checks<br>      if: github.event_name == &#39;pull_request&#39; &amp;&amp; (github.event.action == &#39;opened&#39; || github.event.action == &#39;synchronize&#39;)<br>      runs-on: ubuntu-latest<br>      permissions:<br>        contents: read<br>        pull-requests: write # Required to post comments<br>      # env:<br>        # If you store Terraform variables or modules in a 3rd party such as TFC or Spacelift,<br>        # specify the following so Infracost can automatically retrieve them.<br>        # See https://www.infracost.io/docs/features/terraform_modules/#registry-modules for details.<br>        #   INFRACOST_TERRAFORM_CLOUD_TOKEN: ${{ secrets.TFC_TOKEN }}<br>        #   INFRACOST_TERRAFORM_CLOUD_HOST: app.terraform.io<br>      steps:<br>        # If you use private modules, add an environment variable or secret<br>        # called GIT_SSH_KEY with your private key, so Infracost CLI can access<br>        # private repositories (similar to how Terraform/Terragrunt does).<br>        # - name: add GIT_SSH_KEY<br>        #   run: |<br>        #     ssh-agent -a $SSH_AUTH_SOCK<br>        #     mkdir -p ~/.ssh<br>        #     echo &quot;${{ secrets.GIT_SSH_KEY }}&quot; | tr -d &#39;\r&#39; | ssh-add -<br>        #     ssh-keyscan github.com &gt;&gt; ~/.ssh/known_hosts<br>  <br>        - name: Setup Infracost<br>          uses: infracost/actions/setup@v3<br>          # See https://github.com/infracost/actions/tree/master/setup for other inputs<br>          # If you can&#39;t use this action, use Docker image infracost/infracost:ci-0.10<br>          with:<br>            api-key: ${{ secrets.INFRACOST_API_KEY }}<br>  <br>        # Checkout the base branch of the pull request (e.g. main/master).<br>        - name: Checkout base branch<br>          uses: actions/checkout@v4<br>          with:<br>            ref: &#39;${{ github.event.pull_request.base.ref }}&#39;<br>  <br>        # Generate Infracost JSON file as the baseline.<br>        - name: Generate Infracost cost estimate baseline<br>          run: |<br>            infracost breakdown --path=. \<br>                                --format=json \<br>                                --out-file=/tmp/infracost-base.json<br>  <br>        # Checkout the current PR branch so we can create a diff.<br>        - name: Checkout PR branch<br>          uses: actions/checkout@v4<br>  <br>        # Generate an Infracost diff and save it to a JSON file.<br>        - name: Generate Infracost diff<br>          run: |<br>            infracost diff --path=. \<br>                            --format=json \<br>                            --compare-to=/tmp/infracost-base.json \<br>                            --out-file=/tmp/infracost.json<br>  <br>        # Posts a comment to the PR using the &#39;update&#39; behavior.<br>        # This creates a single comment and updates it. The &quot;quietest&quot; option.<br>        # The other valid behaviors are:<br>        #   delete-and-new - Delete previous comments and create a new one.<br>        #   hide-and-new - Minimize previous comments and create a new one.<br>        #   new - Create a new cost estimate comment on every push.<br>        # See https://www.infracost.io/docs/features/cli_commands/#comment-on-pull-requests for other options.<br>        - name: Post Infracost comment<br>          run: |<br>              infracost comment github --path=/tmp/infracost.json \<br>                                       --repo=$GITHUB_REPOSITORY \<br>                                       --github-token=${{ github.token }} \<br>                                       --pull-request=${{ github.event.pull_request.number }} \<br>                                       --behavior=update<br>  <br>    # Run Infracost on default branch and update Infracost Cloud<br>    infracost-default-branch-update:<br>      # If you use private modules, or store Terraform variables or modules in a 3rd party<br>      # such as TFC or Spacelift, include the same steps/variables as the infracost-pull-request-checks job<br>      name: Infracost Default Branch Update<br>      if: github.event_name == &#39;push&#39; &amp;&amp; (github.ref_name == &#39;main&#39; || github.ref_name == &#39;master&#39;)<br>      runs-on: ubuntu-latest<br>      steps:<br>        - name: Setup Infracost<br>          uses: infracost/actions/setup@v3<br>          with:<br>            api-key: ${{ secrets.INFRACOST_API_KEY }}<br>  <br>        - name: Checkout main/master branch<br>          uses: actions/checkout@v4<br>  <br>        - name: Run Infracost on default branch and update Infracost Cloud<br>          run: |<br>            infracost breakdown --path=. \<br>                      --format=json \<br>                      --out-file=infracost.json<br>  <br>            infracost upload --path=infracost.json || echo &quot;Always pass main branch runs even if there are policy failures&quot;<br>  <br>    # Update PR status in Infracost Cloud<br>    infracost-pull-request-status-update:<br>      name: Infracost PR Status Update<br>      if: github.event_name == &#39;pull_request&#39; &amp;&amp; github.event.action == &#39;closed&#39;<br>      runs-on: ubuntu-latest<br>      steps:<br>      - name: Infracost PR Status Update<br>        run: |<br>          PR_STATUS=&quot;MERGED&quot;<br>          if [[ ${{ github.event.pull_request.merged }} = false ]]; then PR_STATUS=&quot;CLOSED&quot;; fi<br>  <br>          echo &quot;Updating status of ${{ github.event.pull_request.html_url }} to $PR_STATUS&quot;<br>          curl -i \<br>            --request POST \<br>            --header &quot;Content-Type: application/json&quot; \<br>            --header &quot;X-API-Key: $INFRACOST_API_KEY&quot; \<br>            --data &quot;{ \&quot;query\&quot;: \&quot;mutation {updatePullRequestStatus( url: \\\&quot;${{ github.event.pull_request.html_url }}\\\&quot;, status: $PR_STATUS )}\&quot; }&quot; \<br>            &quot;https://dashboard.api.infracost.io/graphql&quot;;<br>        env:<br>          INFRACOST_API_KEY: ${{ secrets.INFRACOST_API_KEY }}</pre><p>2️⃣ Trigger Workflow on Pull Requests</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UGf2hRpYR5h0OKguYK9Xlw.png" /></figure><p>The workflow is triggered when a pull request is created for the main branch. It performs the following actions:</p><ul><li>✅ <strong>Checks out the code</strong>.</li><li>✅ <strong>Sets up Infracost</strong> using the API key.</li><li>✅ <strong>Runs Infracost</strong> to calculate the cost breakdown of the Terraform configuration.</li><li>✅ <strong>Posts a comment</strong> to the pull request with the cost estimate.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*9caIIR8ywOhJNt-zKOThlw.png" /></figure><h3>💡 Example Scenario: VM Size Change</h3><p>To demonstrate the workflow:</p><ol><li><strong>Create a new branch</strong> for modifying the VM size in your Terraform configuration.</li><li><strong>Change the VM size</strong> from Standard_F2s to Standard_NC24s_v3 (a more expensive option).</li><li><strong>Open a pull request</strong> for the branch.</li></ol><p>After the workflow runs, a comment will be added to the pull request showing the <strong>cost difference</strong>. You can also view detailed graphs and explanations on the <strong>Infracost cloud platform</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WMTQKE5iJ_dtZHCKF-33MA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NdgEROdML6eSvSabfJMLCw.png" /></figure><h3>🏁 Conclusion</h3><p><strong>Infracost</strong> is an excellent platform and open-source tool for identifying the cloud cost of infrastructure deployments. By automating cost calculations via CI/CD pipelines, organizations can:</p><ul><li>🔍 <strong>Identify cost changes</strong> before deploying resources.</li><li>📊 <strong>Optimize cloud expenditure</strong>.</li><li>⚡ <strong>Speed up the deployment process</strong>.</li></ul><p>💡 Start automating your infrastructure cost estimation today with <strong>Infracost</strong> and GitHub Actions! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d2f6a287e713" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cost Estimation with Infracost -Terraform]]></title>
            <link>https://medium.com/@ravisharma0527/cost-estimation-with-infracost-terraform-382928c32285?source=rss-38dc9877a6c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/382928c32285</guid>
            <dc:creator><![CDATA[Ravi Sharma]]></dc:creator>
            <pubDate>Sat, 28 Jun 2025 05:31:30 GMT</pubDate>
            <atom:updated>2025-06-28T05:31:30.318Z</atom:updated>
            <content:encoded><![CDATA[<h3>🌟 Get to Know Your Infrastructure Cost 🌟</h3><h3>🚀 Introduction</h3><p>Provisioning infrastructure has become faster and more robust with the advent of <strong>cloud computing</strong>. It enables organizations to spin up application infrastructure quickly compared to traditional on-premises data centers. Cloud computing offers unique advantages such as:</p><ul><li>🌐 <strong>Elasticity</strong></li><li>🤖 <strong>Automation</strong></li><li>⚡ <strong>Rapid provisioning</strong></li></ul><p>While cloud computing simplifies resource acquisition, it also introduces challenges in managing and maintaining those resources effectively.</p><h3>💡 Enter Infrastructure as Code (IaC)</h3><p>IaC is the solution to efficiently managing cloud resources. It allows the codification of cloud infrastructure, enabling <strong>reusability</strong> and <strong>consistency</strong>. For example, if your organization needs to provision <strong>Development</strong>, <strong>Staging</strong>, and <strong>Production</strong> environments with similar configurations, IaC makes it possible to deploy all environments using the same code base, changing only the necessary parameters.</p><h3>💰 Calculating Infrastructure Costs</h3><p>In today’s blog, we’ll explore how to calculate the cost incurred from infrastructure provisioning using <strong>Infracost</strong>, a tool designed to work seamlessly with Terraform.</p><h3>🔍 Getting to Know Infracost</h3><p><strong>Infracost</strong> is a powerful tool that helps DevOps and SRE engineers determine the cost impact of infrastructure changes <strong>before</strong> implementing them. It can be triggered via:</p><ul><li>🖥️ <strong>CLI</strong></li><li>🔄 <strong>Pull Requests</strong> in code repositories</li></ul><h3>🛠️ Get Started with Infracost</h3><h3>📥 Installing Infracost CLI</h3><p>Installing Infracost is simple! Use the relevant package manager for your OS. Refer to the <a href="https://www.infracost.io/docs/">official documentation</a> for detailed instructions.</p><h3>🔑 Signup for Free and Get Your API Key</h3><ol><li>Create a free account on Infracost.</li><li>Authenticate the CLI with your API key using the command:</li></ol><pre>infracost auth login</pre><h3>📄 Sample Terraform File</h3><p>Here’s a simple Terraform file that provisions a Linux virtual machine and storage account:</p><pre>provider &quot;aws&quot; {<br>  region = &quot;ap-south-1&quot;<br>}<br><br>resource &quot;aws_instance&quot; &quot;example&quot; {<br>  ami           = &quot;ami-00bb6a80f01f03502&quot; # Replace with your desired AMI ID<br>  instance_type = &quot;t2.medium&quot;<br><br>  tags = {<br>    Name = &quot;ExampleInstance&quot;<br>  }<br>}<br>terraform {<br>  backend &quot;s3&quot; {<br>    bucket         = &quot;radhasoami&quot;<br>    key            = &quot;terraform.tfstate&quot;<br>    region         = &quot;ap-south-1&quot;<br>    encrypt        = true<br>  }<br>}</pre><h3>📊 View Infracost Breakdown for Terraform</h3><p>After logging into Infracost via CLI, navigate to the folder containing your Terraform files and run:</p><pre>infracost breakdown - path .</pre><p>You’ll get an output showing the <strong>cost breakdown</strong> for each resource. 🧾</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WdJloSaNSeekMihhpPp2Fw.png" /></figure><h3>🔄 View Cost Estimate Diff</h3><h3>Step 1: Create a Baseline JSON File</h3><p>Generate a baseline file for comparison:</p><pre>infracost breakdown - path . - format json - out-file infracost-base.json</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Py-rRaBkjp6dnZVgNDas2Q.png" /></figure><h3>Step 2: Modify Your Terraform File</h3><p>Change the VM size in your Terraform file (e.g., from Standard_B2s to Basic_A2).</p><h3>Step 3: Compare the Changes</h3><p>Run the following command to compare the new configuration with the baseline:</p><pre>infracost diff - path . - compare-to infracost-base.json</pre><p>The output will show the <strong>price difference</strong> and <strong>percentage change</strong>. 📉📈</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GMGAL8TDO9o9N5BuP04ghw.png" /></figure><h3>🏁 Conclusion</h3><p><strong>Infracost</strong> is an invaluable tool for provisioning IaC. It enables DevOps and SRE teams to:</p><ul><li>🔍 Identify cost breakdowns when adding or removing resources.</li><li>📊 View detailed dashboards.</li><li>🔄 Automate cost calculations via CI/CD tools like GitHub and Azure DevOps.</li></ul><p>💡 In the next article, we’ll dive deeper into automating Infracost via CI/CD pipelines to identify costs seamlessly.</p><p>🌟 Start optimizing your cloud infrastructure costs today with <strong>Infracost</strong>! 🌟</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=382928c32285" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>