Skip to content

Commit f414906

Browse files
authored
Data Server Updates (#185)
1 parent 949135f commit f414906

12 files changed

+175
-154
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ RUN apk --update --no-cache add git openssh \
1515
&& chmod 755 ./kubectl /viya4-iac-azure/docker-entrypoint.sh \
1616
&& mv ./kubectl /usr/local/bin/kubectl \
1717
&& chmod g=u -R /etc/passwd /etc/group /viya4-iac-azure \
18-
&& chdir /viya4-iac-azure ; terraform init
18+
&& terraform init
1919

2020
ENV TF_VAR_iac_tooling=docker
2121
ENTRYPOINT ["/viya4-iac-azure/docker-entrypoint.sh"]

docs/CONFIG-VARS.md

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Supported configuration variables are listed in the tables below. All variables
1919
- [NFS Server VM (only when `storage_type=standard`)](#nfs-server-vm-only-when-storage_typestandard)
2020
- [Azure NetApp Files (only when `storage_type=ha`)](#azure-netapp-files-only-when-storage_typeha)
2121
- [Azure Container Registry (ACR)](#azure-container-registry-acr)
22-
- [PostgreSQL](#postgresql)
22+
- [Postgres Servers](#postgres-servers)
2323

2424
Terraform input variables can be set in the following ways:
2525

@@ -298,20 +298,54 @@ When `storage_type=ha` (high availability), [Microsoft Azure NetApp Files](https
298298
| container_registry_admin_enabled | Enables the admin user | bool | false | |
299299
| container_registry_geo_replica_locs | List of Azure locations where the container registry should be geo-replicated. | list of strings | null | This is only supported when `container_registry_sku` is set to `"Premium"`. |
300300

301-
## PostgreSQL
301+
## Postgres Servers
302+
303+
When setting up ***external database servers***, you must provide information about those servers in the `postgres_servers` variable block. Each entry in the variable block represents a ***single database server***.
304+
305+
This code only configures database servers. No databases are created during the infrastructure setup.
306+
307+
The variable has the following format:
308+
309+
```terraform
310+
postgres_servers = {
311+
default = {},
312+
...
313+
}
314+
```
315+
316+
**NOTE**: The `default = {}` elements is always required when creating external databases. This is the systems default database server.
317+
318+
Each server element, like `foo = {}`, can contain none, some, or all of the parameters listed below:
302319

303320
| Name | Description | Type | Default | Notes |
304321
| :--- | ---: | ---: | ---: | ---: |
305-
| create_postgres | Create an Azure Database for PostgreSQL server instance | bool | false | |
306-
| postgres_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).|
307-
| postgres_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 |
308-
| postgres_backup_retention_days | Backup retention days for the PostgreSQL server. | number | 7 | Supported values are between 7 and 35 days. |
309-
| postgres_geo_redundant_backup_enabled | Whether to enable Geo-redundant for server backup. | bool | false | Not supported for the basic tier. |
310-
| postgres_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) |
311-
| postgres_administrator_password | The password associated with the postgres_administrator_login for the PostgreSQL Server. | string | | 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.). |
312-
| postgres_server_version | The version of the Azure Database for PostgreSQL server instance. Valid values are "9.5", "9.6", "10.0", and "11". Changing this forces a new resource to be created.| string | "11" | |
313-
| postgres_ssl_enforcement_enabled | Enforce SSL on connection to the Azure Database for PostgreSQL server instance | bool | true | |
314-
| postgres_db_names | List of names for databases to create for the Azure Database for PostgreSQL server instance. Each name needs to be a valid PostgreSQL identified. Changes this forces a new resource to be created. | list of strings | [] | |
315-
| postgres_db_charset | The Charset for the PostgreSQL Database. Must be a valid PostgreSQL Charset. Changing this forces a new resource to be created. | string | "UTF8" | |
316-
| postgres_db_collation | The Collation for the PostgreSQL Database. Needs to be a valid PostgreSQL Collation. Changing this forces a new resource to be created. |string| "English_United States.1252" | |
317-
| postgres_configurations | Configurations to enable on the PostgreSQL Database server instance. | map | {} | |
322+
| 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).|
323+
| 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 |
324+
| backup_retention_days | Backup retention days for the PostgreSQL server | number | 7 | Supported values are between 7 and 35 days. |
325+
| geo_redundant_backup_enabled | Enable Geo-redundant or not for server backup | bool | false | Not supported for the basic tier. |
326+
| 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) |
327+
| 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.). |
328+
| server_version | The version of the Azure Database for PostgreSQL server instance. Changing this forces a new resource to be created.| string | "11" | |
329+
| ssl_enforcement_enabled | Enforce SSL on connection to the Azure Database for PostgreSQL server instance | bool | true | |
330+
| 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) |
331+
332+
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:
333+
334+
```terraform
335+
postgres_servers = {
336+
default = {
337+
administrator_password = "D0ntL00kTh1sWay"
338+
},
339+
another_server = {
340+
sku_name = "GP_Gen5_32"
341+
storage_mb = 51200
342+
backup_retention_days = 7
343+
geo_redundant_backup_enabled = false
344+
administrator_login = "pgadmin"
345+
administrator_password = "1tsAB3aut1fulDay"
346+
server_version = "11"
347+
ssl_enforcement_enabled = true
348+
postgresql_configurations = { foo = "true", bar = "false" }
349+
}
350+
}
351+
```

