Azure Database PostgreSQL Server
This page shows how to write Terraform and Azure Resource Manager for Database PostgreSQL Server and write them securely.
azurerm_postgresql_server (Terraform)
The PostgreSQL Server in Database can be configured in Terraform with the resource name azurerm_postgresql_server. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_postgresql_server" "basic_2core" {
name = "example-mariadb-server"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
administrator_login = "fake"
resource "azurerm_postgresql_server" "basic_2core" {
name = "example-mariadb-server"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
administrator_login = "fake"
resource "azurerm_postgresql_server" "example" {
name = "example-psqlserver"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
administrator_login = "psqladminun"
resource "azurerm_postgresql_server" "post_server" {
name = "postgresql-server-1"
location = var.location
resource_group_name = var.rg1
sku_name = "B_Gen5_2"
resource "azurerm_postgresql_server" "pssql_db" {
name = "kaorl-psqlserver"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
administrator_login = var.db_name
resource "azurerm_postgresql_server" "post_server" {
name = "postgresql-server-1"
location = var.location
resource_group_name = var.rg1
sku_name = "B_Gen5_2"
resource "azurerm_postgresql_server" "wt_app" {
name = var.postgresql_server_name
location = var.cloud_location
resource_group_name = var.rg_name
# cheap sku
resource "azurerm_postgresql_server" "alphasite-pgsql-server-dev" {
name = var.database_server_dev
location = var.location
resource_group_name = var.resource_group_name
sku_name = "B_Gen5_2"
resource "azurerm_postgresql_server" "positive1" {
name = "example-psqlserver"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
administrator_login = "psqladminun"
resource "azurerm_postgresql_server" "default" {
name = "diploma-psqlserver"
location = azurerm_resource_group.default.location
resource_group_name = azurerm_resource_group.default.name
administrator_login = "psqladminun"
Security Best Practices for azurerm_postgresql_server
There are 3 settings in azurerm_postgresql_server that should be taken care of for security reasons. The following section explain an overview and example code.
Ensure to disable public access to database
It is better to disable public access to the database to avoid unwilling communications with unknown services if not required.
Ensure to configure the most modern TLS policies available
It is better to use the latest TLS version for database connections.
Ensure to enable SSL enforcement
It is better to enable SSL enforcement to ensure secure transfer and mitigate the risks of compromising the communication data.
Parameters
-
administrator_loginoptional computed - string -
administrator_login_passwordoptional - string -
auto_grow_enabledoptional computed - bool -
backup_retention_daysoptional computed - number -
create_modeoptional - string -
creation_source_server_idoptional - string -
fqdnoptional computed - string -
geo_redundant_backup_enabledoptional computed - bool -
idoptional computed - string -
infrastructure_encryption_enabledoptional - bool -
locationrequired - string -
namerequired - string -
public_network_access_enabledoptional - bool -
resource_group_namerequired - string -
restore_point_in_timeoptional - string -
sku_namerequired - string -
ssl_enforcementoptional computed - string -
ssl_enforcement_enabledoptional - bool -
ssl_minimal_tls_version_enforcedoptional - string -
storage_mboptional computed - number -
tagsoptional - map from string to string -
versionrequired - string -
identitylist block-
principal_idoptional computed - string -
tenant_idoptional computed - string -
typerequired - string
-
-
storage_profilelist block-
auto_growoptional computed - string -
backup_retention_daysoptional - number -
geo_redundant_backupoptional computed - string -
storage_mboptional - number
-
-
threat_detection_policylist block-
disabled_alertsoptional - set of string -
email_account_adminsoptional - bool -
email_addressesoptional - set of string -
enabledoptional - bool -
retention_daysoptional - number -
storage_account_access_keyoptional - string -
storage_endpointoptional - string
-
-
timeoutssingle block
Explanation in Terraform Registry
Manages a PostgreSQL Server.
Tips: Best Practices for The Other Azure Database Resources
In addition to the azurerm_mariadb_firewall_rule, Azure Database has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
azurerm_mariadb_firewall_rule
Ensure database firewalls do not permit public access
It is better to restrict IP address ranges that can access the database by firewall rules. If both start_ip_address and end_ip_address are set to 0.0.0.0, it blocks connections from the Internet and accepts connections from all Azure datacenter IP addresses.
azurerm_mariadb_server
Ensure that access to Azure SQL Database is restricted
It is better to disable public access to the database to avoid unwilling communications with unknown services if not required.
azurerm_mssql_database_extended_auditing_policy
Ensure to configure retention periods of database auditing to enough duration
It is better to configure retention periods of database auditing to enough duration. It would be better to set greater than at least 90 days.
azurerm_mssql_server
Ensure to enable auditing on Azure SQL databases
It is better to enable auditing on Azure SQL databases. It helps you maintain regulatory compliance, monitor the activities indicating unexpected incidents or suspected security violations.
azurerm_mssql_server_security_alert_policy
Ensure to configure at least one email address for threat alerts
It is better to configure at least one email address for threat alerts. SQL Server is able to send alerts for threat detection via emails and it could support us to notice the incident on time.
azurerm_mysql_firewall_rule
Ensure database firewalls do not permit public access
It is better to restrict IP address ranges that can access the database by firewall rules. If both start_ip_address and end_ip_address are set to 0.0.0.0, it blocks connections from the Internet and accepts connections from all Azure datacenter IP addresses.
azurerm_mysql_server
Ensure to disable public access to database
It is better to disable public access to the database to avoid unwilling communications with unknown services if not required.
azurerm_postgresql_firewall_rule
Ensure database firewalls do not permit public access
It is better to restrict IP address ranges that can access the database by firewall rules. If both start_ip_address and end_ip_address are set to 0.0.0.0, it blocks connections from the Internet and accepts connections from all Azure datacenter IP addresses.
azurerm_sql_firewall_rule
Ensure database firewalls do not permit public access
It is better to restrict IP address ranges that can access the database by firewall rules. If both start_ip_address and end_ip_address are set to 0.0.0.0, it blocks connections from the Internet and accepts connections from all Azure datacenter IP addresses.
azurerm_sql_server
Ensure to enable auditing on Azure SQL databases
It is better to enable auditing on Azure SQL databases. It helps you maintain regulatory compliance, monitor the activities indicating unexpected incidents or suspected security violations.
Microsoft.DBforPostgreSQL/servers (Azure Resource Manager)
The servers in Microsoft.DBforPostgreSQL can be configured in Azure Resource Manager with the resource name Microsoft.DBforPostgreSQL/servers. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
An example could not be found in GitHub.
Frequently asked questions
What is Azure Database PostgreSQL Server?
Azure Database PostgreSQL Server is a resource for Database of Microsoft Azure. Settings can be wrote in Terraform.
Where can I find the example code for the Azure Database PostgreSQL Server?
For Terraform, the gilyas/infracost, infracost/infracost and awsdevopsbykumar/at source code examples are useful. See the Terraform Example section for further details.