<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ipadeola Taiwo</title>
    <description>The latest articles on DEV Community by Ipadeola Taiwo (@highpee1991).</description>
    <link>https://dev.to/highpee1991</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1894849%2F48eadcb7-7cf7-4299-8728-58c535f1e6bd.jpeg</url>
      <title>DEV Community: Ipadeola Taiwo</title>
      <link>https://dev.to/highpee1991</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/highpee1991"/>
    <language>en</language>
    <item>
      <title>Building and Testing a Java Application with Gradle and GitHub Actions</title>
      <dc:creator>Ipadeola Taiwo</dc:creator>
      <pubDate>Fri, 27 Nov 2026 10:29:37 +0000</pubDate>
      <link>https://dev.to/highpee1991/building-and-testing-a-java-application-with-gradle-and-github-actions-4ooj</link>
      <guid>https://dev.to/highpee1991/building-and-testing-a-java-application-with-gradle-and-github-actions-4ooj</guid>
      <description>&lt;p&gt;As part of my CodeAlpha DevOps Internship, I worked on a project that helped me understand how Java applications can be built, tested, and packaged using Gradle.&lt;/p&gt;

&lt;p&gt;Before this project, I had been working more with Docker, Terraform, and cloud deployment. This project gave me the opportunity to focus on the application build process and how CI/CD automation can help make it more reliable.&lt;/p&gt;

&lt;p&gt;The goal was simple: build a Java application, test it, generate a JAR file, and automate the process using GitHub Actions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3ol4sfqmp4hyebieylz9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3ol4sfqmp4hyebieylz9.png" alt=" " width="800" height="873"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I wanted to achieve
&lt;/h2&gt;

&lt;p&gt;For this project, I wanted to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a simple Java application.&lt;/li&gt;
&lt;li&gt;Use Gradle to manage the build process and dependencies.&lt;/li&gt;
&lt;li&gt;Write unit tests using JUnit 5.&lt;/li&gt;
&lt;li&gt;Generate an executable JAR file.&lt;/li&gt;
&lt;li&gt;Automate the build and testing process with GitHub Actions.&lt;/li&gt;
&lt;li&gt;Make the generated JAR available as a workflow artifact.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Tools and technologies
&lt;/h2&gt;

&lt;p&gt;The project used the following tools:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tool&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Java 21&lt;/td&gt;
&lt;td&gt;Application development&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gradle 8.14.3&lt;/td&gt;
&lt;td&gt;Build automation and dependency management&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;JUnit 5&lt;/td&gt;
&lt;td&gt;Unit testing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GitHub Actions&lt;/td&gt;
&lt;td&gt;CI automation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Git and GitHub&lt;/td&gt;
&lt;td&gt;Version control and code hosting&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Creating the Java application
&lt;/h2&gt;

&lt;p&gt;I created a Java project named &lt;code&gt;cloudops-java-app&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The application is a simple CloudOps build monitor. It displays information such as the application name, version, build status, Java version, and a greeting.&lt;/p&gt;

&lt;p&gt;Although the application itself is small, it gave me a practical way to work through the Java build lifecycle.&lt;/p&gt;

&lt;p&gt;The application entry point is:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;com.codealpha.cloudops.App&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I also configured the project to generate an executable JAR with the correct &lt;code&gt;Main-Class&lt;/code&gt; in its manifest. This allows the application to be run directly using the Java command.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up Gradle
&lt;/h2&gt;

&lt;p&gt;I used the Gradle Wrapper rather than depending on a globally installed Gradle version.&lt;/p&gt;

&lt;p&gt;The wrapper helps ensure that the project uses the Gradle version defined for it. This is useful when another developer or a CI runner needs to build the project.&lt;/p&gt;

&lt;p&gt;I configured the project to use Java 21 and added the dependencies required for the application and its tests.&lt;/p&gt;

&lt;p&gt;Gradle handled the build tasks, dependency resolution, compilation, testing, and packaging.&lt;/p&gt;

&lt;h2&gt;
  
  
  Writing and running unit tests
&lt;/h2&gt;

&lt;p&gt;I added unit tests using JUnit 5.&lt;/p&gt;

&lt;p&gt;The tests helped me verify that the application behaved as expected before creating the final package.&lt;/p&gt;

&lt;p&gt;I ran the tests locally using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;./gradlew &lt;span class="nb"&gt;test&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The test task completed successfully, with &lt;strong&gt;5 tests passed and 0 failures&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgmd9tjlikgxcmtu00fm7.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgmd9tjlikgxcmtu00fm7.PNG" alt=" " width="800" height="314"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I then ran the complete build:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;./gradlew clean build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This cleaned the previous build output and ran the build tasks again.&lt;/p&gt;

&lt;p&gt;The build completed successfully.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbb7900uz148szuvkioyp.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbb7900uz148szuvkioyp.PNG" alt=" " width="800" height="161"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Generating and running the JAR
&lt;/h2&gt;

&lt;p&gt;After the build, Gradle generated the executable JAR file at:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app/build/libs/app.jar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I checked the contents of the JAR to confirm that the application classes and manifest were included.&lt;/p&gt;

&lt;p&gt;I also ran the application directly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;java -jar app/build/libs/app.jar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This confirmed that the packaged application could start without needing to run it through Gradle.&lt;/p&gt;

&lt;h2&gt;
  
  
  Automating the build with GitHub Actions
&lt;/h2&gt;

&lt;p&gt;Once the local build was working, I moved on to CI automation.&lt;/p&gt;

&lt;p&gt;I created a GitHub Actions workflow at:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.github/workflows/gradle-ci.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The workflow runs when I push changes or create a pull request affecting the Project 3 files. It can also be started manually.&lt;/p&gt;

&lt;p&gt;The workflow performs the following steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Checks out the repository.&lt;/li&gt;
&lt;li&gt;Sets up Java 21.&lt;/li&gt;
&lt;li&gt;Prepares the Gradle build environment.&lt;/li&gt;
&lt;li&gt;Runs the Gradle build and tests.&lt;/li&gt;
&lt;li&gt;Uploads the generated JAR file as a workflow artifact.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5sck6bjsm321l8uu6y35.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5sck6bjsm321l8uu6y35.PNG" alt=" " width="626" height="779"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The build command used in the workflow is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;./gradlew build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I encountered a small issue during the initial workflow run. GitHub Actions reported that the Gradle Wrapper could not be executed because it did not have executable permission.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fi5mjypyxhltv2s20fd70.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fi5mjypyxhltv2s20fd70.PNG" alt=" " width="800" height="407"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I fixed the file permission in Git and pushed the change.&lt;/p&gt;

&lt;p&gt;After that, the workflow ran successfully.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1gqc9i7bewp5c3wwqrm2.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1gqc9i7bewp5c3wwqrm2.PNG" alt=" " width="690" height="137"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Successful CI pipeline
&lt;/h2&gt;

&lt;p&gt;The final GitHub Actions run completed successfully.&lt;/p&gt;

&lt;p&gt;The pipeline built the Java application, ran the tests, and uploaded the JAR file as an artifact.&lt;/p&gt;

&lt;p&gt;This was an important part of the project because it showed that the application could be built and tested in a clean CI environment, not only on my local machine.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2803bng3zdgt0toxx170.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2803bng3zdgt0toxx170.PNG" alt=" " width="800" height="415"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The uploaded artifact can be downloaded from the successful workflow run in GitHub Actions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Build workflow
&lt;/h2&gt;

&lt;p&gt;The process I implemented can be summarized as:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;I make changes to the Java application.&lt;/li&gt;
&lt;li&gt;I push the changes to GitHub.&lt;/li&gt;
&lt;li&gt;GitHub Actions starts the workflow.&lt;/li&gt;
&lt;li&gt;Gradle builds the application and runs the tests.&lt;/li&gt;
&lt;li&gt;If the build succeeds, the JAR file is uploaded.&lt;/li&gt;
&lt;li&gt;The artifact can then be downloaded and run.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If the build or tests fail, the workflow reports the failure so I can review the logs, fix the issue, and push the changes again.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I learned
&lt;/h2&gt;

&lt;p&gt;This project helped me understand the role of build automation in a software delivery process.&lt;/p&gt;

&lt;p&gt;I learned how Gradle manages a Java project's build tasks and dependencies, how JUnit can be used to test application behavior, and how an executable JAR is generated.&lt;/p&gt;

&lt;p&gt;I also gained practical experience configuring GitHub Actions and troubleshooting a CI issue related to file permissions.&lt;/p&gt;

&lt;p&gt;One important lesson was that a successful local build is not enough. Automating the build in GitHub Actions helps confirm that the project can be built consistently in another environment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This project was a useful step in my DevOps learning journey.&lt;/p&gt;

&lt;p&gt;I was able to take a Java application from source code through testing and packaging, then automate the process using GitHub Actions.&lt;/p&gt;

&lt;p&gt;The project does not deploy the application to a live server. Instead, it focuses on the build and test stage of a CI/CD workflow, with the JAR file delivered as a downloadable artifact.&lt;/p&gt;

&lt;p&gt;I look forward to applying these build automation and CI practices to larger applications and more complete deployment pipelines.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project repository:&lt;/strong&gt; &lt;a href="https://github.com/highpee1991/CodeAlpha_ProjectName" rel="noopener noreferrer"&gt;CodeAlpha DevOps Internship Projects&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project 3:&lt;/strong&gt; Java Application Using Gradle&lt;/p&gt;

</description>
      <category>cicd</category>
      <category>devops</category>
      <category>githubactions</category>
      <category>java</category>
    </item>
    <item>
      <title>Building and Running a Dockerized Web Server with Nginx: My CodeAlpha Project 4 Experience</title>
      <dc:creator>Ipadeola Taiwo</dc:creator>
      <pubDate>Thu, 26 Nov 2026 15:34:47 +0000</pubDate>
      <link>https://dev.to/highpee1991/building-and-running-a-dockerized-web-server-with-nginx-my-codealpha-project-4-experience-4hh2</link>
      <guid>https://dev.to/highpee1991/building-and-running-a-dockerized-web-server-with-nginx-my-codealpha-project-4-experience-4hh2</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;As part of my CodeAlpha DevOps Internship, I worked on a project that focused on containerizing a web server using Docker.&lt;/p&gt;

&lt;p&gt;For this project, I built a static website using HTML and CSS, packaged it into a Docker image using Nginx, and ran it as a container.&lt;/p&gt;

&lt;p&gt;At first, this looked like a straightforward Docker exercise. However, I wanted to understand more than just how to run a few Docker commands. I wanted to understand why I needed a web server, how Docker packages an application, how files get served from inside a container, how port mapping works, and how to confirm that a running container is actually healthy.&lt;/p&gt;

&lt;p&gt;This article documents my implementation, the decisions I made, the commands I used, the verification process, and what I learned along the way.&lt;/p&gt;

&lt;p&gt;The project is part of my CodeAlpha DevOps Internship portfolio.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project repository:&lt;/strong&gt; &lt;a href="https://github.com/highpee1991/CodeAlpha_ProjectName" rel="noopener noreferrer"&gt;CodeAlpha DevOps Internship Projects&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project directory:&lt;/strong&gt; &lt;code&gt;Project_4_Docker_Web_Server&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Understanding the Project Requirements
&lt;/h2&gt;

&lt;p&gt;Before writing the Dockerfile, I first considered what I was expected to build.&lt;/p&gt;

&lt;p&gt;The objective was to create a web server and run it inside a Docker container.&lt;/p&gt;

&lt;p&gt;I broke the work into smaller tasks:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a website using HTML and CSS.&lt;/li&gt;
&lt;li&gt;Select a suitable web server.&lt;/li&gt;
&lt;li&gt;Write a Dockerfile.&lt;/li&gt;
&lt;li&gt;Build a Docker image.&lt;/li&gt;
&lt;li&gt;Run the image as a container.&lt;/li&gt;
&lt;li&gt;Access the website through a browser.&lt;/li&gt;
&lt;li&gt;Verify that the container and web server were working correctly.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I also wanted to include a health check so Docker could monitor whether the web server was responding.&lt;/p&gt;

&lt;p&gt;One of the first decisions I needed to make was which web server to use.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Creating the Website
&lt;/h2&gt;

&lt;p&gt;I decided to build a simple website called &lt;strong&gt;CloudOps Web Server&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I used HTML5 for the structure and CSS3 for the presentation.&lt;/p&gt;

&lt;p&gt;The website includes sections introducing containerization, web servers, health monitoring, Docker workflows, and the technologies used in the project.&lt;/p&gt;

&lt;p&gt;I kept the application simple because the main objective was to learn containerization and web server deployment rather than build a complex application.&lt;/p&gt;

&lt;p&gt;My project files at this stage were:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Project_4_Docker_Web_Server/
│
├── index.html
└── styles.css
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I created the HTML file first and then added the stylesheet.&lt;/p&gt;

&lt;p&gt;The HTML file contains a reference to the CSS file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"styles.css"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This was important when I later wrote the Dockerfile. Since the website depends on both files, I needed to make sure that both would be available inside the container.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Choosing Nginx as the Web Server
&lt;/h2&gt;

&lt;p&gt;After creating the website, I needed something that could serve the HTML and CSS files over HTTP.&lt;/p&gt;

&lt;p&gt;I chose Nginx.&lt;/p&gt;

&lt;p&gt;Nginx is a popular web server that can serve static content such as HTML, CSS, JavaScript, and images. It is also available as an official Docker image.&lt;/p&gt;

&lt;p&gt;I used the Alpine-based version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;nginx:alpine
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I selected this image because it provides a lightweight Nginx environment without requiring me to install and configure a web server manually.&lt;/p&gt;

&lt;p&gt;This was a practical choice for a small static website.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why did I need Nginx?
&lt;/h3&gt;

&lt;p&gt;Creating HTML and CSS files alone does not mean I have a running web server.&lt;/p&gt;

&lt;p&gt;I needed a service that could listen for HTTP requests, locate the requested files, and return them to a browser.&lt;/p&gt;

&lt;p&gt;Nginx handles that responsibility inside the Docker container.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Understanding the Nginx Web Directory
&lt;/h2&gt;

&lt;p&gt;Before writing my Dockerfile, I needed to understand where Nginx expects its website files.&lt;/p&gt;

&lt;p&gt;The default document root in the official Nginx image is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/usr/share/nginx/html/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is where Nginx looks for static website content.&lt;/p&gt;

&lt;p&gt;I therefore needed to copy my two website files into that directory.&lt;/p&gt;

&lt;p&gt;The mapping would be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;index.html  →  /usr/share/nginx/html/index.html
styles.css  →  /usr/share/nginx/html/styles.css
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This was an important part of understanding the Dockerfile.&lt;/p&gt;

&lt;p&gt;Rather than copying files randomly into a container, I needed to know which directory the web server actually uses.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Writing the Dockerfile
&lt;/h2&gt;

&lt;p&gt;With the application files and Nginx document root understood, I created a file named &lt;code&gt;Dockerfile&lt;/code&gt; in the project directory.&lt;/p&gt;

&lt;p&gt;This was the Dockerfile I used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt; nginx:alpine

&lt;span class="k"&gt;COPY&lt;/span&gt; index.html /usr/share/nginx/html/index.html
&lt;span class="k"&gt;COPY&lt;/span&gt; styles.css /usr/share/nginx/html/styles.css

&lt;span class="k"&gt;EXPOSE&lt;/span&gt; 80

&lt;span class="k"&gt;HEALTHCHECK&lt;/span&gt; --interval=30s --timeout=3s \
    &lt;span class="k"&gt;CMD&lt;/span&gt; wget -qO- http://127.0.0.1/ &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;exit&lt;/span&gt; 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I wanted to understand what each instruction was doing instead of simply copying a Dockerfile from somewhere else.&lt;/p&gt;

&lt;h3&gt;
  
  
  FROM nginx:alpine
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt; nginx:alpine
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This specifies the base image.&lt;/p&gt;

&lt;p&gt;Docker uses the official Nginx Alpine image as the starting point for building my image.&lt;/p&gt;

&lt;p&gt;It provides the Nginx web server and the environment needed to run it.&lt;/p&gt;

&lt;h3&gt;
  
  
  COPY index.html
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;COPY&lt;/span&gt; index.html /usr/share/nginx/html/index.html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This copies my website's HTML file from the build context on my computer into the Nginx document root inside the container.&lt;/p&gt;

&lt;h3&gt;
  
  
  COPY styles.css
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;COPY&lt;/span&gt; styles.css /usr/share/nginx/html/styles.css
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This copies the stylesheet into the same directory.&lt;/p&gt;

&lt;p&gt;I needed both files because the HTML page references the stylesheet. Copying only the HTML file would mean the browser could load the page without its intended styling.&lt;/p&gt;

&lt;h3&gt;
  
  
  EXPOSE 80
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;EXPOSE&lt;/span&gt; 80
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nginx listens on port 80 by default for HTTP traffic.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;EXPOSE&lt;/code&gt; instruction documents the port that the containerized application is expected to use.&lt;/p&gt;

&lt;p&gt;It is worth noting that &lt;code&gt;EXPOSE&lt;/code&gt; does not publish the port on my computer by itself. I would configure that when starting the container.&lt;/p&gt;

&lt;h3&gt;
  
  
  HEALTHCHECK
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;HEALTHCHECK&lt;/span&gt; --interval=30s --timeout=3s \
    &lt;span class="k"&gt;CMD&lt;/span&gt; wget -qO- http://127.0.0.1/ &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;exit&lt;/span&gt; 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7k7nlnwirtymerh8vig6.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7k7nlnwirtymerh8vig6.PNG" alt=" " width="722" height="82"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I added a health check to monitor whether the web server was responding.&lt;/p&gt;

&lt;p&gt;Here is what the options mean:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;--interval=30s&lt;/code&gt;: Docker runs the health check every 30 seconds.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--timeout=3s&lt;/code&gt;: The check is allowed three seconds to complete.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;wget -qO-&lt;/code&gt;: Sends an HTTP request quietly and writes the response to standard output.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;|| exit 1&lt;/code&gt;: Returns a failure status if the request fails.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The health check allows Docker to report whether the container is healthy or unhealthy based on the result of the command.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Building the Docker Image
&lt;/h2&gt;

&lt;p&gt;After creating the Dockerfile, I opened my Git Bash terminal in the project directory.&lt;/p&gt;

&lt;p&gt;I first checked that I was in the correct location and that the necessary files were present.&lt;/p&gt;

&lt;p&gt;I then built the Docker image:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker build -t cloudops-web-server:1.0 .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let me break down this command.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;docker build&lt;/code&gt; tells Docker to build an image.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-t&lt;/code&gt; assigns a name and tag to the image.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;cloudops-web-server&lt;/code&gt; is the image name.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;1.0&lt;/code&gt; is the image tag.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.&lt;/code&gt; tells Docker to use the current directory as the build context.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The build context matters because Docker needs access to the Dockerfile and the files referenced by the &lt;code&gt;COPY&lt;/code&gt; instructions.&lt;/p&gt;

&lt;p&gt;Since I was running the command from the project directory, Docker could access &lt;code&gt;index.html&lt;/code&gt; and &lt;code&gt;styles.css&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The build completed successfully, creating:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cloudops-web-server:1.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this point, I had an image, but I did not yet have a running container.&lt;/p&gt;

&lt;p&gt;That distinction is important: an image is the packaged application, while a container is a running instance of that image.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fr7vts1r2uywscwegbczw.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fr7vts1r2uywscwegbczw.PNG" alt=" " width="799" height="535"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Running the Docker Container
&lt;/h2&gt;

&lt;p&gt;After building the image, I needed to start a container from it.&lt;/p&gt;

&lt;p&gt;I used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run -d --name cloudops-web-server -p 8080:80 cloudops-web-server:1.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command starts the container in detached mode.&lt;/p&gt;

&lt;p&gt;Here is what the options mean:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;docker run&lt;/code&gt;: Creates and starts a container from an image.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-d&lt;/code&gt;: Runs the container in the background.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--name cloudops-web-server&lt;/code&gt;: Assigns a recognizable name to the container.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-p 8080:80&lt;/code&gt;: Maps port 8080 on my computer to port 80 inside the container.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;cloudops-web-server:1.0&lt;/code&gt;: Specifies the image to run.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffgtmprxvdm9vt4jz38tj.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffgtmprxvdm9vt4jz38tj.PNG" alt=" " width="800" height="317"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding port mapping
&lt;/h3&gt;

&lt;p&gt;The port mapping was one of the important concepts in this project.&lt;/p&gt;

&lt;p&gt;I used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;8080:80
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first port is the host port, while the second port is the container port.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;My Computer                  Docker Container
-----------                  ----------------
localhost:8080  ----------&amp;gt;  Nginx:80
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nginx listens on port 80 inside the container.&lt;/p&gt;

&lt;p&gt;However, I wanted to access the website from my computer using port 8080.&lt;/p&gt;

&lt;p&gt;Docker's port mapping makes that possible.&lt;/p&gt;

&lt;p&gt;After starting the container, Docker returned a container ID, confirming that the container had been created and started.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Verifying the Running Container
&lt;/h2&gt;

&lt;p&gt;I did not want to assume that the container was working simply because the &lt;code&gt;docker run&lt;/code&gt; command returned an ID.&lt;/p&gt;

&lt;p&gt;I needed to verify it.&lt;/p&gt;

&lt;p&gt;First, I ran:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker ps
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command lists running containers.&lt;/p&gt;

&lt;p&gt;I checked for the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Container name: &lt;code&gt;cloudops-web-server&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Status: Running&lt;/li&gt;
&lt;li&gt;Port mapping: &lt;code&gt;8080-&amp;gt;80/tcp&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The container appeared in the output, confirming that it was running and that the expected port mapping had been configured.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. Checking the Container Health
&lt;/h2&gt;

&lt;p&gt;I also wanted to confirm that the health check defined in the Dockerfile was working.&lt;/p&gt;

&lt;p&gt;I used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker inspect --format=&lt;span class="s1"&gt;'{{.State.Health.Status}}'&lt;/span&gt; cloudops-web-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The command returned:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;healthy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2v49t1h9kufxq02x8h3u.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2v49t1h9kufxq02x8h3u.PNG" alt=" " width="722" height="82"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This was an important verification step.&lt;/p&gt;

&lt;p&gt;It showed that Docker was able to execute the health check successfully and that the Nginx server was responding to the request.&lt;/p&gt;

&lt;p&gt;I also observed that a container can briefly show a &lt;code&gt;starting&lt;/code&gt; health status immediately after launch. This is expected while Docker waits for the initial health check to complete.&lt;/p&gt;

&lt;p&gt;The important thing was to allow the check to run and verify the final status rather than assume that &lt;code&gt;starting&lt;/code&gt; meant the deployment had failed.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. Testing the Website from the Browser
&lt;/h2&gt;

&lt;p&gt;With the container running and reporting a healthy status, I opened my browser and visited:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://localhost:8080
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fimhyqmwlo1jgcrwur6xe.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fimhyqmwlo1jgcrwur6xe.PNG" alt=" " width="800" height="453"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The CloudOps Web Server website loaded successfully.&lt;/p&gt;

&lt;p&gt;This confirmed that:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Docker container was running.&lt;/li&gt;
&lt;li&gt;Nginx was serving the website.&lt;/li&gt;
&lt;li&gt;Docker's port mapping was working.&lt;/li&gt;
&lt;li&gt;My computer could access the web server through the published host port.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This was the point where the different parts of the project came together.&lt;/p&gt;

&lt;p&gt;The website files were inside the Docker image, Nginx was running inside the container, and I could access the application from my browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  11. Testing the Website with curl
&lt;/h2&gt;

&lt;p&gt;I also wanted to verify the web server from the terminal rather than relying only on what I could see in the browser.&lt;/p&gt;

&lt;p&gt;I used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl http://localhost:8080
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe84n9g93tnjqmmmt8rmo.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe84n9g93tnjqmmmt8rmo.PNG" alt=" " width="800" height="486"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The command returned the HTML content of my website.&lt;/p&gt;

&lt;p&gt;This confirmed that the web server was responding to HTTP requests.&lt;/p&gt;

&lt;p&gt;I then tested the CSS file separately:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -I http://localhost:8080/styles.css
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The response returned:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTTP/1.1 200 OK
Content-Type: text/css
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fm4wbalqilts7cnelmivm.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fm4wbalqilts7cnelmivm.PNG" alt=" " width="692" height="221"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This was useful because a website can return its HTML successfully while still having a problem loading its stylesheet.&lt;/p&gt;

&lt;p&gt;By testing the CSS file separately, I confirmed that Nginx could serve both the HTML document and the stylesheet.&lt;/p&gt;

&lt;h2&gt;
  
  
  12. Updating and Rebuilding the Container
&lt;/h2&gt;

&lt;p&gt;During the project, I made some corrections to the website's displayed Docker command examples and the repository link in the footer.&lt;/p&gt;

&lt;p&gt;I needed to make sure that the changes were reflected in the container.&lt;/p&gt;

&lt;p&gt;One important thing I learned here is that changing a file on my computer does not automatically update a file that has already been copied into a Docker image.&lt;/p&gt;

&lt;p&gt;The files are included in the image during the build process.&lt;/p&gt;

&lt;p&gt;Therefore, I rebuilt the image and recreated the container.&lt;/p&gt;

&lt;p&gt;The commands I used were:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker build -t cloudops-web-server:1.0 .
docker stop cloudops-web-server
docker rm cloudops-web-server
docker run -d --name cloudops-web-server -p 8080:80 cloudops-web-server:1.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is what happened:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;I rebuilt the image using the updated website files.&lt;/li&gt;
&lt;li&gt;I stopped the existing container.&lt;/li&gt;
&lt;li&gt;I removed the old container.&lt;/li&gt;
&lt;li&gt;I created a new container using the rebuilt image.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I then repeated the verification steps:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker ps
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker inspect --format=&lt;span class="s1"&gt;'{{.State.Health.Status}}'&lt;/span&gt; cloudops-web-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl http://localhost:8080
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The new container started successfully, the health check returned &lt;code&gt;healthy&lt;/code&gt;, and the updated HTML was returned by the web server.&lt;/p&gt;

&lt;p&gt;This helped me understand the difference between updating files in a build context and updating an existing container.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fm5doq9mibw02mo8uk6hy.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fm5doq9mibw02mo8uk6hy.PNG" alt=" " width="800" height="486"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  13. Project Structure
&lt;/h2&gt;

&lt;p&gt;After completing the implementation and documentation, I organised the project as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Project_4_Docker_Web_Server/
│
├── docs/
│   └── screenshots/
│       ├── container.PNG
│       ├── curl css.PNG
│       ├── curl.PNG
│       ├── docker build.PNG
│       ├── docker desktop container.PNG
│       ├── docker destop image.PNG
│       ├── docker health bash.PNG
│       ├── flowchat.png
│       └── website.PNG
│
├── index.html
├── styles.css
├── Dockerfile
└── README.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I kept the screenshots in a separate documentation directory so that the main project files would remain easy to identify.&lt;/p&gt;

&lt;h2&gt;
  
  
  14. Challenges and Things I Learned
&lt;/h2&gt;

&lt;p&gt;This project was smaller than my Azure CI/CD project, but it helped reinforce several important Docker concepts.&lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding the difference between an image and a container
&lt;/h3&gt;

&lt;p&gt;One thing I paid attention to was the difference between building an image and running a container.&lt;/p&gt;

&lt;p&gt;Building an image does not automatically mean the application is running.&lt;/p&gt;

&lt;p&gt;I first built &lt;code&gt;cloudops-web-server:1.0&lt;/code&gt;, then created a container named &lt;code&gt;cloudops-web-server&lt;/code&gt; from that image.&lt;/p&gt;

&lt;p&gt;Understanding this distinction made the Docker workflow clearer.&lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding where Nginx serves files from
&lt;/h3&gt;

&lt;p&gt;I needed to understand the default Nginx document root before writing the &lt;code&gt;COPY&lt;/code&gt; instructions.&lt;/p&gt;

&lt;p&gt;This helped me understand why the destination path in a Dockerfile matters.&lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding port mapping
&lt;/h3&gt;

&lt;p&gt;I used port 8080 on my computer and port 80 inside the container.&lt;/p&gt;

&lt;p&gt;Understanding the relationship between the host and container ports helped me troubleshoot access to the website and understand how Docker publishes container services.&lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding Docker health checks
&lt;/h3&gt;

&lt;p&gt;I added a health check rather than relying only on &lt;code&gt;docker ps&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This helped me distinguish between a container that is running and an application inside that container that is responding successfully to a health probe.&lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding image rebuilds
&lt;/h3&gt;

&lt;p&gt;When I updated the website files, I needed to rebuild the image and recreate the container.&lt;/p&gt;

&lt;p&gt;This reinforced the idea that a Docker image contains the files and configuration captured during its build.&lt;/p&gt;

&lt;h2&gt;
  
  
  15. What I Would Improve in a Future Version
&lt;/h2&gt;

&lt;p&gt;There are several things I would consider if I extended this project.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add a CI/CD pipeline to automate image builds.&lt;/li&gt;
&lt;li&gt;Publish the image to a container registry.&lt;/li&gt;
&lt;li&gt;Deploy the container to a cloud hosting environment.&lt;/li&gt;
&lt;li&gt;Configure HTTPS and a domain name.&lt;/li&gt;
&lt;li&gt;Introduce a more comprehensive monitoring solution.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are possible improvements rather than features implemented in this project.&lt;/p&gt;

&lt;p&gt;The current implementation focuses on building and running a Dockerized Nginx web server locally.&lt;/p&gt;

&lt;h2&gt;
  
  
  16. Final Thoughts
&lt;/h2&gt;

&lt;p&gt;This project allowed me to practise the fundamentals of Docker using a practical example.&lt;/p&gt;

&lt;p&gt;I started with two simple website files and worked through selecting a web server, writing a Dockerfile, building an image, running a container, mapping ports, and checking application health.&lt;/p&gt;

&lt;p&gt;More importantly, I focused on understanding what each instruction and command was doing.&lt;/p&gt;

&lt;p&gt;For me, the value of this project was not just getting a website to load in a browser. It was understanding how the website moved from local source files into a Docker image and eventually into a running container.&lt;/p&gt;

&lt;p&gt;This is another step in my journey towards becoming a Cloud and DevOps Engineer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project repository:&lt;/strong&gt; &lt;a href="https://github.com/highpee1991/CodeAlpha_ProjectName" rel="noopener noreferrer"&gt;CodeAlpha DevOps Internship Projects&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project 4 source files:&lt;/strong&gt; &lt;a href="https://github.com/highpee1991/CodeAlpha_ProjectName/tree/main/Project_4_Docker_Web_Server" rel="noopener noreferrer"&gt;CloudOps Web Server – GitHub&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This project was completed as part of the CodeAlpha DevOps Internship.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>devops</category>
      <category>docker</category>
      <category>webdev</category>
    </item>
    <item>
      <title>From a Local Node.js App to Azure: My Docker, Terraform and Azure DevOps Deployment</title>
      <dc:creator>Ipadeola Taiwo</dc:creator>
      <pubDate>Wed, 25 Nov 2026 05:35:44 +0000</pubDate>
      <link>https://dev.to/highpee1991/from-a-local-nodejs-app-to-azure-my-docker-terraform-and-azure-devops-deployment-o7g</link>
      <guid>https://dev.to/highpee1991/from-a-local-nodejs-app-to-azure-my-docker-terraform-and-azure-devops-deployment-o7g</guid>
      <description>&lt;p&gt;I built this project as part of my CodeAlpha DevOps training. The goal was to take a small Node.js application, package it with Docker, create the Azure infrastructure with Terraform, and automate the deployment with Azure DevOps Pipelines.&lt;/p&gt;

&lt;p&gt;This post is a record of how I approached the work, the commands I used, the decisions I made and the problems I had to solve along the way. I have included the points where I would place screenshots from my own setup so readers can follow the work and see what each stage looked like.&lt;/p&gt;