examples/sample-input-byo.tfvars

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ default_public_access_cidrs = [] # e.g., ["123.45.6.89/32"]
2929
# Tags for all taggable items in your cluster.
3030
tags = {} # e.g., { "key1" = "value1", "key2" = "value2" }
3131

32-
# Azure Postgres config
33-
create_postgres = true # set this to "false" when using internal Crunchy Postgres
34-
postgres_ssl_enforcement_enabled = false
35-
postgres_administrator_password = "mySup3rS3cretPassw0rd"
32+
# Postgres config - By having this entry a database server is created. If you do not
33+
# need an external database server remove the 'postgres_servers'
34+
# block below.
35+
postgres_servers = {
36+
default = {},
37+
}
3638

3739
# Azure Container Registry config
3840
create_container_registry = false

examples/sample-input-ha.tfvars

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ default_public_access_cidrs = [] # e.g., ["123.45.6.89/32"]
1919
# Tags can be specified matching your tagging strategy.
2020
tags = {} # for example: { "owner|email" = "<you>@<domain>.<com>", "key1" = "value1", "key2" = "value2" }
2121

22-
# Azure Postgres config
23-
create_postgres = true # set this to "false" when using internal Crunchy Postgres
24-
postgres_ssl_enforcement_enabled = false
25-
postgres_administrator_password = "mySup3rS3cretPassw0rd"
22+
# Postgres config - By having this entry a database server is created. If you do not
23+
# need an external database server remove the 'postgres_servers'
24+
# block below.
25+
postgres_servers = {
26+
default = {},
27+
}
2628

2729
# Azure Container Registry config
2830
create_container_registry = false

examples/sample-input-minimal.tfvars

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ default_public_access_cidrs = [] # e.g., ["123.45.6.89/32"]
1919
# Tags can be specified matching your tagging strategy.
2020
tags = {} # for example: { "owner|email" = "<you>@<domain>.<com>", "key1" = "value1", "key2" = "value2" }
2121

22-
# Azure Postgres config
23-
create_postgres = false # set this to "false" when using internal Crunchy Postgres
24-
postgres_ssl_enforcement_enabled = false
25-
postgres_administrator_password = "mySup3rS3cretPassw0rd"
22+
# Postgres config - By having this entry a database server is created. If you do not
23+
# need an external database server remove the 'postgres_servers'
24+
# block below.
25+
# postgres_servers = {
26+
# default = {},
27+
# }
2628

2729
# Azure Container Registry config
2830
create_container_registry = false

examples/sample-input-ppg.tfvars

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ default_public_access_cidrs = [] # e.g., ["123.45.6.89/32"]
1919
# Tags can be specified matching your tagging strategy.
2020
tags = {} # for example: { "owner|email" = "<you>@<domain>.<com>", "key1" = "value1", "key2" = "value2" }
2121

22-
# Azure Postgres config
23-
create_postgres = true # set this to "false" when using internal Crunchy Postgres
24-
postgres_ssl_enforcement_enabled = false
25-
postgres_administrator_password = "mySup3rS3cretPassw0rd"
22+
# Postgres config - By having this entry a database server is created. If you do not
23+
# need an external database server remove the 'postgres_servers'
24+
# block below.
25+
postgres_servers = {
26+
default = {},
27+
}
2628

