Example repository for this blogpost to show how a relatively minimal Python application can be provisioned with Terraform in Azure, and then built and deployed remotely with a .zip file as Azure function app.
The README is written by a Linux user. Modify the examples for your platform where necessary.
The following tools should be installed and available on your terminal PATH:
- azure (az)
- terraform
- zip
Also, you should be logged in to your Azure account (az login
) and have selected your desired Azure subscription
(see e.g. az-account-switcher)
Follow these steps to deploy the Azure resources with Terraform:
- Update the default values in
terraform/variables.tf
. You can additionally check if the naming conventions used inmain.tf
follow your (company's) style. - Go to the terraform folder on the command line (
{project root}/terraform/
). - Run
terraform init
to setup Terraform (download providers and setup initial state). - Run
terraform apply
.
Besides deploying the resources in Azure, the last step also creates the deployment script as
{project root}/scripts/deploy_function_app.sh
.
In the previous step Terraform created the deploy script at {project root}/scripts/deploy_function_app.sh
.
This script consists of two steps, first building the zip, then using the Azure cli to trigger the remote build
and deployment.
The script must be run from the project root so that the path references are correct. There are many ways to run a script on the commandline, I like:
sh scripts/deploy_function_app.sh
Note: in case you're extending this example application, the zip file should contain:
- all files and folders required for the 'business logic' (in this example the
app
folder) - all functions folders (in this example there's only one function: the
function
folder) - the
host.json
file - the
requirements.txt
file
You can perform a simple smoke-test with curl
to check that the function is running. The command looks like this for the default values in {project root}/terraform/variables.tf
curl https://dev-zipdeploy-functions.azurewebsites.net