<?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 Sudhakarkadam on Medium]]></title>
        <description><![CDATA[Stories by Sudhakarkadam on Medium]]></description>
        <link>https://medium.com/@23sudhakarkadam?source=rss-4fffa7059a22------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*I-Fd3RBNYwe5_cxg</url>
            <title>Stories by Sudhakarkadam on Medium</title>
            <link>https://medium.com/@23sudhakarkadam?source=rss-4fffa7059a22------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 16:48:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@23sudhakarkadam/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[APIOps on Azure: Automate API Deployments with Azure DevOps CI/CD]]></title>
            <link>https://medium.com/@23sudhakarkadam/apiops-on-azure-automate-api-deployments-with-azure-devops-ci-cd-7c688d3b9765?source=rss-4fffa7059a22------2</link>
            <guid isPermaLink="false">https://medium.com/p/7c688d3b9765</guid>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[api-management]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[azure-devops]]></category>
            <dc:creator><![CDATA[Sudhakarkadam]]></dc:creator>
            <pubDate>Tue, 24 Mar 2026 15:31:00 GMT</pubDate>
            <atom:updated>2026-03-24T15:31:00.647Z</atom:updated>
            <content:encoded><![CDATA[<ol><li>You have an Azure API Management (APIM) instance already running in production. This guide shows you how to bring it under version control using the APIOps extractor — no need to rebuild from scratch.</li><li>You will use an Azure DevOps CI/CD pipeline to push API changes back to that same APIM instance — fully automated, no manual portal clicks.</li><li>You will then extend that same pipeline to promote APIs across environments — Dev to Prod — using pull-request and approvals as the only gate between them.</li></ol><h3>Why APIOps?</h3><p>If you manage Azure API Management, you know the drill. An API needs a policy change. Someone logs into the Azure portal, finds the right operation, edits the XML inline, clicks Save — and hopes nothing breaks. There’s No review. No rollback. If it works, great. If it doesn’t, you’re hunting through portal activity logs trying to reconstruct what changed.</p><p>The root cause is always the same: API configuration lives in the portal, not in code. It can’t be reviewed. It can’t be versioned. It can’t be automated.</p><p>APIOps is the answer to that problem. It applies the same GitOps principles that transformed infrastructure management — everything as code, everything through a pipeline, every change traceable. Your APIM configuration lives in a Git repository. Changes go through pull requests. Pipelines handle deployment. The portal becomes read-only.</p><h3>How APIOps Solves the Problem</h3><p>APIOps works by treating your APIM instance as a desired-state system. The Git repository is the source of truth. The pipeline is the enforcement mechanism. Here is how the two scenarios in this guide map to that model:</p><h4><strong>Scenario 1 — Onboarding an existing APIM instance.</strong></h4><p>The APIOps Toolkit’s extractor reads your live APIM instance over the Azure REST API and pulls down every API definition, policy, product, subscription, and named value as structured files YAML and XML, committed into your Azure DevOps repo. From that point on, any change you want to make goes through a PR. The publisher pipeline reads those files and applies them back to APIM using your Service Connection. The portal reflects what’s in Git, not the other way around.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*smGkNffyVj1wOHc7oJE7qg.png" /><figcaption>Extractor — Publisher Pipeline</figcaption></figure><h4><strong>Scenario 2 — Promoting across environments.</strong></h4><p>Once your APIs are in Git, moving them from Dev to Prod is just a matter of which APIM endpoint the publisher targets. A separate pipeline stage, triggered by a PR merge into your prod branch and gated by a manual approval, runs the same publisher against your production APIM instance. The API definition is identical. Only the environment-specific values — backend URLs, named values, subscription keys — swap out via variable groups scoped per environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*poNZPcX9Njaoa8rIaKRekA.png" /><figcaption>Promoting across environment</figcaption></figure><h3>Prerequisites</h3><ol><li>Two Azure API Management instances — any tier works, including the Developer tier for non-production setups. If you are onboarding a single existing instance first (Scenario 1), one instance is sufficient to get started.</li><li>Service principal with at least Contributor access on both the Dev and Prod APIM resource groups. Save the following values securely after creation — you will need them in the steps below: Client_ID, Client_Secret, Tenant_ID, Subscription_ID</li><li>An Azure DevOps Git repository where your extracted APIM configuration will live. Create it empty, the extractor will populate it.</li><li>A service connection that wraps the service principal you created above. Follow these steps in Azure DevOps: Go to <strong>Project Settings → Service Connections → New Service Connection → Azure Resource Manager</strong> and configure the following:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*D93sJtduyuL1bdSgWpC9HA.png" /></figure><p>Click Verify and Save to confirm the service principal credentials are valid before proceeding.</p><p><em>Note: You can create a separate service connection for the Prod environment if your security policy requires it. In this guide, the same service connection — APIOps_Connection — is used for both Dev and Prod for simplicity.</em></p><p>A variable group configured in Azure DevOps under <strong>Pipelines → Library</strong> with the following name: <strong>Name: apim-automation</strong> This variable group will hold all pipeline variables referenced throughout this guide, including APIM instance names, resource group names, and the service connection name. Refer to the variable group table in Step 2 for the full list of variables to add.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*BKmaGP2rZwwjxry7PhTfHg.png" /><figcaption><strong>Variable Group</strong></figcaption></figure><h3>Extract your existing APIM into code</h3><p>The APIOps Toolkit extractor reads every resource from your live APIM instance and writes it to disk as structured files. From this point on, those files are your source of truth.</p><p>We are using the Microsoft APIOps Toolkit to extract the APIM configuration into code. The APIOps Toolkit places your Azure API Management infrastructure under version control. Rather than making changes directly in the API Management portal, all operations happen through code changes that can be reviewed, audited, and rolled back.</p><h4><strong>Pipeline Explanation — Extractor</strong></h4><p>A manually triggered Azure DevOps pipeline that extracts API configurations from a live APIM instance, In the OpenAPI specs, and raises a Pull Request to commit the extracted artifacts into Git.</p><p><strong>Trigger: </strong>Manual only (trigger: none) — must be run on demand to prevent unintended artifact overwrites.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*UWvssfId8OVQ6_zdhYW3XA.png" /><figcaption>Parameters</figcaption></figure><p><strong>Variable group: </strong>Requires the <strong>apim-automation</strong> variable group containing <strong>SERVICE_CONNECTION_NAME</strong>, <strong>apiops_release_version</strong>, and Azure credentials.</p><p><strong>Stages</strong></p><p><strong>Stage 1: create_artifact_from_portal</strong></p><p>Runs on ubuntu-latest.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*8Bn6tbSai7fWH0FWZ34GHg.png" /><figcaption>Stage 1 steps</figcaption></figure><p><strong>Stage 2: create_template_branch</strong></p><p>Runs on ubuntu-latest. Depends on Stage 1 completing successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*UVraXMa_a_pt3FC2tu-r-Q.png" /><figcaption>Stage 2 steps</figcaption></figure><h4><strong>Important notes before running</strong></h4><p>Named values marked as secrets in APIM are extracted as references — the extractor will not dump your Key Vault secrets into the repo. Policy XML is extracted verbatim, meaning whatever has been manually written in the portal over the years comes out exactly as-is.</p><p>Rather than running the extractor locally and committing files by hand, run it directly as a pipeline. This gives you a repeatable, auditable extraction that any team member can trigger. Create a file called run-extractor.yaml in your repo root, paste in the pipeline YAML, and run it.</p><p>Once the pipeline completes, navigate to your repo in Azure DevOps. You should see a Pull Request raised against your main branch. Review and approve the PR to merge the artifacts folder into your main branch.</p><p>Before you wire up the publisher pipeline, take a few minutes to review what was extracted. Specifically look for policies with hardcoded values — backend URLs, hostnames, or IP addresses baked directly into policy XML will cause problems when you promote to Prod. You can replace them with named values in APIM before running the publisher.</p><p><strong><em>Note:</em></strong><em> Normalising APIs and removing hardcoded values from policy XML is outside the scope of this article.</em></p><h3>Build the Publisher Pipeline</h3><p>The publisher pipeline is split across two YAML files.</p><p><strong>run-publisher.yaml</strong></p><p>This is the pipeline you register in Azure DevOps. It defines the trigger, parameters, variable groups, and stages. It does not contain any deployment logic itself — instead, each stage delegates to the second file via a template reference.</p><p><strong>Trigger</strong></p><p>Automatic on every commit to main.</p><p><strong>Parameter</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*aqiCXn2GNRHeK-YuveTDlA.png" /><figcaption>Parameters</figcaption></figure><p><strong><em>Note:</em></strong><em> The default behaviour — publish-artifacts-in-last-commit — is fast and safe for day-to-day use. Only switch to publish-all-artifacts-in-repo when you need to recover from a pipeline failure or force a full resync.</em></p><p><strong>Variable group</strong></p><p>Requires the <strong>apim-automation</strong> variable group containing APIM connection details and Azure credentials.</p><p><strong>Stages</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*ncB6XQL1w0UORSyKKC_0Ug.png" /><figcaption>Stages</figcaption></figure><p>The Prod stage uses an Azure DevOps deployment environment (environment: ‘Prod’), which enables manual approval gates before any production deployment runs.</p><p><strong>run-publisher-with-env.yaml</strong></p><p>This is the reusable template that does the actual work — setting Azure credentials, optionally substituting secrets into a configuration file, fetching the publisher binary, and running it. Because it is a template, it executes identically for both Dev and Prod. Only the parameters change between stages.</p><p>This separation is intentional. If you ever need to add a new environment — for example, a UAT stage between Dev and Prod — you add one new stage block in run-publisher.yaml and point it at the same template. No deployment logic gets duplicated.</p><p><strong>Parameters</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*YS3sVUJ37AEeo_r0_adbBQ.png" /><figcaption>Parameters</figcaption></figure><p><strong>Steps</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*W39oKrlS3nPPF-Gq2xo2yQ.png" /><figcaption>Steps</figcaption></figure><h3><strong>Configuration File — configuration.prod.yaml</strong></h3><p>When the publisher pipeline runs, it reads your artifacts/ folder and applies everything it finds to the target APIM instance. For Dev, that is fine — the artifacts are extracted directly from Dev, so they match. For Prod, there is a problem. Your Dev artifacts contain Dev-specific values — Dev backend URLs, Dev Application Insights resource IDs, and Dev named values. You cannot push those to Prod as-is.</p><p>configuration.prod.yaml is how you solve that. It is a simple override file. You list only the values that need to change for Prod, and the publisher swaps them in before deploying. Everything not mentioned in the file is deployed exactly as it appears in the artifacts.</p><p>Before using configuration.prod.yaml with secret token substitution, two things must be in place:</p><ol><li>The replacetokens@6 marketplace extension must be installed in your Azure DevOps organisation.</li></ol><p><strong>Azure DevOps → Organisation Settings → Extensions → Browse Marketplace → search “Replace Tokens” → Install</strong></p><p>Install it at the organisation level so it is available across all projects. Without it, the Prod stage fails immediately</p><h4><strong>Alternate option — skip this file entirely</strong></h4><p>If your Dev and Prod APIM instances are near-identical in configuration — same backends, same named values, same logging setup — you do not need this file at all. Simply omit the CONFIGURATION_YAML_PATH parameter from the Prod stage in run-publisher.yaml, exactly the same way it is omitted for the Dev stage. The publisher will deploy the base artifacts to Prod unchanged.</p><p>This is actually a reasonable starting point. Get the pipeline working end-to-end with no overrides first, verify that the full Dev-to-Prod promotion loop is healthy, and then introduce configuration.prod.yaml incrementally as you identify values that genuinely need to differ between environments. Trying to configure every override upfront before the pipeline has run once is a common way to get stuck.</p><h3><strong>This is Azure DevOps — but it does not have to be</strong></h3><p>Everything in this tutorial uses Azure DevOps Repos and Azure Pipelines because that is the most common setup for teams already working in the Microsoft ecosystem. But the APIOps Toolkit itself has no hard dependency on Azure DevOps. The extractor and publisher are standalone binaries that authenticate to Azure via environment variables. Any CI/CD platform that can set environment variables and run a shell command can drive them.</p><p>The two things that are Azure DevOps-specific in this tutorial are the pipeline YAML syntax and the service connection mechanism for authentication. Everything else — the folder structure, the configuration.prod.yaml override pattern, the approval gate concept, the variable substitution approach — maps directly onto equivalent constructs in any other platform.</p><p>The Microsoft APIOps toolkit repository includes ready-made workflow files for GitHub Actions alongside the Azure DevOps templates, so if your team moves or you want to run both in parallel, you are not starting from scratch.</p><p>The one Azure DevOps-specific dependency worth calling out is the replacetokens@6 task used for secret substitution in configuration.prod.yaml. On any other platform, a simple envsubst command in a shell step achieves the same result — replace the {# #} token syntax in the YAML with your platform’s native variable syntax before running the publisher. The concept is the same, only the tooling changes.</p><h3><strong>Wrap-up</strong></h3><p>You now have the full APIOps loop running: your APIs are in Git, every change goes through a pull request, a pipeline deploys to Dev automatically, and nothing reaches Prod without a deliberate manual approval.</p><p>If you want to go deeper on policy-as-code and APIM governance across multiple teams, Microsoft’s official APIOps documentation is the right starting point:</p><p><strong>Microsoft APIOps Toolkit — official documentation and reference</strong> <a href="https://azure.github.io/apiops">https://azure.github.io/apiops</a></p><p>The toolkit’s GitHub repository also has a detailed wiki covering every resource type the extractor and publisher support, including edge cases for SOAP APIs, GraphQL, and self-hosted gateways:</p><p><strong>Azure/apiops on GitHub</strong> <a href="https://github.com/Azure/apiops">https://github.com/Azure/apiops</a></p><p>For a working end-to-end lab — including the actual pipeline YAML files used in this article and Terraform code to provision the full Azure environment from scratch — the complete source is on GitHub:</p><p><a href="https://github.com/23sudhakarkadam/APIMOps">GitHub — 23sudhakarkadam/APIMOps · GitHub</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7c688d3b9765" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 1: Automate Java Application Deployment on Azure AKS using Jenkins CI/CD, Nexus, SonarQube…]]></title>
            <link>https://medium.com/@23sudhakarkadam/part-1-automate-java-application-deployment-on-azure-aks-using-jenkins-ci-cd-nexus-sonarqube-0b5e5be2bfb7?source=rss-4fffa7059a22------2</link>
            <guid isPermaLink="false">https://medium.com/p/0b5e5be2bfb7</guid>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[devsecops]]></category>
            <category><![CDATA[azure-kubernetes-service]]></category>
            <category><![CDATA[azure]]></category>
            <dc:creator><![CDATA[Sudhakarkadam]]></dc:creator>
            <pubDate>Wed, 29 Oct 2025 12:31:52 GMT</pubDate>
            <atom:updated>2025-10-29T12:31:52.436Z</atom:updated>
            <content:encoded><![CDATA[<h3>Part 1: Automate Java Application Deployment on Azure AKS using Jenkins CI/CD, Nexus, SonarQube, and Trivy</h3><p><em>In this article, we will explore how to build and deploy a Java application on Azure Kubernetes Service (AKS) using Jenkins, Docker, and Kubernetes. We will learn how to create an end-to-end DevSecOps pipeline that automates your CI/CD process — from code analysis with SonarQube and vulnerability scanning with Trivy, to building, testing, and deploying containers on AKS with Jenkins.</em></p><p><em>We will also </em>explore <em>how to containerize the application with Docker, securely manage artifacts using Nexus, and send real-time deployment notifications through Azure Communication Service. By the end of this guide, you will have a clear understanding of how to implement a secure, automated CI/CD pipeline using Jenkins.</em></p><h3>Jenkins DevOps Pipeline Flow</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*4PMgpcF35Od0dY-gy72npw.png" /><figcaption><strong>Jenkins Pipeline flow</strong></figcaption></figure><h3>Architecture Components:</h3><ul><li><strong>Azure DevOps Repos:</strong> A Git-based repository service used for source code management and version control. You can use Github as well.</li><li><strong>Jenkins Server:</strong> An open-source server that orchestrates CI/CD pipelines for building, testing, and deploying applications.</li><li><strong>Trivy:</strong> An open-source vulnerability scanner for containers, file systems, and dependencies.</li><li><strong>SonarQube:</strong> A code quality and security analysis tool that detects bugs, vulnerabilities, and code smells in your source code.</li><li><strong>Nexus Repository:</strong> A universal artifact repository manager for storing and managing Docker images, dependencies, and build artifacts.</li><li><strong>Docker:</strong> A containerization platform that packages applications and their dependencies into lightweight, portable containers.</li><li><strong>Docker Hub: </strong>A<strong> </strong>cloud-based registry service for building, storing, and sharing container images publicly or privately.</li><li><strong>Azure Kubernetes Service (AKS):</strong> A managed Kubernetes service that simplifies deploying, managing, and scaling containerized applications in Azure.</li><li><strong>Azure Communication Service:</strong> A cloud-based communication platform that enables sending emails, SMS, or notifications from applications.</li></ul><h3>Architecture Overview:</h3><p>Before we get into the setup, let’s look at the overall architecture of our solution. The goal is to create a fully automated DevOps pipeline using Jenkins that handles everything from code commit to deployment and monitoring on Azure Kubernetes Service (AKS).</p><p><strong>Here’s how the pipeline works, step by step:</strong></p><ul><li>Developers push their application code to an Azure DevOps repository. This can include both application logic and configuration files.</li><li>The commit automatically triggers a Jenkins pipeline, which runs<em> mvn compile</em> and <em>mvn test</em> to prepare the code for the next stages.</li><li>Trivy scans the application for security vulnerabilities, such as outdated libraries or known risks.</li><li>SonarQube performs in-depth analysis to ensure the code follows best practices and is free of bugs and errors.</li><li>SonarQube enforces a quality gate, allowing only code that meets predefined standards to proceed further.</li><li>Maven compiles the code, downloads dependencies, and packages the application (e.g., JAR or WAR).</li><li>The build artifacts are published to Nexus Repository, making them versioned, traceable, and ready for deployment.</li><li>The application is packaged into a Docker image and scanned again with Trivy for vulnerabilities.</li><li>The Docker image is pushed to Docker Hub repository, ensuring it’s securely stored and available for deployment.</li><li>The image is deployed to an Azure Kubernetes Service (AKS) cluster, making the application scalable and resilient.</li><li>An Azure Load Balancer directs incoming traffic to the appropriate AKS instances, ensuring availability and reliability.</li><li>Finally, users access the application through the Azure Load Balancer.</li></ul><h3>Pre-requisites:</h3><p>Before we start configuring the pipeline, you need to deploy the following infrastructure in your Azure subscription:</p><ul><li>Virtual Machines for: 1. Jenkins 2. SonarQube 3. Nexus Repository 4. Jump Server (Windows Server)</li><li>Azure Kubernetes Service (AKS) cluster for the application deployment.</li><li>Azure Communication Service for Email notification.</li></ul><p>You can simplify the deployment process by using Terraform. Clone the provided repository to your local directory to deploy the required resources in your subscription.</p><p>If you would like to learn how to automate Azure resource deployment using Terraform and Azure DevOps pipelines, check out <a href="https://medium.com/@23sudhakarkadam/heres-how-you-can-automate-azure-infrastructure-deployment-using-azure-devops-and-terraform-2185985309d5">this article</a> where I cover the complete process step by step.</p><p>Git Repository: <a href="https://github.com/23sudhakarkadam/Blogging_App.git">https://github.com/23sudhakarkadam/Blogging_App.git</a></p><h3>Configuration:</h3><p>This section covers the configuration of SonarQube, Nexus, and Jenkins servers, along with the installation of all required software components.</p><h4><strong>1. SonarQube Server Setup:</strong></h4><p><strong>Step 1: Install docker and enable rootless mode.</strong></p><pre>sudo apt update<br>sudo apt install -y ca-certificates curl gnupg lsb-release<br><br>curl -fsSL https://get.docker.com -o get-docker.sh<br>sudo sh get-docker.sh<br><br>sudo apt-get install -y uidmap dbus-user-session<br><br>dockerd-rootless-setuptool.sh install<br>systemctl --user enable docker<br>systemctl --user start docker<br>loginctl enable-linger $(whoami)</pre><p><strong>Step 2: Run SonarQube Docker Container</strong></p><pre>docker volume create sonarqube_data<br><br>docker run -d --name sonarqube  -v sonarqube_data:/opt/sonarqube  --restart unless-stopped  -p 9000:9000  sonarqube:community<br><br>docker ps</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*6B0f5qvI8aAGbZAR2dLISQ.png" /></figure><p>Access SonarQube: <strong>http://&lt;Private_IP_Address&gt;:9000</strong></p><p><strong>Default Credentials:</strong></p><p>Username: <strong>admin</strong></p><p>Password: <strong>admin</strong></p><p>Once logged in, set the new password for SonarQube.</p><p><strong>Step 3: Generate Authentication token</strong></p><p>Go to: <strong>Administration → Security → Users →Tokens</strong></p><p>Generate Token:</p><p>Name: <strong>sonar-auth-token</strong></p><p>Click <strong>Generate and copy the token</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*C6W3pAFE4VyIw7CoJltzeQ.png" /></figure><p><strong>Step 4: Configure Webhook for Jenkins</strong></p><p>Go to <strong>Administration → Configuration → Webhooks</strong></p><p>Click on <strong>Create</strong></p><p>Name:<strong> Jenkins</strong></p><p>URL:<strong> http://&lt;jenkins_private_ip&gt;:8080/sonarqube-webhook/</strong></p><p>Ensure Jenkins is reachable from SonarQube server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*f-XVWn-_SSuXprdB-10HTg.png" /></figure><h4><strong>2. Nexus Server Setup</strong></h4><p><strong>Step 1: Install docker and enable rootless mode</strong></p><pre>sudo apt update<br>sudo apt install -y ca-certificates curl gnupg lsb-release<br><br>curl -fsSL https://get.docker.com -o get-docker.sh<br>sudo sh get-docker.sh<br><br>sudo apt-get install -y uidmap dbus-user-session<br><br>dockerd-rootless-setuptool.sh install<br>systemctl --user enable docker<br>systemctl --user start docker<br>loginctl enable-linger $(whoami)</pre><p><strong>Step 2: Run Nexus Docker Container</strong></p><pre>Docker volume create nexus_data<br><br>docker run -d --name Nexus  -v nexus_data:/opt/nexus_data  --restart unless-stopped  -p 8081:8081 –p 8000:8000  sonatype/nexus3 <br><br>docker ps</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*RE8AdMTNzGqm3zCmLtztQg.png" /></figure><p><strong>Step 3: Get Admin password</strong></p><pre>docker exec -it &lt;container id&gt; sh<br>cat sonatype-work/nexus3/admin.password<br><br># Copy and store the password</pre><p><strong>Step 4: Access Nexus and get URL</strong></p><p>Access Nexus:<strong> http://&lt;Private_IP_Address&gt;:8081</strong></p><p>Username: <strong>admin</strong></p><p>Password:<strong> Copy paste from the file</strong></p><p>Now, click <strong>Browse</strong></p><p>maven-release → Copy URL: <a href="http://10.0.1.6:8081/repository/maven-releases/">http://10.0.1.6:8081/repository/maven-releases/</a></p><p>maven-snapshot → Copy URL: <a href="http://10.0.1.6:8081/repository/maven-snapshots/">http://10.0.1.6:8081/repository/maven-snapshots/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*MBogsya0psTB1BOSE5H0LQ.png" /></figure><p><strong>Step 5: Update Maven pom.xml file</strong></p><p>Update your maven pom.xml file with Nexus repository URL</p><pre>&lt;distributionManagement&gt;<br>        &lt;repository&gt;<br>            &lt;id&gt;maven-releases&lt;/id&gt;<br>            &lt;url&gt;http://10.0.1.6:8081/repository/maven-releases/&lt;/url&gt; <br>        &lt;/repository&gt;<br>        &lt;snapshotRepository&gt;<br>            &lt;id&gt;maven-snapshots&lt;/id&gt;<br>            &lt;url&gt;http://10.0.1.6:8081/repository/maven-snapshots/&lt;/url&gt;<br>        &lt;/snapshotRepository&gt;<br>&lt;/distributionManagement&gt;<br><br># Replace the IP address with your Nexus server&#39;s IP address</pre><h3><strong>3. Jenkins Server Setup</strong></h3><p><strong>Step 1: Install docker with rootless mode</strong></p><pre>sudo apt update<br>sudo apt upgrade<br>sudo apt install -y ca-certificates curl gnupg lsb-release<br><br>curl -fsSL https://get.docker.com -o get-docker.sh<br>sudo sh get-docker.sh<br><br>sudo apt-get install -y uidmap dbus-user-session<br><br>dockerd-rootless-setuptool.sh install<br>systemctl --user enable docker<br>systemctl --user start docker<br>loginctl enable-linger $(whoami)</pre><p><strong>Step 2: Install Trivy</strong></p><pre>curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sudo sh -s -- -b /usr/local/bin<br><br>trivy –version</pre><p><strong>Step 3: Install Jenkins</strong></p><pre># Install latest stable OpenJDK (currently JDK 21)<br>sudo apt install openjdk-21-jdk -y<br><br># Verify Java installation<br>java -version<br><br># Add Jenkins key and repository<br>sudo mkdir -p /usr/share/keyrings<br>sudo wget -O /usr/share/keyrings/jenkins-keyring.asc  https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key<br><br>echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \<br>https://pkg.jenkins.io/debian-stable binary/ | \<br>sudo tee /etc/apt/sources.list.d/jenkins.list &gt; /dev/null<br><br><br># Update package list<br>sudo apt-get update -y<br><br># Install latest stable Jenkins<br>sudo apt-get install jenkins -y<br><br># Enable and start Jenkins service<br>sudo systemctl enable jenkins<br>sudo systemctl start jenkins<br><br># Check Jenkins service status<br>sudo systemctl status jenkins --no-pager</pre><p><strong>Step 4: Get admin password and access Jenkins</strong></p><pre>sudo cat /var/lib/jenkins/secrets/initialAdminPassword</pre><p>Access Jenkins: <strong>http://&lt;Private_IP_Address&gt;:8080</strong></p><p>Username: <strong>admin</strong></p><p>Paste administrator password</p><p><strong>Step 5: Install Kubectl on Jenkins Server</strong></p><pre># Download the latest stable kubectl binary for Linux (amd64)<br>sudo curl -LO &quot;https://dl.k8s.io/release/$(curl -Ls https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl&quot;<br><br># Make it executable<br>sudo chmod +x kubectl<br><br># Move it to a directory in your PATH<br>sudo mv kubectl /usr/local/bin/<br><br># Verify installation<br>kubectl version –client<br><br># Add Jenkins to docker group <br>sudo usermod -aG docker jenkins<br>sudo systemctl restart jenkins</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/877/1*1QEidqts_87f61qDz9PeHQ.png" /></figure><h3>4. Jenkins Configuration</h3><h4><strong>Step 1: Install required plugins</strong></h4><p>Go to:<strong> Manage Jenkins → Plugins → Available plugins</strong></p><pre># Install following plugins<br>- Git<br>- Git client<br>- Docker<br>- Docker Pipeline<br>- Kubernetes <br>- Kubernetes CLI<br>- Kubernetes Client API <br>- Kubernetes Credentials <br>- Prometheus Metrics <br>- Pipeline: Stage View <br>- Pipeline Maven Integration <br>- Maven Integration <br>- SonarQube Scanner <br>- Config File Provider <br>- Eclipse Temurin installer</pre><p>Restart Jenkins after plugin installation</p><h4><strong>Step 2: Configure Tools</strong></h4><p>Navigate to <strong>Dashboard → Manage Jenkins → Tools</strong></p><p><strong>A. JDK:</strong></p><p>Name: <strong>jdk24</strong></p><p>Click <strong>“Install Automatically”</strong></p><p>Source: <strong>Adoptium.net</strong></p><p>Version: <strong>jdk-24.0.2 +12</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*jm7RN1Nf5OLmXplcdnvUbw.png" /></figure><p><strong>B. SonarQube Scanner:</strong></p><p>Name: <strong>sonar-scanner</strong></p><p>Click <strong>“Install Automatically”</strong></p><p>Version: <strong>#Install latest available version</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*bxuzP7MAYSImwhp4vQwYGQ.png" /></figure><p><strong>C. Maven:</strong></p><p>Name: <strong>maven</strong></p><p>Version: <strong># Select latest available version</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*U0juXAEMYVc5lLAq-dh3Pw.png" /></figure><p><strong>D. Docker:</strong></p><p>Name: <strong>docker</strong></p><p>Click <strong>“Install Automatically”</strong></p><p>Source: <strong>Download from docker.com</strong></p><p>Docker Version: <strong>latest</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*joS6qw7FJ3UMWdxyciXODw.png" /></figure><h4>Step 3: <strong>Setup Credentials</strong></h4><p>Navigate to<strong> Dashboard → Manage Jenkins → Credentials → System → Global Credentials → Add Credentials</strong></p><p><strong>A. Azure Git Repo:</strong></p><p>Generate git Credentials in Azure Repos</p><p>Navigate to <strong>Azure DevOps →</strong> <strong>Repo → Clone repositories → Click Generate Git credentials</strong></p><p>Copy username and Git credentials</p><p>Now, in Jenkins add credentials,</p><p>Kind: <strong>Username with password</strong></p><p>Username:<strong> &lt;Enter your username&gt;</strong></p><p>Password: <strong>&lt;Paste Git credentials which you copied from Azure DevOps&gt;</strong></p><p>ID: <strong>git-cred</strong></p><p>Description: <strong>git-cred</strong></p><p><strong>B. SonarQube:</strong></p><p>Kind: <strong>Secret text</strong></p><p>Secret: <strong>&lt;sonar-auth-token generated in SonarQube setup&gt;</strong></p><p>ID: <strong>sonar-auth-token</strong></p><p>Description: <strong>sonar-auth-token</strong></p><p><strong>C. Docker hub Credentials:</strong></p><p><strong>Before adding credential in Jenkins, create Personal Access Token(PAT) in Docker Hub</strong></p><p>Now in Jenkins,</p><p>Kind: <strong>Username with password</strong></p><p>Username: <strong>&lt;Docker Hub Username&gt;</strong></p><p>Password:<strong> &lt;PAT you created in Docker Hub&gt;</strong></p><p>Id: <strong>docker-cred</strong></p><p>Description: <strong>docker-cred</strong></p><p><strong>D. Generate Credential for AKS:</strong></p><p>Before you add credential in Jenkins for AKS, first generate the credential file using Azure CLI.</p><p>Follow the steps given below.</p><pre># Install Azure CLI in your device and run following command to generate AKS credentials<br># We need to upload this credential file in Jenkins.<br><br>az login <br>az aks get-credentials -n &lt;AKS Name&gt; -g &lt;Resource_Group_Name&gt; --file aksconfig</pre><p>We will use <strong>“aksconfig”</strong> file to authenticate Azure Kubernetes service.</p><p>Kind: <strong>Secret file</strong></p><p>Choose file: <strong>&lt;Upload the aksconfig file&gt;</strong></p><p>ID:<strong> kube-cred</strong></p><p>Description: <strong>kube-cred</strong></p><h4>Step 4: <strong>Add Maven settings for Nexus</strong></h4><p>Navigate: <strong>Manage Jenkins → Managed Files → Add a New Config</strong></p><p>Type:<strong> Global Maven settings.xml</strong></p><p>ID:<strong> global-settings</strong></p><p>Paste the following:</p><pre>&lt;settings&gt;<br>  &lt;servers&gt;<br>    &lt;server&gt;<br>      &lt;id&gt;maven-releases&lt;/id&gt;<br>      &lt;username&gt;nexus_username&lt;/username&gt;<br>      &lt;password&gt;nexus_password&lt;/password&gt;<br>    &lt;/server&gt;<br>    &lt;server&gt;<br>      &lt;id&gt;maven-snapshots&lt;/id&gt;<br>      &lt;username&gt;nexus_username&lt;/username&gt;<br>      &lt;password&gt;nexus_password&lt;/password&gt;<br>    &lt;/server&gt;<br>  &lt;/servers&gt;<br>&lt;/settings&gt;<br><br># Replace nexus_username and nexus_password with the actual values.</pre><h4><strong>Step 5: Add SonarQube Server information</strong></h4><p>Navigate:<strong> Manage Jenkins → System → SonarQube Servers → + Add SonarQube</strong></p><p>Name: <strong>sonar</strong></p><p>Server URL: <strong>http://&lt;Private_IP_Address_of_SonarQube_Server&gt;:9000</strong></p><p>Server Authentication Token: <strong>Select sonar-auth-token</strong></p><h4>Step 6: <strong>Create New Pipeline</strong></h4><p>Create Job → Go to <strong>Jenkins Dashboard → </strong>Click <strong>New Item</strong></p><p>Name: <strong>Blogging_App</strong></p><p>Type: <strong>Pipeline</strong></p><p><strong>Click OK</strong></p><p>Now, Navigate to: <strong>Blogging_App → Configure → Pipeline → Pipeline Script</strong></p><p><strong>Paste following pipeline script</strong></p><pre>pipeline {<br>    agent any<br>    <br>    tools {<br>        jdk &#39;jdk24&#39;<br>        maven &#39;maven&#39;<br>    }<br>   <br>    environment {<br>        SCANNER_HOME = tool &#39;sonar-scanner&#39;<br>    }<br><br>    stages {<br>        stage(&#39;Git Checkout&#39;) {<br>            steps {<br>                git branch: &#39;main&#39;, credentialsId: &#39;git-cred&#39;, url: &#39;&lt;Complete URL of your git repository&gt;&#39;<br>            }<br>        }<br><br>        stage(&#39;Compile&#39;) {<br>            steps {<br>                sh &quot;mvn compile&quot;<br>            }<br>        }<br><br>        stage(&#39;Test&#39;) {<br>            steps {<br>                sh &quot;mvn test&quot;<br>            }<br>        }<br><br>        stage(&#39;File System Scan&#39;) {<br>            steps {<br>                sh &quot;trivy fs --format table -o trivy-fs-report.html .&quot;<br>            }<br>        }<br><br>        stage(&#39;SonarQube Analysis&#39;) {<br>            steps {<br>                withSonarQubeEnv(&#39;sonar&#39;) {<br>                    sh &quot;&quot;&quot;<br>                        \$SCANNER_HOME/bin/sonar-scanner \<br>                        -Dsonar.projectName=bloggingapp \<br>                        -Dsonar.projectKey=bloggingapp \<br>                        -Dsonar.java.binaries=.<br>                    &quot;&quot;&quot;<br>                }<br>            }<br>        }<br><br>        stage(&#39;Quality Gate&#39;) {<br>            steps {<br>                script {<br>                    waitForQualityGate abortPipeline: false, credentialsId: &#39;sonar-auth-token&#39;<br>                }<br>            }<br>        }<br><br># Set abortPipeline to true, Jenkins will stop the pipeline when<br># the quality gate fails.<br><br>        stage(&#39;Build&#39;) {<br>            steps {<br>                sh &quot;mvn package&quot;<br>            }<br>        }<br><br>        stage(&#39;Publish To Nexus&#39;) {<br>            steps {<br>                withMaven(globalMavenSettingsConfig: &#39;global-settings&#39;, traceability: true) {<br>                    sh &quot;mvn deploy&quot;<br>                }<br>            }<br>        }<br><br>        stage(&#39;Build &amp; Tag Docker Image&#39;) {<br>            steps {<br>               script {<br>                   withDockerRegistry(credentialsId: &#39;docker-cred&#39;, toolName: &#39;docker&#39;) {<br>                            sh &quot;docker build -t sudhakarkadam/blogging_app:latest .&quot;<br>                    }<br>               }<br>            }<br>        }<br><br># Change docker repository name.<br><br>        stage(&#39;Docker Image Scan&#39;) {<br>            steps {<br>                sh &quot;trivy image --format table -o trivy-image-report.html sudhakarkadam/blogging_app:latest&quot;<br>            }<br>        }<br><br>        stage(&#39;Push Docker Image&#39;) {<br>            steps {<br>               script {<br>                   withDockerRegistry(credentialsId: &#39;docker-cred&#39;, toolName: &#39;docker&#39;) {<br>                            sh &quot;docker push sudhakarkadam/blogging_app:latest&quot;<br>                    }<br>               }<br>            }<br>        }<br><br>        stage(&#39;Deploy To Kubernetes&#39;) {<br>            steps {<br>                withKubeConfig(<br>                    caCertificate: &#39;&#39;,<br>                    clusterName: &#39;app-aks&#39;,<br>                    credentialsId: &#39;kube-cred&#39;,<br>                    namespace: &#39;webapps&#39;,<br>                    serverUrl: &#39;https://app-dns-uyhpqra8.hcp.centralindia.azmk8s.io&#39;<br>                ) {<br>                    sh &quot;kubectl apply -f deployment-service.yml&quot;<br>                }<br>            }<br>        }<br><br>        stage(&#39;Verify the Deployment&#39;) {<br>            steps {<br>                withKubeConfig(<br>                    caCertificate: &#39;&#39;,<br>                    clusterName: &#39;app-aks&#39;,<br>                    credentialsId: &#39;kube-cred&#39;,<br>                    namespace: &#39;webapps&#39;,<br>                    serverUrl: &#39;https://app-dns-uyhpqra8.hcp.centralindia.azmk8s.io&#39;<br>                ) {<br>                    sh &quot;kubectl get pods -n webapps&quot;<br>                    sh &quot;kubectl get svc -n webapps&quot;<br>                }<br>            }<br>        }<br>    }<br><br>    post {<br>        always {<br>            script {<br>                def jobName = env.JOB_NAME<br>                def buildNumber = env.BUILD_NUMBER<br>                def pipelineStatus = currentBuild.result ?: &#39;UNKNOWN&#39;<br>                def bannerColor = pipelineStatus.toUpperCase() == &#39;SUCCESS&#39; ? &#39;green&#39; : &#39;red&#39;<br><br>                def body = &quot;&quot;&quot;<br>                    &lt;html&gt;<br>                    &lt;body&gt;<br>                    &lt;div style=&quot;border: 4px solid ${bannerColor}; padding: 10px;&quot;&gt;<br>                    &lt;h2&gt;${jobName} - Build ${buildNumber}&lt;/h2&gt;<br>                    &lt;div style=&quot;background-color: ${bannerColor}; padding: 10px;&quot;&gt;<br>                    &lt;h3 style=&quot;color: white;&quot;&gt;Pipeline Status: ${pipelineStatus.toUpperCase()}&lt;/h3&gt;<br>                    &lt;/div&gt;<br>                    &lt;p&gt;Check the &lt;a href=&quot;${BUILD_URL}&quot;&gt;console output&lt;/a&gt;.&lt;/p&gt;<br>                    &lt;/div&gt;<br>                    &lt;/body&gt;<br>                    &lt;/html&gt;<br>                &quot;&quot;&quot;<br><br>                emailext (<br>                    subject: &quot;${jobName} - Build ${buildNumber} - ${pipelineStatus.toUpperCase()}&quot;,<br>                    body: body,<br>                    to: &#39;&lt;Email ID which should receive the notification&gt;&#39;,<br>                    from: &#39;donotreply@af8ef541-247e-4dce-b80c-d1585b7864eb.azurecomm.net&#39;,<br>                    replyTo: &#39;donotreply@af8ef541-247e-4dce-b80c-d1585b7864eb.azurecomm.net&#39;,<br>                    mimeType: &#39;text/html&#39;,<br>                    attachmentsPattern: &#39;trivy-image-report.html&#39;<br>                )<br>            }<br>        }<br>    }<br>}</pre><p>Click <strong>Apply &amp; Save</strong>.<br>Then, run the pipeline by clicking <strong>Build Now</strong>.<br>The following will be your stage view, where you can see all the stages of your pipeline.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZoTyu6HG1--JN8VE4mR-SQ.png" /><figcaption>Stage view</figcaption></figure><p>Once the pipeline runs successfully, you will be able to access the Blogging_App using Azure Load Balancer Public IP address.</p><p>Navigate to: <strong>Azure Portal → app-aks → Services and ingresses</strong></p><p>Use the <strong>External IP</strong> to access the application.</p><p>Later, you can configure an A record in your DNS server to access it via a custom domain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CjBuJgVmkD2VGUnPZ_jkzw.png" /><figcaption>Azure Portal</figcaption></figure><h3>Conclusion</h3><p>We have walked through every step required to automate the deployment of a Java Spring Boot application on Azure Kubernetes using Jenkins CI/CD. From scanning and testing your code to pushing Docker images and deploying to AKS, this pipeline demonstrates how automation simplifies DevOps workflows. Whether you are new to CI/CD or looking to implement a more secure delivery model, this approach gives you a strong starting point for production-grade deployments. You can extend this setup by integrating tools like Prometheus for monitoring and Grafana for visualization to enhance observability and performance tracking.</p><h3>Next Step</h3><p>In the upcoming article, we will explore how to configure Prometheus for monitoring, import dashboards, and integrate them with Prometheus for visualization. We will also cover how to configure Jenkins for email notifications using Azure Communication Service.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0b5e5be2bfb7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learn how to automate Azure infrastructure deployment with Terraform and Azure DevOps.]]></title>
            <link>https://medium.com/@23sudhakarkadam/heres-how-you-can-automate-azure-infrastructure-deployment-using-azure-devops-and-terraform-2185985309d5?source=rss-4fffa7059a22------2</link>
            <guid isPermaLink="false">https://medium.com/p/2185985309d5</guid>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[azure-devops]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Sudhakarkadam]]></dc:creator>
            <pubDate>Tue, 07 Oct 2025 08:47:33 GMT</pubDate>
            <atom:updated>2025-10-07T11:46:55.806Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>This blog explains how to automate Azure infrastructure deployments using Terraform and Azure DevOps. You’ll learn how to store Terraform code in Azure Repos, set up Azure DevOps pipelines, configure service connections, and implement a CI/CD workflow to deploy resources to Azure seamlessly. Perfect for anyone starting with Infrastructure as Code and DevOps practices in the cloud.</blockquote><h3>Overview:</h3><p>In the last article, we learned to deploy a 3-tier architecture using Terraform. Now, let’s automate it with Azure DevOps.</p><p>In this article, we will deep dive into automating Azure deployments with Terraform and Azure DevOps pipeline. You’ll learn how to establish a complete DevOps workflow that ensures your Azure resources are deployed securely, consistently, and in a controlled manner.</p><p><strong>This article will cover the following key learnings:</strong></p><ul><li>How to structure a Git workflow for Terraform code using main and feature branches.</li><li>Implement code reviews and manual checkpoints in your pipeline, validate infrastructure changes, and safely apply approved changes.</li><li>Along with a ready-to-use multi-stage pipeline configuration to run Terraform in Azure DevOps.</li></ul><h3>Pre-requisites:</h3><ul><li>Azure Subscription</li><li>Azure DevOps organization</li><li>Azure Repos</li><li>Terraform, Visual code and Git installed locally</li></ul><h3>Branching Strategy:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/423/1*wmSCd1ENeyM9jhtyXvHXqg.png" /><figcaption>Branching Strategy</figcaption></figure><p>We will follow a simple branching strategy for our Terraform deployment:</p><ul><li>The main branch will contain the Terraform code for the deployed infrastructure and act as the single source of truth.</li><li>A feature branch will be cloned from the main branch, where infrastructure changes are committed.</li><li>Code merges will be done through a pull request, followed by a code review and manual approval from the reviewer.</li><li>Once the pull request is approved, the feature branch will be merged back into the main branch, which will then trigger the Terraform plan stage.</li></ul><h3><strong>Azure DevOps Pipeline Flowchart:</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*ms4DwcSIuMIeQwiYbAwUmw.png" /><figcaption>DevOps Pipeline Flow Diagram</figcaption></figure><p>The diagram illustrates the end-to-end flow of automating Azure infrastructure deployments using Azure DevOps Pipelines, Terraform, and Azure Artifacts.</p><ul><li>A developer writes infrastructure code in Visual Studio code.</li><li>The code is then pushed to Azure Repos.</li><li>Infrastructure changes are committed into the feature branch.</li><li>A pull request is created to merge changes from feature branch to the main branch.</li><li>The pull request undergoes code review and manual approval.</li><li>Once merged into the main branch, the Terraform plan stage is triggered.</li><li>Plan artifacts are published to Azure Artifacts for the next stage.</li><li>The Terraform apply stage is triggered after reviews and approvals.</li><li>Artifacts from the plan stage are pulled from Azure Artifacts.</li><li>Infrastructure is deployed across multiple environments / subscriptions.</li></ul><h3>Configure Repository:</h3><p>Before setting up Repos and automating Terraform deployments with Azure DevOps, you will need a few things in place:</p><ul><li>An Azure DevOps organization and project already created.</li><li>You should be a Project Administrator to configure branch policies.</li><li>Git installed and configured locally.</li><li>Install Visual Studio Code locally.</li><li>Install Terraform locally.</li><li>Azure Subscription with at least contributor access.</li></ul><p><strong>Step 1: Create the repository</strong></p><p>Go to <strong>Project → Repos → New Repository → &lt;Name&gt;</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*UxQ_nrc5nbENYQvtI4wqvA.png" /><figcaption>Create new repository in DevOps</figcaption></figure><p>Or you can use Import Repository feature to import your existing git repository in Azure Repo.</p><p>Git Project 1: <a href="https://github.com/23sudhakarkadam/DevOps_Project_1.git">https://github.com/23sudhakarkadam/DevOps_Project_1.git</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*P-vWwFBnyVhjxCdNGWNiEw.png" /><figcaption>Import Git repository in DevOps</figcaption></figure><p><strong>Step 2: Clone the repository on your local machine.</strong></p><p>Go to <strong>Repos → Files → Clone → Clone in VS Code (Or select any other IDE)</strong></p><p>It will open VS code and clone your repository to the local machine in the selected folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*APNXdRBZQBGP6OSjEl_plg.png" /><figcaption>Clone Azure Repo on Local Machine</figcaption></figure><p>You can also use git command to clone Azure Repository</p><pre>mkdir lab<br>cd lab<br>git clone &lt;Paste Repo URL from Azure DevOps&gt;<br>cd &lt;Repo-Name&gt;<br>git checkout main</pre><p><strong>Step 3: Create feature branch from main</strong></p><pre># Create new feature branch<br><br>git checkout -b feature/feature<br><br># Open feature branch in VS Code<br>code .<br><br># Now, make some changes in infrastructure code (Terraform file)<br># Commit the changes to the feature branch<br><br>git add .<br>git commit -m &quot;Add new RG&quot;<br><br># Push feature branch to remote<br><br>git push -u origin feature/feature</pre><p>Now, try to push to the main branch. If branch policies are not configured, developers can push code directly to the main branch.</p><pre>git checkout main<br>git merge feature/feature<br>git push origin main</pre><p>This is allowed because the main branch is not protected by branch policies or security restrictions. Once the policies are applied, direct pushes will be prevented.</p><p><strong>Step 4: Configure Branch Policy (Pull Request Policy)</strong></p><p>In Azure DevOps go to, <strong>Repos → Branches.</strong></p><p>Find main branch, <strong>click the vertical ellipsis → Branch Policies.</strong></p><p>Enable “Require a minimum number of reviewers” and set to 1 or 2 depending on your team</p><p>Uncheck “Allow users to approve their own changes” (Recommended)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qwFOoUD41pqtQfTR1FvwCw.png" /></figure><p>In Security tab, configure security permission for group which contain developers and set:</p><p><strong>Contributor → Deny</strong></p><p><strong>Force Push → Deny</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1021/1*CLfX5KtyqOB68EssJuowAw.png" /></figure><p>Make sure you don’t deny Contributor permissions to the Project Administrators or yourself, as this may lock you out.</p><p>Now, let’s try merging the feature branch again.</p><pre># Make changes in infrastructure code (Terraform file)<br># Commit the changes to the feature branch<br><br>git add .<br>git commit -m &quot;Add new RG&quot;<br><br># Push feature branch to remote<br><br>git push -u origin feature/feature<br><br># Let&#39;s try to merge and push feature branch into main branch<br><br>git checkout main<br>git merge feature/feature<br>git push origin main<br><br># You should see the following error message<br><br># ! [remote rejected] main -&gt; main (TF402455: Pushes to this branch are not permitted; you must use a pull request to update this branch.)<br># error: failed to push some refs to &#39;https://dev.azure.com/23sudhakarkadam/23sudhakarkadam/_git/DevOps_Project_1.git&#39;</pre><p><strong>Step 5: Create Pull Request</strong></p><p>In Azure DevOps go to: <strong>Repos → Pull Request → New Pull Request</strong></p><p><strong>Select a source branch (feature branch) and Target (Main branch) → Add title → Reviewers → Click Create</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*sCYihzxtGfriqSD0gXAPrw.png" /><figcaption>Create Pull Request</figcaption></figure><p>Reviewers verify and approve the code changes. Once all required approvals are in place, select Complete or Auto complete to merge into the main branch, which triggers the Terraform plan pipeline.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TLDPTkHF8Cb7Hx3VrZrncg.png" /><figcaption>Approve Pull Request</figcaption></figure><h3><strong>Configure Pipeline:</strong></h3><p><strong>Step 1: Store secrets in variable group for authentication</strong></p><p>To successfully authenticate Terraform with an Azure subscription using a service principal, the following details are required Subscription ID, Tenant ID, Client ID, Client Secret.</p><p>Instead of storing these values in plain text within the .tf files, it is recommended to create a Variable Group in Azure DevOps and reference it in the Azure Pipeline for authentication.</p><p><strong>Create Variable Group</strong></p><p><strong>Go to Azure DevOps → Pipelines → Library → Variable Group</strong></p><p>Provide <strong>Variable Group Name</strong> and <strong>Add variable → Save</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NyU3lMmiBqwbIlamrMnogA.png" /><figcaption>Variable Group</figcaption></figure><p><strong>Step 2: Create Terraform Plan and Apply Pipeline using YAML</strong></p><p>Now that we have created the variable group in Azure DevOps, let’s look at how the pipeline flow works. We will define the pipeline using a YAML script in Azure DevOps.</p><p>The pipeline is divided into <strong>two stages</strong>:</p><ol><li><strong>Terraform Plan</strong> — In this stage, the pipeline generates a Terraform execution plan and publishes it to Azure Artifacts. This plan acts as a preview of all the infrastructure changes that will be applied. Reviewers can then validate and approve the plan to ensure the proposed changes are correct and safe.</li><li><strong>Terraform Apply</strong> — Once the plan is approved, the pipeline retrieves the published artifact and executes Terraform Apply. This step deploys the infrastructure changes to the respective Azure environment, ensuring deployments are consistent with the reviewed and approved plan.</li></ol><p>By separating the pipeline into plan and apply stages, we introduce an additional layer of governance, safety, and transparency, making the deployment process both secure and auditable.</p><p>Let’s understand the YAML file,</p><pre>trigger:<br>- main<br><br># The pipeline is triggered automatically whenever code is <br># pushed to the main branch<br><br>pool:<br>  vmImage: &#39;ubuntu-latest&#39;<br><br># Specifies the pipeline will run on Microsoft hosted Ubuntu agent.<br><br>variables:<br>  - group: Terraform-SP-Auth<br>  - name: terraformVersion<br>    value: &#39;1.13.2&#39;<br>  - name: environmentName<br>    value: &#39;Prod&#39;<br>  - name: workingDir<br>    value: &#39;$(System.DefaultWorkingDirectory)/Infrastructure&#39;<br><br># Defining the variable which will be used in this yml configuration.<br># Terraform-SP-Auth: This variable stores Azure Service principal credentials<br># terraformVersion: The version of Terraform to install.<br># environmentName: Logical environment name<br># workingDir: Directory path where Terraform code is located. You will need<br>#             change the directory path if you have any other sub folder under <br>#             e.g. /Infrastructure/App for resource in ./Infra../App subfolder<br><br>stages:<br>- stage: Plan<br>  displayName: &#39;Terraform Plan&#39;<br><br># This stage validates the infrastructure changes and publishes a plan for review<br><br>  jobs:<br>  - job: TerraformPlan<br>    displayName: &#39;Run Terraform Plan&#39;<br>    steps:<br>    - script: |<br>        curl -LO https://releases.hashicorp.com/terraform/$(terraformVersion)/terraform_$(terraformVersion)_linux_amd64.zip<br>        unzip terraform_$(terraformVersion)_linux_amd64.zip<br>        sudo mv terraform /usr/local/bin/<br>        terraform -version<br>      displayName: &#39;Install Terraform&#39;<br><br># This job downloads and install the specified version of terraform<br># Verifies installation by running terraform -version<br><br>    - script: |<br>        echo &quot;Environment: $(environmentName)&quot;<br>        mkdir -p $(Build.ArtifactStagingDirectory)/tfplan<br>        terraform init<br>        terraform plan -var-file=$(System.DefaultWorkingDirectory)/Infrastructure/terraform.tfvars -out=$(Build.ArtifactStagingDirectory)/tfplan/tfplan<br>      displayName: &#39;Terraform Init &amp; Plan&#39;<br>      workingDirectory: $(workingDir)<br>      env:<br>        ARM_CLIENT_ID: $(ARM_CLIENT_ID)<br>        ARM_CLIENT_SECRET: $(ARM_CLIENT_SECRET)<br>        ARM_SUBSCRIPTION_ID: $(ARM_SUBSCRIPTION_ID)<br>        ARM_TENANT_ID: $(ARM_TENANT_ID)<br><br># Runs terraform init to initialize the backend and providers.<br># Execute terraform plan with variables defined in terraform.tfvars file.<br># workingDirectory is mention so that plan is executed specified working <br># directory only.<br># -out: Outputs the plan file to artifact directory.<br># Azure credentials are securely passed from variable group for authentication.<br><br>    - publish: $(Build.ArtifactStagingDirectory)/tfplan<br>      artifact: tfplan<br><br># Publishes the generated Terraform plan as a Pipeline Artifacts<br><br>- stage: Apply<br>  displayName: &#39;Terraform Apply&#39;<br>  dependsOn: Plan<br>  condition: succeeded(&#39;Plan&#39;)<br><br># This stage depends on Plan stage and rus only if the plan succeeds.<br># This stage deploy the infrastructure defined in the approved Terraform plan<br><br>  jobs:<br>  - job: ManualApproval<br>    displayName: &#39;Manual Approval Before Apply&#39;<br>    pool: server<br>    steps:<br>    - task: ManualValidation@0<br>      inputs:<br>        notifyUsers: &#39;&lt;Define user EMAIL ID for approval&gt;&#39;<br>        instructions: &#39;Approve to apply Terraform changes to Azure.&#39;<br>        onTimeout: &#39;reject&#39;<br>      timeoutInMinutes: 60<br><br># Adds a manual approval gate before running Terraform apply<br># Sends approval request to the defined users<br># If no approval is given within 60 minutes, the pipeline fails.<br><br>  - job: TerraformApply<br>    displayName: &#39;Run Terraform Apply&#39;<br>    dependsOn: ManualApproval<br>    steps:<br>    - script: |<br>        curl -LO https://releases.hashicorp.com/terraform/$(terraformVersion)/terraform_$(terraformVersion)_linux_amd64.zip<br>        unzip terraform_$(terraformVersion)_linux_amd64.zip<br>        sudo mv terraform /usr/local/bin/<br>        terraform -version<br>      displayName: &#39;Install Terraform&#39;<br><br># Install Terraform same as in the plan stage.<br><br>    - download: current<br>      artifact: tfplan<br><br># Download the previously published Terraform plan artifacts.<br><br>    - script: |<br>        echo &quot;Environment: $(environmentName)&quot;<br>        terraform init<br>        terraform apply $(Pipeline.Workspace)/tfplan/tfplan<br>      displayName: &#39;Terraform Apply&#39;<br>      workingDirectory: $(workingDir)<br>      env:<br>        ARM_CLIENT_ID: $(ARM_CLIENT_ID)<br>        ARM_CLIENT_SECRET: $(ARM_CLIENT_SECRET)<br>        ARM_SUBSCRIPTION_ID: $(ARM_SUBSCRIPTION_ID)<br>        ARM_TENANT_ID: $(ARM_TENANT_ID)<br><br># Initialize Terraform again in the working directory<br># Executes terraform apply using previously generated and approved plan file</pre><p>Create .yml file in your working directory and save the above YAML script in that file. We will use this .yml file to create Pipeline in Azure DevOps.</p><p><strong>Step 3: Create Pipeline</strong></p><p>Follow the steps given below to create the pipeline.</p><p>Go to <strong>Azure DevOps → Pipelines → New Pipeline → Select Repository</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7P-keS6n53aipxqAe0g3NA.png" /></figure><p>In Configure, click on “Existing Azure Pipeline YAML file”</p><p>Select Branch = Main</p><p><strong>Path = &lt;Path of your .yml in main repository&gt; → Continue</strong></p><p><strong>Review and Run</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y60ssbpm-w7Sk_RMV-FMOQ.png" /><figcaption>Configure Azure Pipeline</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I6sdeN4tsa1TP6WeIlvH5w.png" /><figcaption>Review and Run Pipeline</figcaption></figure><p>Once you click on <strong>Run</strong>, it will create pipeline and run terraform plan and apply stage.</p><h3>Summary:</h3><p>This guide shows you how to use Terraform and Azure DevOps to set up secure Git workflows, branch policies, and multi-stage YAML pipelines that plan and apply your infrastructure changes automatically.<br>By the end, you’ll have a reliable, scalable, and auditable Infrastructure as Code (IaC) setup that makes managing Azure resources effortless.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2185985309d5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying a 3-Tier Architecture on Azure Using Terraform]]></title>
            <link>https://medium.com/@23sudhakarkadam/deploying-a-3-tier-architecture-on-azure-using-terraform-ccd8b79c04cb?source=rss-4fffa7059a22------2</link>
            <guid isPermaLink="false">https://medium.com/p/ccd8b79c04cb</guid>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[azure-devops]]></category>
            <category><![CDATA[microsoft-azure]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[architecture]]></category>
            <dc:creator><![CDATA[Sudhakarkadam]]></dc:creator>
            <pubDate>Thu, 25 Sep 2025 12:13:19 GMT</pubDate>
            <atom:updated>2025-09-26T10:57:12.741Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>The primary objective of the project is to deploy a scalable, highly available, and secure application using a 3-tier architecture. The application will be hosted on Azure using various services like VMSS, MySQL DBaaS, Load Balancer etc. to ensure its high availability, scalability, and security. The application will be available to end users via the public internet. Deployment can be automated using Terraform and Azure DevOps.</blockquote><h3>Architecture Diagram:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*-SbfYZgQ--7uxw9kalAXHQ.png" /><figcaption>3-Tier Architecture</figcaption></figure><h3>Overview:</h3><p>This solution follows a 3-tier architecture model<strong> </strong>consisting of Web, Application, and Database tiers. All components are deployed across Availability Zones to ensure high availability, scalability, and fault tolerance.</p><p><strong>Web Tier (Nginx):</strong></p><ul><li>A Public Load Balancer acts as the entry point for external user traffic.</li><li>The Azure Load Balancer distributes incoming requests to Nginx VMSS instances.</li><li>Nginx VMSS instances are deployed across multiple zones (Zone 1 and Zone 2).</li><li>Nginx functions as a reverse proxy/load balancer, routing requests to the backend Application tier.</li><li>VMSS (Virtual Machine Scale Set) ensures high availability with zone redundancy.</li></ul><p><strong>Application Tier (Tomcat):</strong></p><ul><li>An Internal Load Balancer distributes traffic internally from the Web tier to the Application tier.</li><li>This keeps application traffic private within the virtual network.</li><li>Applications are hosted on Tomcat VMSS instances deployed in Zone 1 and Zone 2.</li><li>VMSS provides scalability with auto-scaling capabilities.</li></ul><p><strong>Database Tier (MySQL Database):</strong></p><ul><li>Azure Database for MySQL provides a fully managed relational database service.</li><li>The Primary database instance is deployed in Zone 1.</li><li>A Read Replica is deployed in Zone 2 for redundancy and load distribution.</li><li>The replica also supports read-heavy workloads.</li></ul><p><strong>Additional Components:</strong></p><ul><li>DNS resolves domain names for web users and routes requests to the Public IP of the Azure Load Balancer.</li><li>Each tier is isolated within its own subnet, with Network Security Groups (NSGs) for traffic filtering and protection.</li></ul><h3><strong>Architecture Components:</strong></h3><ul><li><strong>Virtual Machine Scale Set (VMSS):</strong> Automatically deploys and manages a set of identical VMs that scale based on demand.</li><li><strong>Azure Load Balancer (Internal &amp; Public):</strong> Distributes inbound traffic across backend resources for high availability and performance.</li><li><strong>Virtual Network and Subnet:</strong> Provides an isolated network environment in Azure with logical segmentation for secure resource communication</li><li><strong>MySQL Database Flexible Server and Read Replica:</strong> Managed MySQL service with flexible deployment options and replicas for high availability and scalability.</li><li><strong>Azure Bastion:</strong> Provides secure, seamless RDP/SSH connectivity to VMs directly through the Azure portal without exposing public IPs.</li></ul><h3>Pre-requisites:</h3><ul><li>Azure Subscription</li></ul><h3>Deployment:</h3><ol><li>Create Image for Nginx and Tomcat:</li></ol><ul><li>Use terraform script to create Nginx and Tomcat image which you can use to deploy Virtual Machine Scale Set.</li></ul><pre># provider.tf<br><br>terraform {<br>  required_providers {<br>    azurerm = {<br>      source = &quot;hashicorp/azurerm&quot;<br>      version = &quot;4.44.0&quot;<br>    }<br>    template = {<br>        source = &quot;hashicorp/template&quot;<br>        version = &quot;2.2.0&quot; <br>    }<br>    <br>  }<br><br>}<br><br>provider &quot;azurerm&quot; {<br>    features {}<br>}</pre><pre># variable.tf<br>variable &quot;resource_group_name&quot; {<br>    description = &quot;Name of the resource group&quot;<br>    type        = string<br>    default     = &quot;image-rg&quot;<br>  <br>}<br><br>variable &quot;location&quot; {<br>    description = &quot;Azure region for the resource group&quot;<br>    type        = string<br>    default     = &quot;Central India&quot;<br>  <br>}<br><br>variable &quot;vnet_name&quot; {<br>    description = &quot;Vnet for image VMs&quot;<br>    type        = string<br>    default     = &quot;vnet-image&quot;<br>}<br><br>variable &quot;vnet_address_space&quot; {<br>    description = &quot;Address space for image Vnet&quot;<br>    type        = list(string)<br>    default     = [&quot;10.1.0.0/24&quot;]<br>  <br>}<br><br>variable &quot;image_vms&quot; {<br>    description = &quot;Number of image VMs to create&quot;<br>    type        = map(string)<br>    default = {<br>        nginx-image = &quot;Standard_D2as_v4&quot;<br>        tomcat-image = &quot;Standard_D2as_v4&quot;<br><br>      }<br>}<br></pre><pre># main.tf<br>resource &quot;azurerm_resource_group&quot; &quot;image_rg&quot; {<br>    name     = var.resource_group_name<br>    location = var.location<br>}<br><br>resource &quot;azurerm_virtual_network&quot; &quot;image_vnet&quot; {<br>    name                = var.vnet_name<br>    address_space       = var.vnet_address_space<br>    location = azurerm_resource_group.image_rg.location<br>    resource_group_name = azurerm_resource_group.image_rg.name<br>}<br><br>resource &quot;azurerm_subnet&quot; &quot;image_subnet&quot; {<br>    name                 = &quot;snet-image&quot;<br>    resource_group_name  = azurerm_resource_group.image_rg.name<br>    virtual_network_name = azurerm_virtual_network.image_vnet.name<br>    address_prefixes     = [&quot;10.1.0.0/24&quot;]<br>}</pre><pre>#imagevm.tf<br><br>resource &quot;azurerm_public_ip&quot; &quot;images_IP&quot; {<br>    for_each = var.image_vms<br>    name = &quot;${each.key}-ip&quot;<br>    location = azurerm_resource_group.image_rg.location<br>    resource_group_name = azurerm_resource_group.image_rg.name<br>    allocation_method = &quot;Static&quot;  <br>}<br><br><br>resource &quot;azurerm_network_interface&quot; &quot;image_nic&quot; {<br>    for_each = var.image_vms<br>    name                = &quot;${each.key}-nic&quot;<br>    location            = azurerm_resource_group.image_rg.location<br>    resource_group_name = azurerm_resource_group.image_rg.name<br><br>    ip_configuration {<br>        name                          = &quot;internal&quot;<br>        subnet_id                     = azurerm_subnet.image_subnet.id<br>        private_ip_address_allocation = &quot;Dynamic&quot;<br>        public_ip_address_id = azurerm_public_ip.images_IP[each.key].id<br>    }<br>}<br><br>resource &quot;azurerm_linux_virtual_machine&quot; &quot;image_vm&quot; {<br>    for_each = var.image_vms<br>    name                = each.key<br>    resource_group_name = azurerm_resource_group.image_rg.name<br>    location            = azurerm_resource_group.image_rg.location<br>    size                = each.value<br>    admin_username      = &quot;azureuser&quot;<br>    admin_password      = &quot;Azure12345678&quot;<br>    disable_password_authentication = false<br><br>    network_interface_ids = [<br>        azurerm_network_interface.image_nic[each.key].id,<br>    ]<br><br>    os_disk {<br>        caching              = &quot;ReadWrite&quot;<br>        storage_account_type = &quot;Standard_LRS&quot;<br>    }<br><br>    source_image_reference {<br>        publisher = &quot;Canonical&quot;<br>        offer     = &quot;UbuntuServer&quot;<br>        sku       = &quot;18.04-LTS&quot;<br>        version   = &quot;latest&quot;<br>    }<br>  <br>}<br><br><br>resource &quot;azurerm_network_security_group&quot; &quot;image_nsg&quot; {<br>    name                = &quot;image_nsg&quot;<br>    location            = azurerm_resource_group.image_rg.location  <br>    resource_group_name = azurerm_resource_group.image_rg.name<br><br>    security_rule {<br>        name                       = &quot;SSH&quot;<br>        priority                   = 1001<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;22&quot;<br>        source_address_prefix      = &quot;*&quot;<br>        destination_address_prefix = &quot;*&quot;<br>    }<br>  <br>}<br><br>resource &quot;azurerm_subnet_network_security_group_association&quot; &quot;nsg_ass&quot; {<br>    subnet_id = azurerm_subnet.image_subnet.id<br>    network_security_group_id = azurerm_network_security_group.image_nsg.id<br>  <br>}</pre><ul><li>Once the VMs are created, install the Nginx and Tomcat on respective VM.</li></ul><p><strong>For Nginx:</strong></p><pre># Install Nginx<br><br>sudo apt update<br>sudo apt install -y nginx<br>sudo systemctl start nginx<br>sudo systemctl enable nginx<br><br># Check Status<br><br>systemctl status nginx<br><br># Verify Installation<br><br>curl http://localhost<br> <br># Or<br><br>http://&lt;Public IP of Nginx VM&gt;  # Make sure port 80 is open at NSG and OS firewall<br><br># You should see the default NGINX welcome page.</pre><p><strong>For Tomcat:</strong></p><pre># Install Tomcat<br><br>sudo apt update<br>sudo apt install -y default-jdk<br>sudo useradd -m -U -d /opt/tomcat -s /bin/false tomcat<br><br># Download and Install<br>cd /tmp<br>wget https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.46/bin/apache-tomcat-10.1.46.tar.gz<br>sudo mkdir /opt/tomcat<br>sudo tar -xvzf apache-tomcat-10.1.46.tar.gz -C /opt/tomcat --strip-components=1<br><br># Set Permission<br><br>sudo chown -R tomcat: /opt/tomcat<br><br># Configure tomcat as service<br>sudo vim /etc/systemd/system/tomcat.service<br>-------------------------------------------------------------------------------<br># Paste following content<br><br>[Unit]<br>Description=Apache Tomcat Web Application Container<br>After=network.target<br><br>[Service]<br>Type=forking<br><br>User=tomcat<br>Group=tomcat<br><br>Environment=&quot;JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64&quot;<br>Environment=&quot;CATALINA_PID=/opt/tomcat/temp/tomcat.pid&quot;<br>Environment=&quot;CATALINA_HOME=/opt/tomcat&quot;<br>Environment=&quot;CATALINA_BASE=/opt/tomcat&quot;<br>ExecStart=/opt/tomcat/bin/startup.sh<br>ExecStop=/opt/tomcat/bin/shutdown.sh<br><br>[Install]<br>WantedBy=multi-user.target<br><br>-------------------------------------------------------------------------------<br><br># Enable and Start tomcat<br><br>sudo systemctl daemon-reload<br>sudo systemctl start tomcat<br>sudo systemctl enable tomcat<br><br># Check Status<br><br>systemctl status tomcat<br><br># Verify Installation<br><br>curl http://localhost:8080<br> <br># Or<br><br>http://&lt;Public IP of Nginx VM&gt;:8080  # Make sure port 80 is open at NSG and OS firewall<br><br># You should see the Tomcat welcome page.<br></pre><p><strong>Create Managed Image</strong></p><p>Before you create managed image, you would need to deallocate and generalize the VM. Run following command on both Nginx and Tomcat VM.</p><pre># Generalize the VM<br><br>sudo waagent -deprovision+user -force<br><br># Then Deallocate and Mark VM as generalized on Azure Portal<br># Run following command in Azure CLI<br><br>az vm deallocate -g &lt;rg-name&gt; -n &lt;vm-name&gt;<br>az vm generalize -g &lt;rg-name&gt; -n &lt;vm-name&gt;<br><br></pre><p>Now, create VM image by using following Terraform script. We will use this image to create Virtual Machine Scale Set (VMSS)</p><pre># Create new file and add following script in Terraform repository.<br># image.tf<br><br>resource &quot;azurerm_image&quot; &quot;image&quot; {<br>    for_each = var.image_vms<br>    name                      = &quot;${each.key}-image&quot;<br>    location                  = var.location<br>    resource_group_name       = var.resource_group_name<br>    source_virtual_machine_id = azurerm_linux_virtual_machine.image_vm[each.key].id<br>}</pre><blockquote><strong>3-Tier Architecture Deployment (VMSS &amp; MySQL DBaaS):</strong></blockquote><p>Create Virtual Machine Scale Set (VMSS) using the image which we created .</p><p>Now, setup Provider and variables which we use in deployment.</p><pre># Provider.tf<br><br>terraform {<br>  required_providers {<br>    azurerm = {<br>      source = &quot;hashicorp/azurerm&quot;<br>      version = &quot;4.44.0&quot;<br>    }<br>    template = {<br>        source = &quot;hashicorp/template&quot;<br>        version = &quot;2.2.0&quot; <br>    }<br>    <br>  }<br><br>}<br><br>provider &quot;azurerm&quot; {<br>    features {}<br>}</pre><pre># variable.tf<br><br>variable &quot;resource_group_name&quot; {<br>    description = &quot;Name of the resource group&quot;<br>    type        = string<br>    default     = &quot;rg-env&quot; <br>}<br><br>variable &quot;location&quot; {<br>    description = &quot;Azure region for the resource group&quot;<br>    type        = string<br>    default     = &quot;Central India&quot;<br>}<br><br>variable &quot;vnet&quot; {<br>    description = &quot;Vnet for Java app&quot;<br>    type        = string<br>    default     = &quot;vnet-env&quot;<br>}<br><br>variable &quot;vnet_address_space&quot; {<br>    description = &quot;Address space for Vnet&quot;<br>    type        = list(string)<br>    default     = [&quot;10.0.0.0/16&quot;]<br>}<br><br>variable &quot;subnet&quot; {<br>    description = &quot;Subnets for the Vnet&quot;<br>    type        = map(string)<br>    default = {<br>        web_subnet = &quot;10.0.1.0/24&quot;<br>        app_subnet = &quot;10.0.2.0/24&quot;<br>      } <br>}<br><br>variable &quot;admin_username&quot; {<br>    description = &quot;Admin username for the VMs&quot;<br>    type        = string<br>    default     = &quot;azureuser&quot;<br>}<br><br>variable &quot;admin_password&quot; {<br>    description = &quot;Admin password for the VMs&quot;<br>    type        = string<br>    default     = &quot;Azure12345678&quot;<br>}<br><br>variable &quot;vm_size&quot; {<br>    description = &quot;Size of the VMs&quot;<br>    type        = string<br>    default     = &quot;Standard_D2as_v4&quot;<br>}<br><br><br>variable &quot;nginx_image_id&quot; {<br>    description = &quot;The ID of the custom image for Nginx&quot;<br>    default = &quot;/subscriptions/28742713-55c3-4ad5-be9f-26540262491d/resourceGroups/image-rg/providers/Microsoft.Compute/images/nginx-image-image&quot; <br>}<br><br>variable &quot;tomcat_image_id&quot; {<br>    description = &quot;The ID of the custom image for Tomcat&quot;<br>    default = &quot;/subscriptions/28742713-55c3-4ad5-be9f-26540262491d/resourceGroups/image-rg/providers/Microsoft.Compute/images/tomcat-image-image&quot; <br>}</pre><p>Create Resource Group, Virtual Network and Subnets.</p><pre># main.tf<br><br>resource &quot;azurerm_resource_group&quot; &quot;rg-env&quot; {<br>    name     = var.resource_group_name<br>    location = var.location<br>}<br><br>resource &quot;azurerm_virtual_network&quot; &quot;vnet-env&quot; {<br>    name                = var.vnet<br>    address_space       = var.vnet_address_space<br>    location = azurerm_resource_group.rg-env.location<br>    resource_group_name = azurerm_resource_group.rg-env.name<br>}<br><br>resource &quot;azurerm_subnet&quot; &quot;subnet&quot; {<br>    for_each = var.subnet<br>    name                 = each.key<br>    resource_group_name  = var.resource_group_name<br>    virtual_network_name = var.vnet<br>    address_prefixes     = [each.value]<br>}<br><br>resource &quot;azurerm_network_security_group&quot; &quot;web_nsg&quot; {<br>    name                = &quot;web_nsg&quot;<br>    location            = var.location<br>    resource_group_name = var.resource_group_name<br><br>    security_rule {<br>        name                       = &quot;Web&quot;<br>        priority                   = 1001<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><br>    depends_on = [ azurerm_resource_group.rg-env ]<br>  <br>}<br><br>resource &quot;azurerm_subnet_network_security_group_association&quot; &quot;web_nsg_ass&quot; {<br>    subnet_id = azurerm_subnet.subnet[&quot;web_subnet&quot;].id<br>    network_security_group_id = azurerm_network_security_group.web_nsg.id<br>}</pre><p>Deploy Bastion service to access VMs securely.</p><pre>#bastion.tf<br><br>resource &quot;azurerm_subnet&quot; &quot;bastion_subnet&quot; {<br>  name                 = &quot;AzureBastionSubnet&quot;<br>  resource_group_name  = var.resource_group_name<br>  virtual_network_name = azurerm_virtual_network.vnet-env.name<br>  address_prefixes     = [&quot;10.0.5.0/27&quot;]<br>}<br><br>resource &quot;azurerm_public_ip&quot; &quot;bastion_pip&quot; {<br>  name                = &quot;bastion-pip&quot;<br>  location            = var.location<br>  resource_group_name = var.resource_group_name<br>  allocation_method   = &quot;Static&quot;<br>  sku                 = &quot;Standard&quot;<br><br>  depends_on = [ azurerm_resource_group.rg-env ]<br>}<br><br>resource &quot;azurerm_bastion_host&quot; &quot;bastion&quot; {<br>  name                = &quot;bastion-host&quot;<br>  location            = var.location<br>  resource_group_name = var.resource_group_name<br>  <br>  ip_configuration {<br>    name                 = &quot;bastion-ip-config&quot;<br>    subnet_id            = azurerm_subnet.bastion_subnet.id<br>    public_ip_address_id = azurerm_public_ip.bastion_pip.id<br>  }<br>}</pre><p>Now, create frontend VMSS along with public load balancer (Standard)</p><pre># web.tf<br><br>resource &quot;azurerm_public_ip&quot; &quot;web_ip&quot; {<br>    name                = &quot;web-ip&quot;<br>    location            = var.location<br>    resource_group_name = var.resource_group_name<br>    allocation_method   = &quot;Static&quot;<br>    sku                 = &quot;Standard&quot;<br><br>    depends_on = [ azurerm_resource_group.rg-env ]<br>}<br><br>resource &quot;azurerm_lb&quot; &quot;web_lb&quot; {<br>    name                = &quot;web-lb&quot;<br>    location            = var.location<br>    resource_group_name = var.resource_group_name<br>    sku                 = &quot;Standard&quot;<br><br>    frontend_ip_configuration {<br>        name                 = &quot;PublicIPAddress&quot;<br>        public_ip_address_id = azurerm_public_ip.web_ip.id<br>    }<br>  <br>}<br><br>resource &quot;azurerm_lb_backend_address_pool&quot; &quot;webbepool&quot; {<br>    loadbalancer_id = azurerm_lb.web_lb.id<br>    name = &quot;web-bepool&quot;<br>}<br><br><br>resource &quot;azurerm_lb_probe&quot; &quot;ilbprobe&quot; {<br>    loadbalancer_id     = azurerm_lb.web_lb.id<br>    name                = &quot;http-probe&quot;<br>    protocol            = &quot;Http&quot;<br>    port                = 80<br>    request_path = &quot;/&quot;<br>    interval_in_seconds = 15<br>    number_of_probes    = 2<br>}<br><br>resource &quot;azurerm_lb_rule&quot; &quot;fronend_rule&quot; {<br>    loadbalancer_id                = azurerm_lb.web_lb.id<br>    name                           = &quot;Frontend_LBRule&quot;<br>    protocol                       = &quot;Tcp&quot;<br>    frontend_port                  = 80<br>    backend_port                   = 80<br>    frontend_ip_configuration_name = &quot;PublicIPAddress&quot;<br>    backend_address_pool_ids = [azurerm_lb_backend_address_pool.webbepool.id]<br>    probe_id = azurerm_lb_probe.ilbprobe.id<br>}<br><br>resource &quot;azurerm_linux_virtual_machine_scale_set&quot; &quot;web_vm&quot; {<br>    name = &quot;web-vmss&quot;<br>    location = var.location<br>    resource_group_name = var.resource_group_name<br>    sku = var.vm_size<br>    instances = 2<br>    admin_username = var.admin_username<br>    admin_password = var.admin_password<br>    disable_password_authentication = false<br>    zones = [&quot;1&quot;, &quot;2&quot;]<br>    <br>    source_image_id = var.nginx_image_id<br>    os_disk {<br>      storage_account_type = &quot;Standard_LRS&quot;<br>      caching = &quot;ReadWrite&quot;<br>    }<br><br>    network_interface {<br>        name = &quot;web-nic&quot;<br>        primary = true<br><br>        ip_configuration {<br>        name = &quot;internal&quot;<br>        primary = true<br>        subnet_id = azurerm_subnet.subnet[&quot;web_subnet&quot;].id<br>        load_balancer_backend_address_pool_ids = [azurerm_lb_backend_address_pool.webbepool.id]<br>        }<br><br>}<br>}</pre><p>Create App (backend) VMSS along with internal load balancer (Standard)</p><pre># App.tf<br><br>resource &quot;azurerm_lb&quot; &quot;app_lb&quot; {<br>    name                = &quot;app-lb&quot;<br>    location            = var.location<br>    resource_group_name = var.resource_group_name<br>    sku                 = &quot;Standard&quot;<br><br>    frontend_ip_configuration {<br>        name                 = &quot;PrivateIPAddress&quot;<br>        subnet_id = azurerm_subnet.subnet[&quot;app_subnet&quot;].id<br>        private_ip_address_allocation = &quot;Static&quot;<br>        private_ip_address = &quot;10.0.2.5&quot;<br>    }<br>  <br>}<br><br>resource &quot;azurerm_lb_backend_address_pool&quot; &quot;appbepool&quot; {<br>    loadbalancer_id = azurerm_lb.app_lb.id<br>    name = &quot;app-bepool&quot;<br>}<br><br><br>resource &quot;azurerm_lb_probe&quot; &quot;appilbprobe&quot; {<br>    loadbalancer_id     = azurerm_lb.app_lb.id<br>    name                = &quot;tcp-probe&quot;<br>    protocol            = &quot;Tcp&quot;<br>    port                = 8080<br><br>}<br><br>resource &quot;azurerm_lb_rule&quot; &quot;backend_rule&quot; {<br>    loadbalancer_id                = azurerm_lb.app_lb.id<br>    name                           = &quot;Backend_LBRule&quot;<br>    protocol                       = &quot;Tcp&quot;<br>    frontend_port                  = 8080<br>    backend_port                   = 8080<br>    frontend_ip_configuration_name = &quot;PrivateIPAddress&quot;<br>    backend_address_pool_ids = [azurerm_lb_backend_address_pool.appbepool.id]<br>    probe_id = azurerm_lb_probe.appilbprobe.id<br>}<br><br><br><br>resource &quot;azurerm_linux_virtual_machine_scale_set&quot; &quot;app_vm&quot; {<br>    name = &quot;app-vmss&quot;<br>    location = var.location<br>    resource_group_name = var.resource_group_name<br>    sku = var.vm_size<br>    instances = 2<br>    admin_username = var.admin_username<br>    admin_password = var.admin_password<br>    disable_password_authentication = false<br>    zones = [&quot;1&quot;, &quot;2&quot;]<br>    <br>    source_image_id = var.tomcat_image_id<br>    os_disk {<br>      storage_account_type = &quot;Standard_LRS&quot;<br>      caching = &quot;ReadWrite&quot;<br>    }<br><br>    network_interface {<br>        name = &quot;app-nic&quot;<br>        primary = true<br><br>        ip_configuration {<br>        name = &quot;internal&quot;<br>        primary = true<br>        subnet_id = azurerm_subnet.subnet[&quot;app_subnet&quot;].id<br>        load_balancer_backend_address_pool_ids = [azurerm_lb_backend_address_pool.appbepool.id]<br>        }<br><br>}<br>}</pre><p>Now, deploy Azure Database for MySQL in high availability. Primary database will be in Zone 1 and read replica in Zone 2.</p><pre># mysql.tf<br><br>resource &quot;azurerm_subnet&quot; &quot;db_subnet&quot; {<br>  name                 = &quot;db_subnet&quot;<br>  resource_group_name  = var.resource_group_name<br>  virtual_network_name = var.vnet<br>  address_prefixes     = [&quot;10.0.3.0/24&quot;]<br><br>  delegation {<br>    name = &quot;mysqlfsdelegation&quot;<br>    service_delegation {<br>      name = &quot;Microsoft.DBforMySQL/flexibleServers&quot;<br>      actions = [<br>        &quot;Microsoft.Network/virtualNetworks/subnets/join/action&quot;,<br>      ]<br>    }<br>  }<br>}<br><br><br>resource &quot;azurerm_mysql_flexible_server&quot; &quot;mysqldbskenvironmentci&quot; {<br><br>    name                   = &quot;mysqldbskenvironmentci&quot;<br>    resource_group_name    = var.resource_group_name<br>    location               = var.location<br>    version = &quot;8.0.21&quot;<br>    administrator_login    = &quot;mysqladmin&quot;<br>    administrator_password = &quot;MyStrongP@ssword123!&quot;<br>    sku_name               = &quot;B_Standard_B2ms&quot;<br><br>    zone = &quot;1&quot;<br>    backup_retention_days = 7<br>    geo_redundant_backup_enabled = false<br>    public_network_access = &quot;Disabled&quot;<br><br>    delegated_subnet_id = azurerm_subnet.db_subnet.id<br>      <br>}<br><br>resource &quot;azurerm_mysql_flexible_database&quot; &quot;Userdb&quot; {<br>  name                = &quot;Userdb&quot;<br>  resource_group_name = var.resource_group_name<br>  server_name         = azurerm_mysql_flexible_server.mysqldbskenvironmentci.name<br>  charset             = &quot;utf8&quot;<br>  collation           = &quot;utf8_unicode_ci&quot;<br>}<br><br>resource &quot;azurerm_mysql_flexible_server&quot; &quot;replica&quot; {<br>  name                = &quot;mysqldbskenvironmentciz2&quot;<br>  resource_group_name = var.resource_group_name<br>  location            = var.location<br>  version             = &quot;8.0.21&quot;<br><br>  create_mode         = &quot;Replica&quot;<br>  source_server_id    = azurerm_mysql_flexible_server.mysqldbskenvironmentci.id<br>  sku_name            = &quot;B_Standard_B2ms&quot;<br>  zone                = &quot;2&quot;<br><br>  public_network_access = &quot;Disabled&quot;<br>  delegated_subnet_id   = azurerm_subnet.db_subnet.id<br>}</pre><p>The above script deploys the 3-tier architecture on Azure. Once deployed, you can access the Nginx home page using the public IP address of the Azure Load Balancer.</p><p>Next, update the Nginx configuration file to forward incoming requests to the Tomcat backend servers by using the private IP address of the internal load balancer.</p><pre># /etc/nginx/sites-available/default<br><br>sudo vim /etc/nginx/sites-available/default<br><br># Paste following content<br><br>server {<br>    listen 80;<br><br>    server_name your-domain.com;  # or public IP of load balancer<br><br>    location / {<br>        proxy_pass http://&lt;Private IP of Internal Load Balancer&gt;:8080;<br>        proxy_set_header Host $host;<br>        proxy_set_header X-Real-IP $remote_addr;<br>        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br>        proxy_set_header X-Forwarded-Proto $scheme;<br>    }<br>}<br><br># Check Nginx configuration<br><br>sudo nginx -t<br><br># Restart Nginx<br><br>sudo systemctl restart nginx</pre><p>You should now be able to access the Tomcat home page through the public IP address of the load balancer.</p><h3>Summary:</h3><p>In this article, we successfully deployed a 3-tier architecture on Azure using Terraform.</p><ul><li>Created managed Image for VMSS deployment</li><li>Deployed Virtual Machine Scale set for frontend (Nginx) and backend (Tomcat) environment</li><li>Configure public and private load balancer.</li><li>Deployed Azure Database for MySQL flexible Server. Primary instance in zone 1 and read replica on zone 2 for high availability.</li><li>Configure Nginx reverse proxy to route requests to the tomcat application servers.</li></ul><h3>Next Step:</h3><p>In the next article, we will explore how to automate this Terraform deployment using Azure Repos or GitHub, combined with Azure Pipelines, including strategies to handle access restrictions, secrets management, and CI/CD best practices.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ccd8b79c04cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>