Skip to content

Commit 94f6676

Browse files
malhussanJohannesRudolph
authored andcommitted
feat: cancel subscription permissions for replicator
1 parent f7baeb8 commit 94f6676

File tree

5 files changed

+43
-3
lines changed

5 files changed

+43
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Option to provide replicator service principal permission to cancel subscriptions on specified scopes (i.e. landing zones)
13+
1014
## [v0.5.0]
1115

1216
### Changed

main.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ module "replicator_service_principal" {
5151

5252
replicator_rg_enabled = var.replicator_rg_enabled
5353

54-
service_principal_name = var.replicator_service_principal_name
55-
custom_role_scope = data.azurerm_management_group.replicator_custom_role_scope.id
56-
assignment_scopes = local.replicator_assignment_scopes
54+
service_principal_name = var.replicator_service_principal_name
55+
custom_role_scope = data.azurerm_management_group.replicator_custom_role_scope.id
56+
assignment_scopes = local.replicator_assignment_scopes
57+
can_cancel_subscriptions_in_scopes = var.can_cancel_subscriptions_in_scopes
5758

5859
additional_required_resource_accesses = var.additional_required_resource_accesses
5960
additional_permissions = var.additional_permissions

modules/meshcloud-replicator-service-principal/module.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@ resource "azurerm_role_definition" "meshcloud_replicator" {
6767
]
6868
}
6969

70+
resource "azurerm_role_definition" "meshcloud_replicator_subscription_canceler" {
71+
count = length(var.can_cancel_subscriptions_in_scopes) > 0 ? 1 : 0
72+
name = var.service_principal_name
73+
scope = var.custom_role_scope
74+
description = "Permissions required by meshcloud in order to cancel subscriptions"
75+
76+
permissions {
77+
actions = ["Microsoft.Subscription/cancel/action"]
78+
}
79+
80+
assignable_scopes = [
81+
var.custom_role_scope
82+
]
83+
}
84+
7085
//---------------------------------------------------------------------------
7186
// Queries Entra ID for information about well-known application IDs.
7287
// Retrieve details about the service principal
@@ -161,6 +176,14 @@ resource "azurerm_role_assignment" "meshcloud_replicator" {
161176
depends_on = [azuread_service_principal.meshcloud_replicator]
162177
}
163178

179+
resource "azurerm_role_assignment" "meshcloud_replicator_subscription_canceler" {
180+
for_each = toset(var.can_cancel_subscriptions_in_scopes)
181+
scope = each.key
182+
role_definition_id = azurerm_role_definition.meshcloud_replicator_subscription_canceler[0].role_definition_resource_id
183+
principal_id = azuread_service_principal.meshcloud_replicator.id
184+
depends_on = [azuread_service_principal.meshcloud_replicator]
185+
}
186+
164187
//---------------------------------------------------------------------------
165188
// Assign Entra ID Roles to the Enterprise application
166189
//---------------------------------------------------------------------------

modules/meshcloud-replicator-service-principal/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ variable "assignment_scopes" {
1313
description = "The scopes to which Service Principal permissions is assigned to. List of management group id of form `/providers/Microsoft.Management/managementGroups/<mgmtGroupId>/`."
1414
}
1515

16+
variable "can_cancel_subscriptions_in_scopes" {
17+
type = list(string)
18+
description = "The scopes to which Service Principal cancel subscription permission is assigned to. List of management group id of form `/providers/Microsoft.Management/managementGroups/<mgmtGroupId>/`."
19+
default = []
20+
}
21+
1622
variable "additional_required_resource_accesses" {
1723
type = list(object({ resource_app_id = string, resource_accesses = list(object({ id = string, type = string })) }))
1824
default = []

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ variable "replicator_assignment_scopes" {
1414
description = "Names or UUIDs of the Management Groups which replicator should manage."
1515
}
1616

17+
variable "can_cancel_subscriptions_in_scopes" {
18+
type = list(string)
19+
description = "The scopes to which Service Principal cancel subscription permission is assigned to. List of management group id of form `/providers/Microsoft.Management/managementGroups/<mgmtGroupId>/`."
20+
default = []
21+
}
22+
1723
variable "metering_service_principal_name" {
1824
type = string
1925
default = "kraken"

0 commit comments

Comments
 (0)