Skip to content

Commit e2fd52b

Browse files
authored
Merge pull request #305 from sassoftware/staging
6.5.0 - April 20, 2023
2 parents ea0b78f + 586e32a commit e2fd52b

File tree

10 files changed

+158
-16
lines changed

10 files changed

+158
-16
lines changed

TODO.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
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-
- add Private access (VNet Integration) for flexible postgres
87

98
## Update docs
109
- Add this line back into CONFIG-VARS.md @ 122

docs/CONFIG-VARS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ You can use `default_public_access_cidrs` to set a default range for all created
8585
| subnets | Subnets to be created and their settings | map(object) | *check below* | This variable is ignored when subnet_names is set (AKA bring your own subnets). All defined subnets must exist within the vnet address space. |
8686
| cluster_egress_type | The outbound (egress) routing method to be used for this Kubernetes Cluster | string | "loadBalancer" | Possible values: <ul><li>`loadBalancer`<li>`userDefinedRouting`</ul> By default, AKS will create and use a [loadbalancer](https://docs.microsoft.com/en-us/azure/aks/load-balancer-standard) for outgoing connections.<p>Set to `userDefinedRouting` when using your own network [egress](https://docs.microsoft.com/en-us/azure/aks/egress-outboundtype).|
8787
| aks_network_plugin | Network plugin to use for networking. Currently supported values are `azure` and `kubenet`| string | `kubenet`| For details see Azure's documentation on: [configure kubenet](https://docs.microsoft.com/en-us/azure/aks/configure-kubenet), [Configure Azure CNI](https://learn.microsoft.com/en-us/azure/aks/configure-azure-cni).<br>**Note**: To support Azure CNI your Subnet must be large enough to accommodate the nodes, pods, and all Kubernetes and Azure resources that might be provisioned in your cluster.<br>To calculate the minimum subnet size including an additional node for upgrade operations use formula: `(number of nodes + 1) + ((number of nodes + 1) * maximum pods per node that you configure)` <br>Example for a 5 node cluster: `(5) + (5 * 110) = 555 (/22 or larger)`|
88-
| aks_network_policy | Sets up network policy to be used with Azure CNI. Network policy allows to control the traffic flow between pods. Currently supported values are `calico` and `azure`.| string | `azure`| Network policy can only be used when `aks_network_plugin` is set to `azure`. |
88+
| aks_network_policy | Sets up network policy to be used with Azure CNI. Network policy allows to control the traffic flow between pods. Currently supported values are `calico` and `azure`.| string | `azure`| Network policy `azure` is only supported for `aks_network_plugin = azure` and network policy `calico` is supported for both `aks_network_plugin` values `azure` and `kubenet`. |
8989

9090

9191
The default values for the `subnets` variable are as follows:
@@ -340,6 +340,7 @@ Each server element, like `foo = {}`, can contain none, some, or all of the para
340340
| 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.). |
341341
| server_version | The version of the PostgreSQL Flexible server instance | string | "13" | Refer to the [SAS Viya Platform Administration Guide](https://go.documentation.sas.com/doc/en/sasadmincdc/default/itopssr/p05lfgkwib3zxbn1t6nyihexp12n.htm?fromDefault=#p1wq8ouke3c6ixn1la636df9oa1u) for the supported versions of PostgreSQL for the SAS Viya platform. |
342342
| ssl_enforcement_enabled | Enforce SSL on connection to the Azure Database for PostgreSQL Flexible server instance | bool | true | |
343+
| connectivity_method | Network connectivity option to connect to your flexible server. There are two connectivity options available: Public access (allowed IP addresses) and Private access (VNet Integration). Defaults to public access with firewall rules enabled.| string | "public" | Valid options are `public` and `private`. See details [here](https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/concepts-networking) |
343344
| 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) |
344345