2729
# Azure Container Registry config
2830
create_container_registry = false

examples/sample-input.tfvars

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ default_public_access_cidrs = [] # e.g., ["123.45.6.89/32"]
2121
# Tags can be specified matching your tagging strategy.
2222
tags = {} # for example: { "owner|email" = "<you>@<domain>.<com>", "key1" = "value1", "key2" = "value2" }
2323

24-
# Azure Postgres config
25-
create_postgres = true # set this to "false" when using internal Crunchy Postgres
26-
postgres_ssl_enforcement_enabled = false
27-
postgres_administrator_password = "mySup3rS3cretPassw0rd"
24+
# Postgres config - By having this entry a database server is created. If you do not
25+
# need an external database server remove the 'postgres_servers'
26+
# block below.
27+
postgres_servers = {
28+
default = {},
29+
}
2830

2931
# Azure Container Registry config
3032
create_container_registry = false

locals.tf

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,40 @@
11
locals {
2-
is_private = var.infra_mode == "private" ? true : false
3-
is_standard = var.infra_mode == "standard" ? true : false
2+
3+
# Useful flags
4+
is_private = var.infra_mode == "private" ? true : false
5+
is_standard = var.infra_mode == "standard" ? true : false
6+
create_jump_public_ip = var.create_jump_public_ip == null ? local.is_standard : var.create_jump_public_ip
7+
create_nfs_public_ip = var.create_nfs_public_ip == null ? local.is_standard : var.create_nfs_public_ip
48

9+
# CIDR/Network
510
default_public_access_cidrs = local.is_private ? [] : (var.default_public_access_cidrs == null ? [] : var.default_public_access_cidrs)
611
vm_public_access_cidrs = local.is_private ? [] : (var.vm_public_access_cidrs == null ? local.default_public_access_cidrs : var.vm_public_access_cidrs)
712
acr_public_access_cidrs = local.is_private ? [] : (var.acr_public_access_cidrs == null ? local.default_public_access_cidrs : var.acr_public_access_cidrs)
813
cluster_endpoint_public_access_cidrs = local.is_private ? [] : (var.cluster_endpoint_public_access_cidrs == null ? local.default_public_access_cidrs : var.cluster_endpoint_public_access_cidrs)
914
postgres_public_access_cidrs = local.is_private ? [] : (var.postgres_public_access_cidrs == null ? local.default_public_access_cidrs : var.postgres_public_access_cidrs)
15+
subnets = { for k, v in var.subnets : k => v if ! ( k == "netapp" && var.storage_type == "standard")}
1016

11-
create_jump_public_ip = var.create_jump_public_ip == null ? local.is_standard : var.create_jump_public_ip
12-
create_nfs_public_ip = var.create_nfs_public_ip == null ? local.is_standard : var.create_nfs_public_ip
17+
# Kubernetes
18+
kubeconfig_filename = "${var.prefix}-aks-kubeconfig.conf"
19+
kubeconfig_path = var.iac_tooling == "docker" ? "/workspace/${local.kubeconfig_filename}" : local.kubeconfig_filename
1320

14-
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)) }]
21+
# PostgreSQL
22+
postgres_servers = var.postgres_servers == null ? {} : { for k, v in var.postgres_servers : k => merge( var.postgres_server_defaults, v, )}
23+
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)) }]
1524

16-
subnets = { for k, v in var.subnets : k => v if ! ( k == "netapp" && var.storage_type == "standard")}
25+
postgres_outputs = length(module.postgresql) != 0 ? { for k,v in module.postgresql :
26+
k => {
27+
"server_name" : module.postgresql[k].server_name,
28+
"fqdn" : module.postgresql[k].server_fqdn,
29+
"admin" : "${module.postgresql[k].administrator_login}@${module.postgresql[k].server_name}",
30+
"password" : module.postgresql[k].administrator_password,
31+
"server_port" : "5432", # TODO - Create a var when supported
32+
"ssl_enforcement_enabled" : local.postgres_servers[k].ssl_enforcement_enabled,
33+
"internal" : false
34+
}
35+
} : {}
36+
37+
# Container Registry
1738
container_registry_sku = title(var.container_registry_sku)
1839

