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).
To use Terraform it is required to have Azure Service Principal.
Create an Azure Service Principal through Azure CLI or Azure portal.
- 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
- Deployment
- Provision Azure VM from Azure Marketplace plan.
- Provision a VM image plan.
- Provision VM or VMSS from a VM image.
1. Create Docker image with Azure CLI and Terraform. Dockerfile
-
Build
docker build -t <containerRegistry>/terraform-az terraform-az
-
Push the Docker image to Azure Container Registry
docker push <containerRegistry>/terraform-az
-
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
plans
andtfstate
storage 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.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.