-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01-terraform-provision-aks-cluster-pipeline.yml
101 lines (95 loc) · 4.14 KB
/
01-terraform-provision-aks-cluster-pipeline.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- master
pool:
vmImage: ubuntu-latest
# Define variables for Environments
variables:
- name: DEV_ENVIRONMENT
value: dev
- name: QA_ENVIRONMENT
value: qa
# Stage-1: Terraform Validate Stage
## Step-1: Publish Artifacts to Pipeline (Pipeline artifacts provide a way to share files between stages in a pipeline or between different pipelines. )
## Step-2: Install Latest Terraform (0.13.5) (Ideally not needed if we use default Ubuntu Agents)
## Step-3: Validate Terraform Manifests (terraform init, terraform validate)
stages:
- stage: TerraformValidate
jobs:
- job: TerraformValidateJob
continueOnError: false
steps:
- task: PublishPipelineArtifact@1
displayName: Publish Artifacts
inputs:
targetPath: '$(System.DefaultWorkingDirectory)/terraform-manifests'
artifact: 'terraform-manifests-out'
publishLocation: 'pipeline'
- task: TerraformInstaller@2
displayName: Terraform install
inputs:
terraformVersion: 'latest'
- task: TerraformCLI@2
displayName: Terraform init
inputs:
command: 'init'
workingDirectory: '$(System.DefaultWorkingDirectory)/terraform-manifests'
backendType: 'azurerm'
backendServiceArm: 'terraform-aks-azurerm-svc-con'
backendAzureRmResourceGroupName: 'terraform-storage-rg'
backendAzureRmStorageAccountName: 'terraformjmcresources'
backendAzureRmContainerName: 'tfstatefiles'
backendAzureRmKey: 'aks-base.tfstate'
allowTelemetryCollection: false
- task: TerraformCLI@2
displayName: Terraform validate
inputs:
command: 'validate'
workingDirectory: '$(System.DefaultWorkingDirectory)/terraform-manifests'
allowTelemetryCollection: false
- stage: DeployAKSClusters
jobs:
- deployment: DeployDevAKSCluster
displayName: DeployDevAKSCluster
pool:
vmImage: 'ubuntu-latest'
environment: $(DEV_ENVIRONMENT)
strategy:
runOnce:
deploy:
steps:
- task: DownloadSecureFile@1
displayName: Download SSH Key
name: sshkey
inputs:
secureFile: 'aks-terraform-devops-ssh-key-ububtu.pub'
- task: TerraformCLI@2
inputs:
command: 'init'
workingDirectory: '$(Pipeline.Workspace)/terraform-manifests-out'
backendType: 'azurerm'
backendServiceArm: 'terraform-aks-azurerm-svc-con'
backendAzureRmResourceGroupName: 'terraform-storage-rg'
backendAzureRmStorageAccountName: 'terraformjmcresources'
backendAzureRmContainerName: 'tfstatefiles'
backendAzureRmKey: 'aks-$(DEV_ENVIRONMENT).tfstate'
allowTelemetryCollection: false
- task: TerraformCLI@2
displayName: Terraform Plan
inputs:
command: 'plan'
workingDirectory: '$(Pipeline.Workspace)/terraform-manifests-out'
environmentServiceName: 'terraform-aks-azurerm-svc-con'
commandOptions: '-var ssh_public_key=$(sshkey.secureFilePath) -var environment=$(DEV_ENVIRONMENT) -out $(Pipeline.Workspace)/terraform-manifests-out/$(DEV_ENVIRONMENT)-$(Build.BuildId).out'
allowTelemetryCollection: false
- task: TerraformCLI@2
displayName: Terraform Apply
inputs:
command: 'apply'
workingDirectory: '$(Pipeline.Workspace)/terraform-manifests-out'
environmentServiceName: 'terraform-aks-azurerm-svc-con'
commandOptions: '$(Pipeline.Workspace)/terraform-manifests-out/$(DEV_ENVIRONMENT)-$(Build.BuildId).out'
allowTelemetryCollection: false