Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add infrastructure as code to deploy database #26

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Several extension need to be installed on our PostGre SQL database :
* postgis
* postgis_topology
* pg_routing

# Database description
## How to edit the database/tables/columns?
Create a new git branch (never work directly on master)
Expand Down Expand Up @@ -200,3 +201,12 @@ Special thanks to all our [Contributors](https://github.com/orgs/surfriderfounda
## License

We’re using the `MIT` License. For more details, check [`LICENSE`](https://github.com/surfriderfoundationeurope/plasticorigins-ops-db/blob/master/LICENSE) file.

# Azure Deployment

You can use [shell.azure.com](https://shell.azure.com) to execute the following commands:

```bash
git clone https://github.com/surfriderfoundationeurope/plasticorigins-ops-db.git
./plasticorigins-ops-db/infrastructure/deploy-prod.sh
```
15 changes: 15 additions & 0 deletions infrastructure/deploy-prod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# Declare a resource group variable
export RESOURCE_GROUP_NAME=rg-plastico-database-fra-prod
az group create --name $RESOURCE_GROUP_NAME --location francecentral

# Generate a GUID and store it in a variable
export PASSWORD=$(uuidgen)

az deployment group create --resource-group $RESOURCE_GROUP_NAME --template-file postgres-db.bicep --parameters environment=prod administratorPassword=$PASSWORD

# Echo the password to the console
echo $PASSWORD

az keyvault secret set --vault-name plastico-keyvault-prod --name "postgres-prod-admin-password" --value $PASSWORD
57 changes: 57 additions & 0 deletions infrastructure/postgres-db.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
param administratorLogin string = 'po_admin_prod'
@secure()
param administratorPassword string

@allowed([
'dev'
'prod'
])
param environment string = 'dev'

var serverName = 'pgdb-plastico-${environment}-fra'

var location = 'francecentral'

resource postGres 'Microsoft.DBforPostgreSQL/flexibleServers@2022-12-01' = {
name: serverName
location: location
tags: {
environment: environment
}
sku: {
name: 'Standard_B1ms'
tier: 'Burstable'
}
properties: {
administratorLogin: administratorLogin
administratorLoginPassword: administratorPassword
authConfig: {
activeDirectoryAuth: 'Enabled'
passwordAuth: 'Enabled'
tenantId: '1fb581f3-43ef-4dfd-b8f7-4ca7bc32ec24'
}
backup: {
backupRetentionDays: 7
geoRedundantBackup: 'Disabled'
}
createMode: 'string'
dataEncryption: {
type: 'SystemManaged'
}
highAvailability: {
mode: 'Disabled'
}
maintenanceWindow: {
customWindow: 'Disabled'
dayOfWeek: 0
startHour: 0
startMinute: 0
}
// replicaCapacity: int
// replicationRole: 'string'
storage: {
storageSizeGB: 32
}
version: '14'
}
}