This is my pet project using Terraform and python with Azure Functions. I want to try out new technologies and tools that I don't use on a daily basis in my job.
As you may read in the title of this project uses mainly two things: Azure Functions to host Python functions and Terraform as an IaC (Infrastructure as a Code) tool.
CI/CD is based on the Azure Pipelines. You can find pipeline definitions in the azure-pipelines folder in this repo. That folder contains:
- PR check pipeline - for PR validation purposes. Azure DevOps view can be found here: PR check pipeline link;
- deployment pipeline - for CD of this project to the Azure environment. Azure DevOps view can be found here: CD pipeline link
Also CD pipeline uses Azure Pipeline Environments to report status of deployment: DevEnv deployment view in Azure DevOps Pipelines
If you want to setup the project on your own computer and try to play with it locally, you need to do a couple of things:
- Clone this repo to your machine.
- Install terraform and az cli on your machine.
- Run
az login
command and login to your Azure account. - Create a Azure Storage Account for Terraform state using tfstate_storage_setup.sh script.
- Set the
ARM_ACCESS_KEY
environment variable to the storage access key that you got from script output from the previous point of this guide. - Change a name of the storage in the main.tf file in the 9th line from
tfstate6671
to a name that you got from script output from the 3rd point of this guide. - Go to a
src/infrastructure
folder, eg.cd src/infrastructure
. - Run a couple of Terraform commands:
terraform init
terraform plan # This will output the changes on the Azure env that terraform will make
terrafrom apply -auto-approve
Now you have prepared the Azure environment to start hacking.
Next thing is to publish Azure Functions to Azure Function App that was created. For this I highly recommend using VS Code with Azure functions extension as this is the easiest approach. You can stick to this Microsoft Tutorial: Create and deploy serverless Azure Functions in Python with Visual Studio Code.