From f20046168f10a21e838c61a43500bc393cb09d9e Mon Sep 17 00:00:00 2001 From: Mike Houston Date: Wed, 13 Nov 2024 15:22:54 +0000 Subject: [PATCH] CCM-7357: Associate domain with branch name rather than module name --- .../components/app/amplify_domain_association.tf | 11 ++++++----- .../terraform/components/app/module_amplify_branch.tf | 2 +- infrastructure/terraform/components/app/variables.tf | 6 ++++++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/infrastructure/terraform/components/app/amplify_domain_association.tf b/infrastructure/terraform/components/app/amplify_domain_association.tf index 1b288e5..dca6eb9 100644 --- a/infrastructure/terraform/components/app/amplify_domain_association.tf +++ b/infrastructure/terraform/components/app/amplify_domain_association.tf @@ -4,13 +4,13 @@ # enable_auto_sub_domain = true # sub_domain { -# branch_name = module.amplify_branch.name +# branch_name = var.branch_name # prefix = "" # } # sub_domain { -# branch_name = module.amplify_branch.name -# prefix = "main" +# branch_name = var.branch_name +# prefix = var.url_prefix # } # } @@ -19,13 +19,14 @@ resource "null_resource" "amplify_domain_association" { triggers = { amplify_app_id = aws_amplify_app.main.id - amplify_branch_name = module.amplify_branch.name + amplify_branch_name = var.branch_name + amplify_url_prefix = var.url_prefix 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"