Skip to content

Commit 9bd1b46

Browse files
authored
[Modules] Updated Cosmos DB Module tests to support dynamic primary and secondary region locations (#3946)
1 parent fe148cd commit 9bd1b46

9 files changed

Lines changed: 172 additions & 24 deletions

File tree

modules/document-db/database-account/.test/gremlindb/dependencies.bicep

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,46 @@ param location string = resourceGroup().location
44
@description('Required. The name of the Managed Identity to create.')
55
param managedIdentityName string
66

7+
@description('Required. The name of the Deployment Script to create to get the paired region name.')
8+
param pairedRegionScriptName string
9+
710
resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
811
name: managedIdentityName
912
location: location
1013
}
1114

15+
resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
16+
name: guid('msi-${location}-${managedIdentity.id}-Reader-RoleAssignment')
17+
properties: {
18+
principalId: managedIdentity.properties.principalId
19+
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'acdd72a7-3385-48ef-bd42-f606fba81ae7') // Reader
20+
principalType: 'ServicePrincipal'
21+
}
22+
}
23+
24+
resource getPairedRegionScript 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
25+
name: pairedRegionScriptName
26+
location: location
27+
kind: 'AzurePowerShell'
28+
identity: {
29+
type: 'UserAssigned'
30+
userAssignedIdentities: {
31+
'${managedIdentity.id}': {}
32+
}
33+
}
34+
properties: {
35+
azPowerShellVersion: '8.0'
36+
retentionInterval: 'P1D'
37+
arguments: '-Location \\"${location}\\"'
38+
scriptContent: loadTextContent('../../../../.shared/.scripts/Get-PairedRegion.ps1')
39+
}
40+
dependsOn: [
41+
roleAssignment
42+
]
43+
}
44+
45+
@description('The name of the paired region.')
46+
output pairedRegionName string = getPairedRegionScript.properties.outputs.pairedRegionName
47+
1248
@description('The principal ID of the created Managed Identity.')
1349
output managedIdentityPrincipalId string = managedIdentity.properties.principalId

modules/document-db/database-account/.test/gremlindb/main.test.bicep

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ module nestedDependencies 'dependencies.bicep' = {
3636
name: '${uniqueString(deployment().name, location)}-nestedDependencies'
3737
params: {
3838
managedIdentityName: 'dep-${namePrefix}-msi-${serviceShort}'
39+
pairedRegionScriptName: 'dep-${namePrefix}-ds-${serviceShort}'
3940
}
4041
}
4142

@@ -67,12 +68,12 @@ module testDeployment '../../main.bicep' = {
6768
{
6869
failoverPriority: 0
6970
isZoneRedundant: false
70-
locationName: 'West Europe'
71+
locationName: location
7172
}
7273
{
7374
failoverPriority: 1
7475
isZoneRedundant: false
75-
locationName: 'North Europe'
76+
locationName: nestedDependencies.outputs.pairedRegionName
7677
}
7778
]
7879
capabilitiesToAdd: [

modules/document-db/database-account/.test/mongodb/dependencies.bicep

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,46 @@ param location string = resourceGroup().location
44
@description('Required. The name of the Managed Identity to create.')
55
param managedIdentityName string
66

7+
@description('Required. The name of the Deployment Script to create to get the paired region name.')
8+
param pairedRegionScriptName string
9+
710
resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
811
name: managedIdentityName
912
location: location
1013
}
1114

15+
resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
16+
name: guid('msi-${location}-${managedIdentity.id}-Reader-RoleAssignment')
17+
properties: {
18+
principalId: managedIdentity.properties.principalId
19+
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'acdd72a7-3385-48ef-bd42-f606fba81ae7') // Reader
20+
principalType: 'ServicePrincipal'
21+
}
22+
}
23+
24+
resource getPairedRegionScript 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
25+
name: pairedRegionScriptName
26+
location: location
27+
kind: 'AzurePowerShell'
28+
identity: {
29+
type: 'UserAssigned'
30+
userAssignedIdentities: {
31+
'${managedIdentity.id}': {}
32+
}
33+
}
34+
properties: {
35+
azPowerShellVersion: '8.0'
36+
retentionInterval: 'P1D'
37+
arguments: '-Location \\"${location}\\"'
38+
scriptContent: loadTextContent('../../../../.shared/.scripts/Get-PairedRegion.ps1')
39+
}
40+
dependsOn: [
41+
roleAssignment
42+
]
43+
}
44+
45+
@description('The name of the paired region.')
46+
output pairedRegionName string = getPairedRegionScript.properties.outputs.pairedRegionName
47+
1248
@description('The principal ID of the created Managed Identity.')
1349
output managedIdentityPrincipalId string = managedIdentity.properties.principalId

modules/document-db/database-account/.test/mongodb/main.test.bicep

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ module nestedDependencies 'dependencies.bicep' = {
3636
name: '${uniqueString(deployment().name, location)}-nestedDependencies'
3737
params: {
3838
managedIdentityName: 'dep-${namePrefix}-msi-${serviceShort}'
39+
pairedRegionScriptName: 'dep-${namePrefix}-ds-${serviceShort}'
3940
}
4041
}
4142

@@ -67,12 +68,12 @@ module testDeployment '../../main.bicep' = {
6768
{
6869
failoverPriority: 0
6970
isZoneRedundant: false
70-
locationName: 'West Europe'
71+
locationName: location
7172
}
7273
{
7374
failoverPriority: 1
7475
isZoneRedundant: false
75-
locationName: 'North Europe'
76+
locationName: nestedDependencies.outputs.pairedRegionName
7677
}
7778
]
7879
diagnosticStorageAccountId: diagnosticDependencies.outputs.storageAccountResourceId

