Skip to content

Commit

Permalink
fix: avm/res/db for postgre sql/flexible server (#3080)
Browse files Browse the repository at this point in the history
## Description
Added "highAvailability: 'ZoneRedundant'" to default test to fix broken
pipeline.
Added updated role assignment logic to conform with new AVM
specification.

Fixes #2388
Closes #2388 

## Pipeline Reference

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

| Pipeline |
| -------- |
|
[![avm.res.db-for-postgre-sql.flexible-server](https://github.com/arnoldna/bicep-registry-modules/actions/workflows/avm.res.db-for-postgre-sql.flexible-server.yml/badge.svg?branch=avm%2Fres%2Fdb-for-postgre-sql%2Fflexible-server)](https://github.com/arnoldna/bicep-registry-modules/actions/workflows/avm.res.db-for-postgre-sql.flexible-server.yml)
|

## Type of Change

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

- [ ] Update to CI Environment or utilities (Non-module affecting
changes)
- [X] Azure Verified Module updates:
- [X] 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`.
- [ ] Breaking changes and I have bumped the MAJOR version in
`version.json`.
  - [X] Update to documentation

## Checklist

- [X] I'm sure there are no other open Pull Requests for the same
update/change
- [X] I have run `Set-AVMModule` locally to generate the supporting
module files.
- [X] My corresponding pipelines / checks run clean and green without
any errors or warnings

<!-- Please keep up to date with the contribution guide at
https://aka.ms/avm/contribute/bicep -->
  • Loading branch information
arnoldna authored Aug 22, 2024
1 parent 6df8e94 commit 073f92e
Show file tree
Hide file tree
Showing 11 changed files with 350 additions and 222 deletions.
70 changes: 58 additions & 12 deletions avm/res/db-for-postgre-sql/flexible-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,18 @@ module flexibleServer 'br/public:avm/res/db-for-postgre-sql/flexible-server:<ver
params: {
// Required parameters
name: 'dfpsfsmin001'
skuName: 'Standard_B2s'
tier: 'Burstable'
skuName: 'Standard_D2s_v3'
tier: 'GeneralPurpose'
// Non-required parameters
administratorLogin: 'adminUserName'
administratorLoginPassword: '<administratorLoginPassword>'
administrators: [
{
objectId: '<objectId>'
principalName: '<principalName>'
principalType: 'ServicePrincipal'
}
]
geoRedundantBackup: 'Enabled'
highAvailability: 'ZoneRedundant'
location: '<location>'
}
}
Expand All @@ -81,21 +87,27 @@ module flexibleServer 'br/public:avm/res/db-for-postgre-sql/flexible-server:<ver
"value": "dfpsfsmin001"
},
"skuName": {
"value": "Standard_B2s"
"value": "Standard_D2s_v3"
},
"tier": {
"value": "Burstable"
"value": "GeneralPurpose"
},
// Non-required parameters
"administratorLogin": {
"value": "adminUserName"
},
"administratorLoginPassword": {
"value": "<administratorLoginPassword>"
"administrators": {
"value": [
{
"objectId": "<objectId>",
"principalName": "<principalName>",
"principalType": "ServicePrincipal"
}
]
},
"geoRedundantBackup": {
"value": "Enabled"
},
"highAvailability": {
"value": "ZoneRedundant"
},
"location": {
"value": "<location>"
}
Expand Down Expand Up @@ -697,7 +709,14 @@ module flexibleServer 'br/public:avm/res/db-for-postgre-sql/flexible-server:<ver
}
]
geoRedundantBackup: 'Enabled'
highAvailability: 'ZoneRedundant'
location: '<location>'
maintenanceWindow: {
customWindow: 'Enabled'
dayOfWeek: 0
startHour: 1
startMinute: 0
}
privateDnsZoneArmResourceId: '<privateDnsZoneArmResourceId>'
tags: {
Environment: 'Non-Prod'
Expand Down Expand Up @@ -782,9 +801,20 @@ module flexibleServer 'br/public:avm/res/db-for-postgre-sql/flexible-server:<ver
"geoRedundantBackup": {
"value": "Enabled"
},
"highAvailability": {
"value": "ZoneRedundant"
},
"location": {
"value": "<location>"
},
"maintenanceWindow": {
"value": {
"customWindow": "Enabled",
"dayOfWeek": 0,
"startHour": 1,
"startMinute": 0
}
},
"privateDnsZoneArmResourceId": {
"value": "<privateDnsZoneArmResourceId>"
},
Expand Down Expand Up @@ -1314,7 +1344,15 @@ Properties for the maintenence window. If provided, 'customWindow' property must

- Required: No
- Type: object
- Default: `{}`
- Default:
```Bicep
{
customWindow: 'Enabled'
dayOfWeek: 0
startHour: 1
startMinute: 0
}
```

### Parameter: `passwordAuth`

Expand Down Expand Up @@ -1361,6 +1399,7 @@ Array of role assignments to create.
| [`conditionVersion`](#parameter-roleassignmentsconditionversion) | string | Version of the condition. |
| [`delegatedManagedIdentityResourceId`](#parameter-roleassignmentsdelegatedmanagedidentityresourceid) | string | The Resource Id of the delegated managed identity resource. |
| [`description`](#parameter-roleassignmentsdescription) | string | The description of the role assignment. |
| [`name`](#parameter-roleassignmentsname) | string | The name (as GUID) of the role assignment. If not provided, a GUID will be generated. |
| [`principalType`](#parameter-roleassignmentsprincipaltype) | string | The principal type of the assigned principal ID. |

### Parameter: `roleAssignments.principalId`
Expand Down Expand Up @@ -1411,6 +1450,13 @@ The description of the role assignment.
- Required: No
- Type: string

### Parameter: `roleAssignments.name`

The name (as GUID) of the role assignment. If not provided, a GUID will be generated.

- Required: No
- Type: string

### Parameter: `roleAssignments.principalType`

The principal type of the assigned principal ID.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.26.170.59819",
"templateHash": "17302939650459446486"
"version": "0.29.47.4906",
"templateHash": "9786947819042824705"
},
"name": "DBforPostgreSQL Flexible Server Administrators",
"description": "This module deploys a DBforPostgreSQL Flexible Server Administrator.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.26.170.59819",
"templateHash": "4808844582468160626"
"version": "0.29.47.4906",
"templateHash": "3802666632340288344"
},
"name": "DBforPostgreSQL Flexible Server Configurations",
"description": "This module deploys a DBforPostgreSQL Flexible Server Configuration.",
Expand Down
4 changes: 2 additions & 2 deletions avm/res/db-for-postgre-sql/flexible-server/database/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.26.170.59819",
"templateHash": "12256776332622303948"
"version": "0.29.47.4906",
"templateHash": "17501165975344742322"
},
"name": "DBforPostgreSQL Flexible Server Databases",
"description": "This module deploys a DBforPostgreSQL Flexible Server Database.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.26.170.59819",
"templateHash": "12309357869547394167"
"version": "0.29.47.4906",
"templateHash": "5110779562094536429"
},
"name": "DBforPostgreSQL Flexible Server Firewall Rules",
"description": "This module deploys a DBforPostgreSQL Flexible Server Firewall Rule.",
Expand Down
41 changes: 28 additions & 13 deletions avm/res/db-for-postgre-sql/flexible-server/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ param managedIdentities managedIdentitiesType
param customerManagedKey customerManagedKeyType

@description('Optional. Properties for the maintenence window. If provided, \'customWindow\' property must exist and set to \'Enabled\'.')
param maintenanceWindow object = {}
param maintenanceWindow object = {
customWindow: 'Enabled'
dayOfWeek: 0
startHour: 1
startMinute: 0
}

@description('Conditional. Required if \'createMode\' is set to \'PointInTimeRestore\'.')
param pointInTimeUTC string = ''
Expand Down Expand Up @@ -182,6 +187,17 @@ var builtInRoleNames = {
)
}

var formattedRoleAssignments = [
for (roleAssignment, index) in (roleAssignments ?? []): union(roleAssignment, {
roleDefinitionId: builtInRoleNames[?roleAssignment.roleDefinitionIdOrName] ?? (contains(
roleAssignment.roleDefinitionIdOrName,
'/providers/Microsoft.Authorization/roleDefinitions/'
)
? roleAssignment.roleDefinitionIdOrName
: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', roleAssignment.roleDefinitionIdOrName))
})
]

#disable-next-line no-deployments-resources
resource avmTelemetry 'Microsoft.Resources/deployments@2024-03-01' = if (enableTelemetry) {
name: '46d3xbcp.res.dbforpostgresql-flexibleserver.${replace('-..--..-', '.', '-')}.${substring(uniqueString(deployment().name, location), 0, 4)}'
Expand Down Expand Up @@ -292,14 +308,10 @@ resource flexibleServer_lock 'Microsoft.Authorization/locks@2020-05-01' = if (!e
}

resource flexibleServer_roleAssignments 'Microsoft.Authorization/roleAssignments@2022-04-01' = [
for (roleAssignment, index) in (roleAssignments ?? []): {
name: guid(flexibleServer.id, roleAssignment.principalId, roleAssignment.roleDefinitionIdOrName)
for (roleAssignment, index) in (formattedRoleAssignments ?? []): {
name: roleAssignment.?name ?? guid(flexibleServer.id, roleAssignment.principalId, roleAssignment.roleDefinitionId)
properties: {
roleDefinitionId: contains(builtInRoleNames, roleAssignment.roleDefinitionIdOrName)
? builtInRoleNames[roleAssignment.roleDefinitionIdOrName]
: contains(roleAssignment.roleDefinitionIdOrName, '/providers/Microsoft.Authorization/roleDefinitions/')
? roleAssignment.roleDefinitionIdOrName
: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', roleAssignment.roleDefinitionIdOrName)
roleDefinitionId: roleAssignment.roleDefinitionId
principalId: roleAssignment.principalId
description: roleAssignment.?description
principalType: roleAssignment.?principalType
Expand All @@ -317,8 +329,8 @@ module flexibleServer_databases 'database/main.bicep' = [
params: {
name: database.name
flexibleServerName: flexibleServer.name
collation: contains(database, 'collation') ? database.collation : ''
charset: contains(database, 'charset') ? database.charset : ''
collation: database.?collation ?? ''
charset: database.?charset ?? ''
}
}
]
Expand All @@ -345,8 +357,8 @@ module flexibleServer_configurations 'configuration/main.bicep' = [
params: {
name: configuration.name
flexibleServerName: flexibleServer.name
source: contains(configuration, 'source') ? configuration.source : ''
value: contains(configuration, 'value') ? configuration.value : ''
source: configuration.?source ?? ''
value: configuration.?value ?? ''
}
dependsOn: [
flexibleServer_firewallRules
Expand All @@ -362,7 +374,7 @@ module flexibleServer_administrators 'administrator/main.bicep' = [
objectId: administrator.objectId
principalName: administrator.principalName
principalType: administrator.principalType
tenantId: contains(administrator, 'tenantId') ? administrator.tenantId : tenant().tenantId
tenantId: administrator.?tenantId ?? tenant().tenantId
}
}
]
Expand Down Expand Up @@ -429,6 +441,9 @@ type lockType = {
}?

type roleAssignmentType = {
@description('Optional. The name (as GUID) of the role assignment. If not provided, a GUID will be generated.')
name: string?

@description('Required. The role to assign. You can provide either the display name of the role definition, the role definition GUID, or its fully qualified ID in the following format: \'/providers/Microsoft.Authorization/roleDefinitions/c2f4ef07-c644-48eb-af81-4b1b4947fb11\'.')
roleDefinitionIdOrName: string

Expand Down
Loading

0 comments on commit 073f92e

Please sign in to comment.