&lt;p&gt;The project is based on an existing Node.js and Express application called &lt;strong&gt;DevOps Status Dashboard&lt;/strong&gt;. It exposes two endpoints:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;/health&lt;/code&gt; returns the health of the application.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/api/status&lt;/code&gt; returns details about the running application, including its environment and version.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At the end of the work, the application was running on Azure App Service as a Linux custom container. Azure Pipelines built the Docker image, pushed it to Azure Container Registry (ACR), updated the Web App to use that image and checked the health endpoint.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Live application:&lt;/strong&gt; &lt;a href="https://app-codealpha-92njum.azurewebsites.net" rel="noopener noreferrer"&gt;https://app-codealpha-92njum.azurewebsites.net&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1kkjciawsj011yaojyv6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1kkjciawsj011yaojyv6.png" alt=" " width="800" height="459"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Health endpoint:&lt;/strong&gt; &lt;a href="https://app-codealpha-92njum.azurewebsites.net/health" rel="noopener noreferrer"&gt;https://app-codealpha-92njum.azurewebsites.net/health&lt;/a&gt;  &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F85pgkcn4ql7vqrtpme1e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F85pgkcn4ql7vqrtpme1e.png" alt=" " width="756" height="384"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Application status:&lt;/strong&gt; &lt;a href="https://app-codealpha-92njum.azurewebsites.net/api/status" rel="noopener noreferrer"&gt;https://app-codealpha-92njum.azurewebsites.net/api/status&lt;/a&gt;  &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcr5rm4lxx8bqz2na5p87.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcr5rm4lxx8bqz2na5p87.png" alt=" " width="800" height="191"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;GitHub repository:&lt;/strong&gt; &lt;a href="https://github.com/highpee1991/CodeAlpha_ProjectName" rel="noopener noreferrer"&gt;https://github.com/highpee1991/CodeAlpha_ProjectName&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The Azure resource names shown in this post are from my completed deployment. If you follow the guide in your own subscription, Terraform will create names based on your configuration and any generated suffix. Do not assume that your names will be identical to mine.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. What I used
&lt;/h2&gt;

&lt;p&gt;These were the main tools and services involved:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tool or service&lt;/th&gt;
&lt;th&gt;What I used it for&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Node.js and Express&lt;/td&gt;
&lt;td&gt;The application&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Docker&lt;/td&gt;
&lt;td&gt;Building and running the application as a container&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Azure CLI&lt;/td&gt;
&lt;td&gt;Signing in and managing Azure resources&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Terraform&lt;/td&gt;
&lt;td&gt;Creating and managing the Azure infrastructure&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Azure Storage&lt;/td&gt;
&lt;td&gt;Keeping Terraform state remotely&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Azure Container Registry&lt;/td&gt;
&lt;td&gt;Storing the Docker image&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Azure App Service&lt;/td&gt;
&lt;td&gt;Running the container&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Azure DevOps&lt;/td&gt;
&lt;td&gt;Building and deploying the image through a pipeline&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GitHub&lt;/td&gt;
&lt;td&gt;Hosting the application source code&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;VS Code and Git Bash&lt;/td&gt;
&lt;td&gt;My working environment&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;I used Git Bash (UCRT64) in the VS Code terminal on Windows. The commands below are written for Bash. If you use PowerShell, some shell variable and line-continuation syntax will be different.&lt;/p&gt;

&lt;h3&gt;
  
  
  Before starting
&lt;/h3&gt;

&lt;p&gt;You need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An Azure account with an active subscription.&lt;/li&gt;
&lt;li&gt;Azure CLI installed.&lt;/li&gt;
&lt;li&gt;Terraform installed.&lt;/li&gt;
&lt;li&gt;Docker Desktop installed and running.&lt;/li&gt;
&lt;li&gt;Git installed.&lt;/li&gt;
&lt;li&gt;A GitHub account.&lt;/li&gt;
&lt;li&gt;An Azure DevOps organization.&lt;/li&gt;
&lt;li&gt;Access to create the Azure resources and role assignments used in this project.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I used East US as the Azure region. The App Service Plan was Basic B1, and the Container Registry used the Basic SKU. Azure quotas and pricing can vary by subscription and region, so check your own subscription before creating resources.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fioqd68kuj46e4uu43ubd.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fioqd68kuj46e4uu43ubd.PNG" alt=" " width="800" height="476"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  2. I checked that the application worked locally first
&lt;/h2&gt;

&lt;p&gt;Before writing a Dockerfile, I wanted to know that the application itself worked. There is little value in trying to debug Docker, Azure and the application at the same time.&lt;/p&gt;

&lt;p&gt;From the application directory, I installed the dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then I started the application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I checked the application in a browser at:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://localhost:3000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbq0hrntg4065dxo7hf4q.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbq0hrntg4065dxo7hf4q.PNG" alt=" " width="800" height="460"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I also checked the endpoints:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl http://localhost:3000/health
curl http://localhost:3000/api/status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2el4e79bgka5dsjwbqp6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2el4e79bgka5dsjwbqp6.png" alt=" " width="799" height="459"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpnulhd5dyic8sfls3vy6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpnulhd5dyic8sfls3vy6.png" alt=" " width="800" height="456"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The important things I confirmed in the application were:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The application starts with &lt;code&gt;node server.js&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;It listens on port &lt;code&gt;3000&lt;/code&gt; by default.&lt;/li&gt;
&lt;li&gt;It binds to &lt;code&gt;0.0.0.0&lt;/code&gt;, not only &lt;code&gt;localhost&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The health and status endpoints respond.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The port and host settings matter when an application runs inside a container. A process listening only on &lt;code&gt;127.0.0.1&lt;/code&gt; inside the container will not be reachable through the container's published port in the way we need.&lt;/p&gt;

&lt;p&gt;My application uses the &lt;code&gt;PORT&lt;/code&gt; environment variable when it is supplied and falls back to port 3000. The server needs to listen on &lt;code&gt;0.0.0.0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Screenshot to add:&lt;/strong&gt; &lt;code&gt;02-local-app-running.png&lt;/code&gt;&lt;br&gt;&lt;br&gt;
Capture the local application running in the browser, or the terminal showing &lt;code&gt;npm start&lt;/code&gt; and a successful request to &lt;code&gt;/health&lt;/code&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  3. I created the Dockerfile
&lt;/h2&gt;

&lt;p&gt;After confirming the application worked locally, I moved on to Docker.&lt;/p&gt;

&lt;p&gt;I created a file named &lt;code&gt;Dockerfile&lt;/code&gt; in the project root:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt; node:20-alpine

&lt;span class="k"&gt;WORKDIR&lt;/span&gt; /app

&lt;span class="k"&gt;COPY&lt;/span&gt; package*.json ./

&lt;span class="k"&gt;RUN&lt;/span&gt; npm ci --omit=dev

&lt;span class="k"&gt;COPY&lt;/span&gt; . .

&lt;span class="k"&gt;EXPOSE&lt;/span&gt; 3000

&lt;span class="k"&gt;USER&lt;/span&gt; node

&lt;span class="k"&gt;CMD&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"node"&lt;/span&gt;, &lt;span class="s2"&gt;"server.js"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgjzuj2r9bi5m1n92kprt.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgjzuj2r9bi5m1n92kprt.PNG" alt=" " width="800" height="476"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A few details are worth explaining.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;node:20-alpine&lt;/code&gt; gives me a smaller Node.js base image.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;WORKDIR /app&lt;/code&gt; sets the working directory inside the container.&lt;/li&gt;
&lt;li&gt;I copy the package files first and install production dependencies with &lt;code&gt;npm ci --omit=dev&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;I then copy the application source.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;EXPOSE 3000&lt;/code&gt; documents the port the application uses.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;USER node&lt;/code&gt; runs the application as the non-root Node user provided by the image.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;CMD ["node", "server.js"]&lt;/code&gt; starts the application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I used &lt;code&gt;npm ci&lt;/code&gt; because the project has a lock file. It installs the dependency versions recorded in that lock file and is suitable for repeatable builds.&lt;/p&gt;

&lt;h3&gt;
  
  
  I also created a &lt;code&gt;.dockerignore&lt;/code&gt; file
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;.dockerignore&lt;/code&gt; file keeps unnecessary files out of the Docker build context. Mine included:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node_modules/
npm-debug.log
.git/
.gitignore
.env
Dockerfile
.dockerignore
README.md

terraform/
*.tfstate
*.tfstate.*
*.tfvars
*.tfplan
tfplan
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The exact exclusions should match your project. Do not exclude files that the application needs at runtime. In particular, keep secrets out of the image and do not copy Terraform state or local environment files into it.&lt;/p&gt;

&lt;p&gt;It is worth understanding the difference between &lt;code&gt;.gitignore&lt;/code&gt; and &lt;code&gt;.dockerignore&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;.gitignore&lt;/code&gt; controls what Git ignores.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.dockerignore&lt;/code&gt; controls what Docker sends as the build context.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;They solve different problems, so I used both.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Screenshot to add:&lt;/strong&gt; &lt;code&gt;03-dockerfile-and-dockerignore.png&lt;/code&gt;&lt;br&gt;&lt;br&gt;
Capture the Dockerfile and &lt;code&gt;.dockerignore&lt;/code&gt; open in VS Code. Make sure the file contents are readable.&lt;/p&gt;


&lt;h2&gt;
  
  
  4. I built and tested the container locally
&lt;/h2&gt;

&lt;p&gt;I built the image from the project root:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker build -t devops-status-dashboard:1.0.0 .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;-t&lt;/code&gt; option gives the image a name and tag. The final dot tells Docker to use the current directory as the build context.&lt;/p&gt;

&lt;p&gt;I checked that the image had been created:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker images
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdeej0h05lporjockvbzh.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdeej0h05lporjockvbzh.PNG" alt=" " width="797" height="112"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then I started a container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run -d \
  -p 3000:3000 \
  --name devops-dashboard-test \
  -e &lt;span class="nv"&gt;APP_ENV&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;development \
  -e &lt;span class="nv"&gt;APP_VERSION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1.0.0 \
  devops-status-dashboard:1.0.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The options mean:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-d&lt;/code&gt; runs the container in the background.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-p 3000:3000&lt;/code&gt; maps port 3000 on my computer to port 3000 in the container.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--name&lt;/code&gt; gives the container a name that is easier to use in later commands.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-e&lt;/code&gt; supplies environment variables to the application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I checked the running container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker ps
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I tested the endpoints from my computer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl http://localhost:3000/health
curl http://localhost:3000/api/status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If a container is not listed by &lt;code&gt;docker ps&lt;/code&gt;, check stopped containers as well:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker ps -a
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To see why a container stopped, check its logs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker logs devops-dashboard-test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Other useful commands are:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker stop devops-dashboard-test
docker rm devops-dashboard-test
docker images
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  A Dockerfile mistake I had to correct
&lt;/h3&gt;

&lt;p&gt;My first Docker build used the wrong application entry point. I had set the Dockerfile to start &lt;code&gt;index.js&lt;/code&gt;, but the actual file was &lt;code&gt;server.js&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The container did not stay running. I checked:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker ps -a
docker logs devops-dashboard-test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The logs showed a Node.js &lt;code&gt;MODULE_NOT_FOUND&lt;/code&gt; error for &lt;code&gt;/app/index.js&lt;/code&gt;. That told me the problem was not the Azure environment or the port. Docker was starting Node with a file that did not exist.&lt;/p&gt;

&lt;p&gt;I corrected the command to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;CMD&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"node"&lt;/span&gt;, &lt;span class="s2"&gt;"server.js"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then I rebuilt the image and replaced the old container. Editing a Dockerfile does not change an image that has already been built, so rebuilding was necessary.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fy73cckmri1pslcmjipml.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fy73cckmri1pslcmjipml.PNG" alt=" " width="799" height="405"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  5. I prepared Azure and checked the subscription
&lt;/h2&gt;

&lt;p&gt;Before creating Azure resources, I signed in through Azure CLI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I checked which subscription was active:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az account show --output table
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I also listed the subscriptions available to my account:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az account list --output table
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you have more than one subscription, select the one you intend to use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az account &lt;span class="nb"&gt;set&lt;/span&gt; --subscription &lt;span class="s2"&gt;"&amp;lt;YOUR_SUBSCRIPTION_ID&amp;gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use the subscription ID from your own &lt;code&gt;az account list&lt;/code&gt; output. Do not copy another person's ID.&lt;/p&gt;

&lt;p&gt;I checked the registration state of the Azure resource providers required by the project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az provider show \
  --namespace Microsoft.Web \
  --query registrationState \
  --output tsv

az provider show \
  --namespace Microsoft.ContainerRegistry \
  --query registrationState \
  --output tsv

az provider show \
  --namespace Microsoft.Storage \
  --query registrationState \
  --output tsv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If a required provider is not registered, register it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az provider register --namespace Microsoft.Web
az provider register --namespace Microsoft.ContainerRegistry
az provider register --namespace Microsoft.Storage
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Provider registration can take a little time. Check the state again before continuing.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. I created a separate Terraform remote state backend
&lt;/h2&gt;

&lt;p&gt;One decision I made early was to keep Terraform's state storage separate from the application resources.&lt;/p&gt;

&lt;p&gt;Terraform state records the resources Terraform manages and the relationship between the configuration and the real Azure resources. If that state is lost or becomes inconsistent, managing the infrastructure becomes much harder.&lt;/p&gt;

&lt;p&gt;I used a separate resource group and storage account for the backend:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Setting&lt;/th&gt;
&lt;th&gt;Value used in my project&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Region&lt;/td&gt;
&lt;td&gt;&lt;code&gt;eastus&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Resource group&lt;/td&gt;
&lt;td&gt;&lt;code&gt;rg-terraform-state&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Storage account&lt;/td&gt;
&lt;td&gt;&lt;code&gt;stcodealphatfstate&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Blob container&lt;/td&gt;
&lt;td&gt;&lt;code&gt;tfstate&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;State key&lt;/td&gt;
&lt;td&gt;&lt;code&gt;codealpha-project1.tfstate&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;I used shell variables to make the commands easier to read:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;LOCATION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"eastus"&lt;/span&gt;
&lt;span class="nv"&gt;RG_NAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"rg-terraform-state"&lt;/span&gt;
&lt;span class="nv"&gt;STORAGE_ACCOUNT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"stcodealphatfstate"&lt;/span&gt;
&lt;span class="nv"&gt;CONTAINER_NAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"tfstate"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check that the storage account name is available before creating your own. Azure storage account names must be globally unique and follow Azure's naming rules.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create the backend resource group
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az group create \
  --name &lt;span class="s2"&gt;"$RG_NAME"&lt;/span&gt; \
  --location &lt;span class="s2"&gt;"$LOCATION"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create the storage account
&lt;/h3&gt;

&lt;p&gt;The storage account should use secure settings. In my setup, I used HTTPS-only access, disabled anonymous blob access and shared-key access, and used locally redundant storage.&lt;/p&gt;

&lt;p&gt;A command for creating a storage account with these settings is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az storage account create \
  --name &lt;span class="s2"&gt;"$STORAGE_ACCOUNT"&lt;/span&gt; \
  --resource-group &lt;span class="s2"&gt;"$RG_NAME"&lt;/span&gt; \
  --location &lt;span class="s2"&gt;"$LOCATION"&lt;/span&gt; \
  --sku Standard_LRS \
  --kind StorageV2 \
  --https-only &lt;span class="kc"&gt;true&lt;/span&gt; \
  --allow-blob-public-access &lt;span class="kc"&gt;false&lt;/span&gt; \
  --allow-shared-key-access &lt;span class="kc"&gt;false&lt;/span&gt; \
  --min-tls-version TLS1_2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fr1g49aq3s9iq85nsxm1z.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fr1g49aq3s9iq85nsxm1z.PNG" alt=" " width="696" height="230"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Enable recovery protections
&lt;/h3&gt;

&lt;p&gt;I enabled blob versioning and soft delete so that accidental changes or deletions would be easier to recover from.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az storage account blob-service-properties update \
  --account-name &lt;span class="s2"&gt;"$STORAGE_ACCOUNT"&lt;/span&gt; \
  --resource-group &lt;span class="s2"&gt;"$RG_NAME"&lt;/span&gt; \
  --enable-versioning &lt;span class="kc"&gt;true&lt;/span&gt; \
  --enable-delete-retention &lt;span class="kc"&gt;true&lt;/span&gt; \
  --delete-retention-days 7 \
  --enable-container-delete-retention &lt;span class="kc"&gt;true&lt;/span&gt; \
  --container-delete-retention-days 7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create the state container
&lt;/h3&gt;

&lt;p&gt;I used Microsoft Entra ID authentication with Azure CLI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az storage container create \
  --name &lt;span class="s2"&gt;"$CONTAINER_NAME"&lt;/span&gt; \
  --account-name &lt;span class="s2"&gt;"$STORAGE_ACCOUNT"&lt;/span&gt; \
  --auth-mode login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Give my signed-in identity access to the state
&lt;/h3&gt;

&lt;p&gt;The identity running Terraform needs permission to read and write blobs in the storage account. I assigned the &lt;strong&gt;Storage Blob Data Contributor&lt;/strong&gt; role at the storage account scope.&lt;/p&gt;

&lt;p&gt;First, I obtained the storage account resource ID and my signed-in user object ID:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;STORAGE_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;az storage account show \
  --name &lt;span class="s2"&gt;"$STORAGE_ACCOUNT"&lt;/span&gt; \
  --resource-group &lt;span class="s2"&gt;"$RG_NAME"&lt;/span&gt; \
  --query id \
  --output tsv&lt;span class="o"&gt;)&lt;/span&gt;

&lt;span class="nv"&gt;USER_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;az ad signed-in-user show \
  --query id \
  --output tsv&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then I assigned the role:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az role assignment create \
  --assignee &lt;span class="s2"&gt;"$USER_ID"&lt;/span&gt; \
  --role &lt;span class="s2"&gt;"Storage Blob Data Contributor"&lt;/span&gt; \
  --scope &lt;span class="s2"&gt;"$STORAGE_ID"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Role assignments can take a short time to become effective. If Terraform immediately reports an authorization error, wait briefly and retry after checking the assignment.&lt;/p&gt;




&lt;h2&gt;
  
  
  7. I configured Terraform
&lt;/h2&gt;

&lt;p&gt;I kept the Terraform configuration in a separate &lt;code&gt;terraform&lt;/code&gt; directory in the project.&lt;/p&gt;

&lt;p&gt;The configuration used the AzureRM provider. I installed the AzureRM 4.0 provider line and used version &lt;code&gt;4.0.1&lt;/code&gt; in my working environment.&lt;/p&gt;

&lt;p&gt;The provider configuration needs to target the subscription you selected. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="n"&gt;terraform&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;required_version&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&amp;gt;= 1.0"&lt;/span&gt;

  &lt;span class="n"&gt;required_providers&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;azurerm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;source&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"hashicorp/azurerm"&lt;/span&gt;
      &lt;span class="n"&gt;version&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"~&amp;gt; 4.0.0"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;random&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;source&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"hashicorp/random"&lt;/span&gt;
      &lt;span class="n"&gt;version&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"~&amp;gt; 3.6"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="n"&gt;backend&lt;/span&gt; &lt;span class="s2"&gt;"azurerm"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;resource_group_name&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"rg-terraform-state"&lt;/span&gt;
    &lt;span class="n"&gt;storage_account_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"stcodealphatfstate"&lt;/span&gt;
    &lt;span class="n"&gt;container_name&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"tfstate"&lt;/span&gt;
    &lt;span class="n"&gt;key&lt;/span&gt;                  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"codealpha-project1.tfstate"&lt;/span&gt;
    &lt;span class="n"&gt;use_azuread_auth&lt;/span&gt;     &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;provider&lt;/span&gt; &lt;span class="s2"&gt;"azurerm"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;features&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="n"&gt;subscription_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;YOUR_SUBSCRIPTION_ID&amp;gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;&amp;lt;YOUR_SUBSCRIPTION_ID&amp;gt;&lt;/code&gt; with your own subscription ID. Do not commit credentials or access keys to GitHub.&lt;/p&gt;

&lt;p&gt;The backend block points Terraform to the storage account and blob container created earlier. The &lt;code&gt;use_azuread_auth = true&lt;/code&gt; setting tells the backend to use Microsoft Entra ID authentication rather than a storage account key.&lt;/p&gt;

&lt;p&gt;I also used variables for values such as the location, project name, environment, App Service Plan SKU, image name and image tag. This made it easier to keep resource names and settings consistent.&lt;/p&gt;

&lt;p&gt;The infrastructure configuration created these resources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A resource group for the application.&lt;/li&gt;
&lt;li&gt;An Azure Container Registry using the Basic SKU.&lt;/li&gt;
&lt;li&gt;A Linux App Service Plan using the Basic B1 tier.&lt;/li&gt;
&lt;li&gt;A Linux Web App configured to run a custom container.&lt;/li&gt;
&lt;li&gt;A system-assigned managed identity for the Web App.&lt;/li&gt;
&lt;li&gt;An &lt;code&gt;AcrPull&lt;/code&gt; role assignment so the Web App could pull the image from ACR.&lt;/li&gt;
&lt;li&gt;A random suffix to help keep globally unique resource names unique.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The application infrastructure was deployed in East US. The Web App was configured to use port 3000 and HTTPS.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt; The subscription ID and the generated resource suffix are specific to each deployment. Keep your own values in your local Terraform configuration. The full Terraform resource definitions should be kept in the project's &lt;code&gt;terraform&lt;/code&gt; directory and committed with the project, excluding state files and secret variable files.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Initialize and validate Terraform
&lt;/h3&gt;

&lt;p&gt;From the Terraform directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; terraform
terraform init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I ran formatting and validation before planning:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform fmt -recursive
terraform validate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then I reviewed the proposed infrastructure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform plan
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I did not want to apply a plan without checking which resources Terraform intended to create.&lt;/p&gt;

&lt;h3&gt;
  
  
  Apply the infrastructure
&lt;/h3&gt;

&lt;p&gt;Once the plan showed the expected resources, I applied it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Review the plan and confirm when Terraform asks for approval.&lt;/p&gt;

&lt;p&gt;After creation, I checked the state:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform state list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I also checked the outputs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform output
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The outputs helped me confirm the registry name, registry login server, resource group and Web App details without guessing resource names.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F78c0s7e4cfysy8gahdz0.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F78c0s7e4cfysy8gahdz0.PNG" alt=" " width="589" height="463"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkgj34r0v2fcchhtoixjo.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkgj34r0v2fcchhtoixjo.PNG" alt=" " width="571" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1ray4ymwd8kfkp5dgt98.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1ray4ymwd8kfkp5dgt98.png" alt=" " width="677" height="514"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  8. I had to resolve an Azure App Service quota issue
&lt;/h2&gt;

&lt;p&gt;My first attempt to create the Basic B1 App Service Plan in East US was blocked by an Azure quota restriction.&lt;/p&gt;

&lt;p&gt;This was not a syntax error in my Terraform configuration. Azure was rejecting the requested App Service capacity for the subscription and region.&lt;/p&gt;

&lt;p&gt;I checked the error and contacted Azure Support to request help with the quota. After the issue was resolved, I ran the Terraform deployment again and the six resources were created.&lt;/p&gt;

&lt;p&gt;This was a useful reminder that a valid Terraform plan does not guarantee that Azure will accept every resource request. Subscription quotas, regional capacity and service restrictions still apply.&lt;/p&gt;

&lt;p&gt;If you encounter a similar error:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Read the full Azure error message.&lt;/li&gt;
&lt;li&gt;Identify the resource type, SKU and region involved.&lt;/li&gt;
&lt;li&gt;Check the quota for that subscription and region.&lt;/li&gt;
&lt;li&gt;Request a quota increase through Azure if needed.&lt;/li&gt;
&lt;li&gt;Re-run the Terraform plan and apply after the quota issue is resolved.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Do not keep changing working Terraform configuration to solve a quota restriction unless the error actually points to a configuration problem.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Screenshot to add:&lt;/strong&gt; &lt;code&gt;13-app-service-quota-error.png&lt;/code&gt;&lt;br&gt;&lt;br&gt;
Show the quota error. Remove subscription IDs or other private details.&lt;/p&gt;


&lt;h2&gt;
  
  
  9. I built the image and pushed it to Azure Container Registry
&lt;/h2&gt;

&lt;p&gt;After the infrastructure was available, I needed to put the Docker image in a registry that Azure App Service could access.&lt;/p&gt;

&lt;p&gt;I first checked the Terraform outputs to get the actual ACR name and login server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform output
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I used the registry name from my own output. In my completed deployment, the registry was:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;acrcodealpha92njum
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The login server was:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;acrcodealpha92njum.azurecr.io
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your registry name will probably be different because the configuration uses a generated suffix.&lt;/p&gt;

&lt;h3&gt;
  
  
  Sign in to ACR
&lt;/h3&gt;

&lt;p&gt;From the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az acr login --name &lt;span class="s2"&gt;"&amp;lt;YOUR_ACR_NAME&amp;gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace the placeholder with the registry name from your Terraform output.&lt;/p&gt;

&lt;h3&gt;
  
  
  Build the image
&lt;/h3&gt;

&lt;p&gt;From the application root, build the image:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker build -t devops-status-dashboard:1.0.0 .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Tag the image for ACR
&lt;/h3&gt;

&lt;p&gt;Use the login server from your own Terraform output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker tag devops-status-dashboard:1.0.0 \
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;YOUR_ACR_LOGIN_SERVER&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/devops-status-dashboard:1.0.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example, the final deployment used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker tag devops-status-dashboard:1.0.0 \
  acrcodealpha92njum.azurecr.io/devops-status-dashboard:1.0.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Push the image
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker push &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;YOUR_ACR_LOGIN_SERVER&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/devops-status-dashboard:1.0.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I then checked the repositories and tags in the Azure Portal to confirm the image was available.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxg0235z3xw8vn0i9ue2z.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxg0235z3xw8vn0i9ue2z.PNG" alt=" " width="546" height="199"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc592zaxnbqjf4gnfy1nb.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc592zaxnbqjf4gnfy1nb.PNG" alt=" " width="484" height="61"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  10. I configured the Web App to pull from ACR using managed identity
&lt;/h2&gt;

&lt;p&gt;I did not want to store an ACR username and password in the Web App configuration.&lt;/p&gt;

&lt;p&gt;Instead, I used the Web App's system-assigned managed identity.&lt;/p&gt;

&lt;p&gt;The identity needs the &lt;code&gt;AcrPull&lt;/code&gt; role on the Container Registry. Terraform created this role assignment.&lt;/p&gt;

&lt;p&gt;The important parts of this arrangement are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Web App has a system-assigned managed identity.&lt;/li&gt;
&lt;li&gt;The identity has the &lt;code&gt;AcrPull&lt;/code&gt; role on the registry.&lt;/li&gt;
&lt;li&gt;ACR admin authentication is disabled.&lt;/li&gt;
&lt;li&gt;The Web App is configured to use its managed identity when pulling the container image.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For the completed deployment, the Web App was configured with the full image path and the system-assigned identity. The equivalent Azure CLI configuration is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az webapp config &lt;span class="nb"&gt;set&lt;/span&gt; \
  --resource-group rg-codealpha-dev \
  --name app-codealpha-92njum \
  --linux-fx-version &lt;span class="s2"&gt;"DOCKER|acrcodealpha92njum.azurecr.io/devops-status-dashboard:1.0.0"&lt;/span&gt; \
  --acr-use-identity &lt;span class="kc"&gt;true&lt;/span&gt; \
  --acr-identity &lt;span class="s1"&gt;'[system]'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use your own resource group, Web App name, registry login server and image tag. Do not copy my generated names if your Terraform outputs are different.&lt;/p&gt;

&lt;p&gt;I also configured the application to use port 3000. For Linux custom containers on App Service, the application port must match the port the application listens on. In this project, that was 3000.&lt;/p&gt;




&lt;h2&gt;
  
  
  11. I prepared Azure DevOps
&lt;/h2&gt;

&lt;p&gt;I used Azure DevOps Pipelines for the CI/CD part of the project.&lt;/p&gt;

&lt;p&gt;I already had Azure CLI installed, so I added the Azure DevOps extension:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az extension list \
  --query &lt;span class="s2"&gt;"[?name=='azure-devops'].name"&lt;/span&gt; \
  --output tsv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If it was not installed, I added it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az extension add --name azure-devops
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I checked the installed version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az extension show \
  --name azure-devops \
  --query version \
  --output tsv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I then checked my Azure CLI login:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az account show --output table
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Azure authentication and Azure DevOps authentication are related, but they are not the same thing. I checked the DevOps CLI configuration too:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az devops configure --list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create the Azure DevOps organization
&lt;/h3&gt;

&lt;p&gt;I created the organization through the Azure DevOps website:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open &lt;a href="https://dev.azure.com" rel="noopener noreferrer"&gt;https://dev.azure.com&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Sign in.&lt;/li&gt;
&lt;li&gt;Create a new organization.&lt;/li&gt;
&lt;li&gt;Choose an available organization name.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;My organization was:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://dev.azure.com/taiwo-cloud-devops
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Configure the CLI to use the organization
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az devops configure --defaults \
  &lt;span class="nv"&gt;organization&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;https://dev.azure.com/taiwo-cloud-devops
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I checked the configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az devops configure --list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I also checked that the organization was accessible:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az devops project list \
  --org https://dev.azure.com/taiwo-cloud-devops \
  --detect &lt;span class="kc"&gt;false&lt;/span&gt; \
  --output table
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;--detect false&lt;/code&gt; option prevents automatic repository detection for that command. Supplying &lt;code&gt;--org&lt;/code&gt; makes it clear which organization the CLI should use.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create the project
&lt;/h3&gt;

&lt;p&gt;I created a private project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az devops project create \
  --name &lt;span class="s2"&gt;"CodeAlpha-DevOps-Project1"&lt;/span&gt; \
  --description &lt;span class="s2"&gt;"Automated CI/CD pipeline for DevOps Status Dashboard"&lt;/span&gt; \
  --visibility private \
  --source-control git \
  --org https://dev.azure.com/taiwo-cloud-devops \
  --detect &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then I verified it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az devops project show \
  --project &lt;span class="s2"&gt;"CodeAlpha-DevOps-Project1"&lt;/span&gt; \
  --org https://dev.azure.com/taiwo-cloud-devops \
  --detect &lt;span class="kc"&gt;false&lt;/span&gt; \
  --output table
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  12. I checked the GitHub repository before connecting the pipeline
&lt;/h2&gt;

&lt;p&gt;Before creating the pipeline, I checked that I was working in the right repository and branch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git remote -v
git branch --show-current
git status --short
ls -la
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I confirmed that the repository remote pointed to my project repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://github.com/highpee1991/CodeAlpha_ProjectName.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I checked whether a pipeline YAML file already existed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; -f azure-pipelines.yml &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Pipeline YAML already exists"&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Pipeline YAML does not exist yet"&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I also checked the security-related files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cat .gitignore
cat .dockerignore
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And checked whether sensitive files were being tracked:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git ls-files .env terraform.tfstate terraform.tfstate.backup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To see whether expected files were ignored:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git check-ignore -v .env terraform.tfstate node_modules/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The point of these checks was to avoid committing secrets, Terraform state or local dependencies to GitHub.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftin5h2x3vi4sqg76ucp5.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftin5h2x3vi4sqg76ucp5.PNG" alt=" " width="800" height="411"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  13. I created the service connections
&lt;/h2&gt;

&lt;p&gt;The pipeline needed permission to push images to ACR and update the Web App.&lt;/p&gt;

&lt;p&gt;I configured two service connections in Azure DevOps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A Docker Registry service connection for Azure Container Registry.&lt;/li&gt;
&lt;li&gt;An Azure Resource Manager service connection for deploying to Azure.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The Azure Resource Manager connection was named:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sc-codealpha-azure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I used workload identity federation (OIDC) for the Azure Resource Manager connection. This avoids putting a long-lived client secret in the pipeline YAML.&lt;/p&gt;

