Skip to content

Commit 4aad077

Browse files
feat(DTOSS-13037): automate app role assignment for Arc machine managed identities
Adds azuread_app_role_assignment per discovered Arc machine so each gateway's system-assigned MI is granted the Gateway.Access app role on spn-manbrs-web-api-<env> automatically on terraform apply.
1 parent 764d9cf commit 4aad077

4 files changed

Lines changed: 30 additions & 2 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Look up the web API enterprise app that the gateway MIs need to access.
2+
data "azuread_service_principal" "enterprise_app" {
3+
count = var.enable_arc_servers ? 1 : 0
4+
display_name = "spn-manbrs-web-api-${var.env_config}"
5+
}
6+
7+
# Assign the configured app role to each discovered Arc machine's managed identity.
8+
# Static machines are excluded — their MIs are not visible until the next apply after onboarding.
9+
resource "azuread_app_role_assignment" "managed_identity" {
10+
for_each = local.arc_machines_discovered
11+
12+
app_role_id = data.azuread_service_principal.enterprise_app[0].app_role_ids[var.enterprise_app_role_value]
13+
principal_object_id = data.azurerm_arc_machine.machines[each.key].identity[0].principal_id
14+
resource_object_id = data.azuread_service_principal.enterprise_app[0].object_id
15+
}

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 "enterprise_app_role_value" {
33+
description = "App role name to assign to each Arc machine's managed identity on the web API enterprise app (spn-manbrs-web-api-<env>). Leave empty to skip assignment."
34+
type = string
35+
default = ""
36+
}

infrastructure/terraform/main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ module "arc_infra" {
99
region = local.region
1010
app_short_name = var.app_short_name
1111
env_config = var.env_config
12-
resource_group_name = local.resource_group_name
13-
enable_arc_servers = var.enable_arc_servers
12+
resource_group_name = local.resource_group_name
13+
enable_arc_servers = var.enable_arc_servers
14+
enterprise_app_role_value = var.enterprise_app_role_value
1415

1516
# Create the HC for the test VM in the same run as VM creation.
1617
# The Arc data source won't see a machine registered in the same apply.

infrastructure/terraform/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ variable "gateway_test_vm_size" {
5050
default = "Standard_B2s"
5151
}
5252

53+
variable "enterprise_app_role_value" {
54+
description = "App role name to assign to each Arc machine's managed identity on the web API enterprise app (spn-manbrs-web-api-<env>). Leave empty to skip assignment."
55+
type = string
56+
default = "Gateway.Access"
57+
}
58+
5359
locals {
5460
region = "uksouth"
5561
resource_group_name = "rg-${var.app_short_name}-${var.environment}-uks"

0 commit comments

Comments
 (0)