From 95c9ecd5bdbfad6bc7362e7fd816f0b652a99f74 Mon Sep 17 00:00:00 2001 From: aidenvaines-bjss Date: Fri, 2 Aug 2024 11:43:51 +0100 Subject: [PATCH] CCM-5680 fix custom domain name and env vars --- .../branch/module_amplify_branch.tf | 2 +- .../iam/amplify_domain_association.tf | 41 +++++++++++++++---- .../components/iam/module_amplify_branch.tf | 2 +- .../terraform/components/iam/outputs.tf | 6 +++ 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/infrastructure/terraform/components/branch/module_amplify_branch.tf b/infrastructure/terraform/components/branch/module_amplify_branch.tf index 70aeea8..0299c68 100644 --- a/infrastructure/terraform/components/branch/module_amplify_branch.tf +++ b/infrastructure/terraform/components/branch/module_amplify_branch.tf @@ -9,7 +9,7 @@ module "amplify_branch" { region = var.region group = var.group - cognito_user_pool_client_id = local.iam.cognito_user_pool["id"] + cognito_user_pool_client_id = local.iam.cognito_user_pool_client["id"] cognito_user_pool_identity_provider_names = local.iam.cognito_user_pool["identity_providers"] amplify_app_id = local.iam.amplify["id"] branch = var.branch_name diff --git a/infrastructure/terraform/components/iam/amplify_domain_association.tf b/infrastructure/terraform/components/iam/amplify_domain_association.tf index cc40b92..8d6980d 100644 --- a/infrastructure/terraform/components/iam/amplify_domain_association.tf +++ b/infrastructure/terraform/components/iam/amplify_domain_association.tf @@ -1,10 +1,35 @@ -resource "aws_amplify_domain_association" "domain" { - app_id = aws_amplify_app.main.id - domain_name = local.acct.dns_zone["name"] - enable_auto_sub_domain = false - - sub_domain { - branch_name = module.amplify_branch.name - prefix = "" +# resource "aws_amplify_domain_association" "domain" { +# app_id = aws_amplify_app.main.id +# domain_name = local.acct.dns_zone["name"] +# enable_auto_sub_domain = true + +# sub_domain { +# branch_name = module.amplify_branch.name +# prefix = "" +# } + +# sub_domain { +# branch_name = module.amplify_branch.name +# prefix = "main" +# } +# } + +# TODO CCM-6078 Revert to above amplify_domain_association resource on closure of https://github.com/hashicorp/terraform-provider-aws/issues/37498 +# Provider does not correctly set autoSubDomainCreationPatterns when enable_auto_sub_domain is set +resource "null_resource" "amplify_domain_association" { + triggers = { + amplify_app_id = aws_amplify_app.main.id + amplify_branch_name = module.amplify_branch.name + amplify_domain_name = local.acct.dns_zone["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*\"" + } + + provisioner "local-exec" { + when = destroy + command = "aws amplify delete-domain-association --app-id ${self.triggers.amplify_app_id} --domain-name ${self.triggers.amplify_domain_name}" } } diff --git a/infrastructure/terraform/components/iam/module_amplify_branch.tf b/infrastructure/terraform/components/iam/module_amplify_branch.tf index d71b4d6..e2b8202 100644 --- a/infrastructure/terraform/components/iam/module_amplify_branch.tf +++ b/infrastructure/terraform/components/iam/module_amplify_branch.tf @@ -9,7 +9,7 @@ module "amplify_branch" { region = var.region group = var.group - cognito_user_pool_client_id = aws_cognito_user_pool_client.main.user_pool_id + cognito_user_pool_client_id = aws_cognito_user_pool_client.main.id cognito_user_pool_identity_provider_names = aws_cognito_user_pool_client.main.supported_identity_providers amplify_app_id = aws_amplify_app.main.id branch = "main" diff --git a/infrastructure/terraform/components/iam/outputs.tf b/infrastructure/terraform/components/iam/outputs.tf index f0bb257..e64a4c9 100644 --- a/infrastructure/terraform/components/iam/outputs.tf +++ b/infrastructure/terraform/components/iam/outputs.tf @@ -5,6 +5,12 @@ output "cognito_user_pool" { } } +output "cognito_user_pool_client" { + value = { + id = aws_cognito_user_pool_client.main.id + } +} + output "amplify" { value = { id = aws_amplify_app.main.id