Getting Started with Terraform: Deploying Docker Images to Azure Container Registry and App Service

Guilherme Pompilio
3 min readApr 8, 2024

--

In this tutorial, you will learn how to utilize Infrastructure as Code created with Terraform using DevOps pipelines developed in the previous article.

Project

For this tutorial, I have created a base Web API project and deployed it in a Docker image. You can use the provided project below, or alternatively, you can use another one that is already set up for deployment in Docker.

Clone this project or use another one, then create a repository in Azure Repos and push the code to it.

Create the Pipeline

The pipeline will build the image and push it to Azure Container Registry. To do this, go to New Pipeline, select your Azure Repos Git, and then choose your project.

In the Configure tab, select Docker, then build and push an image to Azure Container Registry.

Select your subscription and authorize it. In the next phase, choose the Container Registry. Note: After applying the Terraform template, there may be a delay in displaying the Container Registry.

The other options can remain at their default values. Then, click on Validate and configure. Run the pipeline.

Create the Release

Now that we have the image in the Container Registry, the release will deploy the image to an App Service. To initiate this process, navigate to Release and select Create New Release.

Select Azure App Service deployment:

Give a name to the task and release, and in the task configuration, select your subscription and the app as Web App for Containers (Linux). Then, in the next fields, input the configuration from the Container Registry as shown in the next image.

Return to the Pipeline and add the artifact, as shown in the image.

Note: At this time, it is good practice to enable Continuous Deployment trigger.

Save, and then create the release!

Now, you can open the App Service URL and see the Swagger API!

With these three tutorials, you can learn how to create a Terraform template, automate it with a pipeline, and set up CI/CD for an API using the created resources!

--

--

Guilherme Pompilio

Software developer from Brazil, passionate about .NET and cloud technologies. I write about technologies that are useful for the day-to-day tasks of a developer