Skip to content
This repository has been archived by the owner on Dec 20, 2020. It is now read-only.

Terraform plans & commands to provision Azure VMSS and VM from a VM image on demand or from a Jenkins pipeline.

License

Notifications You must be signed in to change notification settings

Azure/terraform-with-jenkins-samples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

image

Requirements

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.

  1. Install Docker on your computer.
  2. Install Kubernetes
  3. Install Jenkins in Kubernetes with Helm and configure Tiller RBAC
  4. Provision a container registry such as Azure Container Registry or create an account with DockerHub.

Contents

  1. Build Docker image with Azure CLI and Terraform. This image will be used later in Jenkins pipeline deployed in Kubernetes
  2. 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
    

2. Deployment - Jenkins Pipeline in Kubernetes

  • Provision VMSS from a VM image.

    1. Create Kubernetes secret with Azure Service principal. This is required for the following pipelines.

    2. Setup Azure Storage in Jenkins and modify the pipelines accordingly with the relevant id, credentials and container name.

    3. Jenkins Pipeline (Provision) Jenkinsfile

    4. Jenkins Pipeline (Deprovision) Jenkinsfile

    The VMSS plan and tfstate are saved in Azure Blob Storage under plans and tfstate storage containers to support better automation

You can follow the detailed installation guide here

Contributing

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.

About

Terraform plans & commands to provision Azure VMSS and VM from a VM image on demand or from a Jenkins pipeline.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •