Provision & Deprovision Azure VMSS using Terraform and a Jenkins pipeline
Terraform enables you to safely and predictably provision, change, and improve infrastructure using plans and commands. This repo contains Terraform plans & commands for provisioning an Azure VMSS from an image using a Jenkins pipeline.
The Jenkins pipelines in this repo leverage Kubernetes features such as pods and secrets while providing an elastic slave pool (each build runs in new pods).
- Install Docker on your computer.
- Install Kubernetes
- Install Jenkins in Kubernetes with Helm and configure Tiller RBAC
- Provision a container registry such as Azure Container Registry or create an account with DockerHub.
- Build Docker image with Azure CLI and Terraform. This image will be used later in Jenkins pipeline deployed in Kubernetes
- Provision Azure VM from Azure Marketplace plan.
- Provision a VM image plan.
- Provision VM or VMSS from a VM image.
docker build -t <containerRegistry>/terraform-az terraform-az
Push the Docker image to Azure Container Registry
docker push <containerRegistry>/terraform-az
2. Deployment - Jenkins Pipeline in Kubernetes
Provision VMSS from a VM image.
Create Kubernetes secret with Azure Service principal. This is required for the following pipelines.
Setup Azure Storage in Jenkins and modify the pipelines accordingly with the relevant id, credentials and container name.
Jenkins Pipeline (Provision) Jenkinsfile
Jenkins Pipeline (Deprovision) Jenkinsfile
The VMSS plan and tfstate are saved in Azure Blob Storage under
tfstatestorage containers to support better automation
You can follow the detailed installation guide here
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.