Skip to content

Commit 93421e4

Browse files
authored
feat: (IAC-91) Support of Azure DB for PostgreSQL flexible server (#261)
* feat: (IAC-91) Support of Azure DB for PostgreSQL flexible server
1 parent f559b86 commit 93421e4

File tree

9 files changed

+358
-192
lines changed

9 files changed

+358
-192
lines changed

TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Changes for SAS locked down
66
- make var for setting outbound_type. Needing for locked down accounts where creating routing tables is not permitted
7-
- make var for postgres vnet_rules. for vpn subscriptions
7+
- add Private access (VNet Integration) for flexible postgres
88

99
## Update docs
1010
- Add this line back into CONFIG-VARS.md @ 122

docs/CONFIG-VARS.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ You can use `default_public_access_cidrs` to set a default range for all created
7272
| default_public_access_cidrs | IP address ranges allowed to access all created cloud resources | list of strings | | Sets a default for all resources. |
7373
| cluster_endpoint_public_access_cidrs | IP address ranges allowed to access the AKS cluster API | list of strings | | For client admin access to the cluster api (by `kubectl`, for example). Only used with `cluster_api_mode=public`|
7474
| vm_public_access_cidrs | IP address ranges allowed to access the VMs | list of strings | | Opens port 22 for SSH access to the jump server and/or NFS VM by adding Ingress Rule on the NSG. Only used with `create_jump_public_ip=true` or `create_nfs_public_ip=true` |
75-
| postgres_public_access_cidrs | IP address ranges allowed to access the Azure PostgreSQL Server | list of strings || Opens port 5432 by adding Ingress Rule on the NSG. Only used when creating postgres instances. |
75+
| postgres_public_access_cidrs | IP address ranges allowed to access the Azure PostgreSQL Flexible Server | list of strings || Opens port 5432 by adding Ingress Rule on the NSG. Only used when creating postgres instances. |
7676
| acr_public_access_cidrs | IP address ranges allowed to access the ACR instance | list of strings || Only used with `create_container_registry=true` |
7777

7878
**NOTE:** In a SCIM environment, the AzureActiveDirectory service tag must be granted access to port 443/HTTPS for the Ingress IP address.
@@ -326,15 +326,15 @@ Each server element, like `foo = {}`, can contain none, some, or all of the para
326326

327327
| Name | Description | Type | Default | Notes |
328328
| :--- | ---: | ---: | ---: | ---: |
329-
| sku_name| The SKU Name for the PostgreSQL Server | string | "GP_Gen5_32" | The name pattern is the SKU, followed by the tier + family + cores (e.g. B_Gen4_1, GP_Gen5_4).|
330-
| storage_mb | Max storage allowed for the PostgreSQL server | number | 51200 | Possible values are between 5120 MB(5GB) and 1048576 MB(1TB) for the Basic SKU and between 5120 MB(5GB) and 4194304 MB(4TB) for General Purpose/Memory Optimized SKUs |
331-
| backup_retention_days | Backup retention days for the PostgreSQL server | number | 7 | Supported values are between 7 and 35 days. |
329+
| sku_name| The SKU Name for the PostgreSQL Flexible Server | string | "GP_Standard_D16s_v3" | The name pattern is the SKU, followed by the tier + family + cores (e.g. B_Standard_B1ms, GP_Standard_D2s_v3, MO_Standard_E4s_v3).|
330+
| storage_mb | The max storage allowed for the PostgreSQL Flexible Server | number | 51200 | Possible values are 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, and 33554432. |
331+
| backup_retention_days | Backup retention days for the PostgreSQL Flexible server | number | 7 | Supported values are between 7 and 35 days. |
332332
| geo_redundant_backup_enabled | Enable Geo-redundant or not for server backup | bool | false | Not supported for the basic tier. |
333-
| administrator_login | The Administrator Login for the PostgreSQL Server. Changing this forces a new resource to be created. | string | "pgadmin" | The admin login name cannot be azure_superuser, azure_pg_admin, admin, administrator, root, guest, or public. It cannot start with pg_. See: [Microsoft Quickstart Server Database](https://docs.microsoft.com/en-us/azure/postgresql/quickstart-create-server-database-portal) |
334-
| administrator_password | The Password associated with the administrator_login for the PostgreSQL Server | string | "my$up3rS3cretPassw0rd" | The password must contain between 8 and 128 characters and must contain characters from three of the following categories: English uppercase letters, English lowercase letters, numbers (0 through 9), and non-alphanumeric characters (!, $, #, %, etc.). |
335-
| server_version | The version of the Azure Database for PostgreSQL server instance. Changing this forces a new resource to be created.| string | "11" | |
336-
| ssl_enforcement_enabled | Enforce SSL on connection to the Azure Database for PostgreSQL server instance | bool | true | |
337-
| postgresql_configurations | Configurations to enable on the PostgreSQL Database server instance | map(string) | {} | More details can be found [here](https://docs.microsoft.com/en-us/azure/postgresql/howto-configure-server-parameters-using-cli) |
333+
| administrator_login | The Administrator Login for the PostgreSQL Flexible Server. Changing this forces a new resource to be created. | string | "pgadmin" | The admin login name cannot be azure_superuser, azure_pg_admin, admin, administrator, root, guest, or public. It cannot start with pg_. See: [Microsoft Quickstart Server Database](https://docs.microsoft.com/en-us/azure/postgresql/flexible-server/quickstart-create-server-portal) |
334+
| administrator_password | The Password associated with the administrator_login for the PostgreSQL Flexible Server | string | "my$up3rS3cretPassw0rd" | The password must contain between 8 and 128 characters and must contain characters from three of the following categories: English uppercase letters, English lowercase letters, numbers (0 through 9), and non-alphanumeric characters (!, $, #, %, etc.). |
335+
| server_version | The version of the Azure Database for PostgreSQL Flexible server instance. Changing this forces a new resource to be created.| string | "13" | |
336+
| ssl_enforcement_enabled | Enforce SSL on connection to the Azure Database for PostgreSQL Flexible server instance | bool | true | |
337+
| postgresql_configurations | Sets a PostgreSQL Configuration value on a Azure PostgreSQL Flexible Server | list(object) | [] | More details can be found [here](https://docs.microsoft.com/en-us/azure/postgresql/flexible-server/howto-configure-server-parameters-using-cli) |
338338

339339
Here is a sample of the `postgres_servers` variable with the `default` entry only overriding the `administrator_password` parameter and the `cps` entry overriding all of the parameters:
340340

@@ -344,15 +344,20 @@ postgres_servers = {
344344
administrator_password = "D0ntL00kTh1sWay"
345345
},
346346
another_server = {
347-
sku_name = "GP_Gen5_32"
348-
storage_mb = 51200
347+
sku_name = "GP_Standard_D16s_v3"
348+
storage_mb = 65536
349349
backup_retention_days = 7
350350
geo_redundant_backup_enabled = false
351351
administrator_login = "pgadmin"
352352
administrator_password = "1tsAB3aut1fulDay"
353-
server_version = "11"
353+
server_version = "13"
354354
ssl_enforcement_enabled = true
355-
postgresql_configurations = { foo = "true", bar = "false" }
355+
postgresql_configurations = [
356+
{
357+
name = "azure.extensions"
358+
value = "PLPGSQL,LTREE"
359+
}
360+
]
356361
}
357362
}
358363
```

locals.tf

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
11
locals {
2-
2+
33
# Useful flags
4-
ssh_public_key = ( var.create_jump_vm || var.storage_type == "standard"
5-
? file(var.ssh_public_key)
6-
: null
7-
)
8-
4+
ssh_public_key = (var.create_jump_vm || var.storage_type == "standard"
5+
? file(var.ssh_public_key)
6+
: null
7+
)
8+
99
# CIDR/Network
1010
default_public_access_cidrs = var.default_public_access_cidrs == null ? [] : var.default_public_access_cidrs
1111
vm_public_access_cidrs = var.vm_public_access_cidrs == null ? local.default_public_access_cidrs : var.vm_public_access_cidrs
1212
acr_public_access_cidrs = var.acr_public_access_cidrs == null ? local.default_public_access_cidrs : var.acr_public_access_cidrs
1313
cluster_endpoint_public_access_cidrs = var.cluster_api_mode == "private" ? [] : (var.cluster_endpoint_public_access_cidrs == null ? local.default_public_access_cidrs : var.cluster_endpoint_public_access_cidrs)
1414
postgres_public_access_cidrs = var.postgres_public_access_cidrs == null ? local.default_public_access_cidrs : var.postgres_public_access_cidrs
1515

16-
subnets = { for k, v in var.subnets : k => v if ! ( k == "netapp" && var.storage_type == "standard")}
16+
subnets = { for k, v in var.subnets : k => v if !(k == "netapp" && var.storage_type == "standard") }
1717

1818
# Kubernetes
1919
kubeconfig_filename = "${var.prefix}-aks-kubeconfig.conf"
2020
kubeconfig_path = var.iac_tooling == "docker" ? "/workspace/${local.kubeconfig_filename}" : local.kubeconfig_filename
2121

2222
# PostgreSQL
23-
postgres_servers = var.postgres_servers == null ? {} : { for k, v in var.postgres_servers : k => merge( var.postgres_server_defaults, v, )}
23+
default_postgres_configuration = [{name: "max_prepared_transactions", value: 1024}]
24+
postgres_servers = var.postgres_servers == null ? {} : { for k, v in var.postgres_servers : k => merge(var.postgres_server_defaults, v, ) }
2425
postgres_firewall_rules = [for addr in local.postgres_public_access_cidrs : { "name" : replace(replace(addr, "/", "_"), ".", "_"), "start_ip" : cidrhost(addr, 0), "end_ip" : cidrhost(addr, abs(pow(2, 32 - split("/", addr)[1]) - 1)) }]
2526

26-
postgres_outputs = length(module.postgresql) != 0 ? { for k,v in module.postgresql :
27+
postgres_outputs = length(module.flex_postgresql) != 0 ? { for k, v in module.flex_postgresql :
2728
k => {
28-
"server_name" : module.postgresql[k].server_name,
29-
"fqdn" : module.postgresql[k].server_fqdn,
30-
"admin" : "${module.postgresql[k].administrator_login}@${module.postgresql[k].server_name}",
31-
"password" : module.postgresql[k].administrator_password,
32-
"server_port" : "5432", # TODO - Create a var when supported
29+
"server_name" : module.flex_postgresql[k].server_name,
30+
"fqdn" : module.flex_postgresql[k].server_fqdn,
31+
"admin" : module.flex_postgresql[k].administrator_login,
32+
"password" : module.flex_postgresql[k].administrator_password,
33+
"server_port" : "5432",
3334
"ssl_enforcement_enabled" : local.postgres_servers[k].ssl_enforcement_enabled,
3435
"internal" : false
3536
}
@@ -38,34 +39,34 @@ locals {
3839
# Container Registry
3940
container_registry_sku = title(var.container_registry_sku)
4041

41-
aks_rg = ( var.resource_group_name == null
42-
? azurerm_resource_group.aks_rg.0
43-
: data.azurerm_resource_group.aks_rg.0
44-
)
42+
aks_rg = (var.resource_group_name == null
43+
? azurerm_resource_group.aks_rg.0
44+
: data.azurerm_resource_group.aks_rg.0
45+
)
4546

46-
network_rg = ( var.vnet_resource_group_name == null
47-
? local.aks_rg
48-
: data.azurerm_resource_group.network_rg.0
49-
)
47+
network_rg = (var.vnet_resource_group_name == null
48+
? local.aks_rg
49+
: data.azurerm_resource_group.network_rg.0
50+
)
5051

5152
nsg = var.nsg_name == null ? azurerm_network_security_group.nsg.0 : data.azurerm_network_security_group.nsg.0
5253
nsg_rg_name = var.nsg_name == null ? local.aks_rg.name : local.network_rg.name
5354

5455
# Use BYO UAI if given, else create a UAI
55-
aks_uai_id = ( var.aks_identity == "uai"
56-
? ( var.aks_uai_name == null
57-
? azurerm_user_assigned_identity.uai.0.id
58-
: data.azurerm_user_assigned_identity.uai.0.id
59-
)
60-
: null
61-
)
56+
aks_uai_id = (var.aks_identity == "uai"
57+
? (var.aks_uai_name == null
58+
? azurerm_user_assigned_identity.uai.0.id
59+
: data.azurerm_user_assigned_identity.uai.0.id
60+
)
61+
: null
62+
)
6263

63-
cluster_egress_type = ( var.cluster_egress_type == null
64-
? ( var.egress_public_ip_name == null
65-
? "loadBalancer"
66-
: "userDefinedRouting"
67-
)
68-
: var.cluster_egress_type
69-
)
64+
cluster_egress_type = (var.cluster_egress_type == null
65+
? (var.egress_public_ip_name == null
66+
? "loadBalancer"
67+
: "userDefinedRouting"
68+
)
69+
: var.cluster_egress_type
70+
)
7071
}
7172

0 commit comments

Comments
 (0)