From 8725509b6db9909664d5ecfde3b28c0f06ee87e2 Mon Sep 17 00:00:00 2001 From: Mike Houston Date: Wed, 13 Nov 2024 14:37:47 +0000 Subject: [PATCH] CCM-7357: Associate domain name with url prefix not branch name --- .../terraform/components/app/amplify_domain_association.tf | 5 +++-- .../terraform/components/app/module_amplify_branch.tf | 2 +- infrastructure/terraform/components/app/variables.tf | 6 ++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/infrastructure/terraform/components/app/amplify_domain_association.tf b/infrastructure/terraform/components/app/amplify_domain_association.tf index 1b288e5..1b5d7df 100644 --- a/infrastructure/terraform/components/app/amplify_domain_association.tf +++ b/infrastructure/terraform/components/app/amplify_domain_association.tf @@ -10,7 +10,7 @@ # sub_domain { # branch_name = module.amplify_branch.name -# prefix = "main" +# prefix = module.amplify_branch.display_name # } # } @@ -20,12 +20,13 @@ resource "null_resource" "amplify_domain_association" { triggers = { amplify_app_id = aws_amplify_app.main.id amplify_branch_name = module.amplify_branch.name + amplify_url_prefix = module.amplify_branch.display_name amplify_domain_name = local.root_domain_name } provisioner "local-exec" { when = create - command = "aws amplify create-domain-association --app-id ${self.triggers.amplify_app_id} --domain-name ${self.triggers.amplify_domain_name} --sub-domain-settings prefix=\"\",branchName=\"${self.triggers.amplify_branch_name}\" prefix=\"${self.triggers.amplify_branch_name}\",branchName=\"${self.triggers.amplify_branch_name}\" --enable-auto-sub-domain --auto-sub-domain-creation-patterns \"*,*/*,pr*\"" + command = "aws amplify create-domain-association --app-id ${self.triggers.amplify_app_id} --domain-name ${self.triggers.amplify_domain_name} --sub-domain-settings prefix=\"\",branchName=\"${self.triggers.amplify_branch_name}\" prefix=\"${self.triggers.amplify_url_prefix}\",branchName=\"${self.triggers.amplify_branch_name}\" --enable-auto-sub-domain --auto-sub-domain-creation-patterns \"*,*/*,pr*\"" } provisioner "local-exec" { diff --git a/infrastructure/terraform/components/app/module_amplify_branch.tf b/infrastructure/terraform/components/app/module_amplify_branch.tf index e15d813..c0c5ecd 100644 --- a/infrastructure/terraform/components/app/module_amplify_branch.tf +++ b/infrastructure/terraform/components/app/module_amplify_branch.tf @@ -1,7 +1,7 @@ module "amplify_branch" { source = "git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/amp_branch?ref=v1.0.0" name = "main" - display_name = "main" + display_name = var.url_prefix aws_account_id = var.aws_account_id component = var.component environment = var.environment diff --git a/infrastructure/terraform/components/app/variables.tf b/infrastructure/terraform/components/app/variables.tf index 52cb0ad..9bcb93c 100644 --- a/infrastructure/terraform/components/app/variables.tf +++ b/infrastructure/terraform/components/app/variables.tf @@ -99,6 +99,12 @@ variable "branch_name" { default = "main" } +variable "url_prefix" { + type = string + description = "The url prefix to use for the deployed branch" + default = "main" +} + variable "commit_id" { type = string description = "The commit to deploy. Must be in the tree for branch_name"