1
- # Provision Azure AKS using Terraform using Azure DevOps
1
+ # Provision Azure AKS using Terraform & Azure DevOps
2
2
3
3
## Step-01: Introduction
4
+ - Create Azure DevOps Pipeline to create AKS cluster using Terraform
5
+ - We are going to create two environments Dev and QA using single pipeline.
4
6
5
7
## Step-02: Install Azure Market Place Plugins in Azure DevOps
6
8
- Install below listed two plugins in your respective Azure DevOps Organization
51
53
52
54
### 08-outputs.tf
53
55
- We will put out output values very simple
54
- - Resource Group Name
55
- - Location
56
- - AKS Cluster ID
57
- - Cluster Name
58
- - Kubernetes Version
59
-
56
+ - Resource Group
57
+ - Location
58
+ - Name
59
+ - ID
60
+ - AKS Cluster
61
+ - AKS Versions
62
+ - AKS Latest Version
63
+ - AKS Cluster ID
64
+ - AKS Cluster Name
65
+ - AKS Cluster Kubernetes Version
66
+ - AD Group
67
+ - ID
68
+ - Object ID
69
+
60
70
### 09-aks-cluster-linux-user-nodepools.tf
61
71
- We will comment this file and leave it that way.
62
72
- If you need to provision the new nodepool , uncomment all lines except first line and check-in code and new nodepool will be created
@@ -89,7 +99,7 @@ cd azure-devops-aks-kubernetes-terraform-pipeline
89
99
kube-manifests
90
100
terraform-manifests
91
101
pipeline-backups
92
- README.md
102
+
93
103
94
104
# Initialize Git Repo
95
105
cd azure-devops-aks-kubernetes-terraform-pipeline
@@ -110,7 +120,7 @@ Example: https://github.com/stacksimplify/azure-devops-aks-kubernetes-terraform-
110
120
111
121
112
122
## Step-05: Create New Azure DevOps Project for IAC
113
- - Go to -> Azure DevOps -> Select Organization -> Create New Project
123
+ - Go to -> Azure DevOps -> Select Organization -> aksdemo2 -> Create New Project
114
124
- Project Name: terraform-azure-aks
115
125
- Project Descritpion: Provision Azure AKS Cluster using Azure DevOps & Terraform
116
126
- Visibility: Private
@@ -191,19 +201,133 @@ Public File: aks-terraform-devops-ssh-key-ububtu.pub (To be uploaded to Azure De
191
201
- Select Pipeline: Starter Pipeline
192
202
- Design your Pipeline
193
203
- Pipeline Name: 01-terraform-provision-aks-cluster-pipeline.yml
194
- ### Create Pipeline
195
-
204
+ ### Stage-1: Validate Stage
196
205
``` yaml
206
+
207
+ trigger :
208
+ - master
209
+
210
+ pool :
211
+ vmImage : ' ubuntu-latest'
212
+
213
+
214
+ # Define Variables
215
+ variables :
216
+ - name : DEV_ENVIRONMENT
217
+ value : dev
218
+ - name : QA_ENVIRONMENT
219
+ value : qa
220
+
221
+
222
+ # Stage-1: Validate Stage
223
+ # # Step-1: Install Latest Terraform (Ideally not needed if we use default Agents)
224
+ # # Step-2: Validate Terraform Manifests
225
+
226
+ stages :
227
+ - stage : Validate
228
+ jobs :
229
+ - job : ValidateJob
230
+ continueOnError : false
231
+ steps :
232
+ - publish : terraform-manifests
233
+ artifact : terraform-manifests-out
234
+ - task : TerraformInstaller@0
235
+ displayName : Terraform Installer
236
+ inputs :
237
+ terraformVersion : ' latest'
238
+ - task : TerraformCLI@0
239
+ displayName : Terraform Init
240
+ inputs :
241
+ command : ' init'
242
+ workingDirectory : ' $(System.DefaultWorkingDirectory)/terraform-manifests'
243
+ backendType : ' azurerm'
244
+ backendServiceArm : ' terraform-aks-azurerm-for-pipe3'
245
+ backendAzureRmResourceGroupName : ' terraform-state-storage-rg2'
246
+ backendAzureRmStorageAccountName : ' tfstatekalyan123'
247
+ backendAzureRmContainerName : ' tfstatefiles'
248
+ backendAzureRmKey : ' aks-base.tfstate'
249
+ allowTelemetryCollection : false
250
+ - task : TerraformCLI@0
251
+ displayName : Terraform Validate
252
+ inputs :
253
+ command : ' validate'
254
+ workingDirectory : ' $(System.DefaultWorkingDirectory)/terraform-manifests'
255
+ allowTelemetryCollection : false
256
+
197
257
```
198
258
199
259
260
+ ### Pipeline Save and Run
261
+ - Click on ** Save and Run**
262
+ - Commit Message: First Commit - Validate terraform manifests
263
+ - Click on ** Job** and Verify Pipeline
264
+
265
+
266
+ ## Stage-12: Deploy Dev AKS Cluster
267
+ ### Stage-2: Deployment-1: Deploy Dev AKS Cluster
268
+ ``` yaml
269
+ # Stage-2: Deploy Stages for Dev & QA
270
+ # Deployment-1: Deploy Dev AKS Cluster
271
+ # # Step-1: Download Secure File
272
+ # # Step-2: Terraform Initialize (State Storage to store in Azure Storage Account)
273
+ # # Step-3: Terraform Plan
274
+ # # Step-4: Terraform Apply
275
+ - stage : DeployAKS
276
+ jobs :
277
+ - deployment : DeployDev
278
+ pool :
279
+ vmImage : ' ubuntu-latest'
280
+ environment : $(DEV_ENVIRONMENT)
281
+ strategy :
282
+ # default deployment strategy
283
+ runOnce :
284
+ deploy :
285
+ steps :
286
+ - task : DownloadSecureFile@1
287
+ displayName : Download SSH Key for Linux VMs
288
+ name : sshkey
289
+ inputs :
290
+ secureFile : ' aks-terraform-devops-ssh-key-ububtu.pub'
291
+ - task : TerraformCLI@0
292
+ displayName : Terraform Init
293
+ inputs :
294
+ command : ' init'
295
+ workingDirectory : ' $(Pipeline.Workspace)/terraform-manifests-out'
296
+ backendType : ' azurerm'
297
+ backendServiceArm : ' terraform-aks-azurerm-for-pipe3'
298
+ backendAzureRmResourceGroupName : ' terraform-state-storage-rg2'
299
+ backendAzureRmStorageAccountName : ' tfstatekalyan123'
300
+ backendAzureRmContainerName : ' tfstatefiles'
301
+ backendAzureRmKey : ' aks-$(DEV_ENVIRONMENT).tfstate'
302
+ allowTelemetryCollection : false
303
+
304
+ - task : TerraformCLI@0
305
+ displayName : Terraform Plan
306
+ inputs :
307
+ command : ' plan'
308
+ workingDirectory : ' $(Pipeline.Workspace)/terraform-manifests-out'
309
+ environmentServiceName : ' terraform-aks-azurerm-for-pipe3'
310
+ commandOptions : ' -var ssh_public_key=$(sshkey.secureFilePath) -var environment=$(DEV_ENVIRONMENT) -out $(Pipeline.Workspace)/terraform-manifests-out/$(DEV_ENVIRONMENT)-$(Build.BuildId).out'
311
+ allowTelemetryCollection : false
312
+
313
+ - task : TerraformCLI@0
314
+ displayName : Terraform Apply
315
+ inputs :
316
+ command : ' apply'
317
+ workingDirectory : ' $(Pipeline.Workspace)/terraform-manifests-out'
318
+ environmentServiceName : ' terraform-aks-azurerm-for-pipe3'
319
+ commandOptions : ' $(Pipeline.Workspace)/terraform-manifests-out/$(DEV_ENVIRONMENT)-$(Build.BuildId).out'
320
+ allowTelemetryCollection : false
321
+ ` ` `
322
+
200
323
201
324
### Pipeline Save and Run
202
325
- Click on **Save and Run**
203
- - Commit Message: First Commit - AKS Provision via terraform
326
+ - Commit Message: Second Commit - Dev AKS Provision via terraform
204
327
- Click on **Job** and Verify Pipeline
205
328
206
- ## Step-12: Verify all the resources created
329
+
330
+ ## Step-13: Verify all the resources created
207
331
### Verify Pipeline logs
208
332
- Verify Pipeline logs for all the tasks
209
333
@@ -232,10 +356,12 @@ kubectl cluster-info
232
356
kubectl get nodes
233
357
```
234
358
235
- ## Step-13: Create QA Environment Deploy Stage in Pipeline
236
- ### Update Pipeline
359
+ ## Step-14: Deploy QA AKS Cluster
360
+ ### Stage-2: Deployment-1: Deploy Dev AKS Cluster
237
361
```yaml
238
- # Stage-2: Deploy for QA
362
+
363
+ # Stage-2: Deploy Stages for Dev & QA
364
+ # Deployment-2: Deploy QA AKS Cluster
239
365
## Step-1: Download Secure File
240
366
## Step-2: Terraform Initialize (State Storage to store in Azure Storage Account)
241
367
## Step-3: Terraform Plan
@@ -286,16 +412,17 @@ kubectl get nodes
286
412
environmentServiceName: 'terraform-aks-azurerm-for-pipe3'
287
413
commandOptions: '$(Pipeline.Workspace)/terraform-manifests-out/$(QA_ENVIRONMENT)-$(Build.BuildId).out'
288
414
allowTelemetryCollection: false
415
+
289
416
```
290
417
291
418
292
419
293
420
### Pipeline Save and Run
294
421
- Click on ** Save and Run**
295
- - Commit Message: First Commit - AKS Provision via terraform
422
+ - Commit Message: Third Commit - QA AKS Cluster Provision via terraform
296
423
- Click on ** Job** and Verify Pipeline
297
424
298
- ## Step-12 : Verify all the resources created
425
+ ## Step-15 : Verify all the resources created
299
426
### Verify Pipeline logs
300
427
- Verify Pipeline logs for all the tasks
301
428
0 commit comments