Skip to content

Commit 57f4d37

Browse files
committed
feat: one joint Audit and Core ADO pipeline for all environments with Audit-common template
1 parent 288f8c5 commit 57f4d37

7 files changed

Lines changed: 497 additions & 8 deletions

File tree

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
3+
name: $(Build.SourceBranchName)-$(Date:yyyyMMdd)_$(Rev:r)
4+
trigger: none
5+
pr: none
6+
7+
pool:
8+
#vmImage: ubuntu-latest
9+
name: private-pool-dev-uks
10+
11+
resources:
12+
repositories:
13+
- repository: dtos-devops-templates
14+
type: github
15+
name: NHSDigital/dtos-devops-templates
16+
ref: 8d9323116e7e0442e3f89750df39af27a2e1a4a7
17+
endpoint: NHSDigital
18+
19+
parameters:
20+
- name: terraformActionsAudit
21+
# This parameter allows the user to run only the plan for testing purposes
22+
displayName: 'Audit: Apply Terraform Plan'
23+
type: string
24+
values:
25+
- 'PlanOnly'
26+
- 'Apply'
27+
default: 'Apply'
28+
29+
- name: dockerImageTag
30+
# Used to set the Docker image tag via Terraform in the Continuous Deployment settings of function and container apps
31+
displayName: 'Core: Docker Image Tag'
32+
type: string
33+
default: sbrk
34+
35+
- name: retagImages
36+
# Only required until commit hashes are passed in by calling pipeline, except for the
37+
# PreProd pipeline which needs to retag images to move them from the Dev ACR to the Prod ACR
38+
displayName: 'Core: Re-tag Images'
39+
type: boolean
40+
default: false
41+
42+
- name: dockerImageReTagFrom
43+
# Only required until commit hashes are passed in by calling pipeline
44+
displayName: 'Core: Docker Image Retag from value'
45+
type: string
46+
default: development
47+
48+
- name: dockerImageReTagTo
49+
# Only required until commit hashes are passed in by calling pipeline
50+
displayName: 'Core: Docker Image Retag to value'
51+
type: string
52+
default: sbrk
53+
54+
- name: terraformActionsCore
55+
# This parameter allows the user to run only the plan for testing purposes
56+
displayName: 'Core: Apply Terraform Plan'
57+
type: string
58+
values:
59+
- 'PlanOnly'
60+
- 'Apply'
61+
default: 'Apply'
62+
63+
- name: testTypes
64+
type: object
65+
default:
66+
- smoke_e2e
67+
68+
variables:
69+
- name: hostPoolName
70+
value: private-pool-dev-uks
71+
- group: SBRK_backend
72+
- group: SBRK_audit_backend_remote_state
73+
- group: SBRK_image_pipelines
74+
- group: SBRK_automation_testing_pipeline
75+
- group: DEV_hub_backend_remote_state
76+
- name: TF_VERSION
77+
value: 1.14.4
78+
- name: TF_PLAN_ARTIFACT
79+
value: tf_plan_core_SANDBOX
80+
- name: TF_DIRECTORY_CORE
81+
value: $(System.DefaultWorkingDirectory)/$(System.TeamProject)/infrastructure/tf-core
82+
- name: TF_DIRECTORY_AUDIT
83+
value: $(System.DefaultWorkingDirectory)/$(System.TeamProject)/infrastructure/tf-audit
84+
- name: ENVIRONMENT
85+
value: sandbox
86+
87+
88+
stages:
89+
# STAGE 1: AUDIT DEPLOYMENT
90+
- template: ../templates/cd-infrastructure-audit-common.yaml
91+
parameters:
92+
terraformActions: ${{ parameters.terraformActionsAudit }}
93+
environment: $(ENVIRONMENT)
94+
95+
# STAGE 2: CORE DEPLOYMENT
96+
- template: ../templates/cd-infrastructure-core-common.yaml
97+
parameters:
98+
hostPoolName: $(hostPoolName)
99+
serviceConnection: $(SERVICE_CONNECTION)
100+
targetSubscriptionId: $(TF_VAR_TARGET_SUBSCRIPTION_ID_CORE)
101+
terraformActions: ${{ parameters.terraformActionsCore }}
102+
tfVarsFile: environments/$(ENVIRONMENT).tfvars
103+
environment: $(ENVIRONMENT)
104+
resourceGroupNameSql: $(RESOURCE_GROUP_NAME_SQL)
105+
databaseManagementJobName: $(DATABASE_MANAGEMENT_JOB_NAME)
106+
dockerImageTag: ${{ parameters.dockerImageTag }}
107+
retagImages: ${{ parameters.retagImages }}
108+
retagImagesFrom: ${{ parameters.dockerImageReTagFrom }}
109+
retagImagesTo: ${{ parameters.dockerImageReTagTo }}
110+
slackWebHook: $(SLACK_WEBHOOK_URL_WORKFLOWS)
111+
112+
- ${{ each testType in parameters.testTypes }}:
113+
- stage: ${{ testType }}_stage
114+
displayName: "Core: Run ${{ testType }} Tests"
115+
condition: always()
116+
jobs:
117+
- job: ${{ testType }}_job
118+
pool:
119+
name: $(hostPoolName)
120+
steps:
121+
- template: .azuredevops/templates/steps/run-post-deployment-pw-tests.yaml@dtos-devops-templates
122+
parameters:
123+
serviceConnection: $(SERVICE_CONNECTION)
124+
testProjectDirectory: "tests/playwright-tests"
125+
testfileDirectory: "src/tests/e2e/testFiles"
126+
testProjectName: "tests"
127+
testType: ${{ testType }}
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
---
2+
name: $(Build.SourceBranchName)-$(Date:yyyyMMdd)_$(Rev:r)
3+
trigger: none
4+
pr: none
5+
6+
pool:
7+
name: private-pool-dev-uks
8+
9+
resources:
10+
repositories:
11+
- repository: dtos-devops-templates
12+
type: github
13+
name: NHSDigital/dtos-devops-templates
14+
ref: 8d9323116e7e0442e3f89750df39af27a2e1a4a7
15+
endpoint: NHSDigital
16+
17+
# 1. RUNTIME PARAMETERS
18+
parameters:
19+
- name: targetEnvironment
20+
displayName: 'Target Environment'
21+
type: string
22+
default: 'development'
23+
values:
24+
- sandbox
25+
- development
26+
- nft
27+
- integration
28+
- preprod
29+
- production
30+
31+
- name: terraformActionsAudit
32+
displayName: 'Audit: Apply Terraform Plan'
33+
type: string
34+
values:
35+
- 'PlanOnly'
36+
- 'Apply'
37+
default: 'Apply'
38+
39+
- name: dockerImageTag
40+
displayName: 'Core: Docker Image Tag'
41+
type: string
42+
default: development
43+
44+
- name: retagImages
45+
displayName: 'Core: Re-tag Images'
46+
type: boolean
47+
default: false
48+
49+
- name: dockerImageReTagFrom
50+
displayName: 'Core: Docker Image Retag from value'
51+
type: string
52+
default: development
53+
54+
- name: dockerImageReTagTo
55+
displayName: 'Core: Docker Image Retag to value'
56+
type: string
57+
default: development
58+
59+
- name: terraformActionsCore
60+
displayName: 'Core: Apply Terraform Plan'
61+
type: string
62+
values:
63+
- 'PlanOnly'
64+
- 'Apply'
65+
default: 'Apply'
66+
67+
- name: testTypes
68+
type: object
69+
default:
70+
- smoke_e2e
71+
72+
# 2. DYNAMIC VARIABLES
73+
variables:
74+
- name: hostPoolName
75+
value: private-pool-dev-uks
76+
- name: TF_VERSION
77+
value: 1.14.4
78+
- name: TF_PLAN_ARTIFACT
79+
value: tf_plan_core_${{ upper(parameters.targetEnvironment) }}
80+
- name: TF_DIRECTORY_CORE
81+
value: $(System.DefaultWorkingDirectory)/$(System.TeamProject)/infrastructure/tf-core
82+
- name: TF_DIRECTORY_AUDIT
83+
value: $(System.DefaultWorkingDirectory)/$(System.TeamProject)/infrastructure/tf-audit
84+
85+
# Variable Template
86+
- template: ../variables/infrastructure-vars.yaml
87+
parameters:
88+
environmentName: ${{ parameters.targetEnvironment }}
89+
90+
# New Secret groups
91+
- group: ${{ parameters.targetEnvironment }}-secrets
92+
- group: ${{ parameters.targetEnvironment }}-automation-testing
93+
94+
95+
# 3. DEPLOYMENT STAGES
96+
stages:
97+
# --- STAGE 1: AUDIT ---
98+
- template: ../templates/cd-infrastructure-audit-common.yaml
99+
parameters:
100+
terraformActions: ${{ parameters.terraformActionsAudit }}
101+
environment: $(ENVIRONMENT)
102+
103+
# --- STAGE 2: CORE ---
104+
- template: ../templates/cd-infrastructure-core-common.yaml
105+
parameters:
106+
hostPoolName: $(hostPoolName)
107+
serviceConnection: $(SERVICE_CONNECTION)
108+
targetSubscriptionId: $(TF_VAR_TARGET_SUBSCRIPTION_ID_CORE)
109+
terraformActions: ${{ parameters.terraformActionsCore }}
110+
tfVarsFile: environments/$(ENVIRONMENT).tfvars
111+
environment: $(ENVIRONMENT)
112+
resourceGroupNameSql: $(RESOURCE_GROUP_NAME_SQL)
113+
databaseManagementJobName: $(DATABASE_MANAGEMENT_JOB_NAME)
114+
dockerImageTag: ${{ parameters.dockerImageTag }}
115+
retagImages: ${{ parameters.retagImages }}
116+
retagImagesFrom: ${{ parameters.dockerImageReTagFrom }}
117+
retagImagesTo: ${{ parameters.dockerImageReTagTo }}
118+
slackWebHook: $(SLACK_WEBHOOK_URL_WORKFLOWS)
119+
120+
# --- STAGE 3: AUTOMATED TESTING ---
121+
- ${{ each testType in parameters.testTypes }}:
122+
- stage: ${{ testType }}_stage
123+
displayName: "Core: Run ${{ testType }} Tests"
124+
condition: always()
125+
jobs:
126+
- job: ${{ testType }}_job
127+
pool:
128+
name: $(hostPoolName)
129+
steps:
130+
- template: .azuredevops/templates/steps/run-post-deployment-pw-tests.yaml@dtos-devops-templates
131+
parameters:
132+
serviceConnection: $(SERVICE_CONNECTION)
133+
testProjectDirectory: "tests/playwright-tests"
134+
testfileDirectory: "src/tests/e2e/testFiles"
135+
testProjectName: "tests"
136+
testType: ${{ testType }}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
parameters:
2+
- name: pipelineAction
3+
displayName: 'Pipeline Action'
4+
type: string
5+
values:
6+
- 'PlanOnly'
7+
- 'Apply'
8+
default: 'Apply'
9+
- name: terraformActions
10+
type: string
11+
default: 'Apply'
12+
- name: environment
13+
type: string
14+
15+
stages:
16+
- stage: terraform_plan
17+
displayName: "Audit: Terraform Plan"
18+
condition: and(in('${{ parameters.pipelineAction }}', 'Apply', 'PlanOnly'), eq(variables['Build.Reason'], 'Manual'))
19+
variables:
20+
tfVarsFile: environments/$(ENVIRONMENT).tfvars
21+
BACKEND_AZURE_STORAGE_ACCOUNT_CONTAINER_NAME: $(BACKEND_AZURE_STORAGE_ACCOUNT_CONTAINER_NAME_AUDIT)
22+
TF_VAR_TARGET_SUBSCRIPTION_ID: $(TF_VAR_TARGET_SUBSCRIPTION_ID_AUDIT)
23+
TF_DIRECTORY: $(TF_DIRECTORY_AUDIT)
24+
jobs:
25+
- job: init_and_plan
26+
displayName: Init, plan, store artifact
27+
steps:
28+
- checkout: self
29+
- checkout: dtos-devops-templates
30+
- template: .azuredevops/templates/steps/tf_plan.yaml@dtos-devops-templates
31+
32+
- stage: terraform_apply
33+
displayName: "Audit: Terraform Apply"
34+
dependsOn: [terraform_plan]
35+
condition: and(eq('${{ parameters.pipelineAction }}', 'Apply'), eq(dependencies.terraform_plan.outputs['init_and_plan.TerraformPlan.changesPresent'], 'true'), eq(variables['Build.Reason'], 'Manual'))
36+
variables:
37+
BACKEND_AZURE_STORAGE_ACCOUNT_CONTAINER_NAME: $(BACKEND_AZURE_STORAGE_ACCOUNT_CONTAINER_NAME_AUDIT)
38+
TF_VAR_TARGET_SUBSCRIPTION_ID: $(TF_VAR_TARGET_SUBSCRIPTION_ID_AUDIT)
39+
TF_DIRECTORY: $(TF_DIRECTORY_AUDIT)
40+
jobs:
41+
- deployment: terraform_apply
42+
displayName: Init, get plan artifact, apply
43+
environment: $(ENVIRONMENT)
44+
strategy:
45+
runOnce:
46+
deploy:
47+
steps:
48+
- checkout: self
49+
- checkout: dtos-devops-templates
50+
- template: .azuredevops/templates/steps/tf_apply.yaml@dtos-devops-templates

