Skip to content

Commit 5afb6b8

Browse files
committed
Welcome to Stack Simplify
1 parent 0df0726 commit 5afb6b8

File tree

2 files changed

+147
-18
lines changed

2 files changed

+147
-18
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ stages:
5454

5555

5656
# Stage-2: Deploy Stages for Dev & QA
57+
# Deployment-1: Deploy Dev AKS Cluster
5758
## Step-1: Download Secure File
5859
## Step-2: Terraform Initialize (State Storage to store in Azure Storage Account)
5960
## Step-3: Terraform Plan
@@ -106,6 +107,7 @@ stages:
106107
allowTelemetryCollection: false
107108

108109
# Stage-2: Deploy Stages for Dev & QA
110+
# Deployment-2: Deploy QA AKS Cluster
109111
## Step-1: Download Secure File
110112
## Step-2: Terraform Initialize (State Storage to store in Azure Storage Account)
111113
## Step-3: Terraform Plan

25-Azure-DevOps-Terraform-Azure-AKS/25-01-Provision-AKS-Cluster-using-Azure-DevOps-and-Terraform/README.md

Lines changed: 145 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# Provision Azure AKS using Terraform using Azure DevOps
1+
# Provision Azure AKS using Terraform & Azure DevOps
22

33
## 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.
46

57
## Step-02: Install Azure Market Place Plugins in Azure DevOps
68
- Install below listed two plugins in your respective Azure DevOps Organization
@@ -51,12 +53,20 @@
5153

5254
### 08-outputs.tf
5355
- 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+
6070
### 09-aks-cluster-linux-user-nodepools.tf
6171
- We will comment this file and leave it that way.
6272
- 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
8999
kube-manifests
90100
terraform-manifests
91101
pipeline-backups
92-
README.md
102+
93103
94104
# Initialize Git Repo
95105
cd azure-devops-aks-kubernetes-terraform-pipeline
@@ -110,7 +120,7 @@ Example: https://github.com/stacksimplify/azure-devops-aks-kubernetes-terraform-
110120

111121

112122
## 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
114124
- Project Name: terraform-azure-aks
115125
- Project Descritpion: Provision Azure AKS Cluster using Azure DevOps & Terraform
116126
- Visibility: Private
@@ -191,19 +201,133 @@ Public File: aks-terraform-devops-ssh-key-ububtu.pub (To be uploaded to Azure De
191201
- Select Pipeline: Starter Pipeline
192202
- Design your Pipeline
193203
- Pipeline Name: 01-terraform-provision-aks-cluster-pipeline.yml
194-
### Create Pipeline
195-
204+
### Stage-1: Validate Stage
196205
```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+
197257
```
198258

199259

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+
200323
201324
### Pipeline Save and Run
202325
- Click on **Save and Run**
203-
- Commit Message: First Commit - AKS Provision via terraform
326+
- Commit Message: Second Commit - Dev AKS Provision via terraform
204327
- Click on **Job** and Verify Pipeline
205328
206-
## Step-12: Verify all the resources created
329+
330+
## Step-13: Verify all the resources created
207331
### Verify Pipeline logs
208332
- Verify Pipeline logs for all the tasks
209333
@@ -232,10 +356,12 @@ kubectl cluster-info
232356
kubectl get nodes
233357
```
234358
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
237361
```yaml
238-
# Stage-2: Deploy for QA
362+
363+
# Stage-2: Deploy Stages for Dev & QA
364+
# Deployment-2: Deploy QA AKS Cluster
239365
## Step-1: Download Secure File
240366
## Step-2: Terraform Initialize (State Storage to store in Azure Storage Account)
241367
## Step-3: Terraform Plan
@@ -286,16 +412,17 @@ kubectl get nodes
286412
environmentServiceName: 'terraform-aks-azurerm-for-pipe3'
287413
commandOptions: '$(Pipeline.Workspace)/terraform-manifests-out/$(QA_ENVIRONMENT)-$(Build.BuildId).out'
288414
allowTelemetryCollection: false
415+
289416
```
290417

291418

292419

293420
### Pipeline Save and Run
294421
- 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
296423
- Click on **Job** and Verify Pipeline
297424

298-
## Step-12: Verify all the resources created
425+
## Step-15: Verify all the resources created
299426
### Verify Pipeline logs
300427
- Verify Pipeline logs for all the tasks
301428

0 commit comments

Comments
 (0)