1
-
2
-
3
1
trigger :
4
2
- master
5
3
6
4
pool :
7
5
vmImage : ' ubuntu-latest'
8
6
9
-
10
- # Define Variables
7
+ # Define Variables for Environments
11
8
variables :
12
9
- name : DEV_ENVIRONMENT
13
- value : dev
10
+ value : dev
14
11
- name : QA_ENVIRONMENT
15
- value : qa
16
-
12
+ value : qa
17
13
18
- # Stage-1: Validate Stage
19
- # # Step-1: Install Latest Terraform (Ideally not needed if we use default Agents)
20
- # # Step-2: Validate Terraform Manifests
14
+ # Stage-1: Terraform Validate Stage
15
+ # # Step-1: Publish Artifacts to Pipeline (Pipeline artifacts provide a way to share files between stages in a pipeline or between different pipelines. )
16
+ # # Step-2: Install Latest Terraform (0.13.5) (Ideally not needed if we use default Ubuntu Agents)
17
+ # # Step-3: Validate Terraform Manifests (terraform init, terraform validate)
21
18
22
19
stages :
23
- - stage : Validate
20
+ - stage : TerraformValidate
24
21
jobs :
25
- - job : ValidateJob
26
- continueOnError : false
27
- steps :
28
- - publish : terraform-manifests
29
- artifact : terraform-manifests-out
22
+ - job : TerraformValidateJob
23
+ continueOnError : false
24
+ steps :
25
+ - task : PublishPipelineArtifact@1
26
+ displayName : Publish Artifacts
27
+ inputs :
28
+ targetPath : ' $(System.DefaultWorkingDirectory)/terraform-manifests'
29
+ artifact : ' terraform-manifests-out'
30
+ publishLocation : ' pipeline'
30
31
- task : TerraformInstaller@0
31
- displayName : Terraform Installer
32
+ displayName : Terraform Install
32
33
inputs :
33
34
terraformVersion : ' latest'
34
35
- task : TerraformCLI@0
@@ -37,9 +38,9 @@ stages:
37
38
command : ' init'
38
39
workingDirectory : ' $(System.DefaultWorkingDirectory)/terraform-manifests'
39
40
backendType : ' azurerm'
40
- backendServiceArm : ' terraform-aks-azurerm-for-pipe3 '
41
- backendAzureRmResourceGroupName : ' terraform-state- storage-rg2 '
42
- backendAzureRmStorageAccountName : ' tfstatekalyan123 '
41
+ backendServiceArm : ' terraform-aks-azurerm-svc-con '
42
+ backendAzureRmResourceGroupName : ' terraform-storage-rg '
43
+ backendAzureRmStorageAccountName : ' terraformstatexlrwdrzs '
43
44
backendAzureRmContainerName : ' tfstatefiles'
44
45
backendAzureRmKey : ' aks-base.tfstate'
45
46
allowTelemetryCollection : false
@@ -49,112 +50,107 @@ stages:
49
50
command : ' validate'
50
51
workingDirectory : ' $(System.DefaultWorkingDirectory)/terraform-manifests'
51
52
allowTelemetryCollection : false
52
-
53
-
54
-
55
53
56
54
# Stage-2: Deploy Stages for Dev & QA
57
55
# Deployment-1: Deploy Dev AKS Cluster
58
- # # Step-1: Download Secure File
59
- # # Step-2: Terraform Initialize (State Storage to store in Azure Storage Account)
60
- # # Step-3: Terraform Plan
61
- # # Step-4: Terraform Apply
62
- - stage : DeployAKS
63
- jobs :
64
- - deployment : DeployDev
65
- pool :
66
- vmImage : ' ubuntu-latest'
67
- environment : $(DEV_ENVIRONMENT)
68
- strategy :
69
- # default deployment strategy
70
- runOnce :
71
- deploy :
72
- steps :
73
- - task : DownloadSecureFile@1
74
- displayName : Download SSH Key for Linux VMs
75
- name : sshkey
76
- inputs :
77
- secureFile : ' aks-terraform-devops-ssh-key-ububtu.pub'
78
- - task : TerraformCLI@0
79
- displayName : Terraform Init
80
- inputs :
81
- command : ' init'
82
- workingDirectory : ' $(Pipeline.Workspace)/terraform-manifests-out'
83
- backendType : ' azurerm'
84
- backendServiceArm : ' terraform-aks-azurerm-for-pipe3'
85
- backendAzureRmResourceGroupName : ' terraform-state-storage-rg2'
86
- backendAzureRmStorageAccountName : ' tfstatekalyan123'
87
- backendAzureRmContainerName : ' tfstatefiles'
88
- backendAzureRmKey : ' aks-$(DEV_ENVIRONMENT).tfstate'
89
- allowTelemetryCollection : false
56
+ # # Step-1: Define Variables for environments
57
+ # # Step-2: Download SSH Secure File
58
+ # # Step-3: Terraform Initialize (State Storage to store in Azure Storage Account for Dev AKS Cluster)
59
+ # # Step-4: Terraform Plan (Create Plan)
60
+ # # Step-5: Terraform Apply (Use the plan created in previous step)
90
61
91
- - task : TerraformCLI@0
92
- displayName : Terraform Plan
93
- inputs :
94
- command : ' plan'
95
- workingDirectory : ' $(Pipeline.Workspace)/terraform-manifests-out'
96
- environmentServiceName : ' terraform-aks-azurerm-for-pipe3'
97
- commandOptions : ' -var ssh_public_key=$(sshkey.secureFilePath) -var environment=$(DEV_ENVIRONMENT) -out $(Pipeline.Workspace)/terraform-manifests-out/$(DEV_ENVIRONMENT)-$(Build.BuildId).out'
98
- allowTelemetryCollection : false
99
-
100
- - task : TerraformCLI@0
101
- displayName : Terraform Apply
102
- inputs :
103
- command : ' apply'
104
- workingDirectory : ' $(Pipeline.Workspace)/terraform-manifests-out'
105
- environmentServiceName : ' terraform-aks-azurerm-for-pipe3'
106
- commandOptions : ' $(Pipeline.Workspace)/terraform-manifests-out/$(DEV_ENVIRONMENT)-$(Build.BuildId).out'
107
- allowTelemetryCollection : false
62
+ - stage : DeployAKSClusters
63
+ jobs :
64
+ - deployment : DeployDevAKSCluster
65
+ displayName : DeployDevAKSCluster
66
+ pool :
67
+ vmImage : ' ubuntu-latest'
68
+ environment : $(DEV_ENVIRONMENT)
69
+ strategy :
70
+ runOnce :
71
+ deploy :
72
+ steps :
73
+ - task : DownloadSecureFile@1
74
+ displayName : Download SSH Key
75
+ name : sshkey
76
+ inputs :
77
+ secureFile : ' aks-terraform-devops-ssh-key-ububtu.pub'
78
+ - task : TerraformCLI@0
79
+ displayName : Terraform Init
80
+ inputs :
81
+ command : ' init'
82
+ workingDirectory : ' $(Pipeline.Workspace)/terraform-manifests-out'
83
+ backendType : ' azurerm'
84
+ backendServiceArm : ' terraform-aks-azurerm-svc-con'
85
+ backendAzureRmResourceGroupName : ' terraform-storage-rg'
86
+ backendAzureRmStorageAccountName : ' terraformstatexlrwdrzs'
87
+ backendAzureRmContainerName : ' tfstatefiles'
88
+ backendAzureRmKey : ' aks-$(DEV_ENVIRONMENT).tfstate'
89
+ allowTelemetryCollection : false
90
+ - task : TerraformCLI@0
91
+ displayName : Terraform Plan
92
+ inputs :
93
+ command : ' plan'
94
+ workingDirectory : ' $(Pipeline.Workspace)/terraform-manifests-out'
95
+ environmentServiceName : ' terraform-aks-azurerm-svc-con'
96
+ commandOptions : ' -var ssh_public_key=$(sshkey.secureFilePath) -var environment=$(DEV_ENVIRONMENT) -out $(Pipeline.Workspace)/terraform-manifests-out/$(DEV_ENVIRONMENT)-$(Build.BuildId).out'
97
+ allowTelemetryCollection : false
98
+ - task : TerraformCLI@0
99
+ displayName : Terraform Apply
100
+ inputs :
101
+ command : ' apply'
102
+ workingDirectory : ' $(Pipeline.Workspace)/terraform-manifests-out'
103
+ environmentServiceName : ' terraform-aks-azurerm-svc-con'
104
+ commandOptions : ' $(Pipeline.Workspace)/terraform-manifests-out/$(DEV_ENVIRONMENT)-$(Build.BuildId).out'
105
+ allowTelemetryCollection : false
108
106
109
107
# Stage-2: Deploy Stages for Dev & QA
110
108
# Deployment-2: Deploy QA AKS Cluster
111
109
# # Step-1: Download Secure File
112
110
# # Step-2: Terraform Initialize (State Storage to store in Azure Storage Account)
113
111
# # Step-3: Terraform Plan
114
- # # Step-4: Terraform Apply
115
-
116
- - deployment : DeployQA
117
- dependsOn : DeployDev
118
- pool :
119
- vmImage : ' ubuntu-latest'
120
- environment : $(QA_ENVIRONMENT)
121
- strategy :
122
- # default deployment strategy
123
- runOnce :
124
- deploy :
125
- steps :
126
- - task : DownloadSecureFile@1
127
- displayName : Download SSH Key for Linux VMs
128
- name : sshkey
129
- inputs :
130
- secureFile : ' aks-terraform-devops-ssh-key-ububtu.pub'
131
- - task : TerraformCLI@0
132
- displayName : Terraform Init
133
- inputs :
134
- command : ' init'
135
- workingDirectory : ' $(Pipeline.Workspace)/terraform-manifests-out'
136
- backendType : ' azurerm'
137
- backendServiceArm : ' terraform-aks-azurerm-for-pipe3'
138
- backendAzureRmResourceGroupName : ' terraform-state-storage-rg2'
139
- backendAzureRmStorageAccountName : ' tfstatekalyan123'
140
- backendAzureRmContainerName : ' tfstatefiles'
141
- backendAzureRmKey : ' aks-$(QA_ENVIRONMENT).tfstate'
142
- allowTelemetryCollection : false
112
+ # # Step-4: Terraform Apply
143
113
144
- - task : TerraformCLI@0
145
- displayName : Terraform Plan
146
- inputs :
147
- command : ' plan'
148
- workingDirectory : ' $(Pipeline.Workspace)/terraform-manifests-out'
149
- environmentServiceName : ' terraform-aks-azurerm-for-pipe3'
150
- commandOptions : ' -var ssh_public_key=$(sshkey.secureFilePath) -var environment=$(QA_ENVIRONMENT) -out $(Pipeline.Workspace)/terraform-manifests-out/$(QA_ENVIRONMENT)-$(Build.BuildId).out'
151
- allowTelemetryCollection : false
152
-
153
- - task : TerraformCLI@0
154
- displayName : Terraform Apply
155
- inputs :
156
- command : ' apply'
157
- workingDirectory : ' $(Pipeline.Workspace)/terraform-manifests-out'
158
- environmentServiceName : ' terraform-aks-azurerm-for-pipe3'
159
- commandOptions : ' $(Pipeline.Workspace)/terraform-manifests-out/$(QA_ENVIRONMENT)-$(Build.BuildId).out'
160
- allowTelemetryCollection : false
114
+ - deployment : DeployQAAKSCluster
115
+ dependsOn : DeployDevAKSCluster
116
+ displayName : DeployQAAKSCluster
117
+ pool :
118
+ vmImage : ' ubuntu-latest'
119
+ environment : $(QA_ENVIRONMENT)
120
+ strategy :
121
+ runOnce :
122
+ deploy :
123
+ steps :
124
+ - task : DownloadSecureFile@1
125
+ displayName : Download SSH Key
126
+ name : sshkey
127
+ inputs :
128
+ secureFile : ' aks-terraform-devops-ssh-key-ububtu.pub'
129
+ - task : TerraformCLI@0
130
+ displayName : Terraform Init
131
+ inputs :
132
+ command : ' init'
133
+ workingDirectory : ' $(Pipeline.Workspace)/terraform-manifests-out'
134
+ backendType : ' azurerm'
135
+ backendServiceArm : ' terraform-aks-azurerm-svc-con'
136
+ backendAzureRmResourceGroupName : ' terraform-storage-rg'
137
+ backendAzureRmStorageAccountName : ' terraformstatexlrwdrzs'
138
+ backendAzureRmContainerName : ' tfstatefiles'
139
+ backendAzureRmKey : ' aks-$(QA_ENVIRONMENT).tfstate'
140
+ allowTelemetryCollection : false
141
+ - task : TerraformCLI@0
142
+ displayName : Terraform Plan
143
+ inputs :
144
+ command : ' plan'
145
+ workingDirectory : ' $(Pipeline.Workspace)/terraform-manifests-out'
146
+ environmentServiceName : ' terraform-aks-azurerm-svc-con'
147
+ commandOptions : ' -var ssh_public_key=$(sshkey.secureFilePath) -var environment=$(QA_ENVIRONMENT) -out $(Pipeline.Workspace)/terraform-manifests-out/$(QA_ENVIRONMENT)-$(Build.BuildId).out'
148
+ allowTelemetryCollection : false
149
+ - task : TerraformCLI@0
150
+ displayName : Terraform Apply
151
+ inputs :
152
+ command : ' apply'
153
+ workingDirectory : ' $(Pipeline.Workspace)/terraform-manifests-out'
154
+ environmentServiceName : ' terraform-aks-azurerm-svc-con'
155
+ commandOptions : ' $(Pipeline.Workspace)/terraform-manifests-out/$(QA_ENVIRONMENT)-$(Build.BuildId).out'
156
+ allowTelemetryCollection : false
0 commit comments