Skip to main content

Example: Azure Container Instances (ACI) with Persistent Storage

Brief overview & GitHub example repo that shows how to create Azure Container Instances (ACI), with persistant storage, with Terraform.

Example Repo

https://github.com/boomam/example-terraform-azure-aci

Pre-Reqs

Terraform & Git is installed.

Windows (10 & 11) - 'Chocolatey'

Main overview for install steps are here

  1. Open an administrative powershell window.
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))  
  1. Test Choco has installed
choco

If you see a choco output, you're good to continue!

MacOS - 'Home Brew'

Main overview for install steps are here

  1. Open Terminal.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"  
  1. Test brew has installed
brew

If you see a brew output, you're good to continue!

Install Terraform

Run, either -

Windows

choco install terraform

MacOS

brew install terraform

Modify example files

In the example repo, you can run the example code mostly 'as-is', however you will need to modify as a minimum one file, as a specific variable needs to be globally unique, and ideally two variables, before the code will work.

Enter your information

First, modify terraform.tfvars and update -

  • Line 15 - dns_name_label - this is the final dns name to use, which will end up in the format of this variable.region.azurecontainer.io (unless specified otherwise when deploying).
  • Line 29 - storage_account_name - this needs to be a globally unique storage account name, meaning, no other storage account on Azure can have the same name. So pick something descriptive to you, and as unique as possible.

Login to Azure

In your chosen terminal/CLI app -

az login
note

If your account has multiple subscriptions, make sure you are setting correct one to deploy too by default.
Whilst you can specify this in the Terraform code, its also good to make sure you arn't deploying to the wrong place by having your default subscription set wrong, too.

Initialize Terraform

Browse to where you have the TF example files downloaded to, and run -

terraform init

This step does a basic check of your files, and pre-downloads files (providers) needed to perform the operations against your Azure account.

Plan

This step 'scans' your files for syntax, and shows the planned operation if ran afresh.

terraform plan
tip

On the output for 'plan' and 'apply', a '+' means it will be created, '-' means it will be deleted, '=' means there is no change.

Apply

This step is similar to 'plan', but at the end will ask if you want to apply the configuration to your Azure subscription.

terraform apply

Add a html file

To complete setup/see the test server, you will need to upload a test html to the file share created with the code. Once added, browsing to the outputted DNS name (or IP) will show you said file.