Skip to content

Commit

Permalink
[Modules] Updated Cosmos DB Module tests to support dynamic primary a…
Browse files Browse the repository at this point in the history
…nd secondary region locations (#3946)
  • Loading branch information
ahmadabdalla authored Sep 9, 2023
1 parent fe148cd commit 9bd1b46
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,46 @@ param location string = resourceGroup().location
@description('Required. The name of the Managed Identity to create.')
param managedIdentityName string

@description('Required. The name of the Deployment Script to create to get the paired region name.')
param pairedRegionScriptName string

resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
name: managedIdentityName
location: location
}

resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid('msi-${location}-${managedIdentity.id}-Reader-RoleAssignment')
properties: {
principalId: managedIdentity.properties.principalId
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'acdd72a7-3385-48ef-bd42-f606fba81ae7') // Reader
principalType: 'ServicePrincipal'
}
}

resource getPairedRegionScript 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
name: pairedRegionScriptName
location: location
kind: 'AzurePowerShell'
identity: {
type: 'UserAssigned'
userAssignedIdentities: {
'${managedIdentity.id}': {}
}
}
properties: {
azPowerShellVersion: '8.0'
retentionInterval: 'P1D'
arguments: '-Location \\"${location}\\"'
scriptContent: loadTextContent('../../../../.shared/.scripts/Get-PairedRegion.ps1')
}
dependsOn: [
roleAssignment
]
}

@description('The name of the paired region.')
output pairedRegionName string = getPairedRegionScript.properties.outputs.pairedRegionName

@description('The principal ID of the created Managed Identity.')
output managedIdentityPrincipalId string = managedIdentity.properties.principalId
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module nestedDependencies 'dependencies.bicep' = {
name: '${uniqueString(deployment().name, location)}-nestedDependencies'
params: {
managedIdentityName: 'dep-${namePrefix}-msi-${serviceShort}'
pairedRegionScriptName: 'dep-${namePrefix}-ds-${serviceShort}'
}
}

Expand Down Expand Up @@ -67,12 +68,12 @@ module testDeployment '../../main.bicep' = {
{
failoverPriority: 0
isZoneRedundant: false
locationName: 'West Europe'
locationName: location
}
{
failoverPriority: 1
isZoneRedundant: false
locationName: 'North Europe'
locationName: nestedDependencies.outputs.pairedRegionName
}
]
capabilitiesToAdd: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,46 @@ param location string = resourceGroup().location
@description('Required. The name of the Managed Identity to create.')
param managedIdentityName string

@description('Required. The name of the Deployment Script to create to get the paired region name.')
param pairedRegionScriptName string

resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
name: managedIdentityName
location: location
}

resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid('msi-${location}-${managedIdentity.id}-Reader-RoleAssignment')
properties: {
principalId: managedIdentity.properties.principalId
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'acdd72a7-3385-48ef-bd42-f606fba81ae7') // Reader
principalType: 'ServicePrincipal'
}
}

resource getPairedRegionScript 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
name: pairedRegionScriptName
location: location
kind: 'AzurePowerShell'
identity: {
type: 'UserAssigned'
userAssignedIdentities: {
'${managedIdentity.id}': {}
}
}
properties: {
azPowerShellVersion: '8.0'
retentionInterval: 'P1D'
arguments: '-Location \\"${location}\\"'
scriptContent: loadTextContent('../../../../.shared/.scripts/Get-PairedRegion.ps1')
}
dependsOn: [
roleAssignment
]
}

@description('The name of the paired region.')
output pairedRegionName string = getPairedRegionScript.properties.outputs.pairedRegionName

@description('The principal ID of the created Managed Identity.')
output managedIdentityPrincipalId string = managedIdentity.properties.principalId
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module nestedDependencies 'dependencies.bicep' = {
name: '${uniqueString(deployment().name, location)}-nestedDependencies'
params: {
managedIdentityName: 'dep-${namePrefix}-msi-${serviceShort}'
pairedRegionScriptName: 'dep-${namePrefix}-ds-${serviceShort}'
}
}

Expand Down Expand Up @@ -67,12 +68,12 @@ module testDeployment '../../main.bicep' = {
{
failoverPriority: 0
isZoneRedundant: false
locationName: 'West Europe'
locationName: location
}
{
failoverPriority: 1
isZoneRedundant: false
locationName: 'North Europe'
locationName: nestedDependencies.outputs.pairedRegionName
}
]
diagnosticStorageAccountId: diagnosticDependencies.outputs.storageAccountResourceId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,46 @@ param location string = resourceGroup().location
@description('Required. The name of the Managed Identity to create.')
param managedIdentityName string

