Skip to content

Commit 8dd25d6

Browse files
committed
[IaC] Create app registration for BFF app using terraform
#2
1 parent be179ca commit 8dd25d6

3 files changed

Lines changed: 46 additions & 1 deletion

File tree

iac/icon-192.png

1.75 KB
Loading

iac/main-appsrv.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ resource "azurerm_linux_web_app" "appsrv" {
2626
}
2727
app_settings = merge(
2828
{
29-
"WEBSITE_RUN_FROM_PACKAGE" = "1"
29+
"WEBSITE_RUN_FROM_PACKAGE" = "1"
30+
"MicrosoftEntraID__Domain" = data.azuread_domains.aad_domains.domains[0].domain_name
31+
"MicrosoftEntraID__TenantId" = var.tenant_id
32+
"MicrosoftEntraID__ClientId" = azuread_application.aadapp.client_id
33+
"MicrosoftEntraID__ClientSecret" = azuread_application_password.aadapppwd.value
3034
}
3135
)
3236
lifecycle {

iac/main-entraid.tf

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
locals {
2+
dev_redirect_uris = ["https://localhost:5001/signin-oidc", "https://${replace(local.name_template, "<service>", "appsrv")}.azurewebsites.net/signin-oidc"]
3+
nondev_redirect_uris = var.custom_domain_name != "" ? ["https://${var.custom_domain_name}/signin-oidc", "https://${replace(local.name_template, "<service>", "appsrv")}.azurewebsites.net/signin-oidc"] : ["https://${replace(local.name_template, "<service>", "appsrv")}.azurewebsites.net/signin-oidc"]
4+
}
5+
6+
resource "azuread_application" "aadapp" {
7+
display_name = format("%s Application %s", var.resource_prefix, var.stage)
8+
identifier_uris = []
9+
sign_in_audience = "AzureADMyOrg"
10+
logo_image = filebase64("icon-192.png")
11+
web {
12+
redirect_uris = var.stage == "dev" ? local.dev_redirect_uris : local.nondev_redirect_uris
13+
logout_url = var.custom_domain_name != "" ? "https://${var.custom_domain_name}/signout-callback-oidc" : "https://${replace(local.name_template, "<service>", "appsrv")}.azurewebsites.net/signout-callback-oidc"
14+
}
15+
api {
16+
requested_access_token_version = 2
17+
}
18+
required_resource_access {
19+
resource_app_id = "00000003-0000-0000-c000-000000000000"
20+
resource_access {
21+
id = "e1fe6dd8-ba31-4d61-89e7-88639da4683d" // User.Read
22+
type = "Scope"
23+
}
24+
}
25+
}
26+
27+
resource "time_rotating" "example" {
28+
rotation_days = 7
29+
}
30+
31+
resource "azuread_application_password" "aadapppwd" {
32+
display_name = "apppwd"
33+
application_id = azuread_application.aadapp.id
34+
rotate_when_changed = {
35+
rotation = time_rotating.example.id
36+
}
37+
}
38+
39+
resource "azuread_service_principal" "aadapp-sp" {
40+
client_id = azuread_application.aadapp.client_id
41+
}

0 commit comments

Comments
 (0)