345346
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:
@@ -358,6 +359,7 @@ postgres_servers = {
358359
administrator_password = "1tsAB3aut1fulDay"
359360
server_version = "13"
360361
ssl_enforcement_enabled = true
362+
connectivity_method = "public"
361363
postgresql_configurations = [
362364
{
363365
name = "azure.extensions"
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Azure Database for PostgreSQL Flexible Server with the Private access (VNet Integration)
2+
3+
Azure Database for PostgreSQL Flexible Server is a managed service that you can use to run, manage, and scale highly available PostgreSQL servers in the cloud. Azure Database for PostgreSQL - Flexible Server supports two types of mutually exclusive network connectivity methods to connect to your flexible server. The two options are:
4+
5+
* Public access (allowed IP addresses)
6+
* Private access (VNet Integration)
7+
8+
In this document, we will focus on PostgreSQL server with Private access (VNet Integration).
9+
10+
You can deploy a flexible server into your Azure virtual network (VNet). Azure virtual networks provide private and secure network communication. Resources in a virtual network can communicate through private IP addresses that were assigned on this network. In Private access, the connections to the PostgreSQL server are restricted to only within your virtual network. To learn more about it, refer to [Private access (VNet Integration)](https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/concepts-networking#private-access-vnet-integration).
11+
12+
To create PostgreSQL Flexible Server with the private access connectivity method use the example file provided [here](../../examples/sample-input-ppg.tfvars).
13+
14+
# Connect Azure Database for PostgreSQL Flexible Server with the private access connectivity method
15+
16+
Since the PostgreSQL Flexible server is in a virtual network, you can only connect to the server from other Azure services in the same virtual network as the server. The virtual machine must be created in the same region and same subscription. The Linux virtual machine can be used as an SSH tunnel to manage your database server. To connect and manage the server, you can either create a separate Linux virtual machine or use the jump server that was created with your cluster. Below we will see the steps to connect to the jump server and access the PostgreSQL Flexible Server.
17+
18+
## Connect to jump server
19+
20+
Create an SSH connection with the VM using Bash or PowerShell. At your prompt, open an SSH connection to your virtual machine. Replace the IP address with the one from your VM, and replace SSH user's private key used during cluster creation.
21+
22+
```bash
23+
ssh -i <path_to_jump_svr_private_key> [email protected]
24+
```
25+
26+
## Install PostgreSQL client tools
27+
28+
You need to install the postgresql-client tool to be able to connect to the server.
29+
30+
```bash
31+
sudo apt-get update
32+
sudo apt-get install postgresql-client
33+
```
34+
35+
Connections to the database are enforced with SSL, hence you need to download the public SSL certificate.
36+
37+
```bash
38+
wget --no-check-certificate https://dl.cacerts.digicert.com/DigiCertGlobalRootCA.crt.pem
39+
```
40+
41+
With the psql client tool installed, we can now connect to the server from your local environment.
42+
43+
```bash
44+
psql --host=mydemoserver-pg.postgres.database.azure.com --port=5432 --username=myadmin --dbname=postgres --set=sslmode=require --set=sslrootcert=DigiCertGlobalRootCA.crt.pem
45+
```

examples/sample-input-ppg.tfvars

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,67 @@ ssh_public_key = "~/.ssh/id_rsa.pub"
1919
# Tags can be specified matching your tagging strategy.
2020
tags = {} # for example: { "owner|email" = "<you>@<domain>.<com>", "key1" = "value1", "key2" = "value2" }
2121

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'
22+
# PostgreSQL
23+
24+
# Postgres config - By having this entry a database server is created.
25+
# Default networking option: Public access (allowed IP addresses) is enabled
26+
# If you do not need an external database server remove the 'postgres_servers'
2427
# block below.
2528
postgres_servers = {
2629
default = {},
2730
}
2831

32+
# To use Private access (VNet Integration) remove the 'postgres_servers' block above and uncomment the blocks below:
33+
# postgres_servers and subnets
34+
35+
# postgres_servers = {
36+
# default = {
37+
# connectivity_method = "private"
38+
# }
39+
# }
40+
#
41+
# # Subnet for PostgreSQL
42+
# subnets = {
43+
# aks = {
44+
# "prefixes" : ["192.168.0.0/23"],
45+
# "service_endpoints" : ["Microsoft.Sql"],
46+
# "private_endpoint_network_policies_enabled" : true,
47+
# "private_link_service_network_policies_enabled" : false,
48+
# "service_delegations" : {},
49+
# }
50+
# misc = {
51+
# "prefixes" : ["192.168.2.0/24"],
52+
# "service_endpoints" : ["Microsoft.Sql"],
53+
# "private_endpoint_network_policies_enabled" : true,
54+
# "private_link_service_network_policies_enabled" : false,
55+
# "service_delegations" : {},
56+
# }
57+
# netapp = {
58+
# "prefixes" : ["192.168.3.0/24"],
59+
# "service_endpoints" : [],
60+
# "private_endpoint_network_policies_enabled" : false,
61+
# "private_link_service_network_policies_enabled" : false,
62+
# "service_delegations" : {
63+
# netapp = {
64+
# "name" : "Microsoft.Netapp/volumes"
65+
# "actions" : ["Microsoft.Network/networkinterfaces/*", "Microsoft.Network/virtualNetworks/subnets/join/action"]
66+
# }
67+
# }
68+
# }
69+
# postgresql = {
70+
# "prefixes": ["192.168.4.0/24"],
71+
# "service_endpoints": ["Microsoft.Sql"],
72+
# "private_endpoint_network_policies_enabled": true,
73+
# "private_link_service_network_policies_enabled": false,
74+
# "service_delegations": {
75+
# flexpostgres = {
76+
# "name" : "Microsoft.DBforPostgreSQL/flexibleServers"
77+
# "actions" : ["Microsoft.Network/virtualNetworks/subnets/join/action"]
78+
# }
79+
# }
80+
# }
81+
# }
82+
2983
# Azure Container Registry config
3084
create_container_registry = false
3185
container_registry_sku = "Standard"

main.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ module "flex_postgresql" {
225225
server_version = each.value.server_version
226226
firewall_rule_prefix = "${var.prefix}-${each.key}-postgres-firewall-"
227227
firewall_rules = local.postgres_firewall_rules
228+
connectivity_method = each.value.connectivity_method
229+
virtual_network_id = each.value.connectivity_method == "private" ? module.vnet.id : null
230+
delegated_subnet_id = each.value.connectivity_method == "private" ? module.vnet.subnets["postgresql"].id : null
228231
postgresql_configurations = each.value.ssl_enforcement_enabled ? concat(each.value.postgresql_configurations, local.default_postgres_configuration) : concat(
229232
each.value.postgresql_configurations, [{ name : "require_secure_transport", value : "OFF" }], local.default_postgres_configuration)
230233
tags = var.tags

modules/azure_aks/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ resource "azurerm_kubernetes_cluster" "aks" {
2020

2121
network_profile {
2222
network_plugin = var.aks_network_plugin
23-
network_policy = var.aks_network_plugin == "azure" ? var.aks_network_policy : null
23+
network_policy = var.aks_network_plugin == "kubenet" && var.aks_network_policy == "azure" ? null : var.aks_network_policy
24+
2425
# Docs on AKS Advanced Networking config
2526
# https://docs.microsoft.com/en-us/azure/architecture/aws-professional/networking
2627
# https://docs.microsoft.com/en-us/azure/virtual-network/virtual-network-vnet-plan-design-arm

modules/azurerm_postgresql_flex/main.tf

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,24 @@
55
### Managed PostgreSQL Flexible server on Azure ###
66
###################################################
77

8-
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/postgresql_flexible_server
8+
## https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/postgresql_flexible_server
9+
10+
resource "azurerm_private_dns_zone" "flexpsql" {
11+
count = var.connectivity_method == "private" ? 1 : 0
12+
13+
name = "${var.server_name}.postgres.database.azure.com"
14+
resource_group_name = var.resource_group_name
15+
}
16+
17+
resource "azurerm_private_dns_zone_virtual_network_link" "flexpsql" {
18+
count = var.connectivity_method == "private" ? 1 : 0
19+
20+
name = var.server_name
21+
private_dns_zone_name = azurerm_private_dns_zone.flexpsql.0.name
22+
virtual_network_id = var.virtual_network_id
23+
resource_group_name = var.resource_group_name
24+
}
25+
926
resource "azurerm_postgresql_flexible_server" "flexpsql" {
1027
name = "${var.server_name}-flexpsql"
1128
location = var.location
@@ -18,12 +35,16 @@ resource "azurerm_postgresql_flexible_server" "flexpsql" {
1835
administrator_password = var.administrator_password
1936
version = var.server_version
2037
tags = var.tags
38+
delegated_subnet_id = var.delegated_subnet_id
39+
private_dns_zone_id = try(azurerm_private_dns_zone.flexpsql.0.id, null)
40+
41+
depends_on = [azurerm_private_dns_zone_virtual_network_link.flexpsql]
2142

2243
lifecycle {
23-
ignore_changes = [
44+
ignore_changes = [
2445
# Ignore changes to zone on updates after intial creation
2546
zone
26-
]
47+
]
2748
}
2849
}
2950

@@ -39,8 +60,8 @@ resource "azurerm_postgresql_flexible_server_configuration" "flexpsql" {
3960
}
4061

4162
resource "azurerm_postgresql_flexible_server_firewall_rule" "flexpsql" {
42-
count = var.public_network_access_enabled ? length(var.firewall_rules) : 0
43-
63+
count = var.connectivity_method == "public" ? length(var.firewall_rules) : 0
64+
4465
name = format("%s%s", var.firewall_rule_prefix, lookup(var.firewall_rules[count.index], "name", count.index))
4566
server_id = azurerm_postgresql_flexible_server.flexpsql.id
4667
start_ip_address = var.firewall_rules[count.index]["start_ip"]
@@ -49,7 +70,7 @@ resource "azurerm_postgresql_flexible_server_firewall_rule" "flexpsql" {
4970

5071
# NOTE: This firewall rule enables the flag - "Allow public access from any Azure service within Azure to this server"
5172
resource "azurerm_postgresql_flexible_server_firewall_rule" "azure_public" {
52-
count = var.public_network_access_enabled ? 1 : 0
73+
count = var.connectivity_method == "public" ? 1 : 0
5374

5475
name = "Allow-public-access-from-any-Azure-service"
5576
server_id = azurerm_postgresql_flexible_server.flexpsql.id

modules/azurerm_postgresql_flex/variables.tf

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ variable "server_version" {
5656
default = "13"
5757
}
5858

59-
variable "public_network_access_enabled" {
60-
description = "Whether or not public network access is allowed for this server. Defaults to true"
61-
type = bool
62-
default = true
59+
variable "connectivity_method" {
60+
description = "Network connectivity options to connect to your flexible server. Valid options are 'public' and 'private'. Defaults to public"
61+
type = string
62+
default = "public"
6363
}
6464

6565
variable "firewall_rule_prefix" {
@@ -88,3 +88,19 @@ variable "postgresql_configurations" {
8888
}))
8989
default = []
9090
}
91+
92+
variable "virtual_network_id" {
93+
description = "The ID of the Virtual Network that should be linked to the DNS Zone. Changing this forces a new resource to be created."
94+
type = string
95+
}
96+
97+
variable "delegated_subnet_id" {
98+
description = "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."
99+
type = string
100+
}
101+
102+
variable "private_dns_zone_id" {
103+
description = "The ID of the private DNS zone to create the PostgreSQL Flexible Server. Changing this forces a new PostgreSQL Flexible Server to be created."
104+
type = string
105+
default = null
106+
}

variables.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ variable "postgres_server_defaults" {
268268
administrator_password = "my$up3rS3cretPassw0rd"
269269
server_version = "13"
270270
ssl_enforcement_enabled = true
271+
connectivity_method = "public"
271272
postgresql_configurations = []
272273
}
273274
}

versions.tf

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

66
required_version = ">= 1.0.0"
7-
7+
88
required_providers {
99
azurerm = {
1010
source = "hashicorp/azurerm"

0 commit comments

Comments
 (0)