How to create Azure container Instance (ACI) with Private Azure File as Mounted Volume

Last week I’ve decided to try Azure Container Instance for processing a Go script that shares images between container registries (ACR). Previously the script was executed manually on my computer and I needed to automate it in order to save time. Below I will describe to you the steps of writing in terraform code to build this useful stuff.

The creation of image and container registry it’s not described on this post. It’s a prerequistes to build them before.

Step 1: Create the Storage account with File Share

The storage account contains a File share that will store the config files of my script. The volume will be mounted on this File Share.

Step 2: Upload config files on File share

I use a null_ressource that execute an az command because currently terraform (version 0.13.6) do not allow upload on a file share (unlike blob storage)

Step 3: Create the ACI and the subnet

The code below creates the subnet, the network_profile, and the container_group for the Container Image.

Step 4: Create the private endpoint to access storage

This step is the main important. Without it, your Container Instance will not be able to mount the volume (Azure File) and will stay in-state “Waiting”. Terraform will stay in error after 30 minutes. It’s taken me a lot of time to find the problem.

Final Step: Deploy Your code

Launch terraform or terragrunt apply and enjoy !

Multi Cloud (Azure/ AWS) Systems/Devops Engineer in France.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store