19-
kubeconfig_filename = "${var.prefix}-aks-kubeconfig.conf"
20-
kubeconfig_path = var.iac_tooling == "docker" ? "/workspace/${local.kubeconfig_filename}" : local.kubeconfig_filename
2140
}

main.tf

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## Azure-AKS
2+
#
3+
# Terraform Registry : https://registry.terraform.io/namespaces/Azure
4+
# GitHub Repository : https://github.com/terraform-azurerm-modules
5+
#
16
provider "azurerm" {
27

38
subscription_id = var.subscription_id
@@ -291,25 +296,23 @@ module "postgresql" {
291296
source = "Azure/postgresql/azurerm"
292297
version = "2.1.0"
293298

294-
count = var.create_postgres ? 1 : 0
299+
for_each = local.postgres_servers != null ? length(local.postgres_servers) != 0 ? local.postgres_servers : {} : {}
300+
295301
resource_group_name = module.resource_group.name
296302
location = var.location
297-
server_name = lower("${var.prefix}-pgsql")
298-
sku_name = var.postgres_sku_name
299-
storage_mb = var.postgres_storage_mb
300-
backup_retention_days = var.postgres_backup_retention_days
301-
geo_redundant_backup_enabled = var.postgres_geo_redundant_backup_enabled
302-
administrator_login = var.postgres_administrator_login
303-
administrator_password = var.postgres_administrator_password
304-
server_version = var.postgres_server_version
305-
ssl_enforcement_enabled = var.postgres_ssl_enforcement_enabled
306-
db_names = var.postgres_db_names
307-
db_charset = var.postgres_db_charset
308-
db_collation = var.postgres_db_collation
309-
firewall_rule_prefix = "${var.prefix}-postgres-firewall-"
303+
server_name = lower("${var.prefix}-${each.key}-pgsql")
304+
sku_name = each.value.sku_name
305+
storage_mb = each.value.storage_mb
306+
backup_retention_days = each.value.backup_retention_days
307+
geo_redundant_backup_enabled = each.value.geo_redundant_backup_enabled
308+
administrator_login = each.value.administrator_login
309+
administrator_password = each.value.administrator_password
310+
server_version = each.value.server_version
311+
ssl_enforcement_enabled = each.value.ssl_enforcement_enabled
312+
firewall_rule_prefix = "${var.prefix}-${each.key}-postgres-firewall-"
310313
firewall_rules = local.postgres_firewall_rules
311-
vnet_rule_name_prefix = "${var.prefix}-postgresql-vnet-rule-"
312-
postgresql_configurations = var.postgres_configurations
314+
vnet_rule_name_prefix = "${var.prefix}-${each.key}-postgresql-vnet-rule-"
315+
postgresql_configurations = each.value.postgresql_configurations
313316
tags = module.resource_group.tags
314317

315318
## TODO : requires specific permissions

outputs.tf

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,10 @@ output "aks_cluster_password" {
2222
}
2323

2424
#postgres
25-
output "postgres_server_name" {
26-
value = var.create_postgres ? element(coalescelist(module.postgresql.*.server_name, [" "]), 0) : null
27-
}
28-
output "postgres_fqdn" {
29-
value = var.create_postgres ? element(coalescelist(module.postgresql.*.server_fqdn, [" "]), 0) : null
30-
}
31-
output "postgres_admin" {
32-
value = var.create_postgres ? "${element(coalescelist(module.postgresql.*.administrator_login, [" "]), 0)}@${element(coalescelist(module.postgresql.*.server_name, [" "]), 0)}" : null
33-
}
34-
output "postgres_password" {
35-
value = var.create_postgres ? element(coalescelist(module.postgresql.*.administrator_password, [" "]), 0) : null
36-
sensitive = true
37-
}
38-
output "postgres_server_id" {
39-
value = var.create_postgres ? element(coalescelist(module.postgresql.*.server_id, [" "]), 0) : null
40-
}
41-
output "postgres_server_port" {
42-
value = var.create_postgres ? "5432" : null
43-
}
4425

45-
output "postgres_ssl_enforcement_enabled" {
46-
value = var.create_postgres ? var.postgres_ssl_enforcement_enabled : null
26+
output "postgres_servers" {
27+
value = length(module.postgresql) != 0 ? local.postgres_outputs : null
28+
sensitive = true
4729
}
4830

4931
# jump server

0 commit comments

Comments
 (0)