Skip to content

Commit

Permalink
Storage accounts, DB and servers, keyvault IDA
Browse files Browse the repository at this point in the history
  • Loading branch information
betaniat committed Oct 9, 2024
1 parent f9f0255 commit 2dbd216
Show file tree
Hide file tree
Showing 8 changed files with 241 additions and 0 deletions.
23 changes: 23 additions & 0 deletions scripts/automation/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

deploymentName="IDA$(date +%Y%m%d%H%M%S)"
location="northeurope"
bicepTemplateFile="scripts/automation/infrastructure.bicep"
bicepParameterFile="scripts/automation/infrastructure.bicepparam"

administratorLoginPassword=$(date +%s%N | sha256sum | head -c48)


az deployment sub create \
--location $location \
--name $deploymentName \
--template-file $bicepTemplateFile \
--parameters $bicepParameterFile \
--parameters administratorLoginPassword="$administratorLoginPassword"

if [ $? -eq 0 ]; then
echo "Deployment succeeded."
else
echo "Deployment failed."
exit 1
fi
73 changes: 73 additions & 0 deletions scripts/automation/infrastructure.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
targetScope = 'subscription'

param environment string
param resourceGroupName string = 'IDA-${environment}'
param location string

param storageAccountNameRaw string
param storageAccountNameAnon string
param storageAccountNameVis string

param keyVaultName string
param objectIdFgRobots string

param administratorLogin string
@secure()
param administratorLoginPassword string
param serverName string

resource resourceGroup 'Microsoft.Resources/resourceGroups@2024-03-01' = {
name: resourceGroupName
location: location
}

module storageAccountRaw 'modules/storage-account-raw.bicep' = {
scope: resourceGroup
name: 'infrastructure-sa-raw'
params: {
location: location
storageAccountNameRaw: storageAccountNameRaw
}
}

module storageAccountAnon 'modules/storage-account-anon.bicep' = {
scope: resourceGroup
name: 'infrastructure-sa-anon'
params: {
location: location
storageAccountNameAnon: storageAccountNameAnon
}
}

module storageAccountVis 'modules/storage-account-visualize.bicep' = {
scope: resourceGroup
name: 'infrastructure-sa-vis'
params: {
location: location
storageAccountNameVis: storageAccountNameVis
}
}

module keyVault 'modules/key-vault.bicep' = {
scope: resourceGroup
name: 'infrastructure-kv'
params: {
location: location
keyVaultName: keyVaultName
objectIdFgRobots: objectIdFgRobots
secrets: [
{ name: 'administratorLoginPassword', value: administratorLoginPassword }
]
}
}

module postgreSQLFlexibleServer 'modules/db-postgreSQL-flexibleserver.bicep' = {
scope: resourceGroup
name: 'infrastructure-db'
params: {
location: location
administratorLogin: administratorLogin
administratorLoginPassword: administratorLoginPassword
serverName: serverName
}
}
17 changes: 17 additions & 0 deletions scripts/automation/infrastructure.bicepparam
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using 'infrastructure.bicep'

param resourceGroupName = 'IDA-${environment}'

param environment = 'YourEnvName'
param location = 'northeurope'
param objectIdFgRobots = '5ac08731-48dd-4499-9151-7bf6b8ab8eac'

param keyVaultName = 'ida1-${environment}'

param administratorLogin = 'idapostgresqlserver_${environment}'
param administratorLoginPassword = ''
param serverName = 'ida-server-${environment}'

param storageAccountNameAnon = 'storageanon1${environment}'
param storageAccountNameRaw = 'storageraw1${environment}'
param storageAccountNameVis = 'storagevis1${environment}'
38 changes: 38 additions & 0 deletions scripts/automation/modules/db-postgreSQL-flexibleserver.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
@description('User name for administrator login')
param administratorLogin string

@description('Password for administrator password login. Required on creation time regardless of authentication method configuration')
@secure()
param administratorLoginPassword string
param location string
param serverName string
param serverEdition string = 'GeneralPurpose'
param skuSizeGB int = 256
param dbInstanceType string = 'Standard_D4ds_v4'
param availabilityZone string = '1'
param version string = '14'

resource serverName_resource 'Microsoft.DBforPostgreSQL/flexibleServers@2021-06-01' = {
name: serverName
location: location
sku: {
name: dbInstanceType
tier: serverEdition
}
properties: {
version: version
administratorLogin: administratorLogin
administratorLoginPassword: administratorLoginPassword
highAvailability: {
mode: 'Disabled'
}
storage: {
storageSizeGB: skuSizeGB
}
backup: {
backupRetentionDays: 7
geoRedundantBackup: 'Disabled'
}
availabilityZone: availabilityZone
}
}
54 changes: 54 additions & 0 deletions scripts/automation/modules/key-vault.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
param location string
param keyVaultName string
param objectIdFgRobots string
param secrets array

resource keyVault 'Microsoft.KeyVault/vaults@2024-04-01-preview' = {
name: keyVaultName
location: location
properties: {
enabledForDeployment: true
enabledForTemplateDeployment: true
enabledForDiskEncryption: true
tenantId: tenant().tenantId
accessPolicies: []
sku: {
name: 'standard'
family: 'A'
}
}
}

resource keyVaultAccessPolicy 'Microsoft.KeyVault/vaults/accessPolicies@2024-04-01-preview' = {
parent: keyVault
name: 'add'
properties: {
accessPolicies: [
{
tenantId: keyVault.properties.tenantId
objectId: objectIdFgRobots
permissions: {
keys: [
'list'
'create'
]
secrets: [
'set'
'get'
'list'
]
}
}
]
}
}

resource keyVaultSecret 'Microsoft.KeyVault/vaults/secrets@2024-04-01-preview' = [
for secret in secrets: {
name: secret.name
parent: keyVault
properties: {
value: secret.value
}
}
]
12 changes: 12 additions & 0 deletions scripts/automation/modules/storage-account-anon.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
param storageAccountNameAnon string
param location string

resource storageAccountAnon 'Microsoft.Storage/storageAccounts@2023-05-01' = {
name: storageAccountNameAnon
location: location
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
properties: {}
}
12 changes: 12 additions & 0 deletions scripts/automation/modules/storage-account-raw.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
param storageAccountNameRaw string
param location string

resource storageAccountRaw 'Microsoft.Storage/storageAccounts@2023-05-01' = {
name: storageAccountNameRaw
location: location
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
properties: {}
}
12 changes: 12 additions & 0 deletions scripts/automation/modules/storage-account-visualize.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
param storageAccountNameVis string
param location string

resource storageAccountVis 'Microsoft.Storage/storageAccounts@2023-05-01' = {
name: storageAccountNameVis
location: location
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
properties: {}
}

0 comments on commit 2dbd216

Please sign in to comment.