diff --git a/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-dev/resources/cas-2-domain-events-queue.tf b/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-dev/resources/cas-2-domain-events-queue.tf new file mode 100644 index 00000000000..b73e26b720d --- /dev/null +++ b/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-dev/resources/cas-2-domain-events-queue.tf @@ -0,0 +1,79 @@ +resource "aws_sns_topic_subscription" "cas-2-domain-events-queue-subscription" { + topic_arn = data.aws_sns_topic.hmpps-domain-events.arn + protocol = "sqs" + endpoint = module.cas-2-domain-events-queue.sqs_arn + filter_policy = jsonencode({ + eventType = [ + "offender-management.handover.changed", + "offender-management.allocation.changed" + ] + }) +} + +module "cas-2-domain-events-queue" { + source = "github.com/ministryofjustice/cloud-platform-terraform-sqs?ref=5.0.0" + + # Queue configuration + sqs_name = "cas-2-domain-events-queue" + redrive_policy = jsonencode({ + deadLetterTargetArn = module.cas-2-domain-events-dlq.sqs_arn + maxReceiveCount = 3 + }) + + # Tags + application = "cas-2-domain-events" + business_unit = var.business_unit + environment_name = var.environment + infrastructure_support = var.infrastructure_support + is_production = var.is_production + namespace = var.namespace + team_name = var.team_name # also used as queue name prefix +} + +resource "aws_sqs_queue_policy" "cas-2-domain-events-queue-policy" { + queue_url = module.cas-2-domain-events-queue.sqs_id + policy = data.aws_iam_policy_document.sns_to_sqs.json +} + +module "cas-2-domain-events-dlq" { + source = "github.com/ministryofjustice/cloud-platform-terraform-sqs?ref=5.0.0" + + # Queue configuration + sqs_name = "cas-2-domain-events-dlq" + message_retention_seconds = 7 * 24 * 3600 # 1 week + + # Tags + business_unit = var.business_unit + application = "cas-2-domain-events" + is_production = var.is_production + team_name = var.team_name # also used as queue name prefix + namespace = var.namespace + environment_name = var.environment + infrastructure_support = var.infrastructure_support +} + +resource "aws_sqs_queue_policy" "cas-2-domain-events-dlq-policy" { + queue_url = module.cas-2-domain-events-dlq.sqs_id + policy = data.aws_iam_policy_document.sns_to_sqs.json +} + +resource "kubernetes_secret" "cas-2-domain-events-queue-secret" { + metadata { + name = "cas-2-domain-events-queue" + namespace = var.namespace + } + data = { + QUEUE_NAME = module.cas-2-domain-events-queue.sqs_name + } +} + +resource "kubernetes_secret" "cas-2-domain-events-dlq-secret" { + metadata { + name = "cas-2-domain-events-dlq" + namespace = var.namespace + } + + data = { + QUEUE_NAME = module.cas-2-domain-events-dlq.sqs_name + } +} diff --git a/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-dev/resources/data.tf b/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-dev/resources/data.tf new file mode 100644 index 00000000000..22b73db717d --- /dev/null +++ b/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-dev/resources/data.tf @@ -0,0 +1,25 @@ +data "aws_iam_policy_document" "sns_to_sqs" { + statement { + sid = "DomainEventsToQueue" + effect = "Allow" + actions = ["sqs:SendMessage"] + principals { + type = "AWS" + identifiers = ["*"] + } + condition { + variable = "aws:SourceArn" + test = "ArnEquals" + values = [data.aws_ssm_parameter.hmpps-domain-events-topic-arn.value] + } + resources = ["*"] + } +} + +data "aws_ssm_parameter" "hmpps-domain-events-topic-arn" { + name = "/hmpps-domain-events-dev/topic-arn" +} + +data "aws_sns_topic" "hmpps-domain-events" { + name = "cloud-platform-Digital-Prison-Services-15b2b4a6af7714848baeaf5f41c85fcd" +} \ No newline at end of file diff --git a/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-dev/resources/irsa.tf b/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-dev/resources/irsa.tf index d41c1535973..08e06f9ca1d 100644 --- a/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-dev/resources/irsa.tf +++ b/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-dev/resources/irsa.tf @@ -22,7 +22,12 @@ module "irsa" { eks_cluster_name = var.eks_cluster_name service_account_name = "hmpps-community-accommodation-api-service-account" namespace = var.namespace - role_policy_arns = local.sns_policies + role_policy_arns = merge( + { + rds = module.cas-2-domain-events-queue.irsa_policy_arn + }, + local.sns_policies + ) business_unit = var.business_unit application = var.application is_production = var.is_production diff --git a/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-preprod/resources/cas-2-domain-events-queue.tf b/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-preprod/resources/cas-2-domain-events-queue.tf new file mode 100644 index 00000000000..b73e26b720d --- /dev/null +++ b/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-preprod/resources/cas-2-domain-events-queue.tf @@ -0,0 +1,79 @@ +resource "aws_sns_topic_subscription" "cas-2-domain-events-queue-subscription" { + topic_arn = data.aws_sns_topic.hmpps-domain-events.arn + protocol = "sqs" + endpoint = module.cas-2-domain-events-queue.sqs_arn + filter_policy = jsonencode({ + eventType = [ + "offender-management.handover.changed", + "offender-management.allocation.changed" + ] + }) +} + +module "cas-2-domain-events-queue" { + source = "github.com/ministryofjustice/cloud-platform-terraform-sqs?ref=5.0.0" + + # Queue configuration + sqs_name = "cas-2-domain-events-queue" + redrive_policy = jsonencode({ + deadLetterTargetArn = module.cas-2-domain-events-dlq.sqs_arn + maxReceiveCount = 3 + }) + + # Tags + application = "cas-2-domain-events" + business_unit = var.business_unit + environment_name = var.environment + infrastructure_support = var.infrastructure_support + is_production = var.is_production + namespace = var.namespace + team_name = var.team_name # also used as queue name prefix +} + +resource "aws_sqs_queue_policy" "cas-2-domain-events-queue-policy" { + queue_url = module.cas-2-domain-events-queue.sqs_id + policy = data.aws_iam_policy_document.sns_to_sqs.json +} + +module "cas-2-domain-events-dlq" { + source = "github.com/ministryofjustice/cloud-platform-terraform-sqs?ref=5.0.0" + + # Queue configuration + sqs_name = "cas-2-domain-events-dlq" + message_retention_seconds = 7 * 24 * 3600 # 1 week + + # Tags + business_unit = var.business_unit + application = "cas-2-domain-events" + is_production = var.is_production + team_name = var.team_name # also used as queue name prefix + namespace = var.namespace + environment_name = var.environment + infrastructure_support = var.infrastructure_support +} + +resource "aws_sqs_queue_policy" "cas-2-domain-events-dlq-policy" { + queue_url = module.cas-2-domain-events-dlq.sqs_id + policy = data.aws_iam_policy_document.sns_to_sqs.json +} + +resource "kubernetes_secret" "cas-2-domain-events-queue-secret" { + metadata { + name = "cas-2-domain-events-queue" + namespace = var.namespace + } + data = { + QUEUE_NAME = module.cas-2-domain-events-queue.sqs_name + } +} + +resource "kubernetes_secret" "cas-2-domain-events-dlq-secret" { + metadata { + name = "cas-2-domain-events-dlq" + namespace = var.namespace + } + + data = { + QUEUE_NAME = module.cas-2-domain-events-dlq.sqs_name + } +} diff --git a/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-preprod/resources/data.tf b/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-preprod/resources/data.tf new file mode 100644 index 00000000000..a3a8ce7aadb --- /dev/null +++ b/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-preprod/resources/data.tf @@ -0,0 +1,25 @@ +data "aws_iam_policy_document" "sns_to_sqs" { + statement { + sid = "DomainEventsToQueue" + effect = "Allow" + actions = ["sqs:SendMessage"] + principals { + type = "AWS" + identifiers = ["*"] + } + condition { + variable = "aws:SourceArn" + test = "ArnEquals" + values = [data.aws_ssm_parameter.hmpps-domain-events-topic-arn.value] + } + resources = ["*"] + } +} + +data "aws_ssm_parameter" "hmpps-domain-events-topic-arn" { + name = "/hmpps-domain-events-preprod/topic-arn" +} + +data "aws_sns_topic" "hmpps-domain-events" { + name = "cloud-platform-Digital-Prison-Services-15b2b4a6af7714848baeaf5f41c85fcd" +} \ No newline at end of file diff --git a/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-preprod/resources/irsa.tf b/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-preprod/resources/irsa.tf index a4fdcafd28f..5689b2eb903 100644 --- a/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-preprod/resources/irsa.tf +++ b/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-preprod/resources/irsa.tf @@ -26,6 +26,9 @@ module "irsa" { { rds = module.rds.irsa_policy_arn }, + { + rds = module.cas-2-domain-events-queue.irsa_policy_arn + }, local.sns_policies ) business_unit = var.business_unit diff --git a/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-prod/resources/cas-2-domain-events-queue.tf b/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-prod/resources/cas-2-domain-events-queue.tf new file mode 100644 index 00000000000..b73e26b720d --- /dev/null +++ b/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-prod/resources/cas-2-domain-events-queue.tf @@ -0,0 +1,79 @@ +resource "aws_sns_topic_subscription" "cas-2-domain-events-queue-subscription" { + topic_arn = data.aws_sns_topic.hmpps-domain-events.arn + protocol = "sqs" + endpoint = module.cas-2-domain-events-queue.sqs_arn + filter_policy = jsonencode({ + eventType = [ + "offender-management.handover.changed", + "offender-management.allocation.changed" + ] + }) +} + +module "cas-2-domain-events-queue" { + source = "github.com/ministryofjustice/cloud-platform-terraform-sqs?ref=5.0.0" + + # Queue configuration + sqs_name = "cas-2-domain-events-queue" + redrive_policy = jsonencode({ + deadLetterTargetArn = module.cas-2-domain-events-dlq.sqs_arn + maxReceiveCount = 3 + }) + + # Tags + application = "cas-2-domain-events" + business_unit = var.business_unit + environment_name = var.environment + infrastructure_support = var.infrastructure_support + is_production = var.is_production + namespace = var.namespace + team_name = var.team_name # also used as queue name prefix +} + +resource "aws_sqs_queue_policy" "cas-2-domain-events-queue-policy" { + queue_url = module.cas-2-domain-events-queue.sqs_id + policy = data.aws_iam_policy_document.sns_to_sqs.json +} + +module "cas-2-domain-events-dlq" { + source = "github.com/ministryofjustice/cloud-platform-terraform-sqs?ref=5.0.0" + + # Queue configuration + sqs_name = "cas-2-domain-events-dlq" + message_retention_seconds = 7 * 24 * 3600 # 1 week + + # Tags + business_unit = var.business_unit + application = "cas-2-domain-events" + is_production = var.is_production + team_name = var.team_name # also used as queue name prefix + namespace = var.namespace + environment_name = var.environment + infrastructure_support = var.infrastructure_support +} + +resource "aws_sqs_queue_policy" "cas-2-domain-events-dlq-policy" { + queue_url = module.cas-2-domain-events-dlq.sqs_id + policy = data.aws_iam_policy_document.sns_to_sqs.json +} + +resource "kubernetes_secret" "cas-2-domain-events-queue-secret" { + metadata { + name = "cas-2-domain-events-queue" + namespace = var.namespace + } + data = { + QUEUE_NAME = module.cas-2-domain-events-queue.sqs_name + } +} + +resource "kubernetes_secret" "cas-2-domain-events-dlq-secret" { + metadata { + name = "cas-2-domain-events-dlq" + namespace = var.namespace + } + + data = { + QUEUE_NAME = module.cas-2-domain-events-dlq.sqs_name + } +} diff --git a/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-prod/resources/data.tf b/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-prod/resources/data.tf new file mode 100644 index 00000000000..2bbe83f2569 --- /dev/null +++ b/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-prod/resources/data.tf @@ -0,0 +1,25 @@ +data "aws_iam_policy_document" "sns_to_sqs" { + statement { + sid = "DomainEventsToQueue" + effect = "Allow" + actions = ["sqs:SendMessage"] + principals { + type = "AWS" + identifiers = ["*"] + } + condition { + variable = "aws:SourceArn" + test = "ArnEquals" + values = [data.aws_ssm_parameter.hmpps-domain-events-topic-arn.value] + } + resources = ["*"] + } +} + +data "aws_ssm_parameter" "hmpps-domain-events-topic-arn" { + name = "/hmpps-domain-events-prod/topic-arn" +} + +data "aws_sns_topic" "hmpps-domain-events" { + name = "cloud-platform-Digital-Prison-Services-15b2b4a6af7714848baeaf5f41c85fcd" +} \ No newline at end of file diff --git a/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-prod/resources/irsa.tf b/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-prod/resources/irsa.tf index 63f3ff0e653..0399575d81b 100644 --- a/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-prod/resources/irsa.tf +++ b/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-prod/resources/irsa.tf @@ -26,6 +26,9 @@ module "irsa" { { rds = module.rds.irsa_policy_arn }, + { + rds = module.cas-2-domain-events-queue.irsa_policy_arn + }, local.sns_policies ) business_unit = var.business_unit diff --git a/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-test/resources/cas-2-domain-events-queue.tf b/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-test/resources/cas-2-domain-events-queue.tf new file mode 100644 index 00000000000..b73e26b720d --- /dev/null +++ b/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-test/resources/cas-2-domain-events-queue.tf @@ -0,0 +1,79 @@ +resource "aws_sns_topic_subscription" "cas-2-domain-events-queue-subscription" { + topic_arn = data.aws_sns_topic.hmpps-domain-events.arn + protocol = "sqs" + endpoint = module.cas-2-domain-events-queue.sqs_arn + filter_policy = jsonencode({ + eventType = [ + "offender-management.handover.changed", + "offender-management.allocation.changed" + ] + }) +} + +module "cas-2-domain-events-queue" { + source = "github.com/ministryofjustice/cloud-platform-terraform-sqs?ref=5.0.0" + + # Queue configuration + sqs_name = "cas-2-domain-events-queue" + redrive_policy = jsonencode({ + deadLetterTargetArn = module.cas-2-domain-events-dlq.sqs_arn + maxReceiveCount = 3 + }) + + # Tags + application = "cas-2-domain-events" + business_unit = var.business_unit + environment_name = var.environment + infrastructure_support = var.infrastructure_support + is_production = var.is_production + namespace = var.namespace + team_name = var.team_name # also used as queue name prefix +} + +resource "aws_sqs_queue_policy" "cas-2-domain-events-queue-policy" { + queue_url = module.cas-2-domain-events-queue.sqs_id + policy = data.aws_iam_policy_document.sns_to_sqs.json +} + +module "cas-2-domain-events-dlq" { + source = "github.com/ministryofjustice/cloud-platform-terraform-sqs?ref=5.0.0" + + # Queue configuration + sqs_name = "cas-2-domain-events-dlq" + message_retention_seconds = 7 * 24 * 3600 # 1 week + + # Tags + business_unit = var.business_unit + application = "cas-2-domain-events" + is_production = var.is_production + team_name = var.team_name # also used as queue name prefix + namespace = var.namespace + environment_name = var.environment + infrastructure_support = var.infrastructure_support +} + +resource "aws_sqs_queue_policy" "cas-2-domain-events-dlq-policy" { + queue_url = module.cas-2-domain-events-dlq.sqs_id + policy = data.aws_iam_policy_document.sns_to_sqs.json +} + +resource "kubernetes_secret" "cas-2-domain-events-queue-secret" { + metadata { + name = "cas-2-domain-events-queue" + namespace = var.namespace + } + data = { + QUEUE_NAME = module.cas-2-domain-events-queue.sqs_name + } +} + +resource "kubernetes_secret" "cas-2-domain-events-dlq-secret" { + metadata { + name = "cas-2-domain-events-dlq" + namespace = var.namespace + } + + data = { + QUEUE_NAME = module.cas-2-domain-events-dlq.sqs_name + } +} diff --git a/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-test/resources/data.tf b/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-test/resources/data.tf new file mode 100644 index 00000000000..22b73db717d --- /dev/null +++ b/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-test/resources/data.tf @@ -0,0 +1,25 @@ +data "aws_iam_policy_document" "sns_to_sqs" { + statement { + sid = "DomainEventsToQueue" + effect = "Allow" + actions = ["sqs:SendMessage"] + principals { + type = "AWS" + identifiers = ["*"] + } + condition { + variable = "aws:SourceArn" + test = "ArnEquals" + values = [data.aws_ssm_parameter.hmpps-domain-events-topic-arn.value] + } + resources = ["*"] + } +} + +data "aws_ssm_parameter" "hmpps-domain-events-topic-arn" { + name = "/hmpps-domain-events-dev/topic-arn" +} + +data "aws_sns_topic" "hmpps-domain-events" { + name = "cloud-platform-Digital-Prison-Services-15b2b4a6af7714848baeaf5f41c85fcd" +} \ No newline at end of file diff --git a/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-test/resources/irsa.tf b/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-test/resources/irsa.tf index 53a5b5c9117..cf503a1eb05 100644 --- a/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-test/resources/irsa.tf +++ b/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-community-accommodation-test/resources/irsa.tf @@ -23,7 +23,12 @@ module "irsa" { eks_cluster_name = var.eks_cluster_name service_account_name = "hmpps-community-accommodation-api-service-account" namespace = var.namespace - role_policy_arns = local.sns_policies + role_policy_arns = merge( + { + rds = module.cas-2-domain-events-queue.irsa_policy_arn + }, + local.sns_policies + ) business_unit = var.business_unit application = var.application is_production = var.is_production