Manages a PostgreSQL Flexible Server.
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "West Europe"
}
resource "azurerm_virtual_network" "example" {
name = "example-vn"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
address_space = ["10.0.0.0/16"]
}
resource "azurerm_subnet" "example" {
name = "example-sn"
resource_group_name = azurerm_resource_group.example.name
virtual_network_name = azurerm_virtual_network.example.name
address_prefixes = ["10.0.2.0/24"]
service_endpoints = ["Microsoft.Storage"]
delegation {
name = "fs"
service_delegation {
name = "Microsoft.DBforPostgreSQL/flexibleServers"
actions = [
"Microsoft.Network/virtualNetworks/subnets/join/action",
]
}
}
}
resource "azurerm_private_dns_zone" "example" {
name = "example.postgres.database.azure.com"
resource_group_name = azurerm_resource_group.example.name
}
resource "azurerm_private_dns_zone_virtual_network_link" "example" {
name = "exampleVnetZone.com"
private_dns_zone_name = azurerm_private_dns_zone.example.name
virtual_network_id = azurerm_virtual_network.example.id
resource_group_name = azurerm_resource_group.example.name
depends_on = [azurerm_subnet.example]
}
resource "azurerm_postgresql_flexible_server" "example" {
name = "example-psqlflexibleserver"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
version = "12"
delegated_subnet_id = azurerm_subnet.example.id
private_dns_zone_id = azurerm_private_dns_zone.example.id
administrator_login = "psqladmin"
administrator_password = "H@Sh1CoR3!"
zone = "1"
storage_mb = 32768
storage_tier = "P30"
sku_name = "GP_Standard_D4s_v3"
depends_on = [azurerm_private_dns_zone_virtual_network_link.example]
}
The following arguments are supported:
name
- (Required) The name which should be used for this PostgreSQL Flexible Server. Changing this forces a new PostgreSQL Flexible Server to be created.resource_group_name
- (Required) The name of the Resource Group where the PostgreSQL Flexible Server should exist. Changing this forces a new PostgreSQL Flexible Server to be created.
location
- (Required) The Azure Region where the PostgreSQL Flexible Server should exist. Changing this forces a new PostgreSQL Flexible Server to be created.
administrator_login
- (Optional) The Administrator login for the PostgreSQL Flexible Server. Required when create_mode
is Default
and authentication.password_auth_enabled
is true
.
administrator_password
- (Optional) The Password associated with the administrator_login
for the PostgreSQL Flexible Server. Required when create_mode
is Default
and authentication.password_auth_enabled
is true
.
authentication
- (Optional) An authentication
block as defined below.
backup_retention_days
- (Optional) The backup retention days for the PostgreSQL Flexible Server. Possible values are between 7
and 35
days.
customer_managed_key
- (Optional) A customer_managed_key
block as defined below. Changing this forces a new resource to be created.
geo_redundant_backup_enabled
- (Optional) Is Geo-Redundant backup enabled on the PostgreSQL Flexible Server. Defaults to false
. Changing this forces a new PostgreSQL Flexible Server to be created.
create_mode
- (Optional) The creation mode which can be used to restore or replicate existing servers. Possible values are Default
, GeoRestore
, PointInTimeRestore
, Replica
and Update
. Changing this forces a new PostgreSQL Flexible Server to be created.
delegated_subnet_id
- (Optional) The ID of the virtual network subnet to create the PostgreSQL Flexible Server. The provided subnet should not have any other resource deployed in it and this subnet will be delegated to the PostgreSQL Flexible Server, if not already delegated. Changing this forces a new PostgreSQL Flexible Server to be created.
private_dns_zone_id
- (Optional) The ID of the private DNS zone to create the PostgreSQL Flexible Server.
high_availability
- (Optional) A high_availability
block as defined below.
identity
- (Optional) An identity
block as defined below.
maintenance_window
- (Optional) A maintenance_window
block as defined below.
point_in_time_restore_time_in_utc
- (Optional) The point in time to restore from source_server_id
when create_mode
is GeoRestore
, PointInTimeRestore
. Changing this forces a new PostgreSQL Flexible Server to be created.
replication_role
- (Optional) The replication role for the PostgreSQL Flexible Server. Possible value is None
.
sku_name
- (Optional) The SKU Name for the PostgreSQL Flexible Server. The name of the SKU, follows the tier
+ name
pattern (e.g. B_Standard_B1ms
, GP_Standard_D2s_v3
, MO_Standard_E4s_v3
).
source_server_id
- (Optional) The resource ID of the source PostgreSQL Flexible Server to be restored. Required when create_mode
is GeoRestore
, PointInTimeRestore
or Replica
. Changing this forces a new PostgreSQL Flexible Server to be created.
auto_grow_enabled
- (Optional) Is the storage auto grow for PostgreSQL Flexible Server enabled? Defaults to false
.
storage_mb
- (Optional) The max storage allowed for the PostgreSQL Flexible Server. Possible values are 32768
, 65536
, 131072
, 262144
, 524288
, 1048576
, 2097152
, 4193280
, 4194304
, 8388608
, 16777216
and 33553408
.
storage_tier
- (Optional) The name of storage performance tier for IOPS of the PostgreSQL Flexible Server. Possible values are P4
, P6
, P10
, P15
,P20
, P30
,P40
, P50
,P60
, P70
or P80
. Default value is dependant on the storage_mb
value. Please see the storage_tier
defaults based on storage_mb
table below.tags
- (Optional) A mapping of tags which should be assigned to the PostgreSQL Flexible Server.
version
- (Optional) The version of PostgreSQL Flexible Server to use. Possible values are 11
,12
, 13
, 14
, 15
and 16
. Required when create_mode
is Default
.
zone
- (Optional) Specifies the Availability Zone in which the PostgreSQL Flexible Server should be located.An authentication
block supports the following:
active_directory_auth_enabled
- (Optional) Whether or not Active Directory authentication is allowed to access the PostgreSQL Flexible Server. Defaults to false
.
password_auth_enabled
- (Optional) Whether or not password authentication is allowed to access the PostgreSQL Flexible Server. Defaults to true
.
tenant_id
- (Optional) The Tenant ID of the Azure Active Directory which is used by the Active Directory authentication. active_directory_auth_enabled
must be set to true
.
A customer_managed_key
block supports the following:
key_vault_key_id
- (Required) The ID of the Key Vault Key.
primary_user_assigned_identity_id
- (Optional) Specifies the primary user managed identity id for a Customer Managed Key. Should be added with identity_ids
.
geo_backup_key_vault_key_id
- (Optional) The ID of the geo backup Key Vault Key. It can't cross region and need Customer Managed Key in same region as geo backup.
geo_backup_user_assigned_identity_id
- (Optional) The geo backup user managed identity id for a Customer Managed Key. Should be added with identity_ids
. It can't cross region and need identity in same region as geo backup.
An identity
block supports the following:
type
- (Required) Specifies the type of Managed Service Identity that should be configured on this PostgreSQL Flexible Server. The only possible value is UserAssigned
.
identity_ids
- (Required) A list of User Assigned Managed Identity IDs to be assigned to this PostgreSQL Flexible Server. Required if used together with customer_managed_key
block.
A maintenance_window
block supports the following:
day_of_week
- (Optional) The day of week for maintenance window, where the week starts on a Sunday, i.e. Sunday = 0
, Monday = 1
. Defaults to 0
.
start_hour
- (Optional) The start hour for maintenance window. Defaults to 0
.
start_minute
- (Optional) The start minute for maintenance window. Defaults to 0
.
A high_availability
block supports the following:
mode
- (Required) The high availability mode for the PostgreSQL Flexible Server. Possible value are SameZone
or ZoneRedundant
.
standby_availability_zone
- (Optional) Specifies the Availability Zone in which the standby Flexible Server should be located.
storage_tier
defaults based on storage_mb
storage_mb |
GiB | TiB | Default | Supported storage_tier 's |
Provisioned IOPS |
---|---|---|---|---|---|
32768 | 32 | - | P4 | P4, P6, P10, P15, P20, P30, P40, P50 | 120 |
65536 | 64 | - | P6 | P6, P10, P15, P20, P30, P40, P50 | 240 |
131072 | 128 | - | P10 | P10, P15, P20, P30, P40, P50 | 500 |
262144 | 256 | - | P15 | P15, P20, P30, P40, P50 | 1,100 |
524288 | 512 | - | P20 | P20, P30, P40, P50 | 2,300 |
1048576 | 1024 | 1 | P30 | P30, P40, P50 | 5,000 |
2097152 | 2048 | 2 | P40 | P40, P50 | 7,500 |
4193280 | 4095 | 4 | P50 | P50 | 7,500 |
4194304 | 4096 | 4 | P50 | P50 | 7,500 |
8388608 | 8192 | 8 | P60 | P60, P70 | 16,000 |
16777216 | 16384 | 16 | P70 | P70, P80 | 18,000 |
33553408 | 32767 | 32 | P80 | P80 | 20,000 |
In addition to the Arguments listed above - the following Attributes are exported:
id
- The ID of the PostgreSQL Flexible Server.
fqdn
- The FQDN of the PostgreSQL Flexible Server.
public_network_access_enabled
- Is public network access enabled?
The timeouts
block allows you to specify timeouts for certain actions:
create
- (Defaults to 1 hour) Used when creating the PostgreSQL Flexible Server.read
- (Defaults to 5 minutes) Used when retrieving the PostgreSQL Flexible Server.update
- (Defaults to 1 hour) Used when updating the PostgreSQL Flexible Server.delete
- (Defaults to 1 hour) Used when deleting the PostgreSQL Flexible Server.PostgreSQL Flexible Servers can be imported using the resource id
, e.g.
terraform import azurerm_postgresql_flexible_server.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.DBforPostgreSQL/flexibleServers/server1