Skip to content

Commit 9c49632

Browse files
authored
DS-2241 Fixing CW query consistency issue (#1147)
# Task Branch Pull Request **<https://nhsd-jira.digital.nhs.uk/browse/DS-2241>** ## Description of Changes This change is to fix the read-after-write eventual consistency issue occuring during terraform apply operation in AWS codebuild jobs across CI/CD pipelines. ## Type of change Delete not appropriate - Bug fix (Fixing CW query consistency issue during terraform apply) ## Development Checklist - [x] I have performed a self-review of my own code - [x] Tests have added that prove my fix is effective or that my feature works (Integration tests) - [x] I have updated Dependabot to include my changes (if applicable) ## Code Reviewer Checklist - [x] I can confirm the changes have been tested or approved by a tester
1 parent 199a8bb commit 9c49632

2 files changed

Lines changed: 26 additions & 52 deletions

File tree

infrastructure/stacks/blue-green-link/cloudwatch-queries.tf

Lines changed: 26 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
// Introduce a short sleep BEFORE creating query definitions to allow
2-
// recently-created log groups (from other modules in the same apply)
3-
// to propagate. Note: This does NOT guarantee post-create consistency
4-
// of the query definitions themselves, but can reduce immediate read
5-
// failures when the provider plans many resources concurrently.
6-
resource "time_sleep" "wait_for_propagation" {
7-
create_duration = "45s"
8-
}
9-
101
resource "aws_cloudwatch_query_definition" "search_for_errors" {
11-
depends_on = [time_sleep.wait_for_propagation]
122
name = "${var.project_id}/${var.blue_green_environment}/search-for-errors"
133

144
log_group_names = [
@@ -27,13 +17,12 @@ fields @timestamp, correlation_id, ods_code, function_name, message
2717
| sort @timestamp
2818
EOF
2919

30-
lifecycle {
31-
create_before_destroy = false
20+
provisioner "local-exec" {
21+
command = "sleep 30"
3222
}
3323
}
3424

3525
resource "aws_cloudwatch_query_definition" "search_by_correlation_id" {
36-
depends_on = [aws_cloudwatch_query_definition.search_for_errors]
3726
name = "${var.project_id}/${var.blue_green_environment}/search-by-correlation-id"
3827

3928
log_group_names = [
@@ -52,13 +41,12 @@ fields @timestamp, message
5241
| sort @timestamp
5342
EOF
5443

55-
lifecycle {
56-
create_before_destroy = false
44+
provisioner "local-exec" {
45+
command = "sleep 30"
5746
}
5847
}
5948

6049
resource "aws_cloudwatch_query_definition" "search_by_correlation_id_expanded" {
61-
depends_on = [aws_cloudwatch_query_definition.search_by_correlation_id]
6250
name = "${var.project_id}/${var.blue_green_environment}/search-by-correlation-id-expanded"
6351

6452
log_group_names = [
@@ -77,13 +65,12 @@ fields @timestamp,correlation_id,ods_code,level,message_received,function_name,
7765
| sort @timestamp
7866
EOF
7967

80-
lifecycle {
81-
create_before_destroy = false
68+
provisioner "local-exec" {
69+
command = "sleep 30"
8270
}
8371
}
8472

8573
resource "aws_cloudwatch_query_definition" "search_by_odscode" {
86-
depends_on = [aws_cloudwatch_query_definition.search_by_correlation_id_expanded]
8774
name = "${var.project_id}/${var.blue_green_environment}/search-by-odscode"
8875

8976
log_group_names = [
@@ -102,13 +89,12 @@ fields @timestamp, message
10289
| sort @timestamp
10390
EOF
10491

105-
lifecycle {
106-
create_before_destroy = false
92+
provisioner "local-exec" {
93+
command = "sleep 30"
10794
}
10895
}
10996

11097
resource "aws_cloudwatch_query_definition" "search_by_odscode_expanded" {
111-
depends_on = [aws_cloudwatch_query_definition.search_by_odscode]
11298
name = "${var.project_id}/${var.blue_green_environment}/search-by-odscode-expanded"
11399

114100
log_group_names = [
@@ -127,13 +113,12 @@ fields @timestamp,correlation_id,ods_code,level,message_received,function_name,
127113
| sort @timestamp
128114
EOF
129115

130-
lifecycle {
131-
create_before_destroy = false
116+
provisioner "local-exec" {
117+
command = "sleep 30"
132118
}
133119
}
134120

135121
resource "aws_cloudwatch_query_definition" "search_for_invalid_postcode" {
136-
depends_on = [aws_cloudwatch_query_definition.search_by_odscode_expanded]
137122
name = "${var.project_id}/${var.blue_green_environment}/search-for-invalid-postcode"
138123

139124
log_group_names = [
@@ -146,13 +131,12 @@ fields @timestamp,correlation_id,ods_code,level,message_received,function_name,
146131
| sort @timestamp
147132
EOF
148133

149-
lifecycle {
150-
create_before_destroy = false
134+
provisioner "local-exec" {
135+
command = "sleep 30"
151136
}
152137
}
153138

154139
resource "aws_cloudwatch_query_definition" "search_for_invalid_opening_times" {
155-
depends_on = [aws_cloudwatch_query_definition.search_for_invalid_postcode]
156140
name = "${var.project_id}/${var.blue_green_environment}/search-for-invalid-opening-times"
157141

158142
log_group_names = [
@@ -165,13 +149,12 @@ fields @timestamp,correlation_id,ods_code,level,message_received,function_name,
165149
| sort @timestamp
166150
EOF
167151

168-
lifecycle {
169-
create_before_destroy = false
152+
provisioner "local-exec" {
153+
command = "sleep 30"
170154
}
171155
}
172156

173157
resource "aws_cloudwatch_query_definition" "search_by_email_correlation_id" {
174-
depends_on = [aws_cloudwatch_query_definition.search_for_invalid_opening_times]
175158
name = "${var.project_id}/${var.blue_green_environment}/search-by-email-correlation-id"
176159

177160
log_group_names = [
@@ -185,13 +168,12 @@ fields correlation_id
185168
| filter email_correlation_id == "ADD_EMAIL_CORRELATION_ID"
186169
EOF
187170

188-
lifecycle {
189-
create_before_destroy = false
171+
provisioner "local-exec" {
172+
command = "sleep 30"
190173
}
191174
}
192175

193176
resource "aws_cloudwatch_query_definition" "search_by_update_request_success" {
194-
depends_on = [aws_cloudwatch_query_definition.search_by_email_correlation_id]
195177
name = "${var.project_id}/${var.blue_green_environment}/update-request-success"
196178

197179
log_group_names = [
@@ -204,13 +186,12 @@ fields @timestamp, correlation_id
204186
| sort @timestamp desc
205187
EOF
206188

207-
lifecycle {
208-
create_before_destroy = false
189+
provisioner "local-exec" {
190+
command = "sleep 30"
209191
}
210192
}
211193

212194
resource "aws_cloudwatch_query_definition" "search_by_update_request_failed" {
213-
depends_on = [aws_cloudwatch_query_definition.search_by_update_request_success]
214195
name = "${var.project_id}/${var.blue_green_environment}/update-request-failed"
215196

216197
log_group_names = [
@@ -223,13 +204,12 @@ fields @timestamp, correlation_id, report_key
223204
| sort @timestamp desc
224205
EOF
225206

226-
lifecycle {
227-
create_before_destroy = false
207+
provisioner "local-exec" {
208+
command = "sleep 30"
228209
}
229210
}
230211

231212
resource "aws_cloudwatch_query_definition" "search_by_dos_data_item_updates" {
232-
depends_on = [aws_cloudwatch_query_definition.search_by_update_request_failed]
233213
name = "${var.project_id}/${var.blue_green_environment}/dos-data-item-updates"
234214

235215
log_group_names = [
@@ -244,13 +224,12 @@ fields @timestamp, correlation_id
244224
| sort @timestamp desc
245225
EOF
246226

247-
lifecycle {
248-
create_before_destroy = false
227+
provisioner "local-exec" {
228+
command = "sleep 30"
249229
}
250230
}
251231

252232
resource "aws_cloudwatch_query_definition" "search_for_report_warnings" {
253-
depends_on = [aws_cloudwatch_query_definition.search_by_dos_data_item_updates]
254233
name = "${var.project_id}/${var.blue_green_environment}/search-for-report-warnings"
255234

256235
log_group_names = [
@@ -270,14 +249,13 @@ fields @timestamp, correlation_id, message
270249
| sort @timestamp desc
271250
EOF
272251

273-
lifecycle {
274-
create_before_destroy = false
252+
provisioner "local-exec" {
253+
command = "sleep 30"
275254
}
276255
}
277256

278257

279258
resource "aws_cloudwatch_query_definition" "search_for_quality_checker_logs_with_odscode" {
280-
depends_on = [aws_cloudwatch_query_definition.search_for_report_warnings]
281259
name = "${var.project_id}/${var.blue_green_environment}/search-for-quality-checker-logs-with-odscode"
282260

283261
log_group_names = [
@@ -290,7 +268,7 @@ fields @timestamp, level, message
290268
| sort @timestamp asc
291269
EOF
292270

293-
lifecycle {
294-
create_before_destroy = false
271+
provisioner "local-exec" {
272+
command = "sleep 30"
295273
}
296274
}

infrastructure/stacks/blue-green-link/terraform.tf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,5 @@ terraform {
77
source = "hashicorp/aws"
88
version = "~> 6.14.1"
99
}
10-
time = {
11-
source = "hashicorp/time"
12-
version = "~> 0.13.1"
13-
}
1410
}
1511
}

0 commit comments

Comments
 (0)