Skip to content

Commit

Permalink
feat: Updated PE scope to create the PE next to the primary resource …
Browse files Browse the repository at this point in the history
…by default (#4449)

## Description

Background:
#3835 (comment)
Linked to: Azure/Azure-Verified-Modules#1857

Changes the deployment so that the main resource's (e.g., Key Vaults) RG
is used as the default location for the PE. The already implemented
`resourceGroupResourceId` will continue to allow the user to specify a
different RG (in a different subscription, if needed).

The primary change is from
```bicep
    scope: resourceGroup(
      split(privateEndpoint.?resourceGroupResourceId ?? privateEndpoint.?subnetResourceId, '/')[2],
      split(privateEndpoint.?resourceGroupResourceId ?? privateEndpoint.?subnetResourceId, '/')[4]
    )
```
to
```bicep
    scope: resourceGroup(
      split(privateEndpoint.?resourceGroupResourceId ?? resourceGroup().id, '/')[2],
      split(privateEndpoint.?resourceGroupResourceId ?? resourceGroup().id, '/')[4]
    )
```

I'll quote from @ahmadabdalla on this matter
> In most scenarios, PEs are deployed alongside their main resource in
their own RG vs. the VNET RG. Customer app teams may have subnet join
permissions on a centralised VNET in a Landing zone, but may not have
permissions to deploy into it. Also considering billing and resource
lifecycle perspective.

cc: @JamesDawson

Ref: #4449

## Pipeline Reference

<!-- Insert your Pipeline Status Badge below -->

| Pipeline |
| -------- |
|          |

## Type of Change

<!-- Use the checkboxes [x] on the options that are relevant. -->

- [ ] Update to CI Environment or utilities (Non-module affecting
changes)
- [ ] Azure Verified Module updates:
- [ ] Bugfix containing backwards-compatible bug fixes, and I have NOT
bumped the MAJOR or MINOR version in `version.json`:
- [ ] Someone has opened a bug report issue, and I have included "Closes
#{bug_report_issue_number}" in the PR description.
- [ ] The bug was found by the module author, and no one has opened an
issue to report it yet.
- [ ] Feature update backwards compatible feature updates, and I have
bumped the MINOR version in `version.json`.
- [x] Breaking changes and I have bumped the MAJOR version in
`version.json`.
  - [ ] Update to documentation
  • Loading branch information
AlexanderSehr authored Feb 18, 2025
1 parent 4d20c8b commit edcc22c
Show file tree
Hide file tree
Showing 54 changed files with 1,644 additions and 1,388 deletions.
16 changes: 8 additions & 8 deletions avm/res/cache/redis/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ module redis_privateEndpoints 'br/public:avm/res/network/private-endpoint:0.10.1
for (privateEndpoint, index) in (privateEndpoints ?? []): {
name: '${uniqueString(deployment().name, location)}-redis-PrivateEndpoint-${index}'
scope: resourceGroup(
split(privateEndpoint.?resourceGroupResourceId ?? privateEndpoint.?subnetResourceId, '/')[2],
split(privateEndpoint.?resourceGroupResourceId ?? privateEndpoint.?subnetResourceId, '/')[4]
split(privateEndpoint.?resourceGroupResourceId ?? resourceGroup().id, '/')[2],
split(privateEndpoint.?resourceGroupResourceId ?? resourceGroup().id, '/')[4]
)
params: {
name: privateEndpoint.?name ?? 'pep-${last(split(redis.id, '/'))}-${privateEndpoint.?service ?? 'redisCache'}-${index}'
Expand Down Expand Up @@ -455,12 +455,12 @@ output location string = redis.location

@description('The private endpoints of the Redis Cache.')
output privateEndpoints privateEndpointOutputType[] = [
for (pe, i) in (!empty(privateEndpoints) ? array(privateEndpoints) : []): {
name: redis_privateEndpoints[i].outputs.name
resourceId: redis_privateEndpoints[i].outputs.resourceId
groupId: redis_privateEndpoints[i].outputs.?groupId!
customDnsConfigs: redis_privateEndpoints[i].outputs.customDnsConfigs
networkInterfaceResourceIds: redis_privateEndpoints[i].outputs.networkInterfaceResourceIds
for (item, index) in (privateEndpoints ?? []): {
name: redis_privateEndpoints[index].outputs.name
resourceId: redis_privateEndpoints[index].outputs.resourceId
groupId: redis_privateEndpoints[index].outputs.?groupId!
customDnsConfigs: redis_privateEndpoints[index].outputs.customDnsConfigs
networkInterfaceResourceIds: redis_privateEndpoints[index].outputs.networkInterfaceResourceIds
}
]

Expand Down
18 changes: 9 additions & 9 deletions avm/res/cache/redis/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.33.93.31351",
"templateHash": "2636464673565813214"
"version": "0.33.13.18514",
"templateHash": "9499818712606838127"
},
"name": "Redis Cache",
"description": "This module deploys a Redis Cache."
Expand Down Expand Up @@ -1167,8 +1167,8 @@
"type": "Microsoft.Resources/deployments",
"apiVersion": "2022-09-01",
"name": "[format('{0}-redis-PrivateEndpoint-{1}', uniqueString(deployment().name, parameters('location')), copyIndex())]",
"subscriptionId": "[split(coalesce(tryGet(coalesce(parameters('privateEndpoints'), createArray())[copyIndex()], 'resourceGroupResourceId'), tryGet(coalesce(parameters('privateEndpoints'), createArray())[copyIndex()], 'subnetResourceId')), '/')[2]]",
"resourceGroup": "[split(coalesce(tryGet(coalesce(parameters('privateEndpoints'), createArray())[copyIndex()], 'resourceGroupResourceId'), tryGet(coalesce(parameters('privateEndpoints'), createArray())[copyIndex()], 'subnetResourceId')), '/')[4]]",
"subscriptionId": "[split(coalesce(tryGet(coalesce(parameters('privateEndpoints'), createArray())[copyIndex()], 'resourceGroupResourceId'), resourceGroup().id), '/')[2]]",
"resourceGroup": "[split(coalesce(tryGet(coalesce(parameters('privateEndpoints'), createArray())[copyIndex()], 'resourceGroupResourceId'), resourceGroup().id), '/')[4]]",
"properties": {
"expressionEvaluationOptions": {
"scope": "inner"
Expand Down Expand Up @@ -1947,8 +1947,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.33.93.31351",
"templateHash": "322534394383651316"
"version": "0.33.13.18514",
"templateHash": "11294861621866290910"
},
"name": "Redis Cache Linked Servers",
"description": "This module connects a primary and secondary Redis Cache together for geo-replication."
Expand Down Expand Up @@ -2073,8 +2073,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.33.93.31351",
"templateHash": "8063348652715653257"
"version": "0.33.13.18514",
"templateHash": "14045530027687796477"
}
},
"definitions": {
Expand Down Expand Up @@ -2261,7 +2261,7 @@
"description": "The private endpoints of the Redis Cache."
},
"copy": {
"count": "[length(if(not(empty(parameters('privateEndpoints'))), array(parameters('privateEndpoints')), createArray()))]",
"count": "[length(coalesce(parameters('privateEndpoints'), createArray()))]",
"input": {
"name": "[reference(format('redis_privateEndpoints[{0}]', copyIndex())).outputs.name.value]",
"resourceId": "[reference(format('redis_privateEndpoints[{0}]', copyIndex())).outputs.resourceId.value]",
Expand Down
4 changes: 2 additions & 2 deletions avm/res/cache/redis/version.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://aka.ms/bicep-registry-module-version-file-schema#",
"version": "0.12",
"version": "0.13",
"pathFilters": [
"./main.json"
]
}
}
16 changes: 8 additions & 8 deletions avm/res/container-registry/registry/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,8 @@ module registry_privateEndpoints 'br/public:avm/res/network/private-endpoint:0.1
for (privateEndpoint, index) in (privateEndpoints ?? []): {
name: '${uniqueString(deployment().name, location)}-registry-PrivateEndpoint-${index}'
scope: resourceGroup(
split(privateEndpoint.?resourceGroupResourceId ?? privateEndpoint.?subnetResourceId, '/')[2],
split(privateEndpoint.?resourceGroupResourceId ?? privateEndpoint.?subnetResourceId, '/')[4]
split(privateEndpoint.?resourceGroupResourceId ?? resourceGroup().id, '/')[2],
split(privateEndpoint.?resourceGroupResourceId ?? resourceGroup().id, '/')[4]
)
params: {
name: privateEndpoint.?name ?? 'pep-${last(split(registry.id, '/'))}-${privateEndpoint.?service ?? 'registry'}-${index}'
Expand Down Expand Up @@ -532,12 +532,12 @@ output credentialSetsResourceIds array = [

@description('The private endpoints of the Azure container registry.')
output privateEndpoints privateEndpointOutputType[] = [
for (pe, i) in (!empty(privateEndpoints) ? array(privateEndpoints) : []): {
name: registry_privateEndpoints[i].outputs.name
resourceId: registry_privateEndpoints[i].outputs.resourceId
groupId: registry_privateEndpoints[i].outputs.?groupId!
customDnsConfigs: registry_privateEndpoints[i].outputs.customDnsConfigs
networkInterfaceResourceIds: registry_privateEndpoints[i].outputs.networkInterfaceResourceIds
for (item, index) in (privateEndpoints ?? []): {
name: registry_privateEndpoints[index].outputs.name
resourceId: registry_privateEndpoints[index].outputs.resourceId
groupId: registry_privateEndpoints[index].outputs.?groupId!
customDnsConfigs: registry_privateEndpoints[index].outputs.customDnsConfigs
networkInterfaceResourceIds: registry_privateEndpoints[index].outputs.networkInterfaceResourceIds
}
]

Expand Down
8 changes: 4 additions & 4 deletions avm/res/container-registry/registry/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"_generator": {
"name": "bicep",
"version": "0.33.13.18514",
"templateHash": "1879570214296822193"
"templateHash": "9895920276913879197"
},
"name": "Azure Container Registries (ACR)",
"description": "This module deploys an Azure Container Registry (ACR)."
Expand Down Expand Up @@ -2175,8 +2175,8 @@
"type": "Microsoft.Resources/deployments",
"apiVersion": "2022-09-01",
"name": "[format('{0}-registry-PrivateEndpoint-{1}', uniqueString(deployment().name, parameters('location')), copyIndex())]",
"subscriptionId": "[split(coalesce(tryGet(coalesce(parameters('privateEndpoints'), createArray())[copyIndex()], 'resourceGroupResourceId'), tryGet(coalesce(parameters('privateEndpoints'), createArray())[copyIndex()], 'subnetResourceId')), '/')[2]]",
"resourceGroup": "[split(coalesce(tryGet(coalesce(parameters('privateEndpoints'), createArray())[copyIndex()], 'resourceGroupResourceId'), tryGet(coalesce(parameters('privateEndpoints'), createArray())[copyIndex()], 'subnetResourceId')), '/')[4]]",
"subscriptionId": "[split(coalesce(tryGet(coalesce(parameters('privateEndpoints'), createArray())[copyIndex()], 'resourceGroupResourceId'), resourceGroup().id), '/')[2]]",
"resourceGroup": "[split(coalesce(tryGet(coalesce(parameters('privateEndpoints'), createArray())[copyIndex()], 'resourceGroupResourceId'), resourceGroup().id), '/')[4]]",
"properties": {
"expressionEvaluationOptions": {
"scope": "inner"
Expand Down Expand Up @@ -2999,7 +2999,7 @@
"description": "The private endpoints of the Azure container registry."
},
"copy": {
"count": "[length(if(not(empty(parameters('privateEndpoints'))), array(parameters('privateEndpoints')), createArray()))]",
"count": "[length(coalesce(parameters('privateEndpoints'), createArray()))]",
"input": {
"name": "[reference(format('registry_privateEndpoints[{0}]', copyIndex())).outputs.name.value]",
"resourceId": "[reference(format('registry_privateEndpoints[{0}]', copyIndex())).outputs.resourceId.value]",
Expand Down
4 changes: 2 additions & 2 deletions avm/res/container-registry/registry/version.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://aka.ms/bicep-registry-module-version-file-schema#",
"version": "0.8",
"version": "0.9",
"pathFilters": [
"./main.json"
]
}
}
34 changes: 16 additions & 18 deletions avm/res/databricks/workspace/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,8 @@ module workspace_privateEndpoints 'br/public:avm/res/network/private-endpoint:0.
for (privateEndpoint, index) in (privateEndpoints ?? []): {
name: '${uniqueString(deployment().name, location)}-workspace-PrivateEndpoint-${index}'
scope: resourceGroup(
split(privateEndpoint.?resourceGroupResourceId ?? privateEndpoint.?subnetResourceId, '/')[2],
split(privateEndpoint.?resourceGroupResourceId ?? privateEndpoint.?subnetResourceId, '/')[4]
split(privateEndpoint.?resourceGroupResourceId ?? resourceGroup().id, '/')[2],
split(privateEndpoint.?resourceGroupResourceId ?? resourceGroup().id, '/')[4]
)
params: {
name: privateEndpoint.?name ?? 'pep-${last(split(workspace.id, '/'))}-${privateEndpoint.service}-${index}'
Expand Down Expand Up @@ -509,8 +509,8 @@ module storageAccount_storageAccountPrivateEndpoints 'br/public:avm/res/network/
for (privateEndpoint, index) in (storageAccountPrivateEndpoints ?? []): if (privateStorageAccount == 'Enabled') {
name: '${uniqueString(deployment().name, location)}-workspacestorage-PrivateEndpoint-${index}'
scope: resourceGroup(
split(privateEndpoint.?resourceGroupResourceId ?? privateEndpoint.?subnetResourceId, '/')[2],
split(privateEndpoint.?resourceGroupResourceId ?? privateEndpoint.?subnetResourceId, '/')[4]
split(privateEndpoint.?resourceGroupResourceId ?? resourceGroup().id, '/')[2],
split(privateEndpoint.?resourceGroupResourceId ?? resourceGroup().id, '/')[4]
)
params: {
name: privateEndpoint.?name ?? 'pep-${_storageAccountName}-${privateEndpoint.service}-${index}'
Expand Down Expand Up @@ -592,25 +592,23 @@ output workspaceResourceId string = workspace.properties.workspaceId

@description('The private endpoints of the Databricks Workspace.')
output privateEndpoints privateEndpointOutputType[] = [
for (pe, i) in (!empty(privateEndpoints) ? array(privateEndpoints) : []): {
name: workspace_privateEndpoints[i].outputs.name
resourceId: workspace_privateEndpoints[i].outputs.resourceId
groupId: workspace_privateEndpoints[i].outputs.?groupId!
customDnsConfigs: workspace_privateEndpoints[i].outputs.customDnsConfigs
networkInterfaceResourceIds: workspace_privateEndpoints[i].outputs.networkInterfaceResourceIds
for (item, index) in (privateEndpoints ?? []): {
name: workspace_privateEndpoints[index].outputs.name
resourceId: workspace_privateEndpoints[index].outputs.resourceId
groupId: workspace_privateEndpoints[index].outputs.?groupId!
customDnsConfigs: workspace_privateEndpoints[index].outputs.customDnsConfigs
networkInterfaceResourceIds: workspace_privateEndpoints[index].outputs.networkInterfaceResourceIds
}
]

@description('The private endpoints of the Databricks Workspace Storage.')
output storagePrivateEndpoints privateEndpointOutputType[] = [
for (pe, i) in ((!empty(storageAccountPrivateEndpoints) && privateStorageAccount == 'Enabled')
? array(storageAccountPrivateEndpoints)
: []): {
name: storageAccount_storageAccountPrivateEndpoints[i].outputs.name
resourceId: storageAccount_storageAccountPrivateEndpoints[i].outputs.resourceId
groupId: storageAccount_storageAccountPrivateEndpoints[i].outputs.?groupId!
customDnsConfigs: storageAccount_storageAccountPrivateEndpoints[i].outputs.customDnsConfigs
networkInterfaceResourceIds: storageAccount_storageAccountPrivateEndpoints[i].outputs.networkInterfaceResourceIds
for (item, index) in (privateStorageAccount == 'Enabled' ? storageAccountPrivateEndpoints ?? [] : []): {
name: storageAccount_storageAccountPrivateEndpoints[index].outputs.name
resourceId: storageAccount_storageAccountPrivateEndpoints[index].outputs.resourceId
groupId: storageAccount_storageAccountPrivateEndpoints[index].outputs.?groupId!
customDnsConfigs: storageAccount_storageAccountPrivateEndpoints[index].outputs.customDnsConfigs
networkInterfaceResourceIds: storageAccount_storageAccountPrivateEndpoints[index].outputs.networkInterfaceResourceIds
}
]

Expand Down
Loading

0 comments on commit edcc22c

Please sign in to comment.