From f0880da2a64d61c94bfa9939a8a904db10ec8b6f Mon Sep 17 00:00:00 2001 From: Ajay Mudgal Date: Mon, 24 Nov 2025 10:23:59 +0000 Subject: [PATCH 1/2] Fixing cloudwatch query terraform error --- .../blue-green-link/cloudwatch-queries.tf | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/infrastructure/stacks/blue-green-link/cloudwatch-queries.tf b/infrastructure/stacks/blue-green-link/cloudwatch-queries.tf index 039a8444d..7e4283607 100644 --- a/infrastructure/stacks/blue-green-link/cloudwatch-queries.tf +++ b/infrastructure/stacks/blue-green-link/cloudwatch-queries.tf @@ -16,6 +16,10 @@ fields @timestamp, correlation_id, ods_code, function_name, message | filter level == 'ERROR' | sort @timestamp EOF + + lifecycle { + create_before_destroy = false + } } resource "aws_cloudwatch_query_definition" "search_by_correlation_id" { @@ -36,6 +40,10 @@ fields @timestamp, message | filter correlation_id == 'REPLACE' | sort @timestamp EOF + + lifecycle { + create_before_destroy = false + } } resource "aws_cloudwatch_query_definition" "search_by_correlation_id_expanded" { @@ -56,6 +64,10 @@ fields @timestamp,correlation_id,ods_code,level,message_received,function_name, | filter correlation_id == 'REPLACE' | sort @timestamp EOF + + lifecycle { + create_before_destroy = false + } } resource "aws_cloudwatch_query_definition" "search_by_odscode" { @@ -76,6 +88,10 @@ fields @timestamp, message | filter ods_code == 'REPLACE' | sort @timestamp EOF + + lifecycle { + create_before_destroy = false + } } resource "aws_cloudwatch_query_definition" "search_by_odscode_expanded" { @@ -96,6 +112,10 @@ fields @timestamp,correlation_id,ods_code,level,message_received,function_name, | filter ods_code == 'REPLACE' | sort @timestamp EOF + + lifecycle { + create_before_destroy = false + } } resource "aws_cloudwatch_query_definition" "search_for_invalid_postcode" { @@ -110,6 +130,10 @@ fields @timestamp,correlation_id,ods_code,level,message_received,function_name, | filter report_key == 'INVALID_POSTCODE' | sort @timestamp EOF + + lifecycle { + create_before_destroy = false + } } resource "aws_cloudwatch_query_definition" "search_for_invalid_opening_times" { @@ -124,6 +148,10 @@ fields @timestamp,correlation_id,ods_code,level,message_received,function_name, | filter report_key == 'INVALID_OPEN_TIMES' | sort @timestamp EOF + + lifecycle { + create_before_destroy = false + } } resource "aws_cloudwatch_query_definition" "search_by_email_correlation_id" { @@ -139,6 +167,10 @@ fields correlation_id | filter message =="Email Correlation Id" | filter email_correlation_id == "ADD_EMAIL_CORRELATION_ID" EOF + + lifecycle { + create_before_destroy = false + } } resource "aws_cloudwatch_query_definition" "search_by_update_request_success" { @@ -153,6 +185,10 @@ fields @timestamp, correlation_id | filter ServiceUpdateSuccess == 1 | sort @timestamp desc EOF + + lifecycle { + create_before_destroy = false + } } resource "aws_cloudwatch_query_definition" "search_by_update_request_failed" { @@ -167,6 +203,10 @@ fields @timestamp, correlation_id, report_key | filter report_key == DOS_DB_UPDATE_DLQ_HANDLER_RECEIVED_EVENT | sort @timestamp desc EOF + + lifecycle { + create_before_destroy = false + } } resource "aws_cloudwatch_query_definition" "search_by_dos_data_item_updates" { @@ -183,6 +223,10 @@ fields @timestamp, correlation_id | filter field == 'REPLACE' | sort @timestamp desc EOF + + lifecycle { + create_before_destroy = false + } } resource "aws_cloudwatch_query_definition" "search_for_report_warnings" { @@ -204,6 +248,10 @@ fields @timestamp, correlation_id, message | filter level == 'WARNING' | sort @timestamp desc EOF + + lifecycle { + create_before_destroy = false + } } @@ -219,4 +267,8 @@ fields @timestamp, level, message | filter odscode = 'TO_ADD' | sort @timestamp asc EOF + + lifecycle { + create_before_destroy = false + } } From f3c1f35b6cdeb016840dee4c66effe5a2bcfcf9a Mon Sep 17 00:00:00 2001 From: Ajay Mudgal Date: Mon, 24 Nov 2025 12:08:17 +0000 Subject: [PATCH 2/2] Fixing cloudwatch query issue in pipeline --- .../blue-green-link/cloudwatch-queries.tf | 22 +++++++++++++++++++ .../stacks/blue-green-link/terraform.tf | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/infrastructure/stacks/blue-green-link/cloudwatch-queries.tf b/infrastructure/stacks/blue-green-link/cloudwatch-queries.tf index 7e4283607..cf69c59cc 100644 --- a/infrastructure/stacks/blue-green-link/cloudwatch-queries.tf +++ b/infrastructure/stacks/blue-green-link/cloudwatch-queries.tf @@ -1,4 +1,14 @@ +// Introduce a short sleep BEFORE creating query definitions to allow +// recently-created log groups (from other modules in the same apply) +// to propagate. Note: This does NOT guarantee post-create consistency +// of the query definitions themselves, but can reduce immediate read +// failures when the provider plans many resources concurrently. +resource "time_sleep" "wait_for_propagation" { + create_duration = "5s" +} + resource "aws_cloudwatch_query_definition" "search_for_errors" { + depends_on = [time_sleep.wait_for_propagation] name = "${var.project_id}/${var.blue_green_environment}/search-for-errors" log_group_names = [ @@ -23,6 +33,7 @@ EOF } resource "aws_cloudwatch_query_definition" "search_by_correlation_id" { + depends_on = [time_sleep.wait_for_propagation] name = "${var.project_id}/${var.blue_green_environment}/search-by-correlation-id" log_group_names = [ @@ -47,6 +58,7 @@ EOF } resource "aws_cloudwatch_query_definition" "search_by_correlation_id_expanded" { + depends_on = [time_sleep.wait_for_propagation] name = "${var.project_id}/${var.blue_green_environment}/search-by-correlation-id-expanded" log_group_names = [ @@ -71,6 +83,7 @@ EOF } resource "aws_cloudwatch_query_definition" "search_by_odscode" { + depends_on = [time_sleep.wait_for_propagation] name = "${var.project_id}/${var.blue_green_environment}/search-by-odscode" log_group_names = [ @@ -95,6 +108,7 @@ EOF } resource "aws_cloudwatch_query_definition" "search_by_odscode_expanded" { + depends_on = [time_sleep.wait_for_propagation] name = "${var.project_id}/${var.blue_green_environment}/search-by-odscode-expanded" log_group_names = [ @@ -119,6 +133,7 @@ EOF } resource "aws_cloudwatch_query_definition" "search_for_invalid_postcode" { + depends_on = [time_sleep.wait_for_propagation] name = "${var.project_id}/${var.blue_green_environment}/search-for-invalid-postcode" log_group_names = [ @@ -137,6 +152,7 @@ EOF } resource "aws_cloudwatch_query_definition" "search_for_invalid_opening_times" { + depends_on = [time_sleep.wait_for_propagation] name = "${var.project_id}/${var.blue_green_environment}/search-for-invalid-opening-times" log_group_names = [ @@ -155,6 +171,7 @@ EOF } resource "aws_cloudwatch_query_definition" "search_by_email_correlation_id" { + depends_on = [time_sleep.wait_for_propagation] name = "${var.project_id}/${var.blue_green_environment}/search-by-email-correlation-id" log_group_names = [ @@ -174,6 +191,7 @@ EOF } resource "aws_cloudwatch_query_definition" "search_by_update_request_success" { + depends_on = [time_sleep.wait_for_propagation] name = "${var.project_id}/${var.blue_green_environment}/update-request-success" log_group_names = [ @@ -192,6 +210,7 @@ EOF } resource "aws_cloudwatch_query_definition" "search_by_update_request_failed" { + depends_on = [time_sleep.wait_for_propagation] name = "${var.project_id}/${var.blue_green_environment}/update-request-failed" log_group_names = [ @@ -210,6 +229,7 @@ EOF } resource "aws_cloudwatch_query_definition" "search_by_dos_data_item_updates" { + depends_on = [time_sleep.wait_for_propagation] name = "${var.project_id}/${var.blue_green_environment}/dos-data-item-updates" log_group_names = [ @@ -230,6 +250,7 @@ EOF } resource "aws_cloudwatch_query_definition" "search_for_report_warnings" { + depends_on = [time_sleep.wait_for_propagation] name = "${var.project_id}/${var.blue_green_environment}/search-for-report-warnings" log_group_names = [ @@ -256,6 +277,7 @@ EOF resource "aws_cloudwatch_query_definition" "search_for_quality_checker_logs_with_odscode" { + depends_on = [time_sleep.wait_for_propagation] name = "${var.project_id}/${var.blue_green_environment}/search-for-quality-checker-logs-with-odscode" log_group_names = [ diff --git a/infrastructure/stacks/blue-green-link/terraform.tf b/infrastructure/stacks/blue-green-link/terraform.tf index 5a3d2f3fc..894f94b0e 100755 --- a/infrastructure/stacks/blue-green-link/terraform.tf +++ b/infrastructure/stacks/blue-green-link/terraform.tf @@ -7,5 +7,9 @@ terraform { source = "hashicorp/aws" version = "~> 6.14.1" } + time = { + source = "hashicorp/time" + version = "~> 0.13.1" + } } }