&lt;p&gt;I scoped the connection to the application resource group, &lt;code&gt;rg-codealpha-dev&lt;/code&gt;, and authorized the pipeline to use it.&lt;/p&gt;

&lt;p&gt;The Docker registry service connection was used by the Docker task to authenticate to ACR and push the image.&lt;/p&gt;

&lt;p&gt;There are two separate identities involved in the deployment:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Identity&lt;/th&gt;
&lt;th&gt;Responsibility&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Azure DevOps service connection&lt;/td&gt;
&lt;td&gt;Allows the pipeline to update Azure resources&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;App Service system-assigned managed identity&lt;/td&gt;
&lt;td&gt;Allows the Web App to pull the image from ACR&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;These identities do different jobs. The pipeline identity deploys the application; the Web App identity pulls the container image when it starts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5b8kdxhc98gcjddnrueq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5b8kdxhc98gcjddnrueq.png" alt=" " width="799" height="454"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  14. I added the Azure Pipelines YAML file
&lt;/h2&gt;

&lt;p&gt;I created &lt;code&gt;azure-pipelines.yml&lt;/code&gt; in the root of the GitHub repository.&lt;/p&gt;

&lt;p&gt;The pipeline has two stages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Build:&lt;/strong&gt; Build the Docker image and push it to ACR.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deploy:&lt;/strong&gt; Update the Web App to use the new image, restart it and check the health endpoint.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is the pipeline used for the completed deployment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;trigger&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;main&lt;/span&gt;

&lt;span class="na"&gt;resources&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;repo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;self&lt;/span&gt;

&lt;span class="na"&gt;variables&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;dockerRegistryServiceConnection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"35bff728-40ea-42a4-bf8f-ead90173c7bd"&lt;/span&gt;
  &lt;span class="na"&gt;azureServiceConnection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"sc-codealpha-azure"&lt;/span&gt;
  &lt;span class="na"&gt;imageRepository&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"devops-status-dashboard"&lt;/span&gt;
  &lt;span class="na"&gt;containerRegistry&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"acrcodealpha92njum.azurecr.io"&lt;/span&gt;
  &lt;span class="na"&gt;dockerfilePath&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"$(Build.SourcesDirectory)/Dockerfile"&lt;/span&gt;
  &lt;span class="na"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"$(Build.BuildId)"&lt;/span&gt;
  &lt;span class="na"&gt;vmImageName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ubuntu-latest"&lt;/span&gt;

