Skip to content

Commit a441c9d

Browse files
committed
Set Postgres Entra admin in Bicep instead of separate script
1 parent c13a613 commit a441c9d

6 files changed

Lines changed: 20 additions & 22 deletions

File tree

.github/workflows/_deploy-infrastructure.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ jobs:
7979
- name: Plan Cluster Resources
8080
id: deploy_cluster
8181
env:
82+
POSTGRES_ADMIN_OBJECT_ID: ${{ inputs.postgres_admin_object_id }}
8283
GOOGLE_OAUTH_CLIENT_ID: ${{ vars.GOOGLE_OAUTH_CLIENT_ID }}
8384
GOOGLE_OAUTH_CLIENT_SECRET: ${{ secrets.GOOGLE_OAUTH_CLIENT_SECRET }}
8485
STRIPE_PUBLISHABLE_KEY: ${{ vars.STRIPE_PUBLISHABLE_KEY }}
@@ -144,6 +145,7 @@ jobs:
144145
- name: Deploy Cluster Resources
145146
id: deploy_cluster
146147
env:
148+
POSTGRES_ADMIN_OBJECT_ID: ${{ inputs.postgres_admin_object_id }}
147149
GOOGLE_OAUTH_CLIENT_ID: ${{ vars.GOOGLE_OAUTH_CLIENT_ID }}
148150
GOOGLE_OAUTH_CLIENT_SECRET: ${{ secrets.GOOGLE_OAUTH_CLIENT_SECRET }}
149151
STRIPE_PUBLISHABLE_KEY: ${{ vars.STRIPE_PUBLISHABLE_KEY }}
@@ -161,9 +163,6 @@ jobs:
161163
- name: Install PostgreSQL Client
162164
run: sudo apt-get update && sudo apt-get install -y postgresql-client
163165

164-
- name: Add PostgreSQL Admin
165-
run: bash ./cloud-infrastructure/cluster/add-postgres-admin.sh ${{ inputs.unique_prefix }} ${{ inputs.azure_environment }} ${{ inputs.cluster_location_acronym }} ${{ inputs.postgres_admin_object_id }}
166-
167166
- name: Open Firewall
168167
working-directory: cloud-infrastructure/cluster
169168
env:

cloud-infrastructure/cluster/add-postgres-admin.sh

Lines changed: 0 additions & 18 deletions
This file was deleted.

cloud-infrastructure/cluster/deploy-cluster.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export UNIQUE_PREFIX
2929
export ENVIRONMENT
3030
export LOCATION=$CLUSTER_LOCATION
3131
export DOMAIN_NAME
32+
export POSTGRES_ADMIN_OBJECT_ID
3233
export GOOGLE_OAUTH_CLIENT_ID
3334
export GOOGLE_OAUTH_CLIENT_SECRET
3435
export STRIPE_PUBLISHABLE_KEY
@@ -105,7 +106,6 @@ then
105106
echo "BACK_OFFICE_IDENTITY_CLIENT_ID=$BACK_OFFICE_IDENTITY_CLIENT_ID" >> $GITHUB_OUTPUT
106107
echo "MAIN_IDENTITY_CLIENT_ID=$MAIN_IDENTITY_CLIENT_ID" >> $GITHUB_OUTPUT
107108
else
108-
. ./add-postgres-admin.sh $UNIQUE_PREFIX $ENVIRONMENT $CLUSTER_LOCATION_ACRONYM $POSTGRES_ADMIN_OBJECT_ID
109109
. ./grant-database-permissions.sh $UNIQUE_PREFIX $ENVIRONMENT $CLUSTER_LOCATION_ACRONYM 'account' $ACCOUNT_IDENTITY_CLIENT_ID
110110
. ./grant-database-permissions.sh $UNIQUE_PREFIX $ENVIRONMENT $CLUSTER_LOCATION_ACRONYM 'back-office' $BACK_OFFICE_IDENTITY_CLIENT_ID
111111
. ./grant-database-permissions.sh $UNIQUE_PREFIX $ENVIRONMENT $CLUSTER_LOCATION_ACRONYM 'main' $MAIN_IDENTITY_CLIENT_ID

cloud-infrastructure/cluster/main-cluster.bicep

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ param communicationServicesDataLocation string = 'europe'
1515
param mailSenderDisplayName string = 'PlatformPlatform'
1616
param revisionSuffix string
1717

18+
@description('Object ID of the Entra ID security group for PostgreSQL administration')
19+
param postgresAdminObjectId string = ''
20+
1821
@secure()
1922
param googleOAuthClientId string
2023
@secure()
@@ -153,6 +156,7 @@ module postgresServer '../modules/postgresql-flexible-server.bicep' = {
153156
virtualNetworkId: virtualNetwork.outputs.virtualNetworkId
154157
isProduction: environment == 'prod'
155158
diagnosticStorageAccountId: diagnosticStorageAccount.outputs.storageAccountId
159+
dbAdminObjectId: postgresAdminObjectId
156160
}
157161
}
158162

cloud-infrastructure/cluster/main-cluster.bicepparam

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ param backOfficeVersion = readEnvironmentVariable('BACK_OFFICE_VERSION')
1313
param mainVersion = readEnvironmentVariable('MAIN_VERSION')
1414
param applicationInsightsConnectionString = readEnvironmentVariable('APPLICATIONINSIGHTS_CONNECTION_STRING')
1515
param revisionSuffix = readEnvironmentVariable('REVISION_SUFFIX')
16+
param postgresAdminObjectId = readEnvironmentVariable('POSTGRES_ADMIN_OBJECT_ID', '')
1617
param googleOAuthClientId = readEnvironmentVariable('GOOGLE_OAUTH_CLIENT_ID', '')
1718
param googleOAuthClientSecret = readEnvironmentVariable('GOOGLE_OAUTH_CLIENT_SECRET', '')
1819
param stripePublishableKey = readEnvironmentVariable('STRIPE_PUBLISHABLE_KEY', '')

cloud-infrastructure/modules/postgresql-flexible-server.bicep

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ param subnetId string
66
param virtualNetworkId string
77
param isProduction bool
88
param diagnosticStorageAccountId string
9+
@description('Object ID of the Entra ID security group to assign as PostgreSQL administrator')
10+
param dbAdminObjectId string = ''
911

1012
resource postgresServer 'Microsoft.DBforPostgreSQL/flexibleServers@2025-08-01' = {
1113
name: name
@@ -44,6 +46,16 @@ resource postgresServer 'Microsoft.DBforPostgreSQL/flexibleServers@2025-08-01' =
4446
}
4547
}
4648

49+
resource postgresServerAdministrator 'Microsoft.DBforPostgreSQL/flexibleServers/administrators@2025-08-01' = if (!empty(dbAdminObjectId)) {
50+
parent: postgresServer
51+
name: dbAdminObjectId
52+
properties: {
53+
principalName: 'PostgreSQL Admins - ${isProduction ? 'Production' : 'Staging'}'
54+
principalType: 'Group'
55+
tenantId: tenantId
56+
}
57+
}
58+
4759
resource privateDnsZone 'Microsoft.Network/privateDnsZones@2024-06-01' = {
4860
name: 'privatelink.postgres.database.azure.com'
4961
location: 'global'

0 commit comments

Comments
 (0)