Skip to content

Commit

Permalink
improved sp redirect uris configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
cmendible authored Apr 10, 2024
1 parent 6d2aba5 commit 8ddc512
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 50 deletions.
2 changes: 2 additions & 0 deletions infra/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ module "ca_chat" {
resource_group_id = azurerm_resource_group.rg.id
ca_name = local.ca_chat_name
cae_id = module.cae.cae_id
cae_default_domain = module.cae.default_domain
managed_identity_id = module.mi.mi_id
chat_gpt_deployment = module.openai.gpt_deployment_name
chat_gpt_model = module.openai.gpt_deployment_model_name
Expand Down Expand Up @@ -196,6 +197,7 @@ module "ca_aihub" {
resource_group_id = azurerm_resource_group.rg.id
ca_name = local.ca_aihub_name
cae_id = module.cae.cae_id
cae_default_domain = module.cae.default_domain
managed_identity_id = module.mi.mi_id
chat_gpt_deployment = module.openai.gpt_deployment_name
chat_gpt_model = module.openai.gpt_deployment_model_name
Expand Down
27 changes: 3 additions & 24 deletions infra/modules/ca-aihub/auth_config.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
locals {
redirect_fqdn = jsondecode(azapi_resource.ca_back.output).properties.configuration.ingress.fqdn
}

module "sp" {
count = var.enable_entra_id_authentication ? 1 : 0
source = "../sp"
sp_name = var.ca_name
redirect_uris = [
"https://${var.ca_name}.${var.cae_default_domain}/.auth/login/aad/callback"
]
}

resource "azapi_resource" "current" {
Expand Down Expand Up @@ -45,23 +44,3 @@ resource "azapi_resource" "current" {
}
})
}

locals {
fqdn = jsondecode(azapi_resource.ca_back.output).properties.configuration.ingress.fqdn
update_redirect_uris_command = var.enable_entra_id_authentication ? "az ad app update --id ${module.sp[0].client_id} --web-redirect-uris https://${local.fqdn}/.auth/login/aad/callback" : ""
}

resource "null_resource" "update_redirect_uris" {
count = var.enable_entra_id_authentication ? 1 : 0
provisioner "local-exec" {
command = local.update_redirect_uris_command
}
depends_on = [
module.sp,
azapi_resource.ca_back,
azapi_resource.current
]
triggers = {
always_run = timestamp()
}
}
1 change: 1 addition & 0 deletions infra/modules/ca-aihub/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ variable "resource_group_id" {}
variable "location" {}
variable "ca_name" {}
variable "cae_id" {}
variable "cae_default_domain" {}
variable "managed_identity_id" {}
variable "managed_identity_client_id" {}
variable "tenant_id" {}
Expand Down
27 changes: 3 additions & 24 deletions infra/modules/ca-chat/auth_config.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
locals {
redirect_fqdn = jsondecode(azapi_resource.ca_back.output).properties.configuration.ingress.fqdn
}

module "sp" {
count = var.enable_entra_id_authentication ? 1 : 0
source = "../sp"
sp_name = var.ca_name
redirect_uris = [
"https://${var.ca_name}.${var.cae_default_domain}/.auth/login/aad/callback"
]
}

resource "azapi_resource" "current" {
Expand Down Expand Up @@ -45,23 +44,3 @@ resource "azapi_resource" "current" {
}
})
}

locals {
fqdn = jsondecode(azapi_resource.ca_back.output).properties.configuration.ingress.fqdn
update_redirect_uris_command = var.enable_entra_id_authentication ? "az ad app update --id ${module.sp[0].client_id} --web-redirect-uris https://${local.fqdn}/.auth/login/aad/callback" : ""
}

resource "null_resource" "update_redirect_uris" {
count = var.enable_entra_id_authentication ? 1 : 0
provisioner "local-exec" {
command = local.update_redirect_uris_command
}
depends_on = [
module.sp,
azapi_resource.ca_back,
azapi_resource.current
]
triggers = {
always_run = timestamp()
}
}
1 change: 1 addition & 0 deletions infra/modules/ca-chat/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ variable "resource_group_id" {}
variable "location" {}
variable "ca_name" {}
variable "cae_id" {}
variable "cae_default_domain" {}
variable "managed_identity_id" {}
variable "managed_identity_client_id" {}
variable "tenant_id" {}
Expand Down
2 changes: 1 addition & 1 deletion infra/modules/sp/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ resource "azuread_application" "sp" {
implicit_grant {
id_token_issuance_enabled = true
}
redirect_uris = []
redirect_uris = var.redirect_uris
}

api {
Expand Down
6 changes: 5 additions & 1 deletion infra/modules/sp/variables.tf
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
variable "sp_name" {}
variable "sp_name" {}
variable "redirect_uris" {
type = list(string)
default = []
}

0 comments on commit 8ddc512

Please sign in to comment.