@description('Required. The name of the Deployment Script to create to get the paired region name.')
param pairedRegionScriptName string

resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
name: managedIdentityName
location: location
}

resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid('msi-${location}-${managedIdentity.id}-Reader-RoleAssignment')
properties: {
principalId: managedIdentity.properties.principalId
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'acdd72a7-3385-48ef-bd42-f606fba81ae7') // Reader
principalType: 'ServicePrincipal'
}
}

resource getPairedRegionScript 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
name: pairedRegionScriptName
location: location
kind: 'AzurePowerShell'
identity: {
type: 'UserAssigned'
userAssignedIdentities: {
'${managedIdentity.id}': {}
}
}
properties: {
azPowerShellVersion: '8.0'
retentionInterval: 'P1D'
arguments: '-Location \\"${location}\\"'
scriptContent: loadTextContent('../../../../.shared/.scripts/Get-PairedRegion.ps1')
}
dependsOn: [
roleAssignment
]
}

@description('The name of the paired region.')
output pairedRegionName string = getPairedRegionScript.properties.outputs.pairedRegionName

@description('The principal ID of the created Managed Identity.')
output managedIdentityPrincipalId string = managedIdentity.properties.principalId
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module nestedDependencies 'dependencies.bicep' = {
name: '${uniqueString(deployment().name, location)}-nestedDependencies'
params: {
managedIdentityName: 'dep-${namePrefix}-msi-${serviceShort}'
pairedRegionScriptName: 'dep-${namePrefix}-ds-${serviceShort}'
}
}

Expand Down Expand Up @@ -67,12 +68,12 @@ module testDeployment '../../main.bicep' = {
{
failoverPriority: 0
isZoneRedundant: false
locationName: 'West Europe'
locationName: location
}
{
failoverPriority: 1
isZoneRedundant: false
locationName: 'North Europe'
locationName: nestedDependencies.outputs.pairedRegionName
}
]
diagnosticStorageAccountId: diagnosticDependencies.outputs.storageAccountResourceId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ param managedIdentityName string
@description('Required. The name of the Virtual Network to create.')
param virtualNetworkName string

@description('Required. The name of the Deployment Script to create to get the paired region name.')
param pairedRegionScriptName string

var addressPrefix = '10.0.0.0/16'

resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
Expand Down Expand Up @@ -50,6 +53,39 @@ resource privateDNSZone 'Microsoft.Network/privateDnsZones@2020-06-01' = {
}
}

resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid('msi-${location}-${managedIdentity.id}-Reader-RoleAssignment')
properties: {
principalId: managedIdentity.properties.principalId
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'acdd72a7-3385-48ef-bd42-f606fba81ae7') // Reader
principalType: 'ServicePrincipal'
}
}

resource getPairedRegionScript 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
name: pairedRegionScriptName
location: location
kind: 'AzurePowerShell'
identity: {
type: 'UserAssigned'
userAssignedIdentities: {
'${managedIdentity.id}': {}
}
}
properties: {
azPowerShellVersion: '8.0'
retentionInterval: 'P1D'
arguments: '-Location \\"${location}\\"'
scriptContent: loadTextContent('../../../../.shared/.scripts/Get-PairedRegion.ps1')
}
dependsOn: [
roleAssignment
]
}

@description('The name of the paired region.')
output pairedRegionName string = getPairedRegionScript.properties.outputs.pairedRegionName

@description('The principal ID of the created Managed Identity.')
output managedIdentityPrincipalId string = managedIdentity.properties.principalId

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module nestedDependencies 'dependencies.bicep' = {
params: {
managedIdentityName: 'dep-${namePrefix}-msi-${serviceShort}'
virtualNetworkName: 'dep-${namePrefix}-vnet-${serviceShort}'
pairedRegionScriptName: 'dep-${namePrefix}-ds-${serviceShort}'
}
}

Expand Down Expand Up @@ -68,12 +69,12 @@ module testDeployment '../../main.bicep' = {
{
failoverPriority: 0
isZoneRedundant: false
locationName: 'West Europe'
locationName: location
}
{
failoverPriority: 1
isZoneRedundant: false
locationName: 'North Europe'
locationName: nestedDependencies.outputs.pairedRegionName
}
]
diagnosticStorageAccountId: diagnosticDependencies.outputs.storageAccountResourceId
Expand Down
Loading

0 comments on commit 9bd1b46

Please sign in to comment.