- Install Terraform Plugins required for Development Machine and set up Azure DevOps Pipeline
- Create a new Azure DevOps Release Pipeline with service connection to Azure ARM, this will provision AKS Cluster to Azure.
- Terraform Apply command will provision AKS Cluster to Azure.
- Terraform Destroy command will de-provision AKS Cluster to Azure.
- Check-in Terraform Codes to Github.
Terraform - Install terraform and run terraform commands to manage resources on Azure, AWS and GCP.
https://marketplace.visualstudio.com/items?itemName=ms-devlabs.custom-terraform-tasks
Terraform Build & Release Tasks
https://marketplace.visualstudio.com/items?itemName=charleszipp.azure-pipelines-tasks-terraform
1.1 Login to https://dev.azure.com/ and create a new Project. Then create a new Pipeline.
1.2 Select your Github repository where you checked-in the Azure Terraform
1.3 Click the starter Pipeline.
1.4 Replace with code from step 2 to 5.
1.5 Create new Service Connection for Azure ARM, DockerHub, and Azure Container Registry.
2. Create a new Azure DevOps Release Pipeline with service connection to Azure ARM, this will provision AKS Cluster to Azure.
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- script: echo Deploy Azure AKS using Terraform - Azure IaC.
displayName: 'Run a multi-line script'
- task: DownloadSecureFile@1
name: publickey
inputs:
secureFile: 'azure_rsa.pub'
- task: TerraformCLI@0
inputs:
command: 'init'
workingDirectory: '$(System.DefaultWorkingDirectory)/Web01.kubernetes.Azure.IAC'
backendType: 'azurerm'
backendServiceArm: 'AzureARMConnectionDev'
ensureBackend: true
backendAzureRmResourceGroupName: 'Dev01-RG'
backendAzureRmResourceGroupLocation: 'eastus'
backendAzureRmStorageAccountName: 'dev01straccnt01'
backendAzureRmContainerName: 'dev01strcontainer01'
backendAzureRmKey: 'kubernetes-dev01.tfstate'
- task: TerraformCLI@0
inputs:
command: 'apply'
workingDirectory: '$(System.DefaultWorkingDirectory)/Web01.kubernetes.Azure.IAC'
environmentServiceName: 'AzureARMConnectionDev'
commandOptions: '-var client_id=$(client_id) -var client_secret=$(client_secret) -var ssh_public_key=$(publickey.secureFilePath) -var tenant_id=$(tenant_id) -var subscription_id=$(subscription_id) -var access_key=$(access_key)'
- task: TerraformCLI@0
inputs:
command: 'destroy'
workingDirectory: '$(System.DefaultWorkingDirectory)/Web01.kubernetes.Azure.IAC'
environmentServiceName: 'AzureARMConnectionDev'
commandOptions: '-var client_id=$(client_id) -var client_secret=$(client_secret) -var ssh_public_key=$(publickey.secureFilePath) -var tenant_id=$(tenant_id) -var subscription_id=$(subscription_id) -var access_key=$(access_key)'
Microsoft Azure Container Ecosystem - "nugget series" > Click this Link
Note: My Favorite -> Microsoft :D