Skip to content

Commit

Permalink
Bicep tidying and add max connections to iac
Browse files Browse the repository at this point in the history
  • Loading branch information
Ceredron committed Jan 8, 2025
1 parent 21dd934 commit 468ec52
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 35 deletions.
19 changes: 2 additions & 17 deletions .azure/infrastructure/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,9 @@ param idportenClientSecret string

@secure()
param storageAccountName string

param maskinporten_token_exchange_environment string

import { Sku as KeyVaultSku } from '../modules/keyvault/create.bicep'
param keyVaultSku KeyVaultSku

param prodLikeEnvironment bool = environment == 'production' || maskinporten_token_exchange_environment == 'yt01'
param postgresSku object = prodLikeEnvironment ? {
name: 'Standard_D8ads_v5'
tier: 'GeneralPurpose'
} : {
name: 'Standard_B1ms'
tier: 'Burstable'
}


var prodLikeEnvironment = environment == 'production' || maskinporten_token_exchange_environment == 'yt01'
var resourceGroupName = '${namePrefix}-rg'

// Create resource groups
Expand All @@ -59,7 +46,6 @@ module environmentKeyVault '../modules/keyvault/create.bicep' = {
params: {
vaultName: sourceKeyVaultName
location: location
sku: keyVaultSku
tenant_id: tenantId
environment: environment
test_client_id: test_client_id
Expand Down Expand Up @@ -129,9 +115,8 @@ module postgresql '../modules/postgreSql/create.bicep' = {
srcKeyVault: srcKeyVault
srcSecretName: correspondenceAdminPasswordSecretName
administratorLoginPassword: correspondencePgAdminPassword
sku: postgresSku
iopsTier: prodLikeEnvironment ? 'P15': 'P4'
tenantId: tenantId
prodLikeEnvironment: prodLikeEnvironment
}
}

Expand Down
5 changes: 0 additions & 5 deletions .azure/infrastructure/params.bicepparam
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,3 @@ param slackUrl = readEnvironmentVariable('SLACK_URL')
param idportenClientId = readEnvironmentVariable('IDPORTEN_CLIENT_ID')
param idportenClientSecret = readEnvironmentVariable('IDPORTEN_CLIENT_SECRET')
param maskinporten_token_exchange_environment = readEnvironmentVariable('MASKINPORTEN_TOKEN_EXCHANGE_ENVIRONMENT')
// SKUs
param keyVaultSku = {
name: 'standard'
family: 'A'
}
11 changes: 4 additions & 7 deletions .azure/modules/keyvault/create.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ param environment string
param tenant_id string
@secure()
param test_client_id string
@export()
type Sku = {
name: 'standard'
family: 'A'
}
param sku Sku

resource keyVault 'Microsoft.KeyVault/vaults@2023-07-01' = {
name: vaultName
Expand All @@ -19,7 +13,10 @@ resource keyVault 'Microsoft.KeyVault/vaults@2023-07-01' = {
enabledForTemplateDeployment: true
enabledForDiskEncryption: true
enabledForDeployment: true
sku: sku
sku: {
name: 'standard'
family: 'A'
}
tenantId: tenant_id
accessPolicies: environment == 'test'
? [
Expand Down
28 changes: 22 additions & 6 deletions .azure/modules/postgreSql/create.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ param location string
param environmentKeyVaultName string
param srcSecretName string

param sku object
param iopsTier string
@secure()
param srcKeyVault object

Expand All @@ -13,6 +11,8 @@ param administratorLoginPassword string
@secure()
param tenantId string

param prodLikeEnvironment bool

var databaseName = 'correspondence'
var databaseUser = 'adminuser'
var poolSize = 100
Expand Down Expand Up @@ -48,7 +48,7 @@ resource postgres 'Microsoft.DBforPostgreSQL/flexibleServers@2023-12-01-preview'
storage: {
storageSizeGB: 32
autoGrow: 'Enabled'
tier: iopsTier
tier: prodLikeEnvironment ? 'P15': 'P4'
}
backup: { backupRetentionDays: 35 }
authConfig: {
Expand All @@ -57,10 +57,16 @@ resource postgres 'Microsoft.DBforPostgreSQL/flexibleServers@2023-12-01-preview'
tenantId: tenantId
}
}
sku: sku
sku: prodLikeEnvironment ? {
name: 'Standard_D8ads_v5'
tier: 'GeneralPurpose'
} : {
name: 'Standard_B1ms'
tier: 'Burstable'
}
}

resource configurations 'Microsoft.DBforPostgreSQL/flexibleServers/configurations@2022-12-01' = {
resource extensionsConfiguration 'Microsoft.DBforPostgreSQL/flexibleServers/configurations@2022-12-01' = {
name: 'azure.extensions'
parent: postgres
dependsOn: [database]
Expand All @@ -70,6 +76,16 @@ resource configurations 'Microsoft.DBforPostgreSQL/flexibleServers/configuration
}
}

resource maxConnectionsConfiguration 'Microsoft.DBforPostgreSQL/flexibleServers/configurations@2022-12-01' = {
name: 'max_connections'
parent: postgres
dependsOn: [database]
properties: {
value: prodLikeEnvironment ? '3000' : '50'
source: 'user-override'
}
}

resource database 'Microsoft.DBforPostgreSQL/flexibleServers/databases@2023-06-01-preview' = {
name: databaseName
parent: postgres
Expand All @@ -82,7 +98,7 @@ resource database 'Microsoft.DBforPostgreSQL/flexibleServers/databases@2023-06-0
resource allowAzureAccess 'Microsoft.DBforPostgreSQL/flexibleServers/firewallRules@2023-06-01-preview' = {
name: 'azure-access'
parent: postgres
dependsOn: [configurations] // Needs to depend on database to avoid updating at the same time
dependsOn: [database, extensionsConfiguration, maxConnectionsConfiguration] // Needs to depend on database to avoid updating at the same time
properties: {
startIpAddress: '0.0.0.0'
endIpAddress: '0.0.0.0'
Expand Down

0 comments on commit 468ec52

Please sign in to comment.