Skip to content

Commit ffd3f8f

Browse files
feat(DTOSS-13037): automate app role assignment for Arc machine managed identities
Adds azuread_app_role_assignment per Arc-enabled machine so each gateway's system-assigned MI is granted the manbrs web API app role automatically on terraform apply, removing the need for manual Entra ID assignment.
1 parent 6410f99 commit ffd3f8f

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Look up the manbrs web API service principal in the same environment.
2+
# App role assignments are created against this SP's object_id.
3+
data "azuread_service_principal" "manbrs_web_api" {
4+
count = var.enable_arc_servers ? 1 : 0
5+
display_name = "spn-manbrs-web-api-${var.env_config}"
6+
}
7+
8+
locals {
9+
# Resolve the app role UUID by matching against the SP's declared roles.
10+
# Falls back to the Entra ID default-access role UUID if the value is not found.
11+
manbrs_api_role_id = var.enable_arc_servers ? try(
12+
[for r in data.azuread_service_principal.manbrs_web_api[0].app_roles : r.id if r.value == var.manbrs_api_app_role_value][0],
13+
"00000000-0000-0000-0000-000000000000"
14+
) : "00000000-0000-0000-0000-000000000000"
15+
}
16+
17+
# Grant each Arc machine's managed identity the manbrs web API app role so the
18+
# gateway services can authenticate to the cloud API using their system-assigned MI.
19+
resource "azuread_app_role_assignment" "manbrs_api" {
20+
for_each = local.arc_machines_discovered
21+
22+
app_role_id = local.manbrs_api_role_id
23+
principal_object_id = data.azurerm_arc_machine.machines[each.key].identity[0].principal_id
24+
resource_object_id = data.azuread_service_principal.manbrs_web_api[0].object_id
25+
}

infrastructure/modules/arc-infra/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,9 @@ variable "static_arc_machine_names" {
2828
type = list(string)
2929
default = []
3030
}
31+
32+
variable "manbrs_api_app_role_value" {
33+
description = "Value of the app role on spn-manbrs-web-api-<env> to assign to each Arc machine managed identity. Must match a role declared on that application registration."
34+
type = string
35+
default = "Gateway.Access"
36+
}

0 commit comments

Comments
 (0)