modules/document-db/database-account/.test/plain/dependencies.bicep

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,46 @@ param location string = resourceGroup().location
44
@description('Required. The name of the Managed Identity to create.')
55
param managedIdentityName string
66

7+
@description('Required. The name of the Deployment Script to create to get the paired region name.')
8+
param pairedRegionScriptName string
9+
710
resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
811
name: managedIdentityName
912
location: location
1013
}
1114

15+
resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
16+
name: guid('msi-${location}-${managedIdentity.id}-Reader-RoleAssignment')
17+
properties: {
18+
principalId: managedIdentity.properties.principalId
19+
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'acdd72a7-3385-48ef-bd42-f606fba81ae7') // Reader
20+
principalType: 'ServicePrincipal'
21+
}
22+
}
23+
24+
resource getPairedRegionScript 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
25+
name: pairedRegionScriptName
26+
location: location
27+
kind: 'AzurePowerShell'
28+
identity: {
29+
type: 'UserAssigned'
30+
userAssignedIdentities: {
31+
'${managedIdentity.id}': {}
32+
}
33+
}
34+
properties: {
35+
azPowerShellVersion: '8.0'
36+
retentionInterval: 'P1D'
37+
arguments: '-Location \\"${location}\\"'
38+
scriptContent: loadTextContent('../../../../.shared/.scripts/Get-PairedRegion.ps1')
39+
}
40+
dependsOn: [
41+
roleAssignment
42+
]
43+
}
44+
45+
@description('The name of the paired region.')
46+
output pairedRegionName string = getPairedRegionScript.properties.outputs.pairedRegionName
47+
1248
@description('The principal ID of the created Managed Identity.')
1349
output managedIdentityPrincipalId string = managedIdentity.properties.principalId

modules/document-db/database-account/.test/plain/main.test.bicep

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ module nestedDependencies 'dependencies.bicep' = {
3636
name: '${uniqueString(deployment().name, location)}-nestedDependencies'
3737
params: {
3838
managedIdentityName: 'dep-${namePrefix}-msi-${serviceShort}'
39+
pairedRegionScriptName: 'dep-${namePrefix}-ds-${serviceShort}'
3940
}
4041
}
4142

@@ -67,12 +68,12 @@ module testDeployment '../../main.bicep' = {
6768
{
6869
failoverPriority: 0
6970
isZoneRedundant: false
70-
locationName: 'West Europe'
71+
locationName: location
7172
}
7273
{
7374
failoverPriority: 1
7475
isZoneRedundant: false
75-
locationName: 'North Europe'
76+
locationName: nestedDependencies.outputs.pairedRegionName
7677
}
7778
]
7879
diagnosticStorageAccountId: diagnosticDependencies.outputs.storageAccountResourceId

modules/document-db/database-account/.test/sqldb/dependencies.bicep

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ param managedIdentityName string
77
@description('Required. The name of the Virtual Network to create.')
88
param virtualNetworkName string
99

10+
@description('Required. The name of the Deployment Script to create to get the paired region name.')
11+
param pairedRegionScriptName string
12+
1013
var addressPrefix = '10.0.0.0/16'
1114

1215
resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
@@ -50,6 +53,39 @@ resource privateDNSZone 'Microsoft.Network/privateDnsZones@2020-06-01' = {
5053
}
5154
}
5255

56+
resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
57+
name: guid('msi-${location}-${managedIdentity.id}-Reader-RoleAssignment')
58+
properties: {
59+
principalId: managedIdentity.properties.principalId
60+
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'acdd72a7-3385-48ef-bd42-f606fba81ae7') // Reader
61+
principalType: 'ServicePrincipal'
62+
}
63+
}
64+
65+
resource getPairedRegionScript 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
66+
name: pairedRegionScriptName
67+
location: location
68+
kind: 'AzurePowerShell'
69+
identity: {
70+
type: 'UserAssigned'
71+
userAssignedIdentities: {
72+
'${managedIdentity.id}': {}
73+
}
74+
}
75+
properties: {
76+
azPowerShellVersion: '8.0'
77+
retentionInterval: 'P1D'
78+
arguments: '-Location \\"${location}\\"'
79+
scriptContent: loadTextContent('../../../../.shared/.scripts/Get-PairedRegion.ps1')
80+
}
81+
dependsOn: [
82+
roleAssignment
83+
]
84+
}
85+
86+
@description('The name of the paired region.')
87+
output pairedRegionName string = getPairedRegionScript.properties.outputs.pairedRegionName
88+
5389
@description('The principal ID of the created Managed Identity.')
5490
output managedIdentityPrincipalId string = managedIdentity.properties.principalId
5591

modules/document-db/database-account/.test/sqldb/main.test.bicep

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module nestedDependencies 'dependencies.bicep' = {
3737
params: {
3838
managedIdentityName: 'dep-${namePrefix}-msi-${serviceShort}'
3939
virtualNetworkName: 'dep-${namePrefix}-vnet-${serviceShort}'
40+
pairedRegionScriptName: 'dep-${namePrefix}-ds-${serviceShort}'
4041
}
4142
}
4243

@@ -68,12 +69,12 @@ module testDeployment '../../main.bicep' = {
6869
{
6970
failoverPriority: 0
7071
isZoneRedundant: false
71-
locationName: 'West Europe'
72+
locationName: location
7273
}
7374
{
7475
failoverPriority: 1
7576
isZoneRedundant: false
76-
locationName: 'North Europe'
77+
locationName: nestedDependencies.outputs.pairedRegionName
7778
}
7879
]
7980
diagnosticStorageAccountId: diagnosticDependencies.outputs.storageAccountResourceId

0 commit comments

Comments
 (0)