terraformpostgresql
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
terraformpostgresql [2024/11/28 22:25] – z0hpvk | terraformpostgresql [2025/03/08 22:24] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
===== Terraform with PostgreSQL ===== | ===== Terraform with PostgreSQL ===== | ||
- | + | ==== Microsoft Azure and PostgreSQL Flexible Server | |
- | + | ||
- | ==== Microsoft Azure ==== | + | |
=== Useful Links === | === Useful Links === | ||
Line 12: | Line 10: | ||
[https:// | [https:// | ||
- | === providers.tf | + | The below commands will initialise Terraform, create an execution plan and apply it.\\ |
- | <code yaml> | + | Afterwards you can clean up the resources created via the terraform destroy command.\\ |
+ | < | ||
+ | terraform init -upgrade | ||
+ | terraform validate | ||
+ | terraform plan -out main.tfplan | ||
+ | terraform apply main.tfplan | ||
+ | |||
+ | terraform plan -destroy -out main.destroy.tfplan | ||
+ | terraform apply main.destroy.tfplan | ||
+ | </ | ||
+ | |||
+ | === Terraform Code === | ||
+ | == providers.tf == | ||
+ | <file yaml providers.tf> | ||
terraform { | terraform { | ||
required_version = "> | required_version = "> | ||
Line 32: | Line 43: | ||
features {} | features {} | ||
} | } | ||
- | </code> | + | </file> |
- | === variables.tf | + | == variables.tf == |
- | <code yaml> | + | <file yaml variables.tf> |
variable " | variable " | ||
default | default | ||
Line 55: | Line 66: | ||
description = " | description = " | ||
} | } | ||
- | </code> | + | </file> |
- | === main.tf | + | == main.tf == |
Uses existing resource group, virtual network and network security group | Uses existing resource group, virtual network and network security group | ||
- | <code yaml> | + | <file yaml main.tf> |
resource " | resource " | ||
length = 20 | length = 20 | ||
Line 79: | Line 90: | ||
backup_retention_days | backup_retention_days | ||
} | } | ||
- | </code> | + | </file> |
+ | == postgresql-fs-db.tf == | ||
+ | <file yaml postgresql-fs-db.tf> | ||
+ | locals { | ||
+ | pg_config = { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | } | ||
+ | |||
+ | resource " | ||
+ | name = " | ||
+ | collation = " | ||
+ | charset | ||
+ | server_id = azurerm_postgresql_flexible_server.default.id | ||
+ | } | ||
+ | |||
+ | resource " | ||
+ | for_each = local.pg_config | ||
+ | name = each.key | ||
+ | value = each.value | ||
+ | server_id = azurerm_postgresql_flexible_server.default.id | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | == outputs.tf == | ||
+ | <file yaml outputs.tf> | ||
+ | output " | ||
+ | value = azurerm_postgresql_flexible_server.default.name | ||
+ | } | ||
+ | |||
+ | output " | ||
+ | value = azurerm_postgresql_flexible_server_database.default.name | ||
+ | } | ||
+ | |||
+ | output " | ||
+ | sensitive = true | ||
+ | value = azurerm_postgresql_flexible_server.default.administrator_password | ||
+ | } | ||
+ | </ |
terraformpostgresql.1732832715.txt.gz · Last modified: 2025/03/08 22:23 (external edit)