File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed
modules/meshcloud-replicator-service-principal Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -196,10 +196,20 @@ resource "azurerm_role_assignment" "meshcloud_replicator_subscription_canceler"
196
196
}
197
197
198
198
resource "azurerm_role_assignment" "meshcloud_replicator_rg_deleter" {
199
- for_each = toset (var. can_delete_rgs_in_scopes )
200
- scope = each. key
201
- role_definition_id = azurerm_role_definition. meshcloud_replicator_rg_deleter . role_definition_resource_id
202
- principal_id = azuread_service_principal. meshcloud_replicator . id
199
+ for_each = toset (var. can_delete_rgs_in_scopes )
200
+ scope = each. key
201
+ principal_id = azuread_service_principal. meshcloud_replicator . id
202
+
203
+ # The azurerm provider requires this must be a scoped id, so unfortuantely we need to construct the id of the role
204
+ # definition at the assignment scope in order to make this stable for subsequent terraform apply's.
205
+ # See https://github.com/hashicorp/terraform-provider-azurerm/issues/4847#issuecomment-2085122502
206
+ # Apparently, this problem only comes up when the scope is a subscription, it seems management groups are not affected.
207
+ # RG deletion is typically only selectively enabled for specific subscriptions.
208
+ role_definition_id = join (" " , [
209
+ each . key ,
210
+ " /providers/Microsoft.Authorization/roleDefinitions/" ,
211
+ azurerm_role_definition . meshcloud_replicator_rg_deleter . role_definition_id
212
+ ])
203
213
}
204
214
205
215
// ---------------------------------------------------------------------------
You can’t perform that action at this time.
0 commit comments