-
Notifications
You must be signed in to change notification settings - Fork 0
/
02-terraform-provision-aks-cluster-pipeline.yml
159 lines (150 loc) · 6.62 KB
/
02-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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
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 Agents)
## Step-3: Validate Terraform Manifests
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@0
displayName: Terraform Install
inputs:
terraformVersion: 'latest'
- task: TerraformCLI@0
displayName: Terraform Init
inputs:
command: 'init'
workingDirectory: '$(System.DefaultWorkingDirectory)/terraform-manifests'
backendType: 'azurerm'
backendServiceArm: 'terraform-aks-azurerm-svc-con'
ensureBackend: true
backendAzureRmResourceGroupName: 'terraform-storage-rg'
backendAzureRmStorageAccountName: 'terraformstatexlrwdrzs2'
backendAzureRmResourceGroupLocation: 'francecentral'
backendAzureRmContainerName: 'tfstatefiles'
backendAzureRmKey: 'aks-base.tfstate'
allowTelemetryCollection: false
- task: TerraformCLI@0
displayName: Terraform Validate
inputs:
command: 'validate'
workingDirectory: '$(System.DefaultWorkingDirectory)/terraform-manifests'
allowTelemetryCollection: false
# Stage-2: Deploy Stages for Dev & QA
# Deployment-1: Deploy Dev AKS Cluster
## Step-1: Define Variables for environments
## Step-2: Download SSH Secure File
## Step-3: Terraform Initialize (State Storage to store in Azure Storage Account for Dev AKS Cluster)
## Step-4: Terraform Plan (Create Plan)
## Step-5: Terraform Apply (Use the plan created in previous step)
- 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@0
displayName: Terraform Init
inputs:
command: 'init'
workingDirectory: '$(Pipeline.Workspace)/terraform-manifests-out'
backendType: 'azurerm'
backendServiceArm: 'terraform-aks-azurerm-svc-con'
backendAzureRmResourceGroupName: 'terraform-storage-rg'
backendAzureRmStorageAccountName: 'terraformstatexlrwdrzs2'
backendAzureRmContainerName: 'tfstatefiles'
backendAzureRmKey: 'aks-$(DEV_ENVIRONMENT).tfstate'
allowTelemetryCollection: false
- task: TerraformCLI@0
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@0
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
# Stage-2: Deploy Stages for Dev & QA
# Deployment-2: Deploy QA AKS Cluster
## Step-1: Download Secure File
## Step-2: Terraform Initialize (State Storage to store in Azure Storage Account)
## Step-3: Terraform Plan
## Step-4: Terraform Apply
- deployment: DeployQAAKSCluster
dependsOn: DeployDevAKSCluster
displayName: DeployQAAKSCluster
pool:
vmImage: 'ubuntu-latest'
environment: $(QA_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@0
displayName: Terraform Init
inputs:
command: 'init'
workingDirectory: '$(Pipeline.Workspace)/terraform-manifests-out'
backendType: 'azurerm'
backendServiceArm: 'terraform-aks-azurerm-svc-con'
backendAzureRmResourceGroupName: 'terraform-storage-rg'
backendAzureRmStorageAccountName: 'terraformstatexlrwdrzs2'
backendAzureRmContainerName: 'tfstatefiles'
backendAzureRmKey: 'aks-$(QA_ENVIRONMENT).tfstate'
allowTelemetryCollection: false
- task: TerraformCLI@0
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=$(QA_ENVIRONMENT) -out $(Pipeline.Workspace)/terraform-manifests-out/$(QA_ENVIRONMENT)-$(Build.BuildId).out'
allowTelemetryCollection: false
- task: TerraformCLI@0
displayName: Terraform Apply
inputs:
command: 'apply'
workingDirectory: '$(Pipeline.Workspace)/terraform-manifests-out'
environmentServiceName: 'terraform-aks-azurerm-svc-con'
commandOptions: '$(Pipeline.Workspace)/terraform-manifests-out/$(QA_ENVIRONMENT)-$(Build.BuildId).out'
allowTelemetryCollection: false