From 00ebb63d4329c2b9503f37adb70095ebecd83316 Mon Sep 17 00:00:00 2001 From: aidenvaines-bjss Date: Mon, 5 Aug 2024 08:55:10 +0100 Subject: [PATCH] CCM-5680 Support dedicated dev envs --- .../terraform/components/branch/module_amplify_branch.tf | 2 +- infrastructure/terraform/components/iam/amplify_app.tf | 4 ++-- .../terraform/components/iam/amplify_domain_association.tf | 4 ++-- infrastructure/terraform/components/iam/locals.tf | 3 +++ .../terraform/components/iam/locals_remote_state.tf | 2 +- .../terraform/components/iam/module_amplify_branch.tf | 2 +- infrastructure/terraform/components/iam/variables.tf | 5 +++++ 7 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 infrastructure/terraform/components/iam/locals.tf diff --git a/infrastructure/terraform/components/branch/module_amplify_branch.tf b/infrastructure/terraform/components/branch/module_amplify_branch.tf index 0299c68..8a1b83d 100644 --- a/infrastructure/terraform/components/branch/module_amplify_branch.tf +++ b/infrastructure/terraform/components/branch/module_amplify_branch.tf @@ -13,6 +13,6 @@ module "amplify_branch" { cognito_user_pool_identity_provider_names = local.iam.cognito_user_pool["identity_providers"] amplify_app_id = local.iam.amplify["id"] branch = var.branch_name - domain_name = local.acct.dns_zone["name"] + domain_name = local.dns_prefix subdomain = var.environment } diff --git a/infrastructure/terraform/components/iam/amplify_app.tf b/infrastructure/terraform/components/iam/amplify_app.tf index f24b1ae..2ad654f 100644 --- a/infrastructure/terraform/components/iam/amplify_app.tf +++ b/infrastructure/terraform/components/iam/amplify_app.tf @@ -16,9 +16,9 @@ resource "aws_amplify_app" "main" { environment_variables = { USER_POOL_ID = aws_cognito_user_pool.main.id - # HOSTED_LOGIN_DOMAIN = "auth.${local.acct.dns_zone["name"]}" + # HOSTED_LOGIN_DOMAIN = "auth.${local.dns_prefix}" NOTIFY_GROUP = var.group NOTIFY_ENVIRONMENT = var.environment - NOTIFY_DOMAIN_NAME = local.acct.dns_zone["name"] + NOTIFY_DOMAIN_NAME = local.dns_prefix } } diff --git a/infrastructure/terraform/components/iam/amplify_domain_association.tf b/infrastructure/terraform/components/iam/amplify_domain_association.tf index 8d6980d..7ed01e8 100644 --- a/infrastructure/terraform/components/iam/amplify_domain_association.tf +++ b/infrastructure/terraform/components/iam/amplify_domain_association.tf @@ -1,6 +1,6 @@ # resource "aws_amplify_domain_association" "domain" { # app_id = aws_amplify_app.main.id -# domain_name = local.acct.dns_zone["name"] +# domain_name = local.dns_prefix # enable_auto_sub_domain = true # sub_domain { @@ -20,7 +20,7 @@ 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"] + amplify_domain_name = local.dns_prefix } provisioner "local-exec" { diff --git a/infrastructure/terraform/components/iam/locals.tf b/infrastructure/terraform/components/iam/locals.tf new file mode 100644 index 0000000..0b78a0a --- /dev/null +++ b/infrastructure/terraform/components/iam/locals.tf @@ -0,0 +1,3 @@ +locals { + dns_prefix = "${var.environment}.${local.acct.dns_zone["name"]}" +} diff --git a/infrastructure/terraform/components/iam/locals_remote_state.tf b/infrastructure/terraform/components/iam/locals_remote_state.tf index f5b3d9c..7f87c1f 100644 --- a/infrastructure/terraform/components/iam/locals_remote_state.tf +++ b/infrastructure/terraform/components/iam/locals_remote_state.tf @@ -32,7 +32,7 @@ data "terraform_remote_state" "acct" { var.project, var.aws_account_id, "eu-west-2", - var.environment + var.parent_acct_environment ) region = "eu-west-2" diff --git a/infrastructure/terraform/components/iam/module_amplify_branch.tf b/infrastructure/terraform/components/iam/module_amplify_branch.tf index e2b8202..02bdce5 100644 --- a/infrastructure/terraform/components/iam/module_amplify_branch.tf +++ b/infrastructure/terraform/components/iam/module_amplify_branch.tf @@ -13,7 +13,7 @@ module "amplify_branch" { 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" - domain_name = local.acct.dns_zone["name"] + domain_name = local.dns_prefix subdomain = var.environment enable_auto_deploy = true } diff --git a/infrastructure/terraform/components/iam/variables.tf b/infrastructure/terraform/components/iam/variables.tf index 44ad61d..b99f282 100644 --- a/infrastructure/terraform/components/iam/variables.tf +++ b/infrastructure/terraform/components/iam/variables.tf @@ -69,6 +69,11 @@ variable "root_domain_name" { default = "nonprod.nhsnotify.national.nhs.uk" } +variable "parent_acct_environment" { + type = string + description = "Name of the environment responsible for the acct resources used, affects things like DNS zone. Useful for named dev environments" + default = "main" +} variable "enable_amplify_branch_auto_build" { type = bool description = "Enable automatic building of branches"