Terraform Azure PostgreSQL Database Module
This Terraform module creates a PostgreSQL database in Azure with a configurable setup.
⚙️ Features
- Customizable Database Configuration:
- Character set and collation can be specified
- Prevents accidental deletion with
prevent_destroy
- Modular and Reusable:
- Defined via
variables.tf - Outputs database details for further use
- Defined via
🚀 Deployment
Prerequisites
- Terraform (≥ 1.3.0)
- Azure CLI authenticated (
az login)
Steps
- Initialize Terraform:
terraform init1 - Preview the deployment:
terraform plan1 - Apply the configuration:
terraform apply -auto-approve1 - Retrieve PostgreSQL database details:
terraform output1
📚 Notes
- Character Set: Defaults to
UTF8, configurable viacharsetvariable. - Collation: Defaults to
English_United States.1252, configurable viacollationvariable. - Deletion Protection:
prevent_destroyis enabled to avoid accidental data loss.
🛠 Configuration
Requirements
| Name | Version |
|---|---|
| terraform | >= 1.5.0 |
| azurerm | 4.22.0 |
Modules
No modules.
Resources
| Name | Type |
|---|---|
| azurerm_postgresql_database.example | resource |
Inputs
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| charset | Character set for the database | string | "UTF8" | no |
| collation | Collation for the database | string | "English_United States.1252" | no |
| database_name | The name of the PostgreSQL database | string | n/a | yes |
| resource_group_name | The name of the resource group where the database will be created | string | n/a | yes |
| server_name | The name of the PostgreSQL server | string | n/a | yes |
| subscription_id | the Azure subscription id | string | n/a | yes |
Outputs
| Name | Description |
|---|---|
| database_id | The ID of the created PostgreSQL database |
| database_name | The name of the created PostgreSQL database |
Source code & Installation
The source code of this kit module can be found here
Run the following command to install the kit module:
collie kit import azure/buildingblocks/postgresql-database/buildingblock
1