.azuredevops/templates/cd-infrastructure-core-common.yaml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ stages:
3131
- stage: retag_images_stage
3232
# Only required until commit hashes are passed in by calling pipeline, except for the
3333
# PreProd pipeline which needs to retag images to move them from the Dev ACR to the Prod ACR
34-
displayName: ACR re-tag
34+
displayName: "Core: ACR re-tag"
3535
pool:
3636
name: ${{ parameters.hostPoolName }}
3737
jobs:
@@ -68,12 +68,15 @@ stages:
6868
6969
- stage: terraform_deploy_stage
7070
${{ if eq(parameters.terraformActions, 'Apply') }}:
71-
displayName: Terraform Deploy
71+
displayName: "Core: Terraform Deploy"
7272
${{ else }}:
73-
displayName: Terraform Plan Only
73+
displayName: "Core: Terraform Plan Only"
7474
condition: in(dependencies.retag_images_stage.result, 'Succeeded', 'Skipped')
7575
variables:
7676
tfVarsFile: ${{ parameters.tfVarsFile }}
77+
BACKEND_AZURE_STORAGE_ACCOUNT_CONTAINER_NAME: $(BACKEND_AZURE_STORAGE_ACCOUNT_CONTAINER_NAME_CORE)
78+
TF_VAR_TARGET_SUBSCRIPTION_ID: $(TF_VAR_TARGET_SUBSCRIPTION_ID_CORE)
79+
TF_DIRECTORY: $(TF_DIRECTORY_CORE)
7780
pool:
7881
name: ${{ parameters.hostPoolName }}
7982
jobs:
@@ -126,9 +129,11 @@ stages:
126129
displayName: Set Stage Status
127130
128131
- stage: db_changes_stage
129-
displayName: Database changes
132+
displayName: "Core: Database changes"
130133
dependsOn: terraform_deploy_stage
131134
condition: in(dependencies.terraform_deploy_stage.result, 'Succeeded', 'Skipped')
135+
variables:
136+
TF_VAR_TARGET_SUBSCRIPTION_ID: $(TF_VAR_TARGET_SUBSCRIPTION_ID_CORE)
132137
pool:
133138
name: ${{ parameters.hostPoolName }}
134139
jobs:
@@ -165,7 +170,7 @@ stages:
165170
displayName: Set Stage Status
166171
167172
- stage: restart_functions_stage
168-
displayName: Restart Function Apps
173+
displayName: "Core: Restart Function Apps"
169174
dependsOn:
170175
- terraform_deploy_stage
171176
- db_changes_stage
@@ -174,6 +179,8 @@ stages:
174179
in(dependencies.terraform_deploy_stage.result, 'Succeeded', 'Skipped'),
175180
in(dependencies.db_changes_stage.result, 'Succeeded', 'Skipped')
176181
)
182+
variables:
183+
TF_VAR_TARGET_SUBSCRIPTION_ID: $(TF_VAR_TARGET_SUBSCRIPTION_ID_CORE)
177184
pool:
178185
name: ${{ parameters.hostPoolName }}
179186
jobs:
@@ -205,7 +212,7 @@ stages:
205212
displayName: Set Stage Status
206213
207214
- stage: notify_stage
208-
displayName: Send Slack Notification
215+
displayName: "Core: Send Slack Notification"
209216
dependsOn:
210217
- retag_images_stage
211218
- terraform_deploy_stage

0 commit comments

Comments
 (0)