&lt;span class="na"&gt;stages&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Build&lt;/span&gt;
    &lt;span class="na"&gt;displayName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Build and push stage&lt;/span&gt;
    &lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;job&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Build&lt;/span&gt;
        &lt;span class="na"&gt;displayName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Build Docker image&lt;/span&gt;
        &lt;span class="na"&gt;pool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;vmImage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;$(vmImageName)&lt;/span&gt;
        &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;task&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Docker@2&lt;/span&gt;
            &lt;span class="na"&gt;displayName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Build and push image to ACR&lt;/span&gt;
            &lt;span class="na"&gt;inputs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
              &lt;span class="na"&gt;command&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;buildAndPush&lt;/span&gt;
              &lt;span class="na"&gt;repository&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;$(imageRepository)&lt;/span&gt;
              &lt;span class="na"&gt;dockerfile&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;$(dockerfilePath)&lt;/span&gt;
              &lt;span class="na"&gt;containerRegistry&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;$(dockerRegistryServiceConnection)&lt;/span&gt;
              &lt;span class="na"&gt;tags&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;
                &lt;span class="s"&gt;$(tag)&lt;/span&gt;

  &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Deploy&lt;/span&gt;
    &lt;span class="na"&gt;displayName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Deploy to Azure App Service&lt;/span&gt;
    &lt;span class="na"&gt;dependsOn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Build&lt;/span&gt;
    &lt;span class="na"&gt;condition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;succeeded()&lt;/span&gt;
    &lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;job&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Deploy&lt;/span&gt;
        &lt;span class="na"&gt;displayName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Deploy container&lt;/span&gt;
        &lt;span class="na"&gt;pool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;vmImage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;$(vmImageName)&lt;/span&gt;
        &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;task&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AzureCLI@2&lt;/span&gt;
            &lt;span class="na"&gt;displayName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Update App Service container&lt;/span&gt;
            &lt;span class="na"&gt;inputs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
              &lt;span class="na"&gt;azureSubscription&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;$(azureServiceConnection)&lt;/span&gt;
              &lt;span class="na"&gt;scriptType&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;bash&lt;/span&gt;
              &lt;span class="na"&gt;scriptLocation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;inlineScript&lt;/span&gt;
              &lt;span class="na"&gt;inlineScript&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;
                &lt;span class="s"&gt;set -e&lt;/span&gt;

                &lt;span class="s"&gt;echo "Configuring App Service with the full ACR image path..."&lt;/span&gt;

                &lt;span class="s"&gt;az webapp config set \&lt;/span&gt;
                  &lt;span class="s"&gt;--resource-group rg-codealpha-dev \&lt;/span&gt;
                  &lt;span class="s"&gt;--name app-codealpha-92njum \&lt;/span&gt;
                  &lt;span class="s"&gt;--linux-fx-version "DOCKER|$(containerRegistry)/$(imageRepository):$(tag)" \&lt;/span&gt;
                  &lt;span class="s"&gt;--acr-use-identity true \&lt;/span&gt;
                  &lt;span class="s"&gt;--acr-identity '[system]'&lt;/span&gt;

                &lt;span class="s"&gt;echo "Restarting App Service..."&lt;/span&gt;

                &lt;span class="s"&gt;az webapp restart \&lt;/span&gt;
                  &lt;span class="s"&gt;--resource-group rg-codealpha-dev \&lt;/span&gt;
                  &lt;span class="s"&gt;--name app-codealpha-92njum&lt;/span&gt;

                &lt;span class="s"&gt;echo "Waiting for application health check..."&lt;/span&gt;

                &lt;span class="s"&gt;for attempt in {1..18}; do&lt;/span&gt;
                  &lt;span class="s"&gt;status=$(curl -sS -o /tmp/health-response -w "%{http_code}" \&lt;/span&gt;
                    &lt;span class="s"&gt;https://app-codealpha-92njum.azurewebsites.net/health || true)&lt;/span&gt;

                  &lt;span class="s"&gt;if [ "$status" = "200" ]; then&lt;/span&gt;
                    &lt;span class="s"&gt;echo "Application is healthy!"&lt;/span&gt;
                    &lt;span class="s"&gt;cat /tmp/health-response&lt;/span&gt;
                    &lt;span class="s"&gt;exit 0&lt;/span&gt;
                  &lt;span class="s"&gt;fi&lt;/span&gt;

                  &lt;span class="na"&gt;echo "Attempt $attempt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;HTTP $status. Waiting..."&lt;/span&gt;
                  &lt;span class="s"&gt;sleep 10&lt;/span&gt;
                &lt;span class="s"&gt;done&lt;/span&gt;

                &lt;span class="s"&gt;echo "Application failed its health check."&lt;/span&gt;
                &lt;span class="s"&gt;cat /tmp/health-response || true&lt;/span&gt;
                &lt;span class="s"&gt;exit 1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Important: update the values for your own Azure deployment
&lt;/h3&gt;

&lt;p&gt;The YAML above contains the actual service connection ID and resource names from my completed environment. For your own deployment, update:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;dockerRegistryServiceConnection&lt;/code&gt; to the ID of your Docker Registry service connection.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;azureServiceConnection&lt;/code&gt; to your Azure Resource Manager service connection name.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;containerRegistry&lt;/code&gt; to your ACR login server.&lt;/li&gt;
&lt;li&gt;The resource group and Web App names in the Azure CLI commands.&lt;/li&gt;
&lt;li&gt;The health URL to your own Web App URL.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Do not copy the service connection ID from this article and expect it to work in another Azure DevOps organization. Service connection IDs are specific to an organization.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;$(Build.BuildId)&lt;/code&gt; variable gives each pipeline run a build-specific image tag. This makes it easier to identify which image was deployed.&lt;/p&gt;

&lt;p&gt;The deployment stage uses the full ACR image path. This detail mattered in my deployment. An earlier configuration caused App Service to try pulling the image from Docker Hub. I corrected the Web App configuration so it pointed to the full ACR image path and used the system-assigned identity.&lt;/p&gt;

&lt;p&gt;The health-check loop gives the Web App time to restart. It checks &lt;code&gt;/health&lt;/code&gt; and only succeeds when it receives HTTP 200. If the endpoint does not become healthy within the retry window, the pipeline fails instead of reporting a successful deployment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcdd4lz6348doejaeo8ao.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcdd4lz6348doejaeo8ao.png" alt=" " width="800" height="451"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5suvr4hyw80xvra7gci5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5suvr4hyw80xvra7gci5.png" alt=" " width="800" height="459"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  15. I connected GitHub and ran the pipeline
&lt;/h2&gt;

&lt;p&gt;In Azure DevOps, I created a pipeline and selected the GitHub repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;highpee1991/CodeAlpha_ProjectName
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I selected the existing &lt;code&gt;azure-pipelines.yml&lt;/code&gt; file from the &lt;code&gt;main&lt;/code&gt; branch.&lt;/p&gt;

&lt;p&gt;After saving the pipeline, I pushed the YAML file and any final changes to GitHub:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add azure-pipelines.yml
git diff --cached
git diff --check
git commit -m &lt;span class="s2"&gt;"Add Azure DevOps CI/CD pipeline"&lt;/span&gt;
git push origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Review the staged changes before committing. Do not commit &lt;code&gt;.env&lt;/code&gt; files, Terraform state, plan files, access keys or other secrets.&lt;/p&gt;

&lt;p&gt;Because the pipeline has a trigger for &lt;code&gt;main&lt;/code&gt;, a push to that branch starts a run.&lt;/p&gt;

&lt;p&gt;I opened the pipeline run in Azure DevOps and followed the two stages.&lt;/p&gt;

&lt;h3&gt;
  
  
  Build stage
&lt;/h3&gt;

&lt;p&gt;The Docker task:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Authenticates to ACR using the Docker Registry service connection.&lt;/li&gt;
&lt;li&gt;Builds the image using the project's Dockerfile.&lt;/li&gt;
&lt;li&gt;Tags the image with the Azure Pipelines build ID.&lt;/li&gt;
&lt;li&gt;Pushes the image to ACR.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Deploy stage
&lt;/h3&gt;

&lt;p&gt;The Azure CLI task:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Uses the Azure Resource Manager service connection.&lt;/li&gt;
&lt;li&gt;Updates the Web App to use the new image in ACR.&lt;/li&gt;
&lt;li&gt;Configures the Web App to pull using its system-assigned identity.&lt;/li&gt;
&lt;li&gt;Restarts the Web App.&lt;/li&gt;
&lt;li&gt;Checks the &lt;code&gt;/health&lt;/code&gt; endpoint.&lt;/li&gt;
&lt;li&gt;Fails the deployment if the health endpoint does not return HTTP 200 within the retry period.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;My successful pipeline run completed both stages and printed the health response.&lt;/p&gt;




&lt;h2&gt;
  
  
  16. I verified the live application
&lt;/h2&gt;

&lt;p&gt;I did not treat a successful pipeline run as the only proof that the deployment worked. I checked the live application itself.&lt;/p&gt;

&lt;p&gt;I opened the health endpoint:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://app-codealpha-92njum.azurewebsites.net/health
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I also tested it from the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -i https://app-codealpha-92njum.azurewebsites.net/health
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then I checked the status endpoint:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -i https://app-codealpha-92njum.azurewebsites.net/api/status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both endpoints returned HTTP 200 in my final verification.&lt;/p&gt;

&lt;p&gt;The health response contained:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"healthy"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The status endpoint returned information about the running application, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Environment: &lt;code&gt;dev&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Application version: &lt;code&gt;1.0.0&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Node.js version: &lt;code&gt;v20.20.2&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The live values can change between restarts, so the timestamp, hostname and uptime in the response may be different when you test your own deployment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Foko7vyi2cp3hf51w4chw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Foko7vyi2cp3hf51w4chw.png" alt=" " width="800" height="459"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzjyfmxurzldery9m3nyg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzjyfmxurzldery9m3nyg.png" alt=" " width="756" height="384"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3g6ebwxjh60238ej6sib.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3g6ebwxjh60238ej6sib.png" alt=" " width="800" height="191"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  17. The deployment flow
&lt;/h2&gt;

&lt;p&gt;This is the flow I implemented:&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart TD
    A["GitHub Repository"] --&amp;gt; B["Azure DevOps Pipelines"]
    B --&amp;gt; C["Build Docker Image"]
    C --&amp;gt; D["Azure Container Registry"]
    D --&amp;gt; E["Azure App Service"]
    E --&amp;gt; F["Health Check"]
    F --&amp;gt; G["Application Running"]&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;The source code lives in GitHub. A push to &lt;code&gt;main&lt;/code&gt; triggers Azure Pipelines. The pipeline builds the container image and pushes it to ACR. The deployment stage updates Azure App Service to use that image. App Service pulls the image with its managed identity, starts the container and the pipeline checks the health endpoint.&lt;/p&gt;




&lt;h2&gt;
  
  
  18. What I struggled with
&lt;/h2&gt;

&lt;p&gt;This project was not a straight line from writing a Dockerfile to getting a successful deployment. I had to stop and investigate a few problems.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Docker container could not find the application entry point
&lt;/h3&gt;

&lt;p&gt;I initially pointed the Dockerfile to &lt;code&gt;index.js&lt;/code&gt;, but the application entry point was &lt;code&gt;server.js&lt;/code&gt;. The container stopped because Node could not find the file.&lt;/p&gt;

&lt;p&gt;I checked &lt;code&gt;docker ps -a&lt;/code&gt; and &lt;code&gt;docker logs&lt;/code&gt;, corrected the Dockerfile and rebuilt the image. This reminded me to check the container logs before changing unrelated configuration.&lt;/p&gt;

&lt;h3&gt;
  
  
  Terraform initialization and configuration issues
&lt;/h3&gt;

&lt;p&gt;I had to correct some Terraform configuration issues during initialization and planning. I learned to read the error message carefully, check the relevant provider and backend settings, make one correction at a time and run initialization or validation again.&lt;/p&gt;

&lt;h3&gt;
  
  
  Azure provider registration
&lt;/h3&gt;

&lt;p&gt;Some Azure resource providers were not registered in the subscription. I checked their registration state and registered the required providers before continuing.&lt;/p&gt;

&lt;h3&gt;
  
  
  The App Service B1 quota
&lt;/h3&gt;

&lt;p&gt;Azure rejected the Basic B1 App Service Plan request in East US because of a subscription quota restriction. I contacted Azure Support and continued after the quota issue was resolved.&lt;/p&gt;

&lt;h3&gt;
  
  
  App Service tried to pull from Docker Hub
&lt;/h3&gt;

&lt;p&gt;During deployment, App Service was not using the ACR image path I intended. I corrected the container configuration to use the full ACR login server and image name, and enabled managed identity authentication for the registry pull.&lt;/p&gt;

&lt;h3&gt;
  
  
  Service connection setup
&lt;/h3&gt;

&lt;p&gt;The Azure DevOps service connection setup also needed care. I used workload identity federation for the Azure Resource Manager connection rather than storing a client secret in the pipeline YAML. I also had to make sure the pipeline was authorized to use the connection.&lt;/p&gt;

&lt;p&gt;These issues took time, but each one helped me understand what was happening instead of just repeating commands.&lt;/p&gt;




&lt;h2&gt;
  
  
  19. What I learned
&lt;/h2&gt;

&lt;p&gt;By completing this project, I gained practical experience with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Checking that an application works before containerising it.&lt;/li&gt;
&lt;li&gt;Writing a Dockerfile for a Node.js application.&lt;/li&gt;
&lt;li&gt;Using &lt;code&gt;.dockerignore&lt;/code&gt; to keep unnecessary files out of the build context.&lt;/li&gt;
&lt;li&gt;Building, running, inspecting and troubleshooting Docker containers.&lt;/li&gt;
&lt;li&gt;Using Azure CLI to inspect subscriptions and register resource providers.&lt;/li&gt;
&lt;li&gt;Creating a separate Azure Storage backend for Terraform state.&lt;/li&gt;
&lt;li&gt;Using Microsoft Entra ID authentication for Terraform remote state.&lt;/li&gt;
&lt;li&gt;Provisioning Azure resources with Terraform.&lt;/li&gt;
&lt;li&gt;Understanding the relationship between an App Service Plan, Web App and Container Registry.&lt;/li&gt;
&lt;li&gt;Using managed identity and the &lt;code&gt;AcrPull&lt;/code&gt; role for registry access.&lt;/li&gt;
&lt;li&gt;Creating an Azure DevOps organization and project.&lt;/li&gt;
&lt;li&gt;Connecting GitHub to Azure Pipelines.&lt;/li&gt;
&lt;li&gt;Using workload identity federation for pipeline access to Azure.&lt;/li&gt;
&lt;li&gt;Building and pushing a versioned container image through a CI/CD pipeline.&lt;/li&gt;
&lt;li&gt;Deploying the image to Azure App Service and checking the application health.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  20. Lessons I took home
&lt;/h2&gt;

&lt;p&gt;The biggest lesson for me was to troubleshoot the layer where the problem is happening.&lt;/p&gt;

&lt;p&gt;When Docker could not start the application, I checked the container logs instead of changing Azure settings. When Terraform was blocked by a quota, I investigated the Azure quota rather than rewriting working Terraform code. When App Service pulled from the wrong registry, I checked the image configuration and corrected the ACR path.&lt;/p&gt;

&lt;p&gt;I also learned that identity and permissions need to be planned as part of the deployment. The pipeline needs permission to deploy, while the Web App needs permission to pull the image. Giving each identity only the access it needs makes the setup easier to understand and safer to manage.&lt;/p&gt;

&lt;p&gt;Another lesson was to verify every stage. I checked the application locally before Docker, tested the container before pushing it, reviewed the Terraform plan before applying it, checked the image in ACR and tested the live endpoints after deployment.&lt;/p&gt;

&lt;p&gt;Most importantly, I learned not to assume that a green pipeline alone means the application is working. The final check should be against the running application.&lt;/p&gt;




&lt;h2&gt;
  
  
  21. Cleaning up Azure resources
&lt;/h2&gt;

&lt;p&gt;After I had captured the screenshots and completed the documentation, I could remove the application resources to avoid leaving them running unnecessarily.&lt;/p&gt;

&lt;p&gt;Before destroying anything, I checked the Terraform workspace and reviewed the destroy plan:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; terraform
terraform plan -destroy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only after confirming that the plan contained the application resources I intended to remove would I run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform destroy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I kept the separate Terraform state backend:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Resource group: &lt;code&gt;rg-terraform-state&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Storage account: &lt;code&gt;stcodealphatfstate&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Container: &lt;code&gt;tfstate&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;State key: &lt;code&gt;codealpha-project1.tfstate&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Do not destroy the remote state backend while you still need the state file. Also remember that resources created outside the Terraform configuration, or resources managed by another state file, will not necessarily be removed by this command.&lt;/p&gt;

&lt;p&gt;Check the destroy plan carefully before approving it. Azure resources can incur charges while they remain deployed.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final thoughts
&lt;/h2&gt;

&lt;p&gt;This project gave me the chance to work through a deployment from the application level to the cloud infrastructure and CI/CD pipeline. I had to understand how the application starts, how Docker packages it, how Terraform creates the Azure resources, how identities allow the services to communicate and how the pipeline moves a new image into production.&lt;/p&gt;

&lt;p&gt;I did run into problems, especially with the Docker entry point, Terraform setup, Azure quota and the ACR image configuration. Working through those issues was an important part of the project.&lt;/p&gt;

&lt;p&gt;The final result was a Node.js application running on Azure App Service as a container, with its image stored in Azure Container Registry and its deployment automated through Azure DevOps Pipelines.&lt;/p&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;




</description>
      <category>azure</category>
      <category>devops</category>
      <category>docker</category>
      <category>terraform</category>
    </item>
    <item>
      <title>Building and automating my portfolio website on Azure with Terraform and GitHub Actions</title>
      <dc:creator>Ipadeola Taiwo</dc:creator>
      <pubDate>Sat, 22 Aug 2026 05:49:27 +0000</pubDate>
      <link>https://dev.to/highpee1991/building-and-automating-my-portfolio-website-on-azure-with-terraform-and-github-actions-4f54</link>
      <guid>https://dev.to/highpee1991/building-and-automating-my-portfolio-website-on-azure-with-terraform-and-github-actions-4f54</guid>
      <description>&lt;p&gt;I wanted a portfolio site that actually shows what I can do as a cloud engineer, not just tells people. So instead of clicking through the Azure Portal and calling it done, I built the whole thing with Terraform, put a real CDN in front of it, attached a custom domain with HTTPS, then automated the entire deployment with GitHub Actions.&lt;/p&gt;

&lt;p&gt;Before I get into it, I want to be upfront about something. Nobody handed me this code. Every resource type, every argument, every fix in this post came from reading the Terraform registry documentation, reading Microsoft Learn, and searching Google whenever something broke. I would hit an error, read it slowly, search for the exact wording, read whatever official doc came up, try something, and if it did not work I would go back and read again. That process is the entire reason I understand what every line in this project actually does. This post is me walking you through that same process, mistakes included, so if you want to build something similar you can follow the same path instead of just copying a finished repo.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitHub repo:&lt;/strong&gt; &lt;a href="https://github.com/highpee1991/azure-portfolio-platform" rel="noopener noreferrer"&gt;https://github.com/highpee1991/azure-portfolio-platform&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Live site:&lt;/strong&gt; &lt;a href="https://taiwoipadeola.space" rel="noopener noreferrer"&gt;https://taiwoipadeola.space&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What I was building
&lt;/h2&gt;

&lt;p&gt;A static portfolio (HTML, CSS, JS, nothing fancy) that lives on Azure, sits behind a CDN so it loads fast anywhere in the world, answers on my own domain with a real HTTPS certificate, and updates itself the moment I push a change to GitHub. No manual uploads, no clicking around the portal after the first setup.&lt;/p&gt;
&lt;h2&gt;
  
  
  The real architecture, from my own Azure portal
&lt;/h2&gt;

&lt;p&gt;Rather than draw a made up diagram, here is what is actually sitting in my subscription right now, resource by resource, taken straight from the portal.&lt;/p&gt;

&lt;p&gt;Two resource groups exist for this project. &lt;code&gt;static-web-production-rg&lt;/code&gt; holds everything that actually serves the live site. &lt;code&gt;portfolio-tfstate-rg&lt;/code&gt; holds nothing except the storage account that Terraform uses to keep its own state file. Keeping these separate matters. If I ever destroy the production resource group to rebuild it, my Terraform state itself stays completely safe in the other one.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkqpa9zneq2mrl9xuqfhp.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkqpa9zneq2mrl9xuqfhp.PNG" alt=" " width="800" height="410"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Inside &lt;code&gt;static-web-production-rg&lt;/code&gt;, there is a storage account called &lt;code&gt;productioncontainerweb&lt;/code&gt;. Inside that storage account is a container named &lt;code&gt;$web&lt;/code&gt;, which is the special container name Azure uses for static website hosting. Right now that container holds six items: &lt;code&gt;404.html&lt;/code&gt;, &lt;code&gt;README.md&lt;/code&gt;, &lt;code&gt;index.html&lt;/code&gt;, &lt;code&gt;script.js&lt;/code&gt;, &lt;code&gt;style.css&lt;/code&gt;, and an &lt;code&gt;assets&lt;/code&gt; folder. Every single one of those was uploaded by GitHub Actions, not by me clicking upload in the portal.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdiqudexz80ubu8qf7x29.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdiqudexz80ubu8qf7x29.PNG" alt=" " width="800" height="453"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Inside &lt;code&gt;portfolio-tfstate-rg&lt;/code&gt; sits a second storage account, &lt;code&gt;portfoliotfstatestorage&lt;/code&gt;, with a container called &lt;code&gt;portfolio-tfstate-container&lt;/code&gt;. That container holds exactly one file, &lt;code&gt;production.tfstate&lt;/code&gt;, which is the entire memory of what Terraform has built for me. If that file gets corrupted or lost, Terraform effectively forgets everything it created and thinks it needs to build it all again, so keeping it in its own isolated backend was a deliberate choice from day one.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzwuorw55gbjewqvk2tie.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzwuorw55gbjewqvk2tie.PNG" alt=" " width="800" height="416"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also sitting in &lt;code&gt;static-web-production-rg&lt;/code&gt; is &lt;code&gt;portfolio-frontdoor-profile&lt;/code&gt;, my Azure Front Door instance. Its overview page shows an endpoint hostname that Azure generated for me automatically, something like &lt;code&gt;portfolio-frontdoor-endpoint-xxxxxxxx.z01.azurefd.net&lt;/code&gt;, and under Custom domains it lists both &lt;code&gt;taiwoipadeola.space&lt;/code&gt; and &lt;code&gt;www.taiwoipadeola.space&lt;/code&gt;, each showing Provision succeeded and Validation approved. Under Routes there is a single route called &lt;code&gt;portfolio-route&lt;/code&gt; pointing back at that endpoint.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvkwvemm79175dsxv40qy.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvkwvemm79175dsxv40qy.PNG" alt=" " width="799" height="413"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the traffic flow as an actual diagram.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                        Visitor's Browser
                                |
                             HTTPS request
                                |
                         Azure Front Door
                  portfolio-frontdoor-profile
              (2 custom domains, managed TLS certs,
                    caching, compression)
                                |
                         forwarded to origin
                                |
                Azure Storage Static Website
              productioncontainerweb / $web container
                 index.html, style.css, script.js,
                       404.html, assets/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the state backend, which is not in that traffic path at all, sits completely off to the side.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        portfolio-tfstate-rg
                |
        portfoliotfstatestorage
                |
        portfolio-tfstate-container
                |
          production.tfstate
     (Terraform's memory of everything above)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Repo structure
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;azure-portfolio-platform/
  .github/workflows/
    terraform.yml
    deploy.yml
  infrastructure/
    environments/production/
      backend.tf
      providers.tf
      main.tf
      variables.tf
      outputs.tf
      terraform.tfvars
    modules/
      storage/
        main.tf
        variables.tf
        outputs.tf
      front-door/
        main.tf
        variables.tf
        outputs.tf
      custom-domain/
        main.tf
        variables.tf
        outputs.tf
  portfolio/
    index.html
    style.css
    script.js
    404.html
    README.md
    assets/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I am sharing most of the code below, but not every single file. A few small variable declaration files and minor output wiring are left out on purpose, mainly because they are repetitive and do not add anything new to the explanation. The full thing is in the repo linked above if you want to see literally everything.&lt;/p&gt;

&lt;h2&gt;
  
  
  Layer one, the storage module
&lt;/h2&gt;

&lt;p&gt;This is where everything started. A resource group, a storage account, and static website hosting turned on.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_storage_account"&lt;/span&gt; &lt;span class="s2"&gt;"storage_account"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;storage_account_name&lt;/span&gt;
  &lt;span class="nx"&gt;resource_group_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resource_group_name&lt;/span&gt;
  &lt;span class="nx"&gt;location&lt;/span&gt;            &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resource_group_location&lt;/span&gt;

  &lt;span class="nx"&gt;account_tier&lt;/span&gt;             &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Standard"&lt;/span&gt;
  &lt;span class="nx"&gt;account_replication_type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"GRS"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_storage_account_static_website"&lt;/span&gt; &lt;span class="s2"&gt;"static-web"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;storage_account_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_storage_account&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;storage_account&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
  &lt;span class="nx"&gt;error_404_document&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"404.html"&lt;/span&gt;
  &lt;span class="nx"&gt;index_document&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"index.html"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;GRS&lt;/code&gt; means geo redundant storage, so my files get replicated to a second Azure region automatically. &lt;code&gt;azurerm_storage_account_static_website&lt;/code&gt; is the resource that actually flips the switch turning a plain storage account into something that can serve HTML pages over the web, and it is where I tell Azure which file to treat as the homepage and which one to serve when a page is not found.&lt;/p&gt;

&lt;p&gt;The outputs from this module are small but important. They expose the resource group name, the storage account name, and &lt;code&gt;primary_web_host&lt;/code&gt;, which is the actual hostname Azure gives the static website. That last one gets consumed later by the Front Door module, since Front Door needs to know where to actually send traffic.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;output&lt;/span&gt; &lt;span class="s2"&gt;"primary_web_host"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_storage_account&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;storage_account&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;primary_web_host&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The part I later removed, and exactly how I removed it
&lt;/h2&gt;

&lt;p&gt;In the beginning, this storage module also had a block that uploaded my actual portfolio files as part of &lt;code&gt;terraform apply&lt;/code&gt;. It looked like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;locals&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;portfolio_files&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fileset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"${path.module}/../../../portfolio"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"**"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_storage_blob"&lt;/span&gt; &lt;span class="s2"&gt;"portfolio"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;for_each&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;portfolio_files&lt;/span&gt;

  &lt;span class="nx"&gt;name&lt;/span&gt;                 &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;
  &lt;span class="nx"&gt;storage_container_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"${azurerm_storage_account.storage_account.id}/blobServices/default/containers/$web"&lt;/span&gt;

  &lt;span class="nx"&gt;type&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Block"&lt;/span&gt;
  &lt;span class="nx"&gt;source&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"${path.module}/../../../portfolio/${each.value}"&lt;/span&gt;
  &lt;span class="nx"&gt;content_md5&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;filemd5&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"${path.module}/../../../portfolio/${each.value}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;fileset&lt;/code&gt; scans my local &lt;code&gt;portfolio&lt;/code&gt; folder and returns the name of every file inside it. The &lt;code&gt;for_each&lt;/code&gt; on the blob resource then loops over that list and creates one blob resource per file. &lt;code&gt;content_md5&lt;/code&gt; calculates a fingerprint of each file's actual bytes, and Terraform stores that fingerprint in state. Every time I ran &lt;code&gt;terraform plan&lt;/code&gt;, Terraform would recalculate the fingerprint of my local files and compare it against what it remembered, and if they did not match it would want to replace the file.&lt;/p&gt;

&lt;p&gt;This worked, but it caused a real problem once I built GitHub Actions. Terraform running in CI would checkout my repository fresh every time, calculate fresh fingerprints, and constantly disagree with what my local machine had calculated the last time I ran apply from my laptop. I will walk through the exact bug that caused later in this post, but the short version is that this whole setup meant Terraform and GitHub Actions were fighting over who actually owned the content of my portfolio files, and that fight needed to end with one clear owner.&lt;/p&gt;

&lt;p&gt;I decided Terraform should stop owning file content entirely. Terraform's job is infrastructure. A CDN caring what my CSS file's bytes look like felt like the wrong tool for that job. So I removed it, step by step, carefully, because doing this wrong would have deleted my live site.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step one, delete the code.&lt;/strong&gt; I removed the entire &lt;code&gt;locals&lt;/code&gt; block and the entire &lt;code&gt;azurerm_storage_blob&lt;/code&gt; resource from &lt;code&gt;main.tf&lt;/code&gt; in the storage module. Nothing else in that file changed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step two, check for references.&lt;/strong&gt; Before running anything, I opened &lt;code&gt;outputs.tf&lt;/code&gt; and &lt;code&gt;variables.tf&lt;/code&gt; in that same module folder and checked whether anything referenced &lt;code&gt;azurerm_storage_blob.portfolio&lt;/code&gt; anywhere. If something had, &lt;code&gt;terraform validate&lt;/code&gt; would fail immediately with an error about an undefined resource, so this was a quick sanity check before moving forward.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step three, and this is the part that actually matters, clean up state without touching the real files.&lt;/strong&gt; Here is the thing I had to understand clearly before doing anything else. Deleting a resource block from a &lt;code&gt;.tf&lt;/code&gt; file only changes what my code says. Terraform's state file, sitting in that separate backend I described earlier, still remembered all seven of those blob resources as things it was responsible for. If I had just run &lt;code&gt;terraform apply&lt;/code&gt; at that point, Terraform would have looked at my config, seen those resources were no longer defined, and concluded I wanted them deleted. It would have gone ahead and deleted my actual live website files.&lt;/p&gt;

&lt;p&gt;The fix is a command called &lt;code&gt;terraform state rm&lt;/code&gt;. This tells Terraform to forget about a resource without touching the real infrastructure at all. I ran it once for every file, from inside &lt;code&gt;infrastructure/environments/production&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform state rm 'module.storage_account.azurerm_storage_blob.portfolio["index.html"]'
terraform state rm 'module.storage_account.azurerm_storage_blob.portfolio["style.css"]'
terraform state rm 'module.storage_account.azurerm_storage_blob.portfolio["script.js"]'
terraform state rm 'module.storage_account.azurerm_storage_blob.portfolio["404.html"]'
terraform state rm 'module.storage_account.azurerm_storage_blob.portfolio["README.md"]'
terraform state rm 'module.storage_account.azurerm_storage_blob.portfolio["assets/taiwo-photo.jpg"]'
terraform state rm 'module.storage_account.azurerm_storage_blob.portfolio["assets/IPADEOLA_OLUWASEUN_TAIWO.pdf"]'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The path inside the quotes matches exactly how the resource was addressed in state, module name, resource type, resource name, and the specific key from the &lt;code&gt;for_each&lt;/code&gt; loop.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step four, confirm nothing destructive is queued up.&lt;/strong&gt; After all seven removals, I ran &lt;code&gt;terraform plan&lt;/code&gt; again. It came back clean, no changes queued for anything, meaning Terraform now genuinely had no memory of those blobs at all and would not try to touch them on the next apply. The actual files sitting in the &lt;code&gt;$web&lt;/code&gt; container were never touched through any of this. They stayed exactly where they were the entire time, because state manipulation only changes what Terraform remembers, never what is actually deployed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmlgvhi8ocfp9sl3halet.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmlgvhi8ocfp9sl3halet.PNG" alt=" " width="800" height="457"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From that point forward, the storage module only manages the storage account and the static website configuration. Nothing else.&lt;/p&gt;

&lt;h2&gt;
  
  
  The deploy workflow that took over file content
&lt;/h2&gt;

&lt;p&gt;With Terraform stepping back, something needed to take over the job of actually getting files into that container. That became &lt;code&gt;deploy.yml&lt;/code&gt;, a completely separate GitHub Actions workflow with nothing to do with Terraform at all.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Deploy Portfolio&lt;/span&gt; 

&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
    &lt;span class="na"&gt;push&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;branches&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;main&lt;/span&gt;
        &lt;span class="na"&gt;paths&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;portfolio/**"&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;deploy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;

        &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;checkout repository&lt;/span&gt;
              &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v4&lt;/span&gt;

            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Azure Login&lt;/span&gt;
              &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;azure/login@v3&lt;/span&gt;
              &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
                &lt;span class="na"&gt;creds&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
                    &lt;span class="s"&gt;{&lt;/span&gt;
                        &lt;span class="s"&gt;"clientId": "${{ secrets.AZURE_CLIENT_ID }}",&lt;/span&gt;
                        &lt;span class="s"&gt;"clientSecret": "${{ secrets.AZURE_CLIENT_SECRET }}",&lt;/span&gt;
                        &lt;span class="s"&gt;"subscriptionId": "${{ secrets.AZURE_SUBSCRIPTION_ID }}",&lt;/span&gt;
                        &lt;span class="s"&gt;"tenantId": "${{ secrets.AZURE_TENANT_ID }}"&lt;/span&gt;
                    &lt;span class="s"&gt;}&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Sync portfolio files to Blob Storage&lt;/span&gt;
              &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
                &lt;span class="s"&gt;az storage blob sync \&lt;/span&gt;
                &lt;span class="s"&gt;--account-name productioncontainerweb \&lt;/span&gt;
                &lt;span class="s"&gt;--container '$web' \&lt;/span&gt;
                &lt;span class="s"&gt;--source portfolio \&lt;/span&gt;
                &lt;span class="s"&gt;--delete-destination true \&lt;/span&gt;

            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Purge Front Door cache&lt;/span&gt;
              &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
                &lt;span class="s"&gt;az config set extension.use_dynamic_install=yes_without_prompt&lt;/span&gt;
                &lt;span class="s"&gt;az config set extension.dynamic_install_allow_preview=true&lt;/span&gt;
                &lt;span class="s"&gt;az afd endpoint purge \&lt;/span&gt;
                &lt;span class="s"&gt;--resource-group static-web-production-rg \&lt;/span&gt;
                &lt;span class="s"&gt;--profile-name portfolio-frontdoor-profile \&lt;/span&gt;
                &lt;span class="s"&gt;--endpoint-name portfolio-frontdoor-endpoint \&lt;/span&gt;
                &lt;span class="s"&gt;--content-paths "/*"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;paths&lt;/code&gt; filter under &lt;code&gt;on.push&lt;/code&gt; is the piece doing the real decoupling work. This workflow only fires when at least one changed file lives inside the &lt;code&gt;portfolio&lt;/code&gt; folder. Touch a Terraform file, this workflow stays completely silent, and my other workflow handles it instead.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhz477kc5aq5axzoumlco.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhz477kc5aq5axzoumlco.PNG" alt=" " width="800" height="397"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;az storage blob sync&lt;/code&gt; is not the first command I reached for. My first version used &lt;code&gt;az storage blob upload-batch&lt;/code&gt;, which just pushes files up one way with no concept of deletion. When I tried adding a &lt;code&gt;--delete-destination&lt;/code&gt; flag to that command, it failed outright with &lt;code&gt;unrecognized arguments&lt;/code&gt;, because that flag genuinely does not exist on &lt;code&gt;upload-batch&lt;/code&gt; at all. Reading the actual Azure CLI reference for storage blob commands is what led me to &lt;code&gt;sync&lt;/code&gt;, which is a completely different command built specifically for this comparison and mirroring behavior, closer in spirit to how &lt;code&gt;rsync&lt;/code&gt; works on Linux. It checks each file's content against what is already sitting in the container, uploads anything new or changed, leaves anything unchanged completely alone, and with &lt;code&gt;--delete-destination true&lt;/code&gt; it also removes any blob whose source file no longer exists locally. That last part means my container is always an exact mirror of my &lt;code&gt;portfolio&lt;/code&gt; folder, which is exactly what I wanted once I understood the tradeoff, meaning an accidental local deletion becomes a real deletion in Azure too, with git history as my only real backup for that scenario.&lt;/p&gt;

&lt;p&gt;The purge step exists because of a caching problem I only discovered by accident. The first time I deployed a CSS change through this workflow, the live site did not update at all, even though the raw storage URL showed the new file correctly. Front Door caches responses at the edge, so even after storage has the new file, visitors can keep getting served an old cached copy for a while. &lt;code&gt;az afd endpoint purge&lt;/code&gt; tells Front Door to throw away its cached copies immediately instead of waiting for them to expire naturally on their own schedule.&lt;/p&gt;

&lt;p&gt;That purge command introduced its own separate problem the first time I ran it in the pipeline. It just hung, no error, no progress, for over four minutes before I gave up and cancelled it. Reading the log carefully showed why. &lt;code&gt;az afd&lt;/code&gt; lives inside a CLI extension called &lt;code&gt;cdn&lt;/code&gt;, and that extension has no stable release, only a preview version. Azure CLI normally asks a confirmation question before installing any new extension automatically, and there is nobody sitting at a keyboard in a GitHub Actions runner to answer that question, so it just sat there waiting on input that would never come.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqscc0c4565u4puac9y2h.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqscc0c4565u4puac9y2h.PNG" alt=" " width="800" height="411"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Fixing it needed two separate config lines, not one, because preview only extensions have an extra gate on top of the normal one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;az config set extension.use_dynamic_install=yes_without_prompt
az config set extension.dynamic_install_allow_preview=true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first line tells the CLI to install any missing extension automatically without asking. The second line specifically allows that automatic install to include preview-only extensions, which &lt;code&gt;cdn&lt;/code&gt; is. Once both were set before the purge command ran, the extension installed silently and the purge finished in seconds.&lt;/p&gt;

&lt;h2&gt;
  
  
  The infrastructure pipeline
&lt;/h2&gt;

&lt;p&gt;Separate from all of that, &lt;code&gt;terraform.yml&lt;/code&gt; handles anything under &lt;code&gt;infrastructure&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Terraform CI&lt;/span&gt;

&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
    &lt;span class="na"&gt;push&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;branches&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;main&lt;/span&gt;

    &lt;span class="na"&gt;pull_request&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;branches&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;main&lt;/span&gt;
&lt;span class="na"&gt;permissions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;id-token&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;write&lt;/span&gt;

&lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;TF_VERSION&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;1.9.0"&lt;/span&gt;
    &lt;span class="na"&gt;WORKING_DIR&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;infrastructure/environments/production"&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;terraform&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;

        &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="na"&gt;ARM_CLIENT_ID&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.AZURE_CLIENT_ID }}&lt;/span&gt;
            &lt;span class="na"&gt;ARM_CLIENT_SECRET&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.AZURE_CLIENT_SECRET }}&lt;/span&gt;
            &lt;span class="na"&gt;ARM_SUBSCRIPTION_ID&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.AZURE_SUBSCRIPTION_ID }}&lt;/span&gt;
            &lt;span class="na"&gt;ARM_TENANT_ID&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.AZURE_TENANT_ID }}&lt;/span&gt;

        &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;checkout repository&lt;/span&gt;
              &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v4&lt;/span&gt;

            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Setup Terraform&lt;/span&gt;
              &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;hashicorp/setup-terraform@v3&lt;/span&gt;
              &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
               &lt;span class="na"&gt;terraform_version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ env.TF_VERSION }}&lt;/span&gt;

            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Azure Login&lt;/span&gt;
              &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;azure/login@v3&lt;/span&gt;
              &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
                &lt;span class="na"&gt;creds&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
                 &lt;span class="s"&gt;{&lt;/span&gt;
                    &lt;span class="s"&gt;"clientId": "${{ secrets.AZURE_CLIENT_ID }}",&lt;/span&gt;
                    &lt;span class="s"&gt;"clientSecret": "${{ secrets.AZURE_CLIENT_SECRET }}",&lt;/span&gt;
                    &lt;span class="s"&gt;"subscriptionId": "${{ secrets.AZURE_SUBSCRIPTION_ID }}",&lt;/span&gt;
                    &lt;span class="s"&gt;"tenantId": "${{ secrets.AZURE_TENANT_ID }}"&lt;/span&gt;
                 &lt;span class="s"&gt;} &lt;/span&gt;

            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Terraform Init&lt;/span&gt;
              &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;terraform init&lt;/span&gt;
              &lt;span class="na"&gt;working-directory&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ env.WORKING_DIR }}&lt;/span&gt;

            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Terraform Format&lt;/span&gt;
              &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;terraform fmt -check -recursive&lt;/span&gt;
              &lt;span class="na"&gt;working-directory&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ env.WORKING_DIR }}&lt;/span&gt;

            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Terraform Validate&lt;/span&gt;
              &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;terraform validate&lt;/span&gt;
              &lt;span class="na"&gt;working-directory&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ env.WORKING_DIR }}&lt;/span&gt;

            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Terraform Plan&lt;/span&gt;
              &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;terraform plan -input=false -out=tfplan&lt;/span&gt;
              &lt;span class="na"&gt;working-directory&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ env.WORKING_DIR }}&lt;/span&gt; 

            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Upload Plan&lt;/span&gt;
              &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/upload-artifact@v4&lt;/span&gt;
              &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
                &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;tfplan&lt;/span&gt;
                &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ env.WORKING_DIR }}&lt;/span&gt;

            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Terraform Apply&lt;/span&gt;
              &lt;span class="na"&gt;working-directory&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ env.WORKING_DIR }}&lt;/span&gt;
              &lt;span class="na"&gt;if &lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;github.event_name == 'push' &amp;amp;&amp;amp; github.ref == 'refs/heads/main'&lt;/span&gt;
              &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;terraform apply -input=false -auto-approve tfplan&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That &lt;code&gt;if&lt;/code&gt; condition on the last step is doing the important safety work. &lt;code&gt;github.event_name == 'push'&lt;/code&gt; is only true on a direct push, never on a pull request. &lt;code&gt;github.ref == 'refs/heads/main'&lt;/code&gt; is only true when the target branch is main. Both have to be true together, so opening a pull request against any branch only ever gets as far as plan, and shows the apply step as skipped rather than run. Nothing about infrastructure changes until code is actually merged.&lt;/p&gt;

&lt;p&gt;Getting the auth working here was its own separate fight. My very first attempt logged into Azure using the &lt;code&gt;azure/login&lt;/code&gt; action and then immediately tried &lt;code&gt;terraform init&lt;/code&gt;, which failed with an error saying authentication using the Azure CLI is only supported as a user, not a service principal. I did not understand this at first. &lt;code&gt;azure/login&lt;/code&gt; had clearly succeeded, so why was Terraform complaining about authentication at all.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmp4kk5q8kt3bgzi3y14y.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmp4kk5q8kt3bgzi3y14y.PNG" alt=" " width="799" height="459"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What I eventually understood is that &lt;code&gt;azure/login&lt;/code&gt; authenticates the runner's Azure CLI session. The &lt;code&gt;azurerm&lt;/code&gt; Terraform provider does not read from that session at all, it does its own completely separate authentication, and logging in as a service principal through the CLI specifically is not a combination that provider knows how to pick up automatically. The fix was giving Terraform its own explicit credentials as environment variables at the job level, which you can see at the top of the job block above. Once &lt;code&gt;ARM_CLIENT_ID&lt;/code&gt; and the others were set there, every step in the job, not just one, had what it needed, and Terraform authenticated completely independently of whatever the CLI login had done.&lt;/p&gt;

&lt;h2&gt;
  
  
  The custom domain and front door modules
&lt;/h2&gt;

&lt;p&gt;Once infrastructure and content were fully separated, the rest of the project was about getting a real domain and HTTPS in front of everything.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_cdn_frontdoor_profile"&lt;/span&gt; &lt;span class="s2"&gt;"fdprofile"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;frontdoor_profile_name&lt;/span&gt;
  &lt;span class="nx"&gt;resource_group_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resource_group_name&lt;/span&gt;
  &lt;span class="nx"&gt;sku_name&lt;/span&gt;            &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sku_name&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_cdn_frontdoor_endpoint"&lt;/span&gt; &lt;span class="s2"&gt;"fdendpoint"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;frontdoor_endpoint_name&lt;/span&gt;
  &lt;span class="nx"&gt;cdn_frontdoor_profile_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_cdn_frontdoor_profile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fdprofile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_cdn_frontdoor_origin_group"&lt;/span&gt; &lt;span class="s2"&gt;"fdoriginggroup"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;frontdoor_origin_group_name&lt;/span&gt;
  &lt;span class="nx"&gt;cdn_frontdoor_profile_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_cdn_frontdoor_profile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fdprofile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
  &lt;span class="nx"&gt;session_affinity_enabled&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;

  &lt;span class="nx"&gt;load_balancing&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;sample_size&lt;/span&gt;                 &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;
    &lt;span class="nx"&gt;successful_samples_required&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;health_probe&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;interval_in_seconds&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;240&lt;/span&gt;
    &lt;span class="nx"&gt;path&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"/"&lt;/span&gt;
    &lt;span class="nx"&gt;protocol&lt;/span&gt;            &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Https"&lt;/span&gt;
    &lt;span class="nx"&gt;request_type&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"HEAD"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_cdn_frontdoor_origin"&lt;/span&gt; &lt;span class="s2"&gt;"fdorigin"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                          &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;frontdoor_origin_name&lt;/span&gt;
  &lt;span class="nx"&gt;cdn_frontdoor_origin_group_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_cdn_frontdoor_origin_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fdoriginggroup&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
  &lt;span class="nx"&gt;enabled&lt;/span&gt;                       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;

  &lt;span class="nx"&gt;certificate_name_check_enabled&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;

  &lt;span class="nx"&gt;host_name&lt;/span&gt;          &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;host_name&lt;/span&gt;
  &lt;span class="nx"&gt;http_port&lt;/span&gt;          &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt;
  &lt;span class="nx"&gt;https_port&lt;/span&gt;         &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;443&lt;/span&gt;
  &lt;span class="nx"&gt;origin_host_header&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;origin_host_header&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_cdn_frontdoor_route"&lt;/span&gt; &lt;span class="s2"&gt;"route"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                          &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;route_name&lt;/span&gt;
  &lt;span class="nx"&gt;cdn_frontdoor_endpoint_id&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_cdn_frontdoor_endpoint&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fdendpoint&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
  &lt;span class="nx"&gt;cdn_frontdoor_origin_group_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_cdn_frontdoor_origin_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fdoriginggroup&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
  &lt;span class="nx"&gt;cdn_frontdoor_origin_ids&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;azurerm_cdn_frontdoor_origin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fdorigin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

  &lt;span class="nx"&gt;cdn_frontdoor_custom_domain_ids&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cdn_frontdoor_custom_domain_ids&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;www_cdn_frontdoor_custom_damain_ids&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

  &lt;span class="nx"&gt;patterns_to_match&lt;/span&gt;   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"/*"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="nx"&gt;supported_protocols&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"Http"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Https"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

  &lt;span class="nx"&gt;cache&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;query_string_caching_behavior&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"IgnoreQueryString"&lt;/span&gt;
    &lt;span class="nx"&gt;compression_enabled&lt;/span&gt;           &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
    &lt;span class="nx"&gt;content_types_to_compress&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"text/html"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"text/javascript"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"text/xml"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"text/css"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A profile is the top level Front Door resource. An endpoint is the actual address traffic arrives at. An origin group and origin describe where Front Door should actually forward that traffic to, which in my case is &lt;code&gt;primary_web_host&lt;/code&gt; from the storage module, passed in as &lt;code&gt;host_name&lt;/code&gt; and &lt;code&gt;origin_host_header&lt;/code&gt;. A route ties all of it together and is also where the custom domains and caching rules attach.&lt;/p&gt;

&lt;p&gt;The custom domain module sits right alongside it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_cdn_frontdoor_custom_domain"&lt;/span&gt; &lt;span class="s2"&gt;"custom_domain"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;frontdoor_custom_domain&lt;/span&gt;
  &lt;span class="nx"&gt;cdn_frontdoor_profile_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cdn_frontdoor_profile_id&lt;/span&gt;
  &lt;span class="nx"&gt;host_name&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;custom_domain_host_name&lt;/span&gt;

  &lt;span class="nx"&gt;tls&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;certificate_type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ManagedCertificate"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_cdn_frontdoor_custom_domain"&lt;/span&gt; &lt;span class="s2"&gt;"www_custom_domain"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"${var.frontdoor_custom_domain}-www"&lt;/span&gt;
  &lt;span class="nx"&gt;cdn_frontdoor_profile_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cdn_frontdoor_profile_id&lt;/span&gt;
  &lt;span class="nx"&gt;host_name&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;www_custom_domain_host_name&lt;/span&gt;

  &lt;span class="nx"&gt;tls&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;certificate_type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ManagedCertificate"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F09bpf3mtsqbt7fclxuve.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F09bpf3mtsqbt7fclxuve.PNG" alt=" " width="799" height="413"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;certificate_type = "ManagedCertificate"&lt;/code&gt; is what tells Azure to issue and renew the TLS certificate automatically, rather than me needing to bring my own. Each custom domain resource also produces a &lt;code&gt;validation_token&lt;/code&gt; output, and that token is the piece I had to manually copy into a TXT record at my domain registrar to prove ownership before Azure would actually issue the certificate.&lt;/p&gt;

&lt;p&gt;My domain is registered at Namecheap, not Azure, and this mattered a lot. I briefly considered creating an Azure DNS zone in Terraform, then realized that only actually does anything if you delegate your domain's nameservers to Azure. Since mine stayed at Namecheap, an Azure DNS zone would have been a completely disconnected setup that the real internet never consults when resolving my domain. So I made a decision early on, keep DNS management entirely at Namecheap, and only use Terraform for the Front Door side of things, manually copying whatever validation tokens and hostnames it outputs into Namecheap's Advanced DNS panel by hand.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flsju1tam29prcem3x2hf.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flsju1tam29prcem3x2hf.PNG" alt=" " width="800" height="374"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Wiring it all together at the root
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt; &lt;span class="s2"&gt;"storage_account"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;source&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"../../modules/storage"&lt;/span&gt;

  &lt;span class="nx"&gt;resource_group_name&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_resource_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prod-rg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
  &lt;span class="nx"&gt;resource_group_location&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_resource_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prod-rg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;
  &lt;span class="nx"&gt;storage_account_name&lt;/span&gt;    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;storage_account_name&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt; &lt;span class="s2"&gt;"frontdoor"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;source&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"../../modules/front-door"&lt;/span&gt;

  &lt;span class="nx"&gt;resource_group_name&lt;/span&gt;                 &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_resource_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prod-rg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
  &lt;span class="nx"&gt;sku_name&lt;/span&gt;                            &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sku_name&lt;/span&gt;
  &lt;span class="nx"&gt;frontdoor_profile_name&lt;/span&gt;              &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;frontdoor_profile_name&lt;/span&gt;
  &lt;span class="nx"&gt;frontdoor_endpoint_name&lt;/span&gt;             &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;frontdoor_endpoint_name&lt;/span&gt;
  &lt;span class="nx"&gt;frontdoor_origin_group_name&lt;/span&gt;         &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;frontdoor_origin_group_name&lt;/span&gt;
  &lt;span class="nx"&gt;frontdoor_origin_name&lt;/span&gt;               &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;frontdoor_origin_name&lt;/span&gt;
  &lt;span class="nx"&gt;host_name&lt;/span&gt;                           &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;storage_account&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;primary_web_host&lt;/span&gt;
  &lt;span class="nx"&gt;origin_host_header&lt;/span&gt;                  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;storage_account&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;primary_web_host&lt;/span&gt;
  &lt;span class="nx"&gt;route_name&lt;/span&gt;                          &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;route_name&lt;/span&gt;
  &lt;span class="nx"&gt;cdn_frontdoor_custom_domain_ids&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;custom-domain&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cdn_frontdoor_custom_domain_ids&lt;/span&gt;
  &lt;span class="nx"&gt;www_cdn_frontdoor_custom_damain_ids&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;custom-domain&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;www_cdn_frontdoor_custom_domain_ids&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt; &lt;span class="s2"&gt;"custom-domain"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;source&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"../../modules/custom-domain"&lt;/span&gt;

  &lt;span class="nx"&gt;frontdoor_custom_domain&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;frontdoor_custom_domain&lt;/span&gt;
  &lt;span class="nx"&gt;cdn_frontdoor_profile_id&lt;/span&gt;    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;frontdoor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cdn_frontdoor_profile_id&lt;/span&gt;
  &lt;span class="nx"&gt;custom_domain_host_name&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;custom_domain_host_name&lt;/span&gt;
  &lt;span class="nx"&gt;www_custom_domain_host_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;www_custom_domain_host_name&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is where you can actually see the dependency chain. The storage module produces &lt;code&gt;primary_web_host&lt;/code&gt;, which feeds into the front door module as the origin. The front door module produces &lt;code&gt;cdn_frontdoor_profile_id&lt;/code&gt;, which the custom domain module needs to attach domains to the right profile. The custom domain module then produces domain IDs that feed back into the front door module's route. Terraform figures out the correct order to create all of this on its own just by tracing these references, I never had to tell it what order to do things in.&lt;/p&gt;

&lt;p&gt;State itself lives in its own backend, completely separate from any of this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;terraform&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;backend&lt;/span&gt; &lt;span class="s2"&gt;"azurerm"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;resource_group_name&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"portfolio-tfstate-rg"&lt;/span&gt;
    &lt;span class="nx"&gt;storage_account_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"portfoliotfstatestorage"&lt;/span&gt;
    &lt;span class="nx"&gt;container_name&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"portfolio-tfstate-container"&lt;/span&gt;
    &lt;span class="nx"&gt;key&lt;/span&gt;                  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"production.tfstate"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fau1sqp75zbsa9rn5iyrm.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fau1sqp75zbsa9rn5iyrm.PNG" alt=" " width="800" height="416"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the exact backend shown in the storage account screenshots earlier, &lt;code&gt;portfoliotfstatestorage&lt;/code&gt;, holding one file, &lt;code&gt;production.tfstate&lt;/code&gt;, inside &lt;code&gt;portfolio-tfstate-container&lt;/code&gt;. Every &lt;code&gt;terraform init&lt;/code&gt;, whether run from my laptop or from a GitHub Actions runner, points at this exact same backend, which is the entire reason local runs and CI runs were ever able to see the same state and conflict with each other in the first place, and also the entire reason the fix for that conflict was possible without me manually copying files around.&lt;/p&gt;

&lt;h2&gt;
  
  
  The bug that genuinely confused me for hours
&lt;/h2&gt;

&lt;p&gt;Once both pipelines were technically working, I noticed something strange in the infrastructure pipeline specifically. Every single run reported that five of my portfolio files needed to be destroyed and recreated. Not changed, destroyed and recreated. Locally, on my own machine, running the exact same plan showed no changes at all. Same code, same backend, same state file, two completely different answers depending on where I ran it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F66bvg0eliz2g0dwrsw9s.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F66bvg0eliz2g0dwrsw9s.PNG" alt=" " width="799" height="413"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I chased the wrong theory first. I added a &lt;code&gt;.gitattributes&lt;/code&gt; file specifying LF line endings and ran &lt;code&gt;git add --renormalize .&lt;/code&gt;, expecting that to fix things. It found nothing to fix, because my repository's actual Git index already stored everything as LF. That theory was wrong, but ruling it out cleanly is what pointed me toward looking one layer deeper.&lt;/p&gt;

&lt;p&gt;The real answer was a Windows specific Git setting called &lt;code&gt;core.autocrlf&lt;/code&gt;, which silently converts files back to CRLF line endings every time they get checked out locally, even though the repository itself stores LF. So my local disk had CRLF versions of my files sitting there this whole time, while GitHub's Linux runners checked out the real LF versions straight from the repository, since Linux never does that conversion at all.&lt;/p&gt;

&lt;p&gt;This mattered because Terraform reads whatever bytes are physically sitting on disk when it calculates a file's content hash. My local machine had been hashing CRLF bytes the entire time, and that CRLF based hash is what got saved into state the very first time I ran apply from my laptop. GitHub's runner was hashing the real LF bytes every single run, which never matched what state remembered, hence the constant plan wanting to replace them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git config core.autocrlf false
git rm -r --cached .
git reset --hard HEAD
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first line stops Windows from doing that conversion for this repository going forward. The second and third lines force a completely fresh checkout of every file straight from what the repository actually stores, which is LF, overwriting whatever CRLF versions were sitting on my disk before. After running these, my local &lt;code&gt;terraform plan&lt;/code&gt; finally showed the exact same five replacements CI had been showing the whole time, meaning local and CI were finally looking at the same bytes and agreeing with each other, they just both disagreed with the old CRLF era state. I ran &lt;code&gt;terraform apply&lt;/code&gt; once locally to resync state to the correct LF based hashes, and from that point on both environments matched cleanly.&lt;/p&gt;

&lt;p&gt;This whole investigation is also part of why I eventually decided Terraform should stop tracking blob content at all. Even after fixing the line ending issue, having two systems both capable of writing to the same files felt fragile. Removing Terraform's ownership of content entirely, the way I described earlier in this post, removed this entire category of bug permanently rather than just patching this one instance of it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would tell someone starting this themselves
&lt;/h2&gt;

&lt;p&gt;Read the actual error message slowly before searching for it. In almost every bug in this post, the real cause was sitting right there in the log, just not in the first line I looked at. The CRLF issue only made sense once I stopped assuming it was a Git problem and started asking what Terraform was actually reading off disk at the moment it calculated a hash.&lt;/p&gt;

&lt;p&gt;Run things locally specifically to compare against what CI is doing. The moment I ran &lt;code&gt;terraform plan&lt;/code&gt; on my own machine and got a different answer than CI gave me, that difference became the actual clue that cracked the whole line ending mystery open. If both had shown the same thing, I would have had no way to know where to even start looking.&lt;/p&gt;

&lt;p&gt;And genuinely, read the official docs before searching for someone else's blog post about your exact error. The Terraform registry page for &lt;code&gt;azurerm_cdn_frontdoor_route&lt;/code&gt; told me exactly what &lt;code&gt;cdn_frontdoor_custom_domain_ids&lt;/code&gt; expected as a type. Microsoft Learn's Azure CLI reference told me exactly what flags &lt;code&gt;az storage blob sync&lt;/code&gt; actually supports versus what &lt;code&gt;upload-batch&lt;/code&gt; supports. Almost every fix in this post came from one of those two places, not from a tutorial.&lt;/p&gt;

&lt;p&gt;If you build something similar, or hit your own version of any of these bugs, I would genuinely like to hear about it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Repo:&lt;/strong&gt; &lt;a href="https://github.com/highpee1991/azure-portfolio-platform" rel="noopener noreferrer"&gt;https://github.com/highpee1991/azure-portfolio-platform&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Live site:&lt;/strong&gt; &lt;a href="https://taiwoipadeola.space" rel="noopener noreferrer"&gt;https://taiwoipadeola.space&lt;/a&gt;&lt;/p&gt;

</description>
      <category>terraform</category>
      <category>azure</category>
      <category>githubactions</category>
      <category>devops</category>
    </item>
    <item>
      <title>Building a Terraform CI/CD Pipeline With GitHub Actions (And Debugging Every Single Thing That Broke)</title>
      <dc:creator>Ipadeola Taiwo</dc:creator>
      <pubDate>Tue, 11 Aug 2026 09:03:45 +0000</pubDate>
      <link>https://dev.to/highpee1991/building-a-terraform-cicd-pipeline-with-github-actions-and-debugging-every-single-thing-that-15bf</link>
      <guid>https://dev.to/highpee1991/building-a-terraform-cicd-pipeline-with-github-actions-and-debugging-every-single-thing-that-15bf</guid>
      <description>&lt;p&gt;After getting comfortable with Terraform modules across multiple environments, I gave myself a new scenario. Imagine the CTO of the company sends down a new rule: no engineer runs terraform apply manually against production ever again. Every infrastructure change goes through a pull request. A pipeline validates it, plans it, and only applies once that change is actually merged to main. If something is wrong, it fails inside the pipeline, not in front of customers.&lt;/p&gt;

&lt;p&gt;This post is the build of that pipeline, and honestly it turned into one of the most instructive things I have done, mostly because of how many small, sharp mistakes I made along the way and had to actually understand before I could fix them. If you are trying to build your first real CI/CD pipeline for Terraform, I want this to save you some of the pain.&lt;/p&gt;

&lt;h2&gt;
  
  
  The plan
&lt;/h2&gt;

&lt;p&gt;Two jobs matter most here. A validate and plan job that runs on every pull request, and an apply job that only runs after code lands on main. I reused the module and one environment, payments, from an earlier project of mine, copied into a fresh repo built specifically for this pipeline.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform-cicd-pipeline/
├── .github/workflows/terraform.yml
├── environments/payments/
│   ├── providers.tf
│   ├── main.tf
│   └── terraform.tfvars
└── modules/infrastructure/
    ├── main.tf
    ├── variables.tf
    ├── outputs.tf
    └── cloud-init.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Setting up the backend and authentication
&lt;/h2&gt;

&lt;p&gt;Same manual backend pattern as always, since Terraform cannot create the storage it depends on.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az group create &lt;span class="nt"&gt;--name&lt;/span&gt; ci-cd-pipeline-backend-rg &lt;span class="nt"&gt;--location&lt;/span&gt; eastus
az storage account create &lt;span class="nt"&gt;--name&lt;/span&gt; cicdpipestorageacc &lt;span class="nt"&gt;--resource-group&lt;/span&gt; ci-cd-pipeline-backend-rg &lt;span class="nt"&gt;--location&lt;/span&gt; eastus &lt;span class="nt"&gt;--sku&lt;/span&gt; Standard_LRS &lt;span class="nt"&gt;--kind&lt;/span&gt; StorageV2
az storage container create &lt;span class="nt"&gt;--name&lt;/span&gt; ci-cd-container &lt;span class="nt"&gt;--account-name&lt;/span&gt; cicdpipestorageacc &lt;span class="nt"&gt;--auth-mode&lt;/span&gt; login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;For authentication, a pipeline should never use a personal login. It needs its own identity, a Service Principal, scoped to what it actually needs to do.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;MSYS_NO_PATHCONV&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1 az ad sp create-for-rbac &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--name&lt;/span&gt; &lt;span class="s2"&gt;"github-actions-terraform"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--role&lt;/span&gt; Contributor &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--scopes&lt;/span&gt; /subscriptions/&amp;lt;subscription-id&amp;gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--sdk-auth&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;That MSYS_NO_PATHCONV bit came from a genuinely confusing early mistake. On Git Bash for Windows, any argument starting with a single slash gets silently rewritten into a Windows filesystem path before Azure CLI even sees it. So /subscriptions/xxxx quietly became C:/Program Files/Git/subscriptions/xxxx, and Azure returned a MissingSubscription error that had nothing obviously to do with slashes. That one environment variable prefix tells Git Bash to leave this specific command alone.&lt;/p&gt;

&lt;p&gt;The four values that command outputs go into GitHub as repository secrets.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcyk4853qnalt0rqksiqm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcyk4853qnalt0rqksiqm.png" alt=" " width="800" height="421"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Two different kinds of authentication living in the same workflow
&lt;/h2&gt;

&lt;p&gt;This tripped me up conceptually before it tripped me up technically. There are two separate things reading those same four secrets, doing two different jobs.&lt;/p&gt;

&lt;p&gt;The azure/login action logs the Azure CLI itself into the runner. Useful if any step needs to run a plain az command.&lt;/p&gt;

&lt;p&gt;Separately, Terraform's own provider and backend need ARM_CLIENT_ID, ARM_CLIENT_SECRET, ARM_SUBSCRIPTION_ID, and ARM_TENANT_ID set as environment variables. Terraform does not automatically inherit whatever the Azure CLI is logged in as. Without these four set explicitly, terraform init fails with a very specific error: authenticating using the Azure CLI is only supported as a user, not a service principal. Both pieces are needed, and neither replaces the other.&lt;/p&gt;
&lt;h2&gt;
  
  
  The workflow file, and everything wrong with my first draft
&lt;/h2&gt;

&lt;p&gt;I want to be honest about how many small mistakes stacked up in the first version of this file, because I think seeing the actual failures is more useful than seeing a clean finished workflow with no context.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgsk0s0s2o41c80akocut.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgsk0s0s2o41c80akocut.png" alt=" " width="800" height="411"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The very first error was a missing comma inside the JSON block that azure/login reads. Plain JSON needs a comma after every property except the last one, and I had none. GitHub Actions caught this before the workflow even ran, which is honestly the best possible time for it to fail.&lt;/p&gt;

&lt;p&gt;Other things I found and fixed one at a time across several pushes: capitalized Terraform subcommands like terraform Init that Terraform's CLI does not recognize since subcommands are lowercase only, a case mismatch between a job named Terraform-validate and another job's needs field referencing terraform-validate lowercase, since job IDs are case sensitive, and a typo in an action name, acttions/download-artifact instead of actions, which fails to resolve entirely since GitHub reads that as a literal, nonexistent repository.&lt;/p&gt;
&lt;h2&gt;
  
  
  The six minute silent hang
&lt;/h2&gt;

&lt;p&gt;This one was the strangest to diagnose because there was no error at all, just a plan step that sat there doing nothing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftuj1da2f19jw2e1a8nfh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftuj1da2f19jw2e1a8nfh.png" alt=" " width="800" height="394"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The cause was a typo in one of my TF_VAR environment variables, admin_usename instead of admin_username. Since that variable had deliberately been given no default value, based on a rule I had already learned about identity related variables never defaulting silently, Terraform tried to do the right thing and ask for a value interactively. On my own terminal that would show a prompt I could just answer. On a GitHub Actions runner, there is no one there to answer it, so it just waits, forever, with zero error output.&lt;/p&gt;

&lt;p&gt;The fix was adding -input=false to both the plan and apply commands. This tells Terraform never to wait for interactive input, ever, and instead fail immediately and loudly if something required is missing. That single flag turned an invisible hang into an instant, readable error the next time a typo happened.&lt;/p&gt;
&lt;h2&gt;
  
  
  Cancelling that hung run left a real problem behind
&lt;/h2&gt;

&lt;p&gt;Cancelling a stuck workflow does not run Terraform's normal cleanup. It just kills the process. Whatever lock Terraform had acquired on the state file right before it started waiting for input never got released.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fs02mdtkd2s4ezml870qs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fs02mdtkd2s4ezml870qs.png" alt=" " width="800" height="397"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The important thing to understand here is that the lock lives on the actual blob in Azure Storage, not inside GitHub Actions itself. So clearing it does not require anything special about CI, it just requires a client authenticated to the same backend.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform force-unlock &amp;lt;lock-id&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Run locally, against the same backend config, and the lock clears the same way it would if the stuck operation had come from a teammate's laptop instead of a runner.&lt;/p&gt;
&lt;h2&gt;
  
  
  A file that only existed on my machine
&lt;/h2&gt;

&lt;p&gt;Once the workflow started actually running plan correctly, it immediately failed on missing required variables I definitely had values for. address_space, subnet_prefix, environment, backend_state_key, all of them living happily in my local terraform.tfvars.&lt;/p&gt;

&lt;p&gt;The lesson here is one of the most important things to understand about any CI system. GitHub Actions runs on a completely fresh, disposable machine that has never seen your laptop and never will. It only ever sees what is actually committed and pushed to the repository. My terraform.tfvars was sitting quietly excluded by a default *.tfvars rule in .gitignore, so it existed locally and nowhere else. Since nothing in that particular file was sensitive, just config values, the fix was removing that line from .gitignore and actually committing the file.&lt;/p&gt;
&lt;h2&gt;
  
  
  SSH keys, and the difference between a path and content
&lt;/h2&gt;

&lt;p&gt;The VM needed an SSH public key, and my module originally read it with file(pathexpand(var.ssh_public_key_path)), the same approach that worked fine on my own machine. It cannot work in CI. That function reads a real file from disk at plan time, and the disposable runner has no ssh folder with my keys in it at all.&lt;/p&gt;

&lt;p&gt;The fix was changing the module to accept the key's actual text content as a variable, rather than a path to read. The public key itself is safe to store as a GitHub secret and pass in directly as TF_VAR_ssh_public_key, no file reading involved.&lt;/p&gt;
&lt;h2&gt;
  
  
  Getting the pipeline to actually deploy a live website
&lt;/h2&gt;

&lt;p&gt;For the VM's own provisioning, update, upgrade, install nginx, clone a portfolio site, I used cloud-init rather than having the pipeline SSH in after the fact. Cloud-init runs automatically the moment the VM boots, which keeps the whole thing declarative instead of needing a private key sitting in my pipeline's secrets.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;#cloud-config&lt;/span&gt;
&lt;span class="na"&gt;package_update&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="na"&gt;package_upgrade&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;

&lt;span class="na"&gt;packages&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;nginx&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;git&lt;/span&gt;

&lt;span class="na"&gt;runcmd&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;rm -rf /var/www/html&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;git clone https://github.com/highpee1991/cloud-devops-portfolio-repo.git /var/www/html&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;systemctl enable nginx&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;systemctl restart nginx&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Two small but completely blocking typos hid in here for a while. First, my header line read hash cloud config with a space, which cloud-init reads as an ordinary comment rather than recognizing the file as a real cloud-config document at all, so it silently did nothing. Second, once that was fixed, I had package-update and package-upgrade with hyphens. Cloud-init's real key names use underscores. That mismatch failed schema validation and quietly skipped the whole final provisioning stage, no nginx, no clone, with almost nothing useful in the general log to point at why.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Furesbfugkm2dkjs6e17u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Furesbfugkm2dkjs6e17u.png" alt=" " width="799" height="439"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Tracing an invisible failure all the way to its root cause
&lt;/h2&gt;

&lt;p&gt;Even after fixing both typos, the site still would not load. This is the part I am most proud of in this whole project, because instead of stopping at the first plausible explanation, I actually traced the failure the whole way down.&lt;/p&gt;

&lt;p&gt;Browser, to nginx, to an empty var www html folder, to no git repository present, to a cloud-init schema error, to a systemd failure, to the actual root cause: the Linux kernel's OOM killer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2mfszg079a6cbrs8tv1z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2mfszg079a6cbrs8tv1z.png" alt=" " width="800" height="649"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;My VM size, Standard B1ls, only has about 393 megabytes of RAM. Asking it to run a full apt upgrade and install two packages unattended, all in one shot, was simply too much. The kernel killed the heaviest process mid operation to protect the system, which is exactly why cloud-init reported finishing with no obvious errors while accomplishing nothing. Sizing up to Standard B2s, with about 3.8 gigabytes of RAM, gave it enough headroom to actually finish the job.&lt;/p&gt;
&lt;h2&gt;
  
  
  It finally worked
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq7l4e2s8fdx775mqspc0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq7l4e2s8fdx775mqspc0.png" alt=" " width="800" height="463"&gt;&lt;/a&gt;&lt;br&gt;
A pipeline that validates, plans, and applies entirely through pull requests and merges, provisioning a real VM that installs its own software and serves a real website, with zero manual terraform apply anywhere in the loop. I tore the infrastructure down after confirming it worked, since there was no reason to keep it running once the point was proven.&lt;/p&gt;
&lt;h2&gt;
  
  
  What actually stuck with me
&lt;/h2&gt;

&lt;p&gt;Almost every failure in this build came down to the same underlying idea in different clothes. A CI runner is a stranger to your machine. It cannot see your files, your SSH keys, your local Azure login, or anything you have not explicitly given it through a commit or a secret. Once that idea genuinely clicked, most of these bugs stopped being mysterious and started being predictable.&lt;/p&gt;

&lt;p&gt;If you want to see the full pipeline, including the workflow file and the cloud-init script:&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/highpee1991" rel="noopener noreferrer"&gt;
        highpee1991
      &lt;/a&gt; / &lt;a href="https://github.com/highpee1991/terraform-cicd-pipeline" rel="noopener noreferrer"&gt;
        terraform-cicd-pipeline
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;terraform-cicd-pipeline — Runbook&lt;/h1&gt;
&lt;/div&gt;

&lt;p&gt;A GitHub Actions pipeline that manages Azure infrastructure through Terraform, so no engineer ever runs &lt;code&gt;terraform apply&lt;/code&gt; by hand against production. Every infrastructure change goes through a pull request; the pipeline validates and plans it, and only applies once that change is merged to &lt;code&gt;main&lt;/code&gt;.&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Scenario&lt;/h2&gt;
&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;No engineer manually runs &lt;code&gt;terraform apply&lt;/code&gt; in production ever again. Every infrastructure change goes through a pull request. The pipeline validates it, posts the plan as a comment, and applies it only when the PR is merged to main. If it fails, it fails in the pipeline, not in production.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Repository layout&lt;/h2&gt;
&lt;/div&gt;

&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;
&lt;pre class="notranslate"&gt;&lt;code&gt;terraform-cicd-pipeline/
├── .github/
│   └── workflows/
│       └── terraform.yml
├── environments/
│   └── payments/
│       ├── providers.tf      # backend + provider blocks
│       ├── main.tf           # module call + variable declarations + outputs
│       └── terraform.tfvars  # non-sensitive config values
└── modules/
    └── infrastructure/
        ├── main.tf           # resource&lt;/code&gt;&lt;/pre&gt;…&lt;/div&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/highpee1991/terraform-cicd-pipeline" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;If you are building something similar and hit a wall, drop a comment, happy to help however I can.&lt;/p&gt;

</description>
      <category>terraform</category>
      <category>azure</category>
      <category>devops</category>
      <category>githubactions</category>
    </item>
    <item>
      <title>Refactoring Terraform Infrastructure Into Reusable Modules (Multi-Environment, One Codebase)</title>
      <dc:creator>Ipadeola Taiwo</dc:creator>
      <pubDate>Thu, 06 Aug 2026 11:12:13 +0000</pubDate>
      <link>https://dev.to/highpee1991/refactoring-terraform-infrastructure-into-reusable-modules-multi-environment-one-codebase-39a</link>
      <guid>https://dev.to/highpee1991/refactoring-terraform-infrastructure-into-reusable-modules-multi-environment-one-codebase-39a</guid>
      <description>&lt;p&gt;After building out the first version of my Azure infrastructure with Terraform, I ran into the problem every team eventually runs into. I needed the same infrastructure in three different places, a payments environment, an analytics environment, and a platform environment, and my first instinct was to just copy the same main.tf into three folders and tweak a few values.&lt;/p&gt;

&lt;p&gt;That works until it doesn't. The moment you need to change one thing, add a tag, fix a rule, adjust a size, you're now updating it in three places by hand. Forget one, and you've got three environments quietly drifting apart from each other. This post is how I refactored that same infrastructure into a single reusable module that all three environments call, what broke along the way, and the two real recovery situations I had to work through when things genuinely went wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  The shape of it
&lt;/h2&gt;

&lt;p&gt;Instead of one flat project, this became two things. A module, which holds the actual resource definitions written once. And three environments, which each call that module with their own values.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fsd2t5zave9qmlc7ufurt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fsd2t5zave9qmlc7ufurt.png" alt=" " width="690" height="573"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The module lives in &lt;code&gt;modules/infrastructure/&lt;/code&gt; with a &lt;code&gt;main.tf&lt;/code&gt;, &lt;code&gt;variables.tf&lt;/code&gt;, and &lt;code&gt;outputs.tf&lt;/code&gt;, same idea as before just without hardcoding anything specific to one environment. Each environment folder under &lt;code&gt;environments/&lt;/code&gt; gets its own &lt;code&gt;providers.tf&lt;/code&gt;, &lt;code&gt;main.tf&lt;/code&gt;, and &lt;code&gt;terraform.tfvars&lt;/code&gt;. The environment's &lt;code&gt;main.tf&lt;/code&gt; doesn't define any resources itself anymore, it just calls the module and passes in values.&lt;/p&gt;

&lt;p&gt;Here's the flow, end to end:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmn4q65pm2utgifc3dowb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmn4q65pm2utgifc3dowb.png" alt=" " width="578" height="624"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You run &lt;code&gt;terraform apply&lt;/code&gt; inside an environment folder. That folder's &lt;code&gt;providers.tf&lt;/code&gt; and &lt;code&gt;terraform.tfvars&lt;/code&gt; feed into a module call, which reaches into &lt;code&gt;modules/infrastructure&lt;/code&gt; where the resource group, virtual network, subnet, NSG, public IP, network interface, and VM are actually defined. Terraform hands the final plan to Azure ARM, and that's what creates the real infrastructure.&lt;/p&gt;

&lt;h2&gt;
  
  
  One backend, three isolated state files
&lt;/h2&gt;

&lt;p&gt;The backend gets created manually, same as before, since Terraform can't create the backend it depends on:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az group create &lt;span class="nt"&gt;--name&lt;/span&gt; backend-rg &lt;span class="nt"&gt;--location&lt;/span&gt; eastus
az storage account create &lt;span class="nt"&gt;--name&lt;/span&gt; backendstorageaccs &lt;span class="nt"&gt;--resource-group&lt;/span&gt; backend-rg &lt;span class="nt"&gt;--location&lt;/span&gt; eastus &lt;span class="nt"&gt;--sku&lt;/span&gt; Standard_LRS &lt;span class="nt"&gt;--kind&lt;/span&gt; StorageV2
az storage container create &lt;span class="nt"&gt;--name&lt;/span&gt; backend-container &lt;span class="nt"&gt;--account-name&lt;/span&gt; backendstorageaccs &lt;span class="nt"&gt;--auth-mode&lt;/span&gt; login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important decision here was not sharing one state file across all three environments. If payments, analytics, and platform all wrote to the same tfstate, a mistake in one could accidentally touch the other two. So each environment points at the same storage account and container, but a different key.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6kypal8h9yjwsvtpwogo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6kypal8h9yjwsvtpwogo.png" alt=" " width="589" height="185"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;backend&lt;/span&gt; &lt;span class="s2"&gt;"azurerm"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;resource_group_name&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"backend-rg"&lt;/span&gt;
  &lt;span class="nx"&gt;storage_account_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"backendstorageaccs"&lt;/span&gt;
  &lt;span class="nx"&gt;container_name&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"backend-container"&lt;/span&gt;
  &lt;span class="nx"&gt;key&lt;/span&gt;                    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"payments.tfstate"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzlo8ztbm6x5xo9w9a6ln.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzlo8ztbm6x5xo9w9a6ln.png" alt=" " width="800" height="477"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Small note on structure. I originally planned separate &lt;code&gt;backend.tf&lt;/code&gt; and &lt;code&gt;provider.tf&lt;/code&gt; files per environment, but ended up combining both into one &lt;code&gt;providers.tf&lt;/code&gt; instead. Functionally identical, Terraform doesn't care which file a block lives in, it reads every &lt;code&gt;.tf&lt;/code&gt; file in the folder as one combined config. Just a naming choice.&lt;/p&gt;

&lt;h2&gt;
  
  
  The design question that actually mattered
&lt;/h2&gt;

&lt;p&gt;Before writing the module's variables, I got stuck on something that seemed small but wasn't. Some variables had default values, some didn't, and I couldn't articulate why.&lt;/p&gt;

&lt;p&gt;The answer turned out to be a real principle, not just a style preference. Any variable that's environment specific, security related, or identity related should never have a default. If &lt;code&gt;admin_username&lt;/code&gt; silently defaults to someone else's name because a new engineer forgot to set it, that new engineer can't log into their own server, and the person whose name it defaulted to now has access to a server they didn't know existed. If &lt;code&gt;project_name&lt;/code&gt; silently defaults, someone on the analytics team could end up deploying into the payments resource group. If &lt;code&gt;environment&lt;/code&gt; silently defaults, dev work could land in what's meant to be staging.&lt;/p&gt;

&lt;p&gt;Compare that to something like &lt;code&gt;location&lt;/code&gt; or &lt;code&gt;vm_size&lt;/code&gt;. If those default to the wrong value, you notice immediately, the resource shows up in the wrong region or the VM is a bit underpowered, and you just fix it. No security incident, no confusion about who owns what.&lt;/p&gt;

&lt;p&gt;So the rule I landed on: infrastructure should fail loudly with a clear error rather than succeed silently with the wrong value. Anything where a wrong guess could hurt someone gets no default, full stop.&lt;/p&gt;

&lt;h2&gt;
  
  
  A copy-paste bug, twice
&lt;/h2&gt;

&lt;p&gt;Copying the module call from one environment to the next introduced two separate bugs, both worth mentioning because they're the kind of thing that's easy to miss and easy to fix once you see them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcze9bbok1qin7xeatub6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcze9bbok1qin7xeatub6.png" alt=" " width="800" height="481"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First, a line assigning the wrong variable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;backend_storage_account_name&lt;/span&gt; &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;backend_container_name&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Right variable name on the left, wrong one on the right. Small thing to catch, easy to miss when everything else validates fine.&lt;/p&gt;

&lt;p&gt;Second, one environment's module call was literally named differently from the other two:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt; &lt;span class="s2"&gt;"enviroment"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;against&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt; &lt;span class="s2"&gt;"infrastructure"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in the other two. Both work, Terraform lets you name a module call whatever you want locally, but having one out of three be inconsistent is exactly the kind of thing that makes a shared codebase harder to reason about later. Renamed it to match, reran &lt;code&gt;terraform init&lt;/code&gt;, and it fell in line.&lt;/p&gt;

&lt;h2&gt;
  
  
  Applying all three
&lt;/h2&gt;

&lt;p&gt;Once the module and all three environments were consistent, applying each one followed the same pattern: &lt;code&gt;terraform validate&lt;/code&gt;, &lt;code&gt;terraform plan&lt;/code&gt;, &lt;code&gt;terraform apply&lt;/code&gt;. Ten resources each, matching what the earlier single-project version had, just parameterized this time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq3l0bq81cwbmmyhd4glc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq3l0bq81cwbmmyhd4glc.png" alt=" " width="800" height="419"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each environment ended up SSH accessible on its own public IP once applied.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ft6sne0suq1jbl08h3xfv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ft6sne0suq1jbl08h3xfv.png" alt=" " width="800" height="487"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And in the portal, all three environments plus the backend show up as separate resource groups, each with their own network interface, NSG, public IP, VM, disk, and virtual network.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7h4hlvdq0ywqk80zxgzw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7h4hlvdq0ywqk80zxgzw.png" alt=" " width="800" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  When the network actually dropped
&lt;/h2&gt;

&lt;p&gt;This is the part worth reading carefully if you're doing anything with a remote backend, because it will happen to you eventually.&lt;/p&gt;

&lt;p&gt;Midway through applying the &lt;code&gt;analytics&lt;/code&gt; environment, my network dropped for a few minutes right as Terraform finished creating the VM and tried to write the final state back to the storage account. The apply itself succeeded, every resource was really created, but the state write failed with a DNS lookup error, since my machine briefly couldn't resolve the storage account's hostname.&lt;/p&gt;

&lt;p&gt;Because it couldn't reach the backend, Terraform did the safe thing. It saved the correct, complete state to a local file called &lt;code&gt;errored.tfstate&lt;/code&gt; and told me exactly what to do next. It also tried to release its lock on the remote state and failed at that too, since the same connection was down, leaving an orphaned lock behind.&lt;/p&gt;

&lt;p&gt;Every apply after that failed with "state blob is already locked," which looked alarming but wasn't actually a conflict with anyone else, just a lock nobody could release because the connection that was supposed to release it was gone. Recovery was three commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform force-unlock &amp;lt;lock-id&amp;gt;
terraform state push errored.tfstate
terraform plan
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The force-unlock cleared the stuck lock. Pushing &lt;code&gt;errored.tfstate&lt;/code&gt; uploaded the correct, complete state that Terraform had already built locally. The follow-up plan came back with "No changes, your infrastructure matches the configuration," confirming everything reconciled correctly. Nothing was lost, nothing had to be rebuilt, and the VM that got created during the outage was sitting there working the whole time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fp3qao94iha23h5xjbmr0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fp3qao94iha23h5xjbmr0.png" alt=" " width="800" height="462"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Tearing it all down
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;terraform destroy&lt;/code&gt; on each environment removed exactly what that environment's module call had created, in the correct dependency order. One of the three hit a second, smaller network hiccup, this time a connection reset while deleting the VM's managed disk mid-teardown. No stuck lock this time, just a straightforward second &lt;code&gt;terraform destroy&lt;/code&gt; picked up exactly where the first one left off and finished the job.&lt;/p&gt;

&lt;p&gt;One thing worth knowing: &lt;code&gt;terraform destroy&lt;/code&gt; only removes what Terraform manages. It doesn't touch the backend itself, since that was created manually and Terraform was never given authority over it. After destroying all three environments, the three state files were still sitting in the container, just now describing empty environments. Removing the backend for good meant one more manual step:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az group delete &lt;span class="nt"&gt;--name&lt;/span&gt; backend-rg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That took the resource group, the storage account, the container, and every state file inside it down in one shot.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmm99erwjv8o1q3iehz51.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmm99erwjv8o1q3iehz51.png" alt=" " width="800" height="410"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What this actually bought me
&lt;/h2&gt;

&lt;p&gt;Going from one flat project to a module plus three environments wasn't just about avoiding copy and paste. It meant a single change to &lt;code&gt;modules/infrastructure/main.tf&lt;/code&gt; would ripple out to payments, analytics, and platform automatically, instead of needing to be applied three separate times by hand and risking one getting missed. It also meant each environment's blast radius was contained, its own resource group, its own state file, its own lock, so a mistake in one couldn't reach into another.&lt;/p&gt;

&lt;p&gt;If you want to see the actual code, including the module and all three environments:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/highpee1991/terraform-enterprise" rel="noopener noreferrer"&gt;https://github.com/highpee1991/terraform-enterprise&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you're building something similar and want to talk through the module structure or the state recovery, drop a comment.&lt;/p&gt;

</description>
      <category>terraform</category>
      <category>azure</category>
      <category>devops</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Building Enterprise Azure Infrastructure With Terraform and Remote State</title>
      <dc:creator>Ipadeola Taiwo</dc:creator>
      <pubDate>Sat, 01 Aug 2026 05:58:12 +0000</pubDate>
      <link>https://dev.to/highpee1991/building-enterprise-azure-infrastructure-with-terraform-and-remote-state-5bm2</link>
      <guid>https://dev.to/highpee1991/building-enterprise-azure-infrastructure-with-terraform-and-remote-state-5bm2</guid>
      <description>&lt;p&gt;A few weeks ago I set myself a scenario. Pretend I joined a company called Big 8 Integrated LLC as a Cloud Engineer. The company has decided that from now on, all infrastructure gets managed as code with Terraform. And because more than one engineer touches the infrastructure, the Terraform state can never sit on anyone's laptop. It has to live somewhere shared, somewhere that locks itself while someone is working, so two people can't step on each other's changes.&lt;/p&gt;

&lt;p&gt;That one requirement, state must never be local, ended up teaching me more than any tutorial I had read before it. This post is that journey, from an empty Azure subscription to a live VM serving a website, written the way it actually happened, mistakes included. If you're new to Terraform and Azure, you should be able to follow this from scratch and end up with the same thing.&lt;/p&gt;

&lt;h2&gt;
  
  
  The plan
&lt;/h2&gt;

&lt;p&gt;Before touching any code, I sketched out what I was building.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9axgv5lxpys76n2wo1ii.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9axgv5lxpys76n2wo1ii.png" alt=" " width="258" height="505"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Two resource groups. One holds the backend, just a storage account with a blob container where the Terraform state file lives. The other holds the actual workload, a virtual network, a subnet, a network security group, a public IP, and a Linux VM. The backend group gets created by hand. Everything in the second group gets created by Terraform.&lt;/p&gt;

&lt;p&gt;Why two groups, and why create the first one by hand? Because Terraform can't create the backend it depends on. It needs somewhere to store its state before it can even start managing anything, so that first piece has to exist before Terraform ever runs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up the backend manually
&lt;/h2&gt;

&lt;p&gt;I already had the Azure CLI installed and was logged in, which I confirmed with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az account show
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then I created the resource group for the backend:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az group create &lt;span class="nt"&gt;--name&lt;/span&gt; big8-rg &lt;span class="nt"&gt;--location&lt;/span&gt; eastus
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That one worked first try. The storage account did not.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az storage account create &lt;span class="nt"&gt;--name&lt;/span&gt; big8-backend-store &lt;span class="nt"&gt;--resource-group&lt;/span&gt; big8-rg &lt;span class="nt"&gt;--location&lt;/span&gt; eastus &lt;span class="nt"&gt;--sku&lt;/span&gt; standard_LRS &lt;span class="nt"&gt;--kind&lt;/span&gt; storageV2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkc4z1y4ytkowitswbzhs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkc4z1y4ytkowitswbzhs.png" alt=" " width="797" height="119"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Azure rejected it. Storage account names can't have dashes, or any special characters at all. Lowercase letters and numbers only, between 3 and 24 characters. Small thing, but it's the kind of rule you only learn by hitting it. I dropped the dashes and tried again with &lt;code&gt;big8backendstore&lt;/code&gt;, and it went through.&lt;/p&gt;

&lt;p&gt;Last piece of the manual setup, the blob container that would actually hold the state file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az storage container create &lt;span class="nt"&gt;--name&lt;/span&gt; bigcontainer &lt;span class="nt"&gt;--account-name&lt;/span&gt; big8backendstore &lt;span class="nt"&gt;--auth-mode&lt;/span&gt; login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fn6c4qf4b11fxp6ab06ds.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fn6c4qf4b11fxp6ab06ds.png" alt=" " width="800" height="393"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmq4qis62l46ce1i2zjkp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmq4qis62l46ce1i2zjkp.png" alt=" " width="799" height="363"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At this point I had a resource group, a storage account, and an empty container. No state file yet. That part comes automatically the first time Terraform runs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Writing the Terraform config
&lt;/h2&gt;

&lt;p&gt;I set up a &lt;code&gt;providers.tf&lt;/code&gt; file with the provider block and the backend block pointing at what I'd just created by hand.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3u70q2n3bz1a3b6yf8v1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3u70q2n3bz1a3b6yf8v1.png" alt=" " width="800" height="282"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;terraform&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;required_providers&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;azurerm&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;source&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"hashicorp/azurerm"&lt;/span&gt;
      &lt;span class="nx"&gt;version&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"~&amp;gt; 4.0"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;backend&lt;/span&gt; &lt;span class="s2"&gt;"azurerm"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;resource_group_name&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"big8-rg"&lt;/span&gt;
    &lt;span class="nx"&gt;storage_account_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"big8backendstore"&lt;/span&gt;
    &lt;span class="nx"&gt;container_name&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"bigcontainer"&lt;/span&gt;
    &lt;span class="nx"&gt;key&lt;/span&gt;                    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"pro/big8store.tfstate"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;provider&lt;/span&gt; &lt;span class="s2"&gt;"azurerm"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;features&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbjw9v25o746yz4528yqd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbjw9v25o746yz4528yqd.png" alt=" " width="696" height="614"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That &lt;code&gt;key&lt;/code&gt; value is just the filename Terraform will use for the state file inside the container. It doesn't have to match anything specific, you choose it. For a bigger setup with multiple environments, you'd usually split this by environment or component, something like &lt;code&gt;dev.tfstate&lt;/code&gt; and &lt;code&gt;prod.tfstate&lt;/code&gt;, or &lt;code&gt;networking/vnet.tfstate&lt;/code&gt; and &lt;code&gt;compute/vm.tfstate&lt;/code&gt;, so nothing shares a state file and nothing risks overwriting something it shouldn't. For this project I kept it simple, one state file for the whole thing.&lt;/p&gt;

&lt;p&gt;Then I ran:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8n4pb2xecmju8mst2t3c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8n4pb2xecmju8mst2t3c.png" alt=" " width="800" height="482"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the moment the backend actually gets used. Terraform connected to the storage account, configured itself to read and write state there, and installed the azurerm provider. And sure enough, checking the container in the Azure portal right after, there it was, a tiny 181 byte file called &lt;code&gt;big8store.tfstate&lt;/code&gt; sitting exactly where I told it to go.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fywrtico115ayhh3vvhsa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fywrtico115ayhh3vvhsa.png" alt=" " width="799" height="413"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The part that finally made variables click
&lt;/h2&gt;

&lt;p&gt;I want to be honest about this part because it tripped me up longer than I expected. I understood that &lt;code&gt;variables.tf&lt;/code&gt; declares a variable exists, and &lt;code&gt;terraform.tfvars&lt;/code&gt; gives it a value, but I couldn't picture how Terraform actually connects the two.&lt;/p&gt;

&lt;p&gt;What clicked for me eventually is that it's just name matching. If &lt;code&gt;variables.tf&lt;/code&gt; declares a variable called &lt;code&gt;location&lt;/code&gt;, and &lt;code&gt;terraform.tfvars&lt;/code&gt; has a line &lt;code&gt;location = "East US"&lt;/code&gt;, Terraform pairs them up because the names match exactly. Nothing more clever than that. Then anywhere in &lt;code&gt;main.tf&lt;/code&gt; you write &lt;code&gt;var.location&lt;/code&gt;, Terraform swaps in the value before it ever talks to Azure. Run &lt;code&gt;terraform plan&lt;/code&gt; and what you're looking at is that swap already done, the fully resolved version of your config.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8b6fzxofz8nwu01ry7mf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8b6fzxofz8nwu01ry7mf.png" alt=" " width="800" height="432"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fyrj22umwbs0p1cio7jqu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fyrj22umwbs0p1cio7jqu.png" alt=" " width="800" height="426"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once that landed, locals made sense as the natural next step. Variables are values you set from outside your config, tfvars, command line flags, environment variables. Locals are values you compute inside your config from other values, and you don't set them from outside at all. I used a locals block to build one tags object from three variables, so instead of retyping the same three tags on every single resource, I write it once and reference &lt;code&gt;local.tags&lt;/code&gt; everywhere.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzbvn5q7yjiaxr3anoqkw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzbvn5q7yjiaxr3anoqkw.png" alt=" " width="800" height="423"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;locals&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;tags&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;Project&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;project_name&lt;/span&gt;
    &lt;span class="nx"&gt;Environment&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;environment&lt;/span&gt;
    &lt;span class="nx"&gt;Owner&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;admin_username&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I actually mixed this up once, declared &lt;code&gt;tags&lt;/code&gt; as both a variable with no default value and a local, and Terraform got confused trying to figure out which one I meant, prompting me for a value on every plan. Deleting the leftover variable declaration and keeping only the local fixed it in one shot. Good practical example of the difference between the two.&lt;/p&gt;

&lt;h2&gt;
  
  
  Writing main.tf
&lt;/h2&gt;

&lt;p&gt;With variables and locals sorted, the actual resource definitions were fairly mechanical. Resource group, then a virtual network sitting inside it, a subnet inside the network, a network security group with rules allowing inbound traffic on port 22 for SSH and port 80 for HTTP, a public IP, a network interface tying the subnet and public IP together, and finally the VM itself.&lt;/p&gt;

&lt;p&gt;Two mistakes came up here worth mentioning. First, my NSG rules were written with &lt;code&gt;destination_address_prefixes&lt;/code&gt; (plural) set to a single string, &lt;code&gt;"*"&lt;/code&gt;. Terraform wants a list for the plural version. The fix was switching to &lt;code&gt;destination_address_prefix&lt;/code&gt; (singular), which takes a plain string. Second, my SSH key path was wrong, I had it pointing somewhere that didn't exist on my machine. Checking my actual &lt;code&gt;.ssh&lt;/code&gt; folder and correcting the path with &lt;code&gt;pathexpand("~/.ssh/id_ed25519.pub")&lt;/code&gt; sorted that out.&lt;/p&gt;

&lt;p&gt;After both fixes, &lt;code&gt;terraform validate&lt;/code&gt; finally came back clean.&lt;/p&gt;

&lt;h2&gt;
  
  
  The plan, and a real deploy error
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;terraform plan&lt;/code&gt; showed exactly ten resources ready to create, matching the diagram I'd sketched at the start. Everything lined up, tags flowing automatically onto the resource group, the network, and the public IP from that one locals block.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;terraform apply&lt;/code&gt; got nine of those ten up without issue. The tenth, the VM itself, failed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Error: creating Linux Virtual Machine: unexpected status 404 (404 Not Found)
PlatformImageNotFound: The platform image 'Canonical:0001-com-ubuntu-server-jammy:22_04_lts:latest' is not available.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I'd written the sku as &lt;code&gt;22_04_lts&lt;/code&gt;, with underscores. Running a quick image list against Azure showed the real current sku uses a hyphen instead, &lt;code&gt;22_04-lts&lt;/code&gt;. One character fix, and re-running apply picked up right where it left off, the nine resources already created stayed untouched, and only the VM got added this time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjtj5xyn0a6lx6zj9p71u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjtj5xyn0a6lx6zj9p71u.png" alt=" " width="800" height="469"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting onto the box and putting something real on it
&lt;/h2&gt;

&lt;p&gt;With a public IP in hand, I connected over SSH:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh &amp;lt;admin_username&amp;gt;@&amp;lt;public-ip&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ff575h47ojs5cqze1nrl9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ff575h47ojs5cqze1nrl9.png" alt=" " width="800" height="482"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ran the usual updates, installed nginx, and visiting the IP in a browser showed the default nginx welcome page, proof the whole networking chain actually worked end to end.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5spstd4syo3yda3bxs97.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5spstd4syo3yda3bxs97.png" alt=" " width="800" height="463"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then I copied a small static site over with &lt;code&gt;scp&lt;/code&gt;, moved it into &lt;code&gt;/var/www/html&lt;/code&gt;, and reloaded the page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fh2su6sgy8fq1z1rez0ez.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fh2su6sgy8fq1z1rez0ez.png" alt=" " width="799" height="459"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That was the moment this stopped feeling like an exercise. A real site, served from a VM I had provisioned entirely through code, sitting behind a network I had also defined entirely through code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Proving the state lock actually works
&lt;/h2&gt;

&lt;p&gt;The whole reason this project insists on remote state is to make collaboration safe. Two engineers, one shared state file, no local copies going stale. I wanted to actually see that protection in action instead of just taking it on faith, so I opened two terminals and simulated it.&lt;/p&gt;

&lt;p&gt;In one terminal, I kicked off &lt;code&gt;terraform apply&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fb0zrj6fnoipec558q1mj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fb0zrj6fnoipec558q1mj.png" alt=" " width="800" height="492"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While that was still running, I switched to the second terminal and ran &lt;code&gt;terraform plan&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fumw2rvf9dp2aj012vy58.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fumw2rvf9dp2aj012vy58.png" alt=" " width="800" height="448"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Error: Error acquiring the state lock
Error message: state blob is already locked
Lock Info:
  Operation: OperationTypeApply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's the mechanism working exactly as intended. Azure Storage puts a lease on the state blob the moment an operation starts writing to it, and any other operation trying to touch that same file gets refused until the lease is released. Without this, two engineers running Terraform at the same time could easily corrupt the state or fight over the same resources. With it, one of them simply gets told to wait.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cleaning up
&lt;/h2&gt;

&lt;p&gt;Once I was done, tearing it all down was just:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform destroy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ten resources removed, in the correct order, associations and rules first, then the VM and its NIC, then the network, and the resource group last since everything else lived inside it.&lt;/p&gt;

&lt;p&gt;The backend pieces were created by hand, so they had to go the same way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az group delete &lt;span class="nt"&gt;--name&lt;/span&gt; big8-rg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A quick &lt;code&gt;az group list&lt;/code&gt; afterward confirmed only Azure's own auto-created &lt;code&gt;NetworkWatcherRG&lt;/code&gt; was left. Clean slate.&lt;/p&gt;

&lt;h2&gt;
  
  
  What actually stuck with me
&lt;/h2&gt;

&lt;p&gt;Reading Terraform state as a genuine record of reality, not just a lock file, changed how I think about every command. &lt;code&gt;plan&lt;/code&gt; isn't guessing, it's comparing your code against a document that describes what's really out there. &lt;code&gt;apply&lt;/code&gt; doesn't blindly create things, it reconciles the two. And the locking isn't a formality, it's the one thing standing between a team and a corrupted state file.&lt;/p&gt;

&lt;p&gt;If you want to follow along with the actual code, it's all here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/highpee1991/terraform-IAC" rel="noopener noreferrer"&gt;https://github.com/highpee1991/terraform-IAC&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you're working through something similar and get stuck, drop a comment, happy to help however I can.&lt;/p&gt;

</description>
      <category>terraform</category>
      <category>azure</category>
      <category>devops</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Building And Securing An Azure Virtual Machine With Terraform, From Zero To A Working Website</title>
      <dc:creator>Ipadeola Taiwo</dc:creator>
      <pubDate>Sun, 12 Jul 2026 11:19:54 +0000</pubDate>
      <link>https://dev.to/highpee1991/building-and-securing-an-azure-virtual-machine-with-terraform-from-zero-to-a-working-website-4n17</link>
      <guid>https://dev.to/highpee1991/building-and-securing-an-azure-virtual-machine-with-terraform-from-zero-to-a-working-website-4n17</guid>
      <description>&lt;p&gt;This is a full walkthrough of a real Terraform project, provisioning a Linux virtual machine on Azure, securing it properly, and deploying a working web server on it. Every command in this post is one I actually ran, every error is one I actually hit, and every fix is exactly how I solved it. My goal here is not just to show you a finished project, my goal is to teach you how to build this yourself, line by line, understanding why each piece exists and what happens when something goes wrong.&lt;/p&gt;

&lt;p&gt;If you follow this post from top to bottom, you will end with your own Linux server running on Azure, provisioned entirely as code, reachable over SSH, and serving a real webpage to anyone who visits its public address.&lt;/p&gt;

&lt;h2&gt;
  
  
  What We Are Building
&lt;/h2&gt;

&lt;p&gt;A single Ubuntu virtual machine, sitting inside its own virtual network, protected by a firewall that only allows the two ports it actually needs, SSH for management and HTTP for web traffic, with a static public IP address so that address never changes once assigned.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Terraform installed on your machine, version one point zero or higher. The Azure CLI installed and signed in with &lt;code&gt;az login&lt;/code&gt;. An active Azure subscription. And an SSH key pair already generated on your machine, most systems already have one sitting at &lt;code&gt;~/.ssh/id_rsa.pub&lt;/code&gt;, if not, generate one with &lt;code&gt;ssh-keygen&lt;/code&gt; before continuing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Project Structure
&lt;/h2&gt;

&lt;p&gt;Four files make up this entire project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;providers.tf
variables.tf
main.tf
outputs.tf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Terraform does not care how you split your code across files. Every file in the same folder is automatically treated as one combined configuration. Splitting things apart like this is purely for readability, so let's go through each file and understand what it is doing.&lt;/p&gt;
&lt;h2&gt;
  
  
  providers.tf, Telling Terraform Which Cloud We Are Talking To
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;terraform&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;required_providers&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;azurerm&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;source&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"hashicorp/azurerm"&lt;/span&gt;
      &lt;span class="nx"&gt;version&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"4.80.0"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;provider&lt;/span&gt; &lt;span class="s2"&gt;"azurerm"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;features&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This file has one job, telling Terraform that this project talks to Azure, using a specific, pinned version of the provider. Pinning the version matters more than it might look like at first, if you leave this open ended, your project could quietly behave differently every time you run it, depending on whatever the latest provider release happens to be that day. Pinning it to &lt;code&gt;4.80.0&lt;/code&gt; means this project behaves exactly the same way every single time, on any machine, forever.&lt;/p&gt;
&lt;h2&gt;
  
  
  variables.tf, The Values That Drive Everything Else
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"project"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"project name"&lt;/span&gt;
  &lt;span class="nx"&gt;type&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
  &lt;span class="nx"&gt;default&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"terraform_vm"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"location"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"azure region"&lt;/span&gt;
  &lt;span class="nx"&gt;type&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
  &lt;span class="nx"&gt;default&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"East US"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"owner"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"owner tag"&lt;/span&gt;
  &lt;span class="nx"&gt;type&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
  &lt;span class="nx"&gt;default&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Hagital"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"vm-size"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"vm size"&lt;/span&gt;
  &lt;span class="nx"&gt;type&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
  &lt;span class="nx"&gt;default&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Standard_B1ls"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Four variables, the project name, the Azure region, an owner tag for organizing resources, and the size of the virtual machine. Every resource in &lt;code&gt;main.tf&lt;/code&gt; pulls its values from here rather than having anything typed directly into it, so changing the region or the VM size later means editing one line here, not hunting through every resource individually.&lt;/p&gt;

&lt;p&gt;One thing worth explaining clearly, since it genuinely confused me the first time I wrote a Terraform project. If you come from a general programming background, you are used to variables needing to be exported from one file and imported into another. Terraform does not work that way at all. There is no export keyword, no import statement, nothing to wire together. Once a variable is declared anywhere in this folder, it is available anywhere else in this same folder, simply by writing &lt;code&gt;var.project&lt;/code&gt;, or &lt;code&gt;var.location&lt;/code&gt;, or whichever name you gave it. The folder itself is the boundary, not the individual file.&lt;/p&gt;
&lt;h2&gt;
  
  
  main.tf, The Actual Infrastructure
&lt;/h2&gt;

&lt;p&gt;This is the heart of the project. Nine resources, built up in the order they logically depend on each other. Let's go through each one.&lt;/p&gt;
&lt;h3&gt;
  
  
  The Resource Group
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_resource_group"&lt;/span&gt; &lt;span class="s2"&gt;"hagital-rg"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;project&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;_hagital_rg"&lt;/span&gt;
  &lt;span class="nx"&gt;location&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;

  &lt;span class="nx"&gt;tags&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;Environment&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Hagital-vm"&lt;/span&gt;
    &lt;span class="nx"&gt;Owner&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;owner&lt;/span&gt;
    &lt;span class="nx"&gt;Project&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;project&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Every resource in Azure needs a container to live inside, called a resource group. This is the first thing created, and every other resource in this file references it, either directly or indirectly.&lt;/p&gt;
&lt;h3&gt;
  
  
  The Virtual Network And Subnet
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_virtual_network"&lt;/span&gt; &lt;span class="s2"&gt;"hagital-vnet"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;project&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;_hagital_vnet"&lt;/span&gt;
  &lt;span class="nx"&gt;location&lt;/span&gt;            &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_resource_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hagital-rg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;
  &lt;span class="nx"&gt;resource_group_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_resource_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hagital-rg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
  &lt;span class="nx"&gt;address_space&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"10.0.0.0/16"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

  &lt;span class="nx"&gt;tags&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;Environment&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Hagital_vnet"&lt;/span&gt;
    &lt;span class="nx"&gt;Owner&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;owner&lt;/span&gt;
    &lt;span class="nx"&gt;Project&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;project&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_subnet"&lt;/span&gt; &lt;span class="s2"&gt;"hagital-subnet"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                 &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;project&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;_hagital_subnet"&lt;/span&gt;
  &lt;span class="nx"&gt;resource_group_name&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_resource_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hagital-rg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
  &lt;span class="nx"&gt;virtual_network_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_virtual_network&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hagital-vnet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
  &lt;span class="nx"&gt;address_prefixes&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"10.0.1.0/24"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;A VM needs a network to sit inside before it can exist. The virtual network defines the overall address space, and the subnet carves out a smaller section of it for this specific machine to live in. Notice how &lt;code&gt;resource_group_name&lt;/code&gt; here is not typed as a plain string, it directly references &lt;code&gt;azurerm_resource_group.hagital-rg.name&lt;/code&gt;. This is how Terraform understands dependency order automatically, it sees that the subnet needs the resource group to exist first, and builds everything in the correct sequence without you having to say so explicitly.&lt;/p&gt;
&lt;h3&gt;
  
  
  The Firewall, And Its Rules
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_network_security_group"&lt;/span&gt; &lt;span class="s2"&gt;"NSG"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;project&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;_hagital_NSG"&lt;/span&gt;
  &lt;span class="nx"&gt;location&lt;/span&gt;            &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_resource_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hagital-rg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;
  &lt;span class="nx"&gt;resource_group_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_resource_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hagital-rg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_network_security_rule"&lt;/span&gt; &lt;span class="s2"&gt;"NSG_rule_port_80"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;project&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;nsg_port_80"&lt;/span&gt;
  &lt;span class="nx"&gt;priority&lt;/span&gt;                    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
  &lt;span class="nx"&gt;direction&lt;/span&gt;                   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Inbound"&lt;/span&gt;
  &lt;span class="nx"&gt;access&lt;/span&gt;                      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Allow"&lt;/span&gt;
  &lt;span class="nx"&gt;protocol&lt;/span&gt;                    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Tcp"&lt;/span&gt;
  &lt;span class="nx"&gt;source_port_range&lt;/span&gt;           &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"*"&lt;/span&gt;
  &lt;span class="nx"&gt;destination_port_range&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"80"&lt;/span&gt;
  &lt;span class="nx"&gt;source_address_prefix&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"*"&lt;/span&gt;
  &lt;span class="nx"&gt;destination_address_prefix&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"*"&lt;/span&gt;
  &lt;span class="nx"&gt;resource_group_name&lt;/span&gt;         &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_resource_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hagital-rg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
  &lt;span class="nx"&gt;network_security_group_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_network_security_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NSG&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_network_security_rule"&lt;/span&gt; &lt;span class="s2"&gt;"NSG_rule_port_22"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;project&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;nsg_port-22"&lt;/span&gt;
  &lt;span class="nx"&gt;priority&lt;/span&gt;                    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;101&lt;/span&gt;
  &lt;span class="nx"&gt;direction&lt;/span&gt;                   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Inbound"&lt;/span&gt;
  &lt;span class="nx"&gt;access&lt;/span&gt;                      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Allow"&lt;/span&gt;
  &lt;span class="nx"&gt;protocol&lt;/span&gt;                    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Tcp"&lt;/span&gt;
  &lt;span class="nx"&gt;source_port_range&lt;/span&gt;           &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"*"&lt;/span&gt;
  &lt;span class="nx"&gt;destination_port_range&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"22"&lt;/span&gt;
  &lt;span class="nx"&gt;source_address_prefix&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"*"&lt;/span&gt;
  &lt;span class="nx"&gt;destination_address_prefix&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"*"&lt;/span&gt;
  &lt;span class="nx"&gt;resource_group_name&lt;/span&gt;         &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_resource_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hagital-rg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
  &lt;span class="nx"&gt;network_security_group_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_network_security_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NSG&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;A network security group, NSG for short, is Azure's firewall. On its own it does nothing, it is just a container for rules. Each rule below it defines exactly one allowed pattern of traffic.&lt;/p&gt;

&lt;p&gt;Both rules here are inbound, meaning traffic coming into the VM from outside, not traffic leaving it. Port eighty allows web visitors to reach the site once it is running. Port twenty two allows SSH connections in, so you can actually manage the server. Notice each rule has its own priority number, one hundred and one hundred one. Two inbound rules in Azure can never share the same priority, each one needs a unique number, and spacing them out, rather than using consecutive numbers, leaves room to insert new rules later without renumbering everything.&lt;/p&gt;

&lt;p&gt;Notice too, &lt;code&gt;source_port_range&lt;/code&gt; is set to a wildcard on both rules, while &lt;code&gt;destination_port_range&lt;/code&gt; is the actual port being protected. This trips a lot of people up at first. The source port is whatever random, temporary port your browser or SSH client happens to open the connection from, you cannot predict or control that, so it is always a wildcard. The destination port is the one you actually care about, the port on the server itself.&lt;/p&gt;
&lt;h3&gt;
  
  
  The Public IP
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_public_ip"&lt;/span&gt; &lt;span class="s2"&gt;"public-ip"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;project&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;_public_ip"&lt;/span&gt;
  &lt;span class="nx"&gt;resource_group_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_resource_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hagital-rg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
  &lt;span class="nx"&gt;location&lt;/span&gt;            &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_resource_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hagital-rg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;
  &lt;span class="nx"&gt;allocation_method&lt;/span&gt;   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Static"&lt;/span&gt;

  &lt;span class="nx"&gt;tags&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;Environment&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"public_ip"&lt;/span&gt;
    &lt;span class="nx"&gt;Owner&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;owner&lt;/span&gt;
    &lt;span class="nx"&gt;Projects&lt;/span&gt;    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;project&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Without this, the VM would only be reachable on a private, internal address, nothing you could actually connect to from your own laptop. &lt;code&gt;allocation_method&lt;/code&gt; is set to &lt;code&gt;Static&lt;/code&gt; rather than &lt;code&gt;Dynamic&lt;/code&gt;, deliberately. A static IP stays the same even if the VM is stopped and restarted, it only changes if the public IP resource itself is deleted. A dynamic IP, by contrast, can change every time the VM restarts, which becomes a real annoyance once you are actively developing against a known address.&lt;/p&gt;
&lt;h3&gt;
  
  
  The Network Interface
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_network_interface"&lt;/span&gt; &lt;span class="s2"&gt;"NIC"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;project&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;_NIC"&lt;/span&gt;
  &lt;span class="nx"&gt;location&lt;/span&gt;            &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_resource_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hagital-rg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;
  &lt;span class="nx"&gt;resource_group_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_resource_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hagital-rg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;

  &lt;span class="nx"&gt;ip_configuration&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;                          &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"internal"&lt;/span&gt;
    &lt;span class="nx"&gt;subnet_id&lt;/span&gt;                     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_subnet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hagital-subnet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
    &lt;span class="nx"&gt;private_ip_address_allocation&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Dynamic"&lt;/span&gt;
    &lt;span class="nx"&gt;public_ip_address_id&lt;/span&gt;          &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_public_ip&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;public-ip&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This is the piece that physically connects everything together. The network interface card, NIC for short, is what actually plugs the VM into the subnet, and it is also where the public IP gets attached. A VM cannot connect directly to a subnet or a public IP on its own, it always goes through a network interface in between.&lt;/p&gt;
&lt;h3&gt;
  
  
  The Virtual Machine Itself
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_linux_virtual_machine"&lt;/span&gt; &lt;span class="s2"&gt;"linux-vm"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;project&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;_linux_vm"&lt;/span&gt;
  &lt;span class="nx"&gt;computer_name&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"hagital-vm"&lt;/span&gt;
  &lt;span class="nx"&gt;resource_group_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_resource_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hagital-rg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
  &lt;span class="nx"&gt;location&lt;/span&gt;            &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_resource_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hagital-rg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;
  &lt;span class="nx"&gt;size&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;vm-size&lt;/span&gt;
  &lt;span class="nx"&gt;admin_username&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;owner&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;user"&lt;/span&gt;
  &lt;span class="nx"&gt;network_interface_ids&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nx"&gt;azurerm_network_interface&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NIC&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;

  &lt;span class="nx"&gt;admin_ssh_key&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;username&lt;/span&gt;   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;owner&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;user"&lt;/span&gt;
    &lt;span class="nx"&gt;public_key&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"~/.ssh/id_rsa.pub"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;os_disk&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;caching&lt;/span&gt;              &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ReadWrite"&lt;/span&gt;
    &lt;span class="nx"&gt;storage_account_type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Standard_LRS"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;source_image_reference&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;publisher&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Canonical"&lt;/span&gt;
    &lt;span class="nx"&gt;offer&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"0001-com-ubuntu-server-jammy"&lt;/span&gt;
    &lt;span class="nx"&gt;sku&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"22_04-lts"&lt;/span&gt;
    &lt;span class="nx"&gt;version&lt;/span&gt;   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"latest"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This resource references everything built above it, the network interface for connectivity, an Ubuntu twenty two image from Canonical for the operating system, and an SSH key read directly from your local machine using the &lt;code&gt;file()&lt;/code&gt; function, rather than pasting the key as text. One detail worth calling out, &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;computer_name&lt;/code&gt; are two different things here, &lt;code&gt;name&lt;/code&gt; is the label Azure uses for the resource itself, while &lt;code&gt;computer_name&lt;/code&gt; becomes the actual hostname inside the running Linux machine, and Linux hostnames follow much stricter naming rules than Azure resource names do, more on that shortly when we get to the errors.&lt;/p&gt;
&lt;h3&gt;
  
  
  The Missing Piece Most Tutorials Skip
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_network_interface_security_group_association"&lt;/span&gt; &lt;span class="s2"&gt;"nsg_association"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;network_interface_id&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_network_interface&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NIC&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
  &lt;span class="nx"&gt;network_security_group_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_network_security_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NSG&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This resource genuinely tripped me up, and I want to explain it clearly because I suspect it will trip other people up too. Creating a network security group and writing rules for it does not automatically apply those rules to anything. The NSG just sits there, unused, until it is explicitly attached to something, in this case, the network interface. Without this association resource, your firewall rules exist in Azure but affect nothing at all, and Azure falls back to blocking inbound internet traffic by default. This one resource is what actually switches your firewall rules on.&lt;/p&gt;
&lt;h2&gt;
  
  
  outputs.tf, Getting Useful Information Back
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;output&lt;/span&gt; &lt;span class="s2"&gt;"resource_group_created"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"resource group name"&lt;/span&gt;
  &lt;span class="nx"&gt;value&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_resource_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hagital-rg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;output&lt;/span&gt; &lt;span class="s2"&gt;"Vnet"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"vnet name"&lt;/span&gt;
  &lt;span class="nx"&gt;value&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_virtual_network&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hagital-vnet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;output&lt;/span&gt; &lt;span class="s2"&gt;"subnet"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"subnet name"&lt;/span&gt;
  &lt;span class="nx"&gt;value&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_subnet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hagital-subnet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;output&lt;/span&gt; &lt;span class="s2"&gt;"NSG"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"NSG name"&lt;/span&gt;
  &lt;span class="nx"&gt;value&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_network_security_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NSG&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;output&lt;/span&gt; &lt;span class="s2"&gt;"port_80_rule"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Inbound port 80 created"&lt;/span&gt;
  &lt;span class="nx"&gt;value&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_network_security_rule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NSG_rule_port_80&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;destination_port_range&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;output&lt;/span&gt; &lt;span class="s2"&gt;"port_22_rule"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Inbound port 22 created"&lt;/span&gt;
  &lt;span class="nx"&gt;value&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_network_security_rule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NSG_rule_port_22&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;destination_port_range&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;output&lt;/span&gt; &lt;span class="s2"&gt;"public_ip"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"public ip"&lt;/span&gt;
  &lt;span class="nx"&gt;value&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_public_ip&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;public-ip&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;output&lt;/span&gt; &lt;span class="s2"&gt;"vm_name"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"azure vm name"&lt;/span&gt;
  &lt;span class="nx"&gt;value&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_linux_virtual_machine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;linux-vm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;output&lt;/span&gt; &lt;span class="s2"&gt;"vm_public_ip"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"vm attached public ip"&lt;/span&gt;
  &lt;span class="nx"&gt;value&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_linux_virtual_machine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;linux-vm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;public_ip_address&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Outputs print useful information to the terminal automatically after every apply, so you are not stuck manually looking things up in the Azure Portal afterward. The most useful one here by far is &lt;code&gt;vm_public_ip&lt;/code&gt;, since that is the exact address needed to actually SSH into the machine once it exists.&lt;/p&gt;
&lt;h2&gt;
  
  
  The Errors I Ran Into, And How They Were Fixed
&lt;/h2&gt;
&lt;h1&gt;
  
  
  A quick note before this section, the code shown above already reflects every correction. You do not need to change anything, this section exists purely to walk through what went wrong the first time and how each issue was diagnosed.
&lt;/h1&gt;

&lt;p&gt;This is the part most tutorials skip entirely, and it is the part I think actually matters most. Nothing here worked perfectly on the first attempt. Every error below is real, and understanding each one teaches you something a clean, error free run never would.&lt;/p&gt;
&lt;h3&gt;
  
  
  Running terraform init
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This command downloads the azurerm provider and prepares the working directory. The very first time I ran this, it failed.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Error: Failed to query available provider packages
Could not retrieve the list of available versions for provider hashcorp/azurerm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Read that carefully. It says &lt;code&gt;hashcorp&lt;/code&gt;, missing the letter i. The real provider is published as &lt;code&gt;hashicorp&lt;/code&gt;, with the i. Somewhere in my configuration, that name had been typed incorrectly, and Terraform was searching for a provider that simply does not exist. Correcting the spelling and running &lt;code&gt;terraform init&lt;/code&gt; again resolved it immediately.&lt;/p&gt;

&lt;p&gt;A second, completely different failure showed up on another attempt.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Error: Failed to install provider
Error while installing hashicorp/azurerm v4.80.0: releases.hashicorp.com: local error: tls: bad record MAC
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This one had nothing to do with my code at all, it was a network connection problem, an interrupted or unstable connection while downloading the provider. The fix here was simply waiting a moment and retrying the same command again.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Once the connection stabilized, it installed cleanly.&lt;/p&gt;
&lt;h3&gt;
  
  
  The Subscription ID Requirement
&lt;/h3&gt;

&lt;p&gt;Running &lt;code&gt;terraform plan&lt;/code&gt; for the first time in this particular project produced a new error I had not seen in earlier Terraform projects.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Error: `subscription_id` is a required provider property when performing a plan/apply operation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This turned out to be a documented change, starting with version four point zero of the azurerm provider, explicitly setting a subscription ID in the provider block became mandatory. In an earlier Terraform project of mine, this had not come up, likely due to how that specific environment resolved it implicitly. The fix here was reverting cleanly to provider version &lt;code&gt;4.80.0&lt;/code&gt; after clearing out the previously cached &lt;code&gt;.terraform&lt;/code&gt; folder and lock file, forcing Terraform to properly resolve the version fresh, which sidestepped the issue entirely for this setup.&lt;/p&gt;
&lt;h3&gt;
  
  
  Reviewing The Plan
&lt;/h3&gt;

&lt;p&gt;Once initialization succeeded, &lt;code&gt;terraform plan&lt;/code&gt; produced a full, detailed preview of every resource about to be created, nine in total, resource group, virtual network, subnet, NSG, two security rules, public IP, network interface, and the VM itself.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Plan: 9 to add, 0 to change, 0 to destroy.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This is the single most important habit in Terraform, always read the plan before applying it. It tells you exactly what is about to happen before it actually happens, and it is your last chance to catch a mistake before real infrastructure gets created and starts costing money.&lt;/p&gt;
&lt;h3&gt;
  
  
  Running terraform apply, And The First Real Failure
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Typing &lt;code&gt;yes&lt;/code&gt; at the confirmation prompt kicked off creation. Eight resources succeeded cleanly, resource group, network, subnet, NSG, both rules, public IP, and network interface, each completing within seconds. Then the VM itself failed.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Error: unable to assume default computer name "computer_name" cannot contain the special characters:
`\/"[]:|&amp;lt;&amp;gt;+=;,?*@&amp;amp;~!#$%^()_{}'`. Please adjust the `name`, or specify an explicit `computer_name`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This is a genuinely useful error to understand. Azure resource names and Linux hostnames follow completely different rule sets. My VM's &lt;code&gt;name&lt;/code&gt; value contained underscores, which Azure resource names allow without issue, that is exactly why the resource group, VNet, and NSG all created successfully with underscores in their own names. But without an explicit &lt;code&gt;computer_name&lt;/code&gt; set, Terraform tries to generate one automatically from the resource name, and a Linux hostname cannot contain underscores at all. The fix was adding an explicit, separate &lt;code&gt;computer_name&lt;/code&gt; value using only letters, numbers, and hyphens, which is exactly what you see in the finished &lt;code&gt;main.tf&lt;/code&gt; above, &lt;code&gt;computer_name = "hagital-vm"&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  The Second Failure, An Invalid VM Size
&lt;/h3&gt;

&lt;p&gt;After fixing the computer name and running &lt;code&gt;terraform plan&lt;/code&gt; again, a different error appeared, this time about the VM size itself.&lt;/p&gt;

&lt;p&gt;The originally typed size, &lt;code&gt;Standard_B1_ls&lt;/code&gt;, is not a valid Azure size string. Azure VM sizes follow a fixed format defined by Azure itself, and this one had an extra underscore that did not belong. The correct value is &lt;code&gt;Standard_B1ls&lt;/code&gt;, no separator between B one and ls, one continuous string. You can always confirm exactly which sizes are valid and available in your specific region directly from the CLI, rather than typing one from memory:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az vm list-sizes &lt;span class="nt"&gt;--location&lt;/span&gt; eastus &lt;span class="nt"&gt;--output&lt;/span&gt; table
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Correcting &lt;code&gt;variables.tf&lt;/code&gt; to &lt;code&gt;Standard_B1ls&lt;/code&gt; and running &lt;code&gt;terraform plan&lt;/code&gt; again confirmed it was accepted.&lt;/p&gt;
&lt;h3&gt;
  
  
  Applying Again, Successfully This Time
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This time, all nine resources built successfully.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Apply complete! Resources: 9 added, 0 changed, 0 destroyed.

Outputs:

NSG = "terraform_vm_hagital_NSG"
Vnet = "terraform_vm_hagital_vnet"
port_22_rule = "22"
port_80_rule = "80"
public_ip = "/subscriptions/.../publicIPAddresses/terraform_vm_public_ip"
resource_group_created = "terraform_vm_hagital_rg"
subnet = "terraform_vm_hagital_subnet"
vm_name = "terraform_vm_linux_vm"
vm_public_ip = "20.169.155.100"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Every output printed automatically, exactly as designed, including the actual public IP address, ready to copy straight into an SSH command.&lt;/p&gt;
&lt;h3&gt;
  
  
  The Connection That Timed Out
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh Hagitaluser@20.169.155.100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh: connect to host 20.169.155.100 port 22: Connection timed out
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This is the error that taught me the most out of this entire project. Everything in the plan had applied successfully, no errors, nine resources created, yet SSH could not reach the machine at all. A connection timeout like this, rather than an outright refusal, is the signature of a firewall silently dropping the request rather than actively rejecting it.&lt;/p&gt;

&lt;p&gt;The cause traced back to something I had genuinely overlooked. Creating a network security group and writing rules for it does not automatically apply those rules to anything. I had built the NSG, and I had written both inbound rules, port twenty two and port eighty, but I had never actually attached that NSG to the network interface. The rules existed, but they were not switched on.&lt;/p&gt;

&lt;p&gt;The fix was adding one more resource, exactly the association block shown earlier in &lt;code&gt;main.tf&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_network_interface_security_group_association"&lt;/span&gt; &lt;span class="s2"&gt;"nsg_association"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;network_interface_id&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_network_interface&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NIC&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
  &lt;span class="nx"&gt;network_security_group_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_network_security_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NSG&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform plan
terraform apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;One resource added. Trying SSH again immediately after:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh Hagitaluser@20.169.155.100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;The authenticity of host '20.169.155.100 (20.169.155.100)' can't be established.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '20.169.155.100' (ED25519) to the list of known hosts.
Welcome to Ubuntu 22.04.5 LTS (GNU/Linux 6.8.0-1059-azure x86_64)
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Connected. That fingerprint warning the first time is completely normal, it is simply your machine confirming, for the first time, that it trusts this brand new server's identity, the same thing happens connecting to any new server for the first time, not just this one.&lt;/p&gt;
&lt;h2&gt;
  
  
  Configuring The Server
&lt;/h2&gt;

&lt;p&gt;With SSH access working, I updated the system and installed Nginx, the actual web server this whole project was built to run.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt upgrade &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;nginx &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Once installed, I confirmed the service was genuinely running, not just installed.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl status nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight systemd"&gt;&lt;code&gt;&lt;span class="err"&gt;●&lt;/span&gt; &lt;span class="err"&gt;nginx.service&lt;/span&gt; &lt;span class="err"&gt;-&lt;/span&gt; &lt;span class="err"&gt;A&lt;/span&gt; &lt;span class="err"&gt;high&lt;/span&gt; &lt;span class="err"&gt;performance&lt;/span&gt; &lt;span class="err"&gt;web&lt;/span&gt; &lt;span class="err"&gt;server&lt;/span&gt; &lt;span class="err"&gt;and&lt;/span&gt; &lt;span class="err"&gt;a&lt;/span&gt; &lt;span class="err"&gt;reverse&lt;/span&gt; &lt;span class="err"&gt;proxy&lt;/span&gt; &lt;span class="err"&gt;server&lt;/span&gt;
     &lt;span class="err"&gt;Active:&lt;/span&gt; &lt;span class="err"&gt;active&lt;/span&gt; &lt;span class="err"&gt;(running)&lt;/span&gt; &lt;span class="err"&gt;since&lt;/span&gt; &lt;span class="err"&gt;Sun&lt;/span&gt; &lt;span class="err"&gt;2026-07-12&lt;/span&gt; &lt;span class="err"&gt;10:30:47&lt;/span&gt; &lt;span class="err"&gt;UTC&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Then verified it was actually serving content, first from directly inside the VM itself.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl 20.169.155.100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Welcome to nginx!&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Verifying From The Outside World
&lt;/h2&gt;

&lt;p&gt;The final and most satisfying check, opening the VM's public IP address directly in a browser from my own laptop, completely outside of Azure and outside of the VM itself.&lt;/p&gt;

&lt;p&gt;The page loaded correctly, the default Nginx welcome page, confirmed reachable from the open internet. That "not secure" warning next to the address bar is expected and not a problem, it simply means the connection is running over plain HTTP rather than HTTPS, adding a TLS certificate would be the natural next step to remove that warning, a good project on its own.&lt;/p&gt;
&lt;h2&gt;
  
  
  What This Project Actually Proves
&lt;/h2&gt;

&lt;p&gt;Every piece of this was provisioned as code, version controlled, and repeatable, not clicked together by hand. Five distinct, real errors were hit along the way, a provider name typo, a network connectivity drop, a Linux hostname naming rule, an invalid Azure VM size string, and a missing NSG association that silently left the firewall rules inactive despite a fully successful apply. Every one of them was diagnosed by actually reading the error message closely and understanding what it was describing, not by guessing or copying a fix blindly.&lt;/p&gt;

&lt;p&gt;The result is a real, working, secured Linux server, reachable over SSH, serving a live webpage to anyone on the internet, built entirely from four Terraform files and a lot of careful debugging.&lt;/p&gt;

&lt;p&gt;If you followed along and built this yourself, or if you hit a different error than the ones documented here, I would genuinely like to hear about it in the comments. Debugging infrastructure is a skill built entirely through hitting exactly this kind of wall and working through it, and comparing notes with someone else doing the same thing is one of the fastest ways to get better at it.&lt;/p&gt;

&lt;p&gt;Github Link:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/highpee1991" rel="noopener noreferrer"&gt;
        highpee1991
      &lt;/a&gt; / &lt;a href="https://github.com/highpee1991/Terraform-Virtual-Machine-Deployment" rel="noopener noreferrer"&gt;
        Terraform-Virtual-Machine-Deployment
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;



</description>
    </item>
    <item>
      <title>My First Real Terraform Project, Two Environments, One Storage Account, And A Few Lessons I Did Not See Coming</title>
      <dc:creator>Ipadeola Taiwo</dc:creator>
      <pubDate>Sat, 11 Jul 2026 15:52:14 +0000</pubDate>
      <link>https://dev.to/highpee1991/my-first-real-terraform-project-two-environments-one-storage-account-and-a-few-lessons-i-did-not-392k</link>
      <guid>https://dev.to/highpee1991/my-first-real-terraform-project-two-environments-one-storage-account-and-a-few-lessons-i-did-not-392k</guid>
      <description>&lt;p&gt;A few days ago I said I was starting Infrastructure as Code. Today I actually sat down and wrote my first proper Terraform project, and I want to walk you through exactly what I built, what confused me at first, and what broke along the way, because the broken parts taught me more than the parts that just worked.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Set Out To Build
&lt;/h2&gt;

&lt;p&gt;The idea was simple on paper. A small payments project needs two separate environments, one for development and one for staging, each represented by its own resource group in Azure. On top of that, the development environment needed a storage account with a blob container inside it, the kind of setup you would actually see on a real team, where dev and staging are kept apart on purpose.&lt;/p&gt;

&lt;p&gt;Nothing here was complicated in terms of what Azure resources were involved. What made it worth doing was doing it the Terraform way, writing it once as code, and letting Terraform figure out how to create everything in the right order.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Part That Actually Confused Me At First, Variables
&lt;/h2&gt;

&lt;p&gt;Before I even got to writing resources, I had to deal with variables, and this is the part I really want to talk about, because it caught me off guard in a way I was not expecting.&lt;/p&gt;

&lt;p&gt;If you come from a general programming background, even a light one, you are used to variables needing to be exported and imported somehow. You define something in one file, and if you want to use it somewhere else, you usually have to explicitly export it, then import it wherever you need it. That is just how most languages work.&lt;/p&gt;

&lt;p&gt;So naturally, when I created a separate file just for my variables, my first thought was, how do I export this so my other files can actually see it. I genuinely sat there for a moment trying to figure out the Terraform equivalent of an export statement.&lt;/p&gt;

&lt;p&gt;Turns out, there isn't one, and there does not need to be.&lt;/p&gt;

&lt;p&gt;In Terraform, every file inside the same working directory is automatically part of the same configuration. It does not matter if your variables live in &lt;code&gt;variables.tf&lt;/code&gt;, your resources live in &lt;code&gt;main.tf&lt;/code&gt;, and your outputs live in &lt;code&gt;outputs.tf&lt;/code&gt;. Terraform reads every &lt;code&gt;.tf&lt;/code&gt; file in that folder as one combined configuration. Once a variable is declared, anywhere in that folder, you can reference it anywhere else in that same folder, just by calling &lt;code&gt;var.whatever_you_named_it&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;No import statement. No export keyword. No file path linking one file to another. The folder itself is the boundary, not the individual file.&lt;/p&gt;

&lt;p&gt;Once that clicked, it actually made the whole language feel simpler than I expected. Splitting files apart in Terraform is purely for organization and readability, not because the tool needs you to wire files together the way you would in something like JavaScript or Python.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting The Foundation, Provider And Variables
&lt;/h2&gt;

&lt;p&gt;Every Terraform project needs to know which provider it is talking to, in this case Azure, and which version of that provider to use. I pinned mine to a specific version rather than leaving it open ended, so the project behaves the same way every time it runs, regardless of what the latest provider release happens to be on a given day.&lt;/p&gt;

&lt;p&gt;Then came the three variables that would drive the whole project, the project name, the Azure region, and an owner tag, each with a sensible default so I would not have to retype the same values across every resource.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building The Actual Infrastructure
&lt;/h2&gt;

&lt;p&gt;With the foundation in place, I defined four resources. Two resource groups, one for dev and one for staging, a storage account sitting inside the dev resource group, and a storage container sitting inside that storage account.&lt;/p&gt;

&lt;p&gt;What I liked here is how naturally Terraform expresses the relationship between resources. I did not have to manually tell the storage account which resource group it belonged to using some ID I copied from somewhere. I just referenced the resource group resource directly, and Terraform understood the dependency and the order to create things in, entirely on its own.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where It Actually Broke, And What Each Break Taught Me
&lt;/h2&gt;

&lt;p&gt;I want to be upfront about this part, because I think it is the most useful part of this whole post. Nothing here worked perfectly on the first attempt, and I think that is normal, and worth documenting honestly rather than pretending it all went smoothly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The first error showed up right at &lt;code&gt;terraform init&lt;/code&gt;.&lt;/strong&gt; Terraform told me it could not find a provider called &lt;code&gt;hashcorp/azurerm&lt;/code&gt;. I stared at that for longer than I want to admit before I noticed the actual issue, the error was missing a letter. The real provider is &lt;code&gt;hashicorp&lt;/code&gt;, not &lt;code&gt;hashcorp&lt;/code&gt;. One missing letter somewhere in my configuration was enough to send Terraform looking for a provider that does not exist. Fixing the spelling and running init again solved it immediately.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The second error happened during &lt;code&gt;terraform plan&lt;/code&gt;.&lt;/strong&gt; This one looked scarier than it actually was. Terraform said it ran into a problem while trying to automatically register an Azure resource provider called Microsoft.Kusto, something I was not even using directly, and the process got interrupted. I simply ran the plan again, and it went through cleanly the second time. Turns out Terraform tries to register a whole set of Azure resource providers behind the scenes the first time you use certain resource types, and on a lighter subscription that step can be slow enough to get cut off.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The third error was the most straightforward, but the easiest to overlook.&lt;/strong&gt; Azure rejected my storage account name because it contained a hyphen. Storage account names in Azure have to be lowercase letters and numbers only, no hyphens allowed, which is different from resource group names, where hyphens are perfectly fine. I had used the same naming pattern across both without realizing storage accounts play by different rules. Removing the hyphen fixed it right away.&lt;/p&gt;

&lt;p&gt;None of these were difficult once I understood what was actually happening, but each one forced me to slow down and actually read the error message properly instead of assuming I already knew what went wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  Confirming It Actually Worked
&lt;/h2&gt;

&lt;p&gt;Once everything applied successfully, I did not just trust the terminal output. I went into the Azure Portal directly and checked every piece, both resource groups showing up correctly under the right region, the storage account sitting inside the correct resource group, and the container present inside that storage account with the access level I had configured. Seeing it match exactly what Terraform said it created was a genuinely satisfying moment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tearing It Down
&lt;/h2&gt;

&lt;p&gt;Since this was a lab and not something meant to run permanently, I finished by running a full destroy, and watched Terraform take everything down in the correct reverse order, the container first, then the storage account, then both resource groups, all cleanly removed with a single command and a typed confirmation.&lt;/p&gt;

&lt;h2&gt;
  
  
  What This Project Actually Taught Me
&lt;/h2&gt;

&lt;p&gt;Beyond the individual errors, the biggest shift for me was realizing how much Terraform handles on its own once you describe what you want clearly. I did not have to think about ordering. I did not have to manually track dependencies between resources. I described the end state, and Terraform figured out how to get there, and how to safely undo it later.&lt;/p&gt;

&lt;p&gt;I also learned something small but important while wrapping up, my working folder had files sitting there that should never end up in version control, the local state files and the provider cache directory in particular, since state files can end up holding sensitive information about the resources they track. That is going straight into a &lt;code&gt;.gitignore&lt;/code&gt; before this project touches GitHub properly.&lt;/p&gt;

&lt;p&gt;This is only the first project in what I expect will be a much longer run with Terraform. If you have worked with it longer than I have, and there is something you wish someone had told you this early on, I would genuinely like to hear it in the comments.&lt;/p&gt;

&lt;p&gt;Below is link to my github repo&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/highpee1991" rel="noopener noreferrer"&gt;
        highpee1991
      &lt;/a&gt; / &lt;a href="https://github.com/highpee1991/azure-terraform-lab" rel="noopener noreferrer"&gt;
        azure-terraform-lab
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      terraform
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Understand the 4 Core Files&lt;/h2&gt;

&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Every Terraform project has this structure:&lt;/h1&gt;

&lt;/div&gt;
&lt;p&gt;azure-terraform-lab/
├── main.tf           # Your resources live here
├── variables.tf      # Input variables (reusable values)
├── outputs.tf        # What Terraform prints after running
└── providers.tf      # Which cloud you are connecting to&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Terraform command to use daily&lt;/h2&gt;

&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;1. Download the Azure provider plugin&lt;/h1&gt;

&lt;/div&gt;
&lt;p&gt;terraform init&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;2. Preview what Terraform WILL do — never skip this&lt;/h1&gt;

&lt;/div&gt;
&lt;p&gt;terraform plan&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;3. Actually build the infrastructure&lt;/h1&gt;

&lt;/div&gt;
&lt;p&gt;terraform apply&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;4. Destroy everything safely when done&lt;/h1&gt;

&lt;/div&gt;
&lt;p&gt;terraform destroy&lt;/p&gt;
&lt;/div&gt;



&lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/highpee1991/azure-terraform-lab" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;


</description>
    </item>
    <item>
      <title>I Deployed a Live Website on Azure Using Only the CLI, No Portal, No Clicking</title>
      <dc:creator>Ipadeola Taiwo</dc:creator>
      <pubDate>Mon, 06 Jul 2026 19:46:15 +0000</pubDate>
      <link>https://dev.to/highpee1991/i-deployed-a-live-website-on-azure-using-only-the-cli-no-portal-no-clicking-4men</link>
      <guid>https://dev.to/highpee1991/i-deployed-a-live-website-on-azure-using-only-the-cli-no-portal-no-clicking-4men</guid>
      <description>&lt;p&gt;There is a certain kind of confidence you only get when you type a command into a terminal and watch an actual server come to life in another part of the world. No dashboard, no wizard, no clicking through screens. Just you, a terminal, and a set of decisions you have to make yourself.&lt;/p&gt;

&lt;p&gt;That is exactly what I set out to do. The brief was simple to read but not simple to execute: deploy a Linux server on Azure, connect to it, configure it, secure it properly, and document the whole process the way a real DevOps engineer would, as a runbook someone else could follow and trust.&lt;/p&gt;

&lt;p&gt;I want to walk you through how I did it, the mistakes I made along the way, and how you can follow the same path yourself if you are trying to build this skill.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I Did This the Hard Way
&lt;/h2&gt;

&lt;p&gt;It is tempting to open the Azure portal, click a few buttons, and have a server running in minutes. That works, but it does not teach you anything that scales. The moment you need to provision ten servers, or repeat the same setup for a client, clicking through a UI becomes a liability rather than a convenience.&lt;/p&gt;

&lt;p&gt;So I chose the terminal instead. Every resource group, every network, every rule was created with a command I typed myself, so that I would actually understand what was happening underneath.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step One, Giving the Project a Home
&lt;/h2&gt;

&lt;p&gt;Every resource in Azure needs a container to live in, called a resource group. Think of it as the folder that keeps everything related to one project together, so you can manage it, monitor it, or delete it as a single unit later.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az group create &lt;span class="nt"&gt;--name&lt;/span&gt; hagital-rg &lt;span class="nt"&gt;--location&lt;/span&gt; eastus
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;That one line created a logical home for everything that followed.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step Two, Building the Network Before the Server
&lt;/h2&gt;

&lt;p&gt;Before you can have a server, you need a network for it to live inside. This is one of those things that feels backwards if you are used to clicking through a portal, where the network gets created for you automatically. On the CLI, you build it yourself, which forces you to actually understand how the pieces fit together.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az network vnet create &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--resource-group&lt;/span&gt; hagital-rg &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--name&lt;/span&gt; provion-server-vnet &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--address-prefix&lt;/span&gt; 10.0.0.0/16 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--subnet-name&lt;/span&gt; provison-server-subnet &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--subnet-prefix&lt;/span&gt; 10.0.0.0/24
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;I then double checked everything before moving forward, because catching a mistake here is far easier than catching it after a server is already attached to the wrong network.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az network vnet show &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--resource-group&lt;/span&gt; hagital-rg &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--name&lt;/span&gt; provion-server-vnet &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--query&lt;/span&gt; &lt;span class="s2"&gt;"{VNet:addressSpace.addressPrefixes, Subnets:subnets[].addressPrefix}"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Step Three, Bringing the Server to Life
&lt;/h2&gt;

&lt;p&gt;With the network ready, I created the virtual machine itself, an Ubuntu server, placed directly inside the network I had just built.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az vm create &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--resource-group&lt;/span&gt; hagital-rg &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--name&lt;/span&gt; hagital-server &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--image&lt;/span&gt; Ubuntu2204 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--size&lt;/span&gt; Standard_B1ls &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--vnet-name&lt;/span&gt; provion-server-vnet &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--subnet&lt;/span&gt; provison-server-subnet &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--admin-username&lt;/span&gt; azureuser &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--generate-ssh-keys&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;One detail worth mentioning here, something that genuinely surprised me. When you create a server through the Azure portal, you are usually handed a private key file to download and guard carefully. On the CLI, the &lt;code&gt;generate-ssh-keys&lt;/code&gt; flag handles that for you. Azure generates the key pair locally and wires up the public key automatically, so there is no separate file to lose track of. Small detail, but it changed how I think about secure access.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step Four, Locking the Front Door, Then Only Opening What Is Needed
&lt;/h2&gt;

&lt;p&gt;A server exposed to the entire internet on every port is a server waiting to be compromised. So the very next thing I did was open only the two ports this server actually needed, port twenty two for SSH access, and port eighty for web traffic. Nothing else.&lt;/p&gt;

&lt;p&gt;Opening the first port went smoothly.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az vm open-port &lt;span class="nt"&gt;--resource-group&lt;/span&gt; hagital-rg &lt;span class="nt"&gt;--name&lt;/span&gt; hagital-server &lt;span class="nt"&gt;--port&lt;/span&gt; 22
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Opening the second one did not.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az vm open-port &lt;span class="nt"&gt;--resource-group&lt;/span&gt; hagital-rg &lt;span class="nt"&gt;--name&lt;/span&gt; hagital-server &lt;span class="nt"&gt;--port&lt;/span&gt; 80
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Azure responded with an error I had never seen before.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SecurityRuleConflict: Security rule open-port-22 conflicts with rule open-port-80. Rules cannot have the same Priority and Direction.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This is the part of the process that actually taught me something. In Azure, every firewall rule, called a network security group rule, has a priority number, and two inbound rules cannot share the same one. The open port command always tries to use the same default priority, nine hundred, no matter how many times you run it. My SSH rule had already claimed that number, so the HTTP rule had nowhere to go.&lt;/p&gt;

&lt;p&gt;I checked the existing rules to see exactly what was going on.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az network nsg rule list &lt;span class="nt"&gt;--resource-group&lt;/span&gt; hagital-rg &lt;span class="nt"&gt;--nsg-name&lt;/span&gt; hagital-serverNSG &lt;span class="nt"&gt;--output&lt;/span&gt; table
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Once I understood the cause, the fix was straightforward. I created the HTTP rule manually and gave it its own priority instead of relying on the default.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az network nsg rule create &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--resource-group&lt;/span&gt; hagital-rg &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--nsg-name&lt;/span&gt; hagital-serverNSG &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--name&lt;/span&gt; AllowHTTP &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--priority&lt;/span&gt; 910 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--direction&lt;/span&gt; Inbound &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--access&lt;/span&gt; Allow &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--protocol&lt;/span&gt; Tcp &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--destination-port-ranges&lt;/span&gt; 80
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;That single error taught me more about how Azure firewall rules work than any tutorial had, because I had to actually understand the priority system to solve it myself.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step Five, Walking In Through SSH
&lt;/h2&gt;

&lt;p&gt;With the network secured, I fetched the server's public IP address and connected directly.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az vm show &lt;span class="nt"&gt;--resource-group&lt;/span&gt; hagital-rg &lt;span class="nt"&gt;--name&lt;/span&gt; hagital-server &lt;span class="nt"&gt;--show-details&lt;/span&gt; &lt;span class="nt"&gt;--query&lt;/span&gt; publicIps &lt;span class="nt"&gt;--output&lt;/span&gt; tsv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh azureuser@&amp;lt;public-ip&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;No password prompt, no key file to search for, just a clean connection using the key pair Azure had already set up.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step Six, Giving the Server a Job
&lt;/h2&gt;

&lt;p&gt;A bare server does nothing on its own. I installed Nginx, a lightweight and widely used web server, so the machine could actually serve web pages to anyone who visited its address.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;nginx &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Running an update before the install is a habit worth keeping. It refreshes the list of available packages so you are installing the current version rather than something outdated sitting in a stale cache.&lt;/p&gt;

&lt;p&gt;A quick check confirmed everything was running as expected.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;systemctl status nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Step Seven, Getting My Own Project Onto the Server
&lt;/h2&gt;

&lt;p&gt;At this point the server could serve a web page, just not mine yet. I copied a portfolio project, built with plain HTML, CSS and JavaScript, from my local machine onto the server using secure copy.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;scp &lt;span class="nt"&gt;-r&lt;/span&gt; ./devops_portfolio azureuser@&amp;lt;public-ip&amp;gt;:/tmp/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The next step introduced two more mistakes, both worth sharing because they are easy to make and easy to learn from.&lt;/p&gt;

&lt;p&gt;The first attempt tried to move the entire project folder directly onto the location of the existing default web page, and Azure's server refused, since you cannot replace a single file with an entire folder.&lt;/p&gt;

&lt;p&gt;The second attempt failed for a different reason, a plain permission error, since the folder that serves web content on a Linux server is owned by the system, not by the everyday user account.&lt;/p&gt;

&lt;p&gt;The working solution handled both issues at once, moving the contents of the folder rather than the folder itself, and running the command with elevated permission.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo mv&lt;/span&gt; /tmp/devops_portfolio/&lt;span class="k"&gt;*&lt;/span&gt; /var/www/html/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;A moment later, visiting the server's public address in a browser showed my actual portfolio, live, served from a machine I had built entirely from a terminal.&lt;/p&gt;
&lt;h2&gt;
  
  
  Turning the Whole Process Into a Script
&lt;/h2&gt;

&lt;p&gt;Doing this manually taught me the mechanics, but repeating it manually every time would not scale, and would not reflect how this is actually done professionally. So I converted the entire workflow into a bash script, with each stage wrapped in its own function, resource group creation, network creation, server creation, and a reusable function for opening ports safely, one that checks whether a rule already exists before attempting to create it again.&lt;/p&gt;

&lt;p&gt;Running the whole provisioning process now takes one command and finishes in a matter of seconds, something that used to take a series of manual steps and careful attention to avoid the exact mistakes I described above.&lt;/p&gt;
&lt;h2&gt;
  
  
  What This Project Actually Demonstrates
&lt;/h2&gt;

&lt;p&gt;If you are a recruiter or a hiring manager reading this, here is what I want you to take away. This was not a copy and paste exercise. Every command here was typed, tested, and in more than one case, broken and then fixed by understanding the actual cause rather than guessing. I hit a real Azure networking conflict and resolved it by reading the error and understanding how security rule priorities work. I hit a real Linux permissions issue and resolved it the same way.&lt;/p&gt;

&lt;p&gt;I also wrote the entire process up as a runbook, the kind of documentation a real engineering team would expect, so that anyone on a team could follow these exact steps and get the same result, safely and predictably.&lt;/p&gt;

&lt;p&gt;The live result of this project is a working website, served entirely from infrastructure I provisioned, secured and configured myself, from the terminal, from the ground up.&lt;/p&gt;

&lt;p&gt;If you would like to see the full runbook, the automation script, or talk through any part of how this was built, I would genuinely welcome the conversation. This is exactly the kind of work I want to keep doing.&lt;/p&gt;

&lt;p&gt;Below is the link to my github repo&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/highpee1991" rel="noopener noreferrer"&gt;
        highpee1991
      &lt;/a&gt; / &lt;a href="https://github.com/highpee1991/azure-cli-lab" rel="noopener noreferrer"&gt;
        azure-cli-lab
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      My Azure CLI learning journey from beginner to pro
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Day 01 — Azure CLI Basics&lt;/h1&gt;
&lt;/div&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;What I Learned&lt;/h2&gt;
&lt;/div&gt;

&lt;p&gt;Azure CLI is a tool that lets you manage Azure resources from the terminal...&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Commands I Ran&lt;/h2&gt;
&lt;/div&gt;

&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Check version&lt;/h3&gt;

&lt;/div&gt;

&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;az --version&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Output:
azure-cli                         2.87.0&lt;/p&gt;
&lt;p&gt;core                              2.87.0
telemetry                          1.1.0&lt;/p&gt;
&lt;p&gt;Dependencies:
msal                              1.36.0
azure-mgmt-resource               24.0.0&lt;/p&gt;
&lt;p&gt;Python location 'C:\Program Files\Microsoft SDKs\Azure\CLI2\python.exe'
Config directory 'C:\Users\Relitorin Orders.azure'
Extensions directory 'C:\Users\Relitorin Orders.azure\cliextensions'&lt;/p&gt;
&lt;p&gt;Python (Windows) 3.13.13 (tags/v3.13.13:01104ce, Apr  7 2026, 19:25:48) [MSC v.1944 64 bit (AMD64)]&lt;/p&gt;
&lt;p&gt;Legal docs and information: aka.ms/AzureCliLegal&lt;/p&gt;
&lt;p&gt;Your CLI is up-to-date.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Login to Azure&lt;/h3&gt;

&lt;/div&gt;
&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;az login
az account show&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Output:
Retrieving tenants and subscriptions for the selection...&lt;/p&gt;
&lt;p&gt;[Tenant and subscription selection]&lt;/p&gt;
&lt;p&gt;No     Subscription name     Subscription ID                       Tenant&lt;/p&gt;

&lt;p&gt;[1] *  Azure subscription 1    Default Directory&lt;/p&gt;
&lt;p&gt;The default is marked with an *; the default tenant is 'Default Directory' and subscription is 'Azure subsc
ription 1' ().&lt;/p&gt;
&lt;p&gt;Select a subscription and tenant (Type a number or Enter for no changes):&lt;/p&gt;
&lt;p&gt;Tenant: Default Directory
Subscription: Azure subscription…&lt;/p&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/highpee1991/azure-cli-lab" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


</description>
    </item>
    <item>
      <title>Multi-Region VNet Peering + Global Load Balancer on Azure, A Step-by-Step Guide</title>
      <dc:creator>Ipadeola Taiwo</dc:creator>
      <pubDate>Mon, 29 Jun 2026 19:12:04 +0000</pubDate>
      <link>https://dev.to/highpee1991/multi-region-vnet-peering-global-load-balancer-on-azure-a-step-by-step-guide-45ap</link>
      <guid>https://dev.to/highpee1991/multi-region-vnet-peering-global-load-balancer-on-azure-a-step-by-step-guide-45ap</guid>
      <description>&lt;h2&gt;
  
  
  What We're Building
&lt;/h2&gt;

&lt;p&gt;A Nigerian fintech has two offices, &lt;strong&gt;Lagos&lt;/strong&gt; and &lt;strong&gt;Abuja&lt;/strong&gt; and wants:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Both offices on the &lt;strong&gt;same private network&lt;/strong&gt;, even though they sit in different parts of the world&lt;/li&gt;
&lt;li&gt;A web app running on a server in each office&lt;/li&gt;
&lt;li&gt;Traffic automatically routed to whichever office is closest to the user, with &lt;strong&gt;automatic failover&lt;/strong&gt; if one office's server goes down&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To simulate this on Azure, Lagos lives in &lt;strong&gt;East US&lt;/strong&gt; and Abuja lives in &lt;strong&gt;South Africa North&lt;/strong&gt; two genuinely different Azure regions, connected privately, with a global load balancer deciding where to send traffic.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fufsns9lkp6rlxfav5jcm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fufsns9lkp6rlxfav5jcm.png" alt=" " width="799" height="436"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;By the end of this guide, you'll have a working multi-region setup you can test from your own terminal.&lt;/p&gt;

&lt;h3&gt;
  
  
  What you'll need
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;An Azure account (the free tier works fine)&lt;/li&gt;
&lt;li&gt;Basic comfort with the Azure Portal&lt;/li&gt;
&lt;li&gt;A terminal that can run &lt;code&gt;ssh&lt;/code&gt; and &lt;code&gt;curl&lt;/code&gt; (Git Bash, macOS/Linux terminal, or Cloud Shell)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Step 1: Create a Resource Group
&lt;/h2&gt;

&lt;p&gt;A resource group is just a logical folder that holds everything we build, so it's easy to manage or delete later as one unit.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In the Azure Portal, search &lt;strong&gt;"Resource groups"&lt;/strong&gt; → &lt;strong&gt;+ Create&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resource group name:&lt;/strong&gt; &lt;code&gt;fintech-rg&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Region:&lt;/strong&gt; pick any region for the resource group itself, it doesn't have to match the resources inside it&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Review + Create&lt;/strong&gt; → &lt;strong&gt;Create&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F554aaiatbqcy1udvbe6n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F554aaiatbqcy1udvbe6n.png" alt=" " width="800" height="358"&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Step 2: Create Two Virtual Networks (VNets)
&lt;/h2&gt;

&lt;p&gt;A VNet is a private network inside Azure. We need one for each branch office, in two different regions.&lt;/p&gt;

&lt;h3&gt;
  
  
  VNet for Lagos (East US)
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Search &lt;strong&gt;"Virtual networks"&lt;/strong&gt; → &lt;strong&gt;+ Create&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Resource group: &lt;code&gt;fintech-rg&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Name: &lt;code&gt;lagos-vnet&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Region: &lt;strong&gt;East US&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Leave the default address space and subnet, or customize if you prefer&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Review + Create&lt;/strong&gt; → &lt;strong&gt;Create&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  VNet for Abuja (South Africa North)
&lt;/h3&gt;

&lt;p&gt;Repeat the same steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Name: &lt;code&gt;abuja-vnet&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Region: &lt;strong&gt;South Africa North&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Review + Create&lt;/strong&gt; → &lt;strong&gt;Create&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fsofku5g0b2nfc682kykz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fsofku5g0b2nfc682kykz.png" alt=" " width="800" height="361"&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Step 3: Peer the Two VNets Together
&lt;/h2&gt;

&lt;p&gt;VNet Peering connects the two networks so resources inside them can talk to each other using &lt;strong&gt;private IP addresses&lt;/strong&gt;, as if they were on the same local network, no public internet involved.&lt;/p&gt;

&lt;p&gt;Peering needs to be set up from &lt;strong&gt;both sides&lt;/strong&gt; once from Lagos's VNet pointing to Abuja, and once from Abuja's VNet pointing to Lagos.&lt;/p&gt;

&lt;h3&gt;
  
  
  From the Lagos VNet
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Open &lt;code&gt;lagos-vnet&lt;/code&gt; → left menu → &lt;strong&gt;Peerings&lt;/strong&gt; → &lt;strong&gt;+ Add&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;This virtual network:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Peering link name: &lt;code&gt;lagos-to-abuja&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Allow traffic to remote virtual network: ✅ enabled&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Remote virtual network:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Peering link name: &lt;code&gt;abuja-to-lagos&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Virtual network: select &lt;code&gt;abuja-vnet&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Allow traffic to remote virtual network: ✅ enabled&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Add&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This single step actually creates both sides of the peering at once.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ff7hg8qkg7zchkyjbus83.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ff7hg8qkg7zchkyjbus83.png" alt=" " width="799" height="357"&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Confirm the Peering Is Connected
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Go back to &lt;code&gt;lagos-vnet&lt;/code&gt; → &lt;strong&gt;Peerings&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;You should see the peering listed with status: &lt;strong&gt;Connected&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Check &lt;code&gt;abuja-vnet&lt;/code&gt; → &lt;strong&gt;Peerings&lt;/strong&gt; too — it should show &lt;strong&gt;Connected&lt;/strong&gt; from its side as well&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F07wwqtpf9myyhe8z2x08.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F07wwqtpf9myyhe8z2x08.png" alt=" " width="799" height="330"&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Step 4: Create a VM in Each VNet
&lt;/h2&gt;

&lt;h3&gt;
  
  
  VM for Lagos
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Search &lt;strong&gt;"Virtual machines"&lt;/strong&gt; → &lt;strong&gt;+ Create&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Resource group: &lt;code&gt;fintech-rg&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;VM name: &lt;code&gt;lagos-vm&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Region: &lt;strong&gt;East US&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Image: &lt;strong&gt;Ubuntu Server&lt;/strong&gt; (any recent LTS version)&lt;/li&gt;
&lt;li&gt;Size: the default/smallest size is fine for this project&lt;/li&gt;
&lt;li&gt;Authentication: &lt;strong&gt;SSH public key&lt;/strong&gt; (recommended) or password&lt;/li&gt;
&lt;li&gt;Username: &lt;code&gt;lagosvm&lt;/code&gt; &lt;em&gt;(or whatever username you prefer, just stay consistent for the rest of the guide)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Networking tab:&lt;/strong&gt; Virtual network → select &lt;code&gt;lagos-vnet&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Review + Create&lt;/strong&gt; → &lt;strong&gt;Create&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  VM for Abuja
&lt;/h3&gt;

&lt;p&gt;Repeat with:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;VM name: &lt;code&gt;abuja-vm&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Region: &lt;strong&gt;South Africa North&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Username: &lt;code&gt;abujavm&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Virtual network: &lt;code&gt;abuja-vnet&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8znllk21tio3luhvi5da.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8znllk21tio3luhvi5da.png" alt=" " width="800" height="361"&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Once both VMs are created, &lt;strong&gt;note down&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each VM's &lt;strong&gt;public IP&lt;/strong&gt; (used to SSH in)&lt;/li&gt;
&lt;li&gt;Each VM's &lt;strong&gt;private IP&lt;/strong&gt; (used for the ping test later)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this guide, the private IPs are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lagos VM private IP: &lt;code&gt;10.0.0.4&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Abuja VM private IP: &lt;code&gt;10.1.0.4&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;(Yours may be different — always use the actual IP shown in your VM's &lt;strong&gt;Overview&lt;/strong&gt; or &lt;strong&gt;Networking&lt;/strong&gt; tab.)&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 5: Secure SSH Access and Connect to Each VM
&lt;/h2&gt;

&lt;p&gt;If you're using an SSH key pair, make sure your private key file has the correct permissions before connecting, otherwise SSH will refuse to use it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;700 lagosvm_key.pem
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(Do the same for the Abuja key if you're using a separate one.)&lt;/p&gt;

&lt;p&gt;Connect to the Lagos VM:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh &lt;span class="nt"&gt;-i&lt;/span&gt; lagosvm_key.pem lagosvm@&amp;lt;lagos-vm-public-ip&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Connect to the Abuja VM in a separate terminal tab:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh &lt;span class="nt"&gt;-i&lt;/span&gt; abujavm_key.pem abujavm@&amp;lt;abuja-vm-public-ip&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fk3dep7526pb8il5rdgcg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fk3dep7526pb8il5rdgcg.png" alt=" " width="478" height="303"&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frdp07wudstf6zlcyjqtb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frdp07wudstf6zlcyjqtb.png" alt=" " width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 6: Install and Start a Web Server on Each VM
&lt;/h2&gt;

&lt;p&gt;Run this on &lt;strong&gt;both&lt;/strong&gt; VMs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;sudo &lt;/span&gt;apt upgrade &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;apache2 &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl start apache2
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl &lt;span class="nb"&gt;enable &lt;/span&gt;apache2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;apt update &amp;amp;&amp;amp; upgrade&lt;/code&gt; refreshes the package list and applies any pending updates&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;apache2&lt;/code&gt; is the web server that will respond to HTTP requests&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;enable&lt;/code&gt; makes sure Apache automatically restarts if the VM ever reboots&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Confirm Apache is running on each VM:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl status apache2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see &lt;code&gt;active (running)&lt;/code&gt; in green.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnkucyb2uh5y9tryzr82i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnkucyb2uh5y9tryzr82i.png" alt=" " width="800" height="472"&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Step 7: Test the Private Network Connection (Ping Test)
&lt;/h2&gt;

&lt;p&gt;This is the moment that proves the VNet peering actually works — two VMs, in two different regions, reaching each other over a private connection.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;From the Lagos VM&lt;/strong&gt;, ping Abuja's private IP:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ping 10.1.0.4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;From the Abuja VM&lt;/strong&gt;, ping Lagos's private IP:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ping 10.0.0.4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If peering is working correctly, you'll see successful replies on both sides, something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;64 bytes from 10.1.0.4: icmp_seq=1 ttl=64 time=142 ms
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Press &lt;code&gt;Ctrl + C&lt;/code&gt; to stop the ping.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmnf6sg3pjx16hxkymk7t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmnf6sg3pjx16hxkymk7t.png" alt=" " width="800" height="419"&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F980pdazng8qdir16b8oy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F980pdazng8qdir16b8oy.png" alt=" " width="482" height="309"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;⚠️ &lt;strong&gt;Note:&lt;/strong&gt; If you don't get replies, double check that each VM's &lt;strong&gt;Network Security Group (NSG)&lt;/strong&gt; allows inbound traffic from the peered VNet (the default &lt;code&gt;AllowVnetInBound&lt;/code&gt; rule usually covers this automatically).&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Step 8: Customize Each Web Page So You Can Tell Them Apart
&lt;/h2&gt;

&lt;p&gt;To visually confirm which server is responding later (especially once the load balancer is involved), give each VM a distinct homepage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;On the Lagos VM:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;h1&amp;gt;Hello from Lagos Server&amp;lt;/h1&amp;gt;"&lt;/span&gt; | &lt;span class="nb"&gt;sudo tee&lt;/span&gt; /var/www/html/index.html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;On the Abuja VM:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;h1&amp;gt;Hello from Abuja Server&amp;lt;/h1&amp;gt;"&lt;/span&gt; | &lt;span class="nb"&gt;sudo tee&lt;/span&gt; /var/www/html/index.html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Test it directly using each VM's &lt;strong&gt;public IP&lt;/strong&gt; in a browser:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://&amp;lt;lagos-vm-public-ip&amp;gt;
http://&amp;lt;abuja-vm-public-ip&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see the matching "Hello from..." message for each one.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuf68w6xesvpowvmjejzd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuf68w6xesvpowvmjejzd.png" alt=" " width="799" height="397"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Step 9: Open Port 80 on Both VMs
&lt;/h2&gt;

&lt;p&gt;Apache runs on port 80, so each VM's NSG needs to allow inbound HTTP traffic — otherwise external requests (including from the load balancer) won't be able to reach it.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open each VM → &lt;strong&gt;Networking&lt;/strong&gt; tab → &lt;strong&gt;Add inbound port rule&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Settings:

&lt;ul&gt;
&lt;li&gt;Destination port: &lt;code&gt;80&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Protocol: &lt;code&gt;TCP&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Action: &lt;code&gt;Allow&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Give the rule a name (anything descriptive works, e.g. &lt;code&gt;Allow-HTTP&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Add&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Repeat for the other VM&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Step 10: Create the Regional Load Balancer for Lagos
&lt;/h2&gt;

&lt;p&gt;Since Lagos and Abuja are in different regions, we can't use one single load balancer to cover both — a standard Azure Load Balancer only operates within a single region. We need &lt;strong&gt;one regional load balancer per region&lt;/strong&gt;, and later, a &lt;strong&gt;Global Load Balancer&lt;/strong&gt; sitting on top of both.&lt;/p&gt;

&lt;h3&gt;
  
  
  10.1 — Create the Public IP
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Search &lt;strong&gt;"Public IP addresses"&lt;/strong&gt; → &lt;strong&gt;+ Create&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Give it a name (e.g. &lt;code&gt;lagos-lb-ip&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;SKU: &lt;strong&gt;Standard&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Tier: &lt;strong&gt;Regional&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Region: &lt;strong&gt;East US&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Assignment: &lt;strong&gt;Static&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Review + Create&lt;/strong&gt; → &lt;strong&gt;Create&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  10.2 — Create the Load Balancer
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Search &lt;strong&gt;"Load balancers"&lt;/strong&gt; → &lt;strong&gt;+ Create&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Give it a name (e.g. &lt;code&gt;lagos-lb&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Region: &lt;strong&gt;East US&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;SKU: &lt;strong&gt;Standard&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Type: &lt;strong&gt;Public&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Tier: &lt;strong&gt;Regional&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Frontend IP configuration:&lt;/strong&gt; add a frontend IP, give it a name, and select the public IP you just created (&lt;code&gt;lagos-lb-ip&lt;/code&gt;) — this becomes your regional frontend IP, in this guide &lt;code&gt;20.121.242.74&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Skip backend pools and rules for now — we'll add them after creation for a cleaner setup&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Review + Create&lt;/strong&gt; → &lt;strong&gt;Create&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fczlfbxgm5ijugj9ep7oy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fczlfbxgm5ijugj9ep7oy.png" alt=" " width="800" height="368"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkh86ospmiwmhcaashe3b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkh86ospmiwmhcaashe3b.png" alt=" " width="800" height="328"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  10.3 — Add the Backend Pool
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Open your Lagos load balancer → &lt;strong&gt;Backend pools&lt;/strong&gt; → &lt;strong&gt;+ Add&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Give it a name&lt;/li&gt;
&lt;li&gt;Virtual network: select &lt;code&gt;lagos-vnet&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Backend pool configuration: &lt;strong&gt;NIC&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;+ Add&lt;/strong&gt; under the IP configurations table → select &lt;code&gt;lagos-vm&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Save&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fye5rfwc1lm23bq6bxwlz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fye5rfwc1lm23bq6bxwlz.png" alt=" " width="800" height="395"&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  10.4 — Add a Health Probe
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Health probes&lt;/strong&gt; → &lt;strong&gt;+ Add&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Give it a name&lt;/li&gt;
&lt;li&gt;Protocol: &lt;strong&gt;HTTP&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Port: &lt;code&gt;80&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Path: &lt;code&gt;/&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Interval: 5–15 seconds&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Add&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  10.5 — Add the Load Balancing Rule
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Load balancing rules&lt;/strong&gt; → &lt;strong&gt;+ Add&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Give it a name&lt;/li&gt;
&lt;li&gt;Frontend IP: select the frontend IP you created&lt;/li&gt;
&lt;li&gt;Backend pool: select the backend pool you created&lt;/li&gt;
&lt;li&gt;Health probe: select the probe you created&lt;/li&gt;
&lt;li&gt;Protocol: &lt;strong&gt;TCP&lt;/strong&gt;, Port: &lt;code&gt;80&lt;/code&gt;, Backend port: &lt;code&gt;80&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Add&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  10.6 — Test the Lagos Load Balancer
&lt;/h3&gt;

&lt;p&gt;From your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl http://20.121.242.74
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(replace with your actual Lagos load balancer frontend IP)&lt;/p&gt;

&lt;p&gt;You should see the "Hello from Lagos Server" response.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvzoc0fpw2cmvkzcddwbq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvzoc0fpw2cmvkzcddwbq.png" alt=" " width="799" height="302"&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Step 11: Create the Regional Load Balancer for Abuja
&lt;/h2&gt;

&lt;p&gt;Repeat &lt;strong&gt;all of Step 10&lt;/strong&gt;, but for the Abuja region:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Public IP: give it a name, Region: &lt;strong&gt;South Africa North&lt;/strong&gt; → in this guide, the resulting frontend IP is &lt;code&gt;20.87.39.70&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Load Balancer: give it a name, Region: &lt;strong&gt;South Africa North&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Backend pool: Virtual network → &lt;code&gt;abuja-vnet&lt;/code&gt;, add &lt;code&gt;abuja-vm&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Health probe and rule: same settings as before (HTTP/80/&lt;code&gt;/&lt;/code&gt;, TCP/80→80)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Test it:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl http://20.87.39.70
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see "Hello from Abuja Server."&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftz984ho19rw2h0ea19ku.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftz984ho19rw2h0ea19ku.png" alt=" " width="800" height="401"&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;⚠️ &lt;strong&gt;Important:&lt;/strong&gt; Don't move to the next step until both regional load balancers pass this test independently. The Global Load Balancer depends on both of these already working correctly.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 12: Create the Global Load Balancer
&lt;/h2&gt;

&lt;p&gt;The Global Load Balancer sits above both regional load balancers and decides which region to send each user's request to, based on which one is geographically closest &lt;strong&gt;and&lt;/strong&gt; healthy.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1173e0ek79vxzng5zx5y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1173e0ek79vxzng5zx5y.png" alt=" " width="800" height="412"&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  12.1 — Create the Global Public IP
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Search &lt;strong&gt;"Public IP addresses"&lt;/strong&gt; → &lt;strong&gt;+ Create&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Give it a name (e.g. &lt;code&gt;global-lb-ip&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;SKU: &lt;strong&gt;Standard&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Tier: &lt;strong&gt;Global&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Region: must be one of Azure's supported &lt;strong&gt;home regions&lt;/strong&gt; for global resources, examples include &lt;code&gt;East US 2&lt;/code&gt;, &lt;code&gt;West Europe&lt;/code&gt;, &lt;code&gt;Southeast Asia&lt;/code&gt;, &lt;code&gt;West US&lt;/code&gt;, &lt;code&gt;North Europe&lt;/code&gt;, &lt;code&gt;Central US&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Assignment: &lt;strong&gt;Static&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Review + Create&lt;/strong&gt; → &lt;strong&gt;Create&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this guide, the resulting global IP is &lt;code&gt;20.15.1.61&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  12.2 — Create the Global Load Balancer
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Search &lt;strong&gt;"Load balancers"&lt;/strong&gt; → &lt;strong&gt;+ Create&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Give it a name (e.g. &lt;code&gt;global-lb&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Region: the same home region you used for the global IP (e.g. &lt;code&gt;East US 2&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;SKU: &lt;strong&gt;Standard&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Tier: &lt;strong&gt;Global&lt;/strong&gt; ⚠️ this is the setting that matters most here — don't select Regional&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Frontend IP configuration:&lt;/strong&gt; add a frontend IP, give it a name, and select your &lt;code&gt;global-lb-ip&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Skip backend pools and rules in the wizard&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Review + Create&lt;/strong&gt; → &lt;strong&gt;Create&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  12.3 — Add the Backend Pool
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Open your Global load balancer → &lt;strong&gt;Backend pools&lt;/strong&gt; → &lt;strong&gt;+ Add&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Give it a name&lt;/li&gt;
&lt;li&gt;Under the configuration table, click &lt;strong&gt;+ Add&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Type: &lt;strong&gt;Load Balancer&lt;/strong&gt; (not NIC, not IP address)&lt;/li&gt;
&lt;li&gt;Add your &lt;strong&gt;Lagos&lt;/strong&gt; load balancer&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;+ Add&lt;/strong&gt; again and add your &lt;strong&gt;Abuja&lt;/strong&gt; load balancer&lt;/li&gt;
&lt;li&gt;Confirm both regional load balancers now appear in the table&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Save&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2m4mi1ib8rllhirc0dzl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2m4mi1ib8rllhirc0dzl.png" alt=" " width="800" height="349"&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  12.4 — Add the Load Balancing Rule
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Load balancing rules&lt;/strong&gt; → &lt;strong&gt;+ Add&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Give it a name&lt;/li&gt;
&lt;li&gt;Frontend IP: your global frontend IP&lt;/li&gt;
&lt;li&gt;Backend pool: your global backend pool&lt;/li&gt;
&lt;li&gt;Protocol: &lt;strong&gt;TCP&lt;/strong&gt;, Port: &lt;code&gt;80&lt;/code&gt;, &lt;strong&gt;Backend port: &lt;code&gt;80&lt;/code&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The backend port here must match the frontend port used in both regional load balancer rules — in this case, both use port 80, so we're consistent.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Add&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Step 13: Test the Global Load Balancer
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl http://20.15.1.61
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(replace with your actual global load balancer IP)&lt;/p&gt;

&lt;p&gt;You should get back a response from whichever region is closest to you, for example, "Hello from Lagos Server."&lt;/p&gt;

&lt;p&gt;This is expected behavior: the Global Load Balancer uses &lt;strong&gt;geo-proximity routing&lt;/strong&gt;, not round robin. It always routes you to the closest healthy region, not a random alternating split.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdw8afa5pa006o2k8ga1x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdw8afa5pa006o2k8ga1x.png" alt=" " width="647" height="312"&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Step 14: Test Automatic Failover
&lt;/h2&gt;

&lt;p&gt;To prove the system can actually fail over between regions, we'll simulate one region going down.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SSH into the Lagos VM&lt;/strong&gt; and stop Apache:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl stop apache2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now curl the global load balancer again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl http://20.15.1.61
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This time, the response should switch to &lt;strong&gt;"Hello from Abuja Server"&lt;/strong&gt; Azure detected that the Lagos region's health probe failed, removed it from rotation, and automatically routed traffic to the healthy Abuja region instead.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgqilnqp2yfx2cy0vi3r2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgqilnqp2yfx2cy0vi3r2.png" alt=" " width="514" height="413"&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Once you're done testing, restart Apache on the Lagos VM so it's back in rotation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl start apache2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Recap: What We Actually Built
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Client
  ↓
Global Load Balancer (home region, e.g. East US 2)
  ↓                              ↓
Regional LB - Lagos          Regional LB - Abuja
(East US)                    (South Africa North)
  ↓                              ↓
lagos-vm                     abuja-vm
  ↳ peered privately with abuja-vm via VNet Peering
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This setup demonstrates three real-world cloud concepts at once:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Private cross-region connectivity&lt;/strong&gt; (VNet Peering)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Regional high availability&lt;/strong&gt; (each region's own load balancer and health probe)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Global resilience and failover&lt;/strong&gt; (the Global Load Balancer routing around an unhealthy region automatically)&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhqlhq9pgtm4aw0c0yjy3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhqlhq9pgtm4aw0c0yjy3.png" alt=" " width="799" height="436"&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you build this yourself, try the failover test a few times — watching traffic automatically reroute in real time is genuinely satisfying, and it's the same underlying pattern real fintechs use to stay online across regions.&lt;/p&gt;

&lt;p&gt;Got stuck somewhere or have a question about a specific step? Drop a comment below 👇&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Day 2: I Stopped Being a Student and Started Acting Like a DevOps Engineer</title>
      <dc:creator>Ipadeola Taiwo</dc:creator>
      <pubDate>Sun, 28 Jun 2026 08:32:59 +0000</pubDate>
      <link>https://dev.to/highpee1991/day-2-i-stopped-being-a-student-and-started-acting-like-a-devops-engineer-4kid</link>
      <guid>https://dev.to/highpee1991/day-2-i-stopped-being-a-student-and-started-acting-like-a-devops-engineer-4kid</guid>
      <description>&lt;p&gt;This is Day 2 of my 90-day cloud engineering challenge. Day 1 was about installing tools and getting familiar with the Azure CLI. Day 2 was different  instead of just running commands to learn syntax, I gave myself a real-world scenario and worked through it the way an actual DevOps engineer would on the job.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Scenario
&lt;/h2&gt;

&lt;p&gt;To push myself past "tutorial mode," I simulated a message from a team lead:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Taiwo, we need a new environment for the payments project. Create a resource group for dev, one for staging. Tag them properly. Create a storage account in dev. List everything and send me a clean output. Then document it."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;No step-by-step instructions. No exact commands handed to me just a goal. That's closer to how real work actually shows up: as an outcome someone needs, not a tutorial to follow. My job was to translate that into the right CLI commands, tag things properly, and produce a clean, professional result.&lt;/p&gt;

&lt;h2&gt;
  
  
  Commands I Used
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Listing and inspecting resource groups
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az group list
az group list &lt;span class="nt"&gt;--output&lt;/span&gt; table
az group list &lt;span class="nt"&gt;--output&lt;/span&gt; tsv
az group list &lt;span class="nt"&gt;--output&lt;/span&gt; jsonc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I started by getting comfortable with different output formats. In a real environment with dozens or hundreds of resources, raw JSON is hard to scan quickly &lt;code&gt;table&lt;/code&gt; and &lt;code&gt;tsv&lt;/code&gt; make it much easier to read at a glance or pipe into other tools/scripts.&lt;/p&gt;

&lt;h3&gt;
  
  
  Filtering with &lt;code&gt;--query&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az group list &lt;span class="nt"&gt;--query&lt;/span&gt; &lt;span class="s2"&gt;"[].{Name:name, Location:location}"&lt;/span&gt; &lt;span class="nt"&gt;--output&lt;/span&gt; table
az group list &lt;span class="nt"&gt;--query&lt;/span&gt; &lt;span class="s2"&gt;"[?location=='eastus'].name"&lt;/span&gt; &lt;span class="nt"&gt;--output&lt;/span&gt; table
az account show &lt;span class="nt"&gt;--query&lt;/span&gt; &lt;span class="s2"&gt;"name"&lt;/span&gt; &lt;span class="nt"&gt;--output&lt;/span&gt; tsv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is where things started feeling like real engineering rather than just running commands. &lt;code&gt;--query&lt;/code&gt; lets you filter and reshape the JSON output before it even hits your screen instead of scrolling through everything, you ask for exactly what you need. When you're dealing with 200+ resources, this isn't optional; it's how you stay sane.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tagging resources properly
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az group update &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--name&lt;/span&gt; taiwo-devops-rg &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--tags&lt;/span&gt; &lt;span class="nv"&gt;Environment&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;Dev &lt;span class="nv"&gt;Owner&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;Taiwo &lt;span class="nv"&gt;Project&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;AzureCLILab

az group show &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--name&lt;/span&gt; taiwo-devops-rg &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--query&lt;/span&gt; &lt;span class="s2"&gt;"tags"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--output&lt;/span&gt; table
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Tags seem like a small detail until you realize how much they matter in a real company. Tags answer three questions instantly, for any resource, at any scale:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Who owns it?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What project does it belong to?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What environment is it dev, staging, or production?&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Without consistent tagging, a subscription with hundreds of resources becomes nearly impossible to manage, audit, or clean up safely.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Automation Script
&lt;/h2&gt;

&lt;p&gt;Rather than running each command by hand every time I needed an environment, I wrote a Bash script to provision the entire setup dev resource group, staging resource group, and a storage account in one run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="c"&gt;# ============================================&lt;/span&gt;
&lt;span class="c"&gt;# Azure Environment Provisioner&lt;/span&gt;
&lt;span class="c"&gt;# Author: Taiwo&lt;/span&gt;
&lt;span class="c"&gt;# Description: Provisions dev environment&lt;/span&gt;
&lt;span class="c"&gt;#              for any project automatically&lt;/span&gt;
&lt;span class="c"&gt;# ============================================&lt;/span&gt;

&lt;span class="c"&gt;# Variables change these for any project&lt;/span&gt;
&lt;span class="nv"&gt;PROJECT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"payments"&lt;/span&gt;
&lt;span class="nv"&gt;OWNER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Taiwo"&lt;/span&gt;
&lt;span class="nv"&gt;LOCATION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"eastus"&lt;/span&gt;
&lt;span class="nv"&gt;STORAGE_NAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"taiwo&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;PROJECT&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;dev001"&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"🚀 Starting provisioning for project: &lt;/span&gt;&lt;span class="nv"&gt;$PROJECT&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="c"&gt;# Step 1: Create Dev Resource Group&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"📁 Creating Dev Resource Group..."&lt;/span&gt;
az group create &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--name&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;PROJECT&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;-dev-rg"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--location&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$LOCATION&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--tags&lt;/span&gt; &lt;span class="nv"&gt;Environment&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;Dev &lt;span class="nv"&gt;Owner&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$OWNER&lt;/span&gt; &lt;span class="nv"&gt;Project&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$PROJECT&lt;/span&gt;

&lt;span class="c"&gt;# Step 2: Create Staging Resource Group&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"📁 Creating Staging Resource Group..."&lt;/span&gt;
az group create &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--name&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;PROJECT&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;-staging-rg"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--location&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$LOCATION&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--tags&lt;/span&gt; &lt;span class="nv"&gt;Environment&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;Staging &lt;span class="nv"&gt;Owner&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$OWNER&lt;/span&gt; &lt;span class="nv"&gt;Project&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$PROJECT&lt;/span&gt;

&lt;span class="c"&gt;# Step 3: Create Storage Account&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"💾 Creating Storage Account..."&lt;/span&gt;
az storage account create &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--name&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$STORAGE_NAME&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--resource-group&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;PROJECT&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;-dev-rg"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--location&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$LOCATION&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--sku&lt;/span&gt; Standard_LRS &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--kind&lt;/span&gt; StorageV2 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--tags&lt;/span&gt; &lt;span class="nv"&gt;Environment&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;Dev &lt;span class="nv"&gt;Owner&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$OWNER&lt;/span&gt; &lt;span class="nv"&gt;Project&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$PROJECT&lt;/span&gt;

&lt;span class="c"&gt;# Step 4: Confirm everything&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"✅ Provisioning complete. Here is your environment:"&lt;/span&gt;
az group list &lt;span class="nt"&gt;--output&lt;/span&gt; table

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"🎉 Done! Project &lt;/span&gt;&lt;span class="nv"&gt;$PROJECT&lt;/span&gt;&lt;span class="s2"&gt; environment is ready."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The script takes a few simple variables  project name, owner, and location  and provisions a complete environment from scratch, consistently, every single time. Change the &lt;code&gt;PROJECT&lt;/code&gt; variable and the same script provisions an environment for a completely different project. That's the difference between "I ran some commands" and "I built something reusable."&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus: A Git Workflow Script
&lt;/h2&gt;

&lt;p&gt;Outside of the Azure work itself, I also wrote a small Bash script to speed up my Git workflow  staging, committing, and pushing in a single command instead of typing three separate ones every time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="c"&gt;# Exit if any command fails&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt;
&lt;span class="nb"&gt;trap&lt;/span&gt; &lt;span class="s1"&gt;'echo "❌ A command failed. Exiting..."'&lt;/span&gt; ERR

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Current branch: &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;git branch &lt;span class="nt"&gt;--show-current&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="c"&gt;# Stage all changes&lt;/span&gt;
git add &lt;span class="nb"&gt;.&lt;/span&gt;

&lt;span class="c"&gt;# Prompt for commit message&lt;/span&gt;
&lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="nb"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
    &lt;/span&gt;&lt;span class="nb"&gt;read&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="s2"&gt;"Enter a commit message: "&lt;/span&gt; commitMessage
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$commitMessage&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
        &lt;/span&gt;&lt;span class="nb"&gt;break
    &lt;/span&gt;&lt;span class="k"&gt;fi
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Commit message cannot be empty."&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;

&lt;span class="c"&gt;# Commit and push&lt;/span&gt;
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$commitMessage&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
git push

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"✅ Changes committed and pushed successfully."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Small touches here matter: &lt;code&gt;set -e&lt;/code&gt; and the &lt;code&gt;trap&lt;/code&gt; ensure the script stops cleanly the moment something fails instead of plowing ahead, and the commit-message prompt won't let me accidentally push with an empty message. It's a small script, but it's the kind of "make my own workflow faster" thinking that DevOps is built on.&lt;/p&gt;

&lt;h2&gt;
  
  
  What This Taught Me About Real DevOps Work
&lt;/h2&gt;

&lt;p&gt;Today reframed how I think about the CLI. It's not just a faster way to click buttons it's a tool for &lt;strong&gt;repeatability, filtering, and automation&lt;/strong&gt; at a scale where doing things manually simply breaks down.&lt;/p&gt;

&lt;p&gt;In a real company, this is what the day-to-day actually looks like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Spinning up a storage account for a dev team on request&lt;/li&gt;
&lt;li&gt;Checking what resources are currently running in production&lt;/li&gt;
&lt;li&gt;Cleaning up a test environment left over from last sprint&lt;/li&gt;
&lt;li&gt;Standing up a new resource group for a new project&lt;/li&gt;
&lt;li&gt;Filtering out the handful of failed resources from a list of 200+&lt;/li&gt;
&lt;li&gt;Wrapping repeatable tasks into scripts instead of typing them out every time&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of that works well through a portal UI when you're dealing with real scale. It works through commands, queries, tags, and scripts exactly what I practiced today.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problems I Faced
&lt;/h2&gt;

&lt;p&gt;The biggest challenge wasn't syntax it was genuinely understanding &lt;em&gt;why&lt;/em&gt; each piece mattered (tagging, querying, scripting) rather than just copying commands. Once I slowed down and researched the reasoning behind each one, things started clicking. I'd rather understand the "why" once than memorize the "what" repeatedly.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Clicked Today
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Provisioned a full dev + staging environment from a single scenario, not a tutorial&lt;/li&gt;
&lt;li&gt;Created a Storage Account via CLI inside the correct resource group&lt;/li&gt;
&lt;li&gt;Used &lt;code&gt;--query&lt;/code&gt; to filter and reshape output like an engineer working at scale&lt;/li&gt;
&lt;li&gt;Wrote a reusable Bash automation script for environment provisioning&lt;/li&gt;
&lt;li&gt;Wrote a separate Git workflow script to speed up my own commit/push process&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What's Next
&lt;/h2&gt;

&lt;p&gt;Day 1 was about learning the tool. Day 2 was about using it to solve a problem someone else gave me. That shift from "following steps" to "interpreting a request and deciding the steps myself" is the part I want to keep practicing for the rest of these 90 days.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Following along with a 90-day hands-on cloud engineering challenge. Catch up on &lt;a href="https://dev.to/highpee1991/day-01-azure-cli-basics-2fh4"&gt;Day 1&lt;/a&gt; here.&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Azure #DevOps #CloudEngineering #100DaysOfCloud #LearningInPublic #BashScripting
&lt;/h1&gt;

</description>
      <category>azure</category>
      <category>career</category>
      <category>devjournal</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
