Skip to content

Commit 1561408

Browse files
authored
feat: Paymcloud 579 pg replica in data (#3630)
* wip * precommit * added spoke_replica variable * fixed vnet * fixed metabase references * precommit
1 parent fc2ad61 commit 1561408

File tree

16 files changed

+158
-90
lines changed

16 files changed

+158
-90
lines changed

src/db-security-configuration/env/prod/terraform.tfvars

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ env = "prod"
66
databases = {
77
GPS = {
88
type = "postgresql"
9-
host = "pagopa-p-weu-gpd-pgflex.postgres.database.azure.com"
9+
host = "pagopa-p-weu-gpd-pgflex-ve.reader.postgres.database.azure.com"
1010
db_name = "apd"
1111
username = "metabase"
1212
password_required = true
@@ -26,7 +26,7 @@ databases = {
2626
}
2727
Nodo = {
2828
type = "postgresql"
29-
host = "pagopa-p-itn-nodo-flexible-postgresql.postgres.database.azure.com"
29+
host = "pagopa-p-weu-nodo-pgflex-ve.reader.postgres.database.azure.com"
3030
db_name = "nodo"
3131
username = "metabase"
3232
password_required = true
@@ -46,7 +46,7 @@ databases = {
4646
}
4747
FDR = {
4848
type = "postgresql"
49-
host = "pagopa-p-itn-fdr-flexible-postgresql.postgres.database.azure.com"
49+
host = "pagopa-p-weu-fdr-pgflex-ve.reader.postgres.database.azure.com"
5050
db_name = "fdr"
5151
username = "metabase"
5252
password_required = true
@@ -56,7 +56,7 @@ databases = {
5656
}
5757
FDR3 = {
5858
type = "postgresql"
59-
host = "pagopa-p-itn-fdr-flexible-postgresql.postgres.database.azure.com"
59+
host = "pagopa-p-weu-fdr-pgflex-ve.reader.postgres.database.azure.com"
6060
db_name = "fdr3"
6161
username = "metabase"
6262
password_required = true

src/domains/fdr-common/.terraform.lock.hcl

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/domains/fdr-common/01_network.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ data "azurerm_virtual_network" "vnet_italy" {
99
resource_group_name = local.vnet_italy_rg_name
1010
}
1111

12+
data "azurerm_virtual_network" "spoke_data_vnet" {
13+
name = local.spoke_data_vnet_name
14+
resource_group_name = local.hub_spoke_vnet_rg_name
15+
}
16+
1217
data "azurerm_private_dns_zone" "internal" {
1318
name = local.internal_dns_zone_name
1419
resource_group_name = local.internal_dns_zone_resource_group_name

src/domains/fdr-common/03_postgresql_replica.tf

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,32 @@
1+
12
# Postgres Flexible Server subnet
2-
module "postgres_flexible_snet_itn_replica" {
3-
count = var.geo_replica_enabled ? 1 : 0
4-
source = "./.terraform/modules/__v4__/subnet"
5-
name = "${local.project_replica}-pgres-flexible-snet"
6-
address_prefixes = var.geo_replica_cidr_subnet_postgresql
7-
resource_group_name = data.azurerm_virtual_network.vnet_italy.resource_group_name
8-
virtual_network_name = data.azurerm_virtual_network.vnet_italy.name
9-
service_endpoints = ["Microsoft.Storage"]
10-
private_link_service_network_policies_enabled = true
11-
12-
delegation = {
13-
name = "delegation"
14-
service_delegation = {
15-
name = "Microsoft.DBforPostgreSQL/flexibleServers"
16-
actions = [
17-
"Microsoft.Network/virtualNetworks/subnets/join/action",
18-
]
19-
}
20-
}
21-
}
223

4+
module "postgres_flexible_itn_spoke_snet_replica" {
5+
count = var.geo_replica_enabled ? 1 : 0
6+
source = "./.terraform/modules/__v4__/IDH/subnet"
7+
name = "${local.project_replica}-pgres-spoke-flexible-snet"
8+
resource_group_name = data.azurerm_virtual_network.spoke_data_vnet.resource_group_name
9+
virtual_network_name = data.azurerm_virtual_network.spoke_data_vnet.name
10+
service_endpoints = ["Microsoft.Storage"]
11+
12+
env = var.env
13+
idh_resource_tier = "postgres_flexible"
14+
product_name = var.prefix
15+
16+
tags = module.tag_config.tags
17+
}
2318

2419

25-
module "postgresql_fdr_replica_itn_db" {
20+
module "postgresql_fdr_spoke_replica_itn_db" {
2621
source = "./.terraform/modules/__v4__/postgres_flexible_server_replica"
2722
count = var.geo_replica_enabled ? 1 : 0
2823

29-
name = "${local.project_replica}-flexible-postgresql"
24+
name = "${local.project_replica}-spoke-flexible-postgresql"
3025
resource_group_name = azurerm_resource_group.db_rg.name
3126
location = var.location_replica
3227

3328
private_dns_zone_id = var.env_short != "d" ? data.azurerm_private_dns_zone.postgres.id : null
34-
delegated_subnet_id = module.postgres_flexible_snet_itn_replica[0].id
29+
delegated_subnet_id = module.postgres_flexible_itn_spoke_snet_replica[0].id
3530
private_endpoint_enabled = var.pgres_flex_params.pgres_flex_private_endpoint_enabled
3631

3732
sku_name = var.pgres_flex_params.sku_name
@@ -57,7 +52,7 @@ resource "azurerm_postgresql_flexible_server_virtual_endpoint" "virtual_endpoint
5752
count = var.geo_replica_enabled ? 1 : 0
5853
name = "${local.project}-pgflex-ve"
5954
source_server_id = module.postgres_flexible_server_fdr.id
60-
replica_server_id = module.postgresql_fdr_replica_itn_db[0].id
55+
replica_server_id = module.postgresql_fdr_spoke_replica_itn_db[0].id
6156
type = "ReadWrite"
6257
}
6358

src/domains/fdr-common/99_locals.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ locals {
2525
vnet_italy_name = "${local.product}-${var.location_replica_short}-vnet"
2626
vnet_italy_rg_name = "${local.product}-${var.location_replica_short}-vnet-rg"
2727

28+
29+
spoke_data_vnet_name = "${local.product}-${var.location_replica_short}-spoke-data-vnet"
30+
hub_spoke_vnet_rg_name = "${local.product}-${var.location_replica_short}-network-hub-spoke-rg"
31+
2832
acr_name = replace("${local.product}commonacr", "-", "")
2933
acr_resource_group_name = "${local.product}-container-registry-rg"
3034

src/domains/fdr-common/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
| <a name="module_identity_cd_01"></a> [identity\_cd\_01](#module\_identity\_cd\_01) | ./.terraform/modules/__v4__/github_federated_identity | n/a |
2727
| <a name="module_identity_ci_01"></a> [identity\_ci\_01](#module\_identity\_ci\_01) | ./.terraform/modules/__v4__/github_federated_identity | n/a |
2828
| <a name="module_identity_oidc_01"></a> [identity\_oidc\_01](#module\_identity\_oidc\_01) | ./.terraform/modules/__v4__/github_federated_identity | n/a |
29+
| <a name="module_postgres_flexible_itn_spoke_snet_replica"></a> [postgres\_flexible\_itn\_spoke\_snet\_replica](#module\_postgres\_flexible\_itn\_spoke\_snet\_replica) | ./.terraform/modules/__v4__/IDH/subnet | n/a |
2930
| <a name="module_postgres_flexible_server_fdr"></a> [postgres\_flexible\_server\_fdr](#module\_postgres\_flexible\_server\_fdr) | ./.terraform/modules/__v4__/postgres_flexible_server | n/a |
3031
| <a name="module_postgres_flexible_snet"></a> [postgres\_flexible\_snet](#module\_postgres\_flexible\_snet) | ./.terraform/modules/__v4__/subnet | n/a |
31-
| <a name="module_postgres_flexible_snet_itn_replica"></a> [postgres\_flexible\_snet\_itn\_replica](#module\_postgres\_flexible\_snet\_itn\_replica) | ./.terraform/modules/__v4__/subnet | n/a |
32-
| <a name="module_postgresql_fdr_replica_itn_db"></a> [postgresql\_fdr\_replica\_itn\_db](#module\_postgresql\_fdr\_replica\_itn\_db) | ./.terraform/modules/__v4__/postgres_flexible_server_replica | n/a |
32+
| <a name="module_postgresql_fdr_spoke_replica_itn_db"></a> [postgresql\_fdr\_spoke\_replica\_itn\_db](#module\_postgresql\_fdr\_spoke\_replica\_itn\_db) | ./.terraform/modules/__v4__/postgres_flexible_server_replica | n/a |
3333
| <a name="module_tag_config"></a> [tag\_config](#module\_tag\_config) | ../../tag_config | n/a |
3434
| <a name="module_workload_identity"></a> [workload\_identity](#module\_workload\_identity) | ./.terraform/modules/__v4__/kubernetes_workload_identity_init | n/a |
3535

@@ -124,6 +124,7 @@
124124
| [azurerm_resource_group.rg_vnet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/resource_group) | data source |
125125
| [azurerm_subnet.aks_subnet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/subnet) | data source |
126126
| [azurerm_subscription.current](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/subscription) | data source |
127+
| [azurerm_virtual_network.spoke_data_vnet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/virtual_network) | data source |
127128
| [azurerm_virtual_network.vnet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/virtual_network) | data source |
128129
| [azurerm_virtual_network.vnet_italy](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/virtual_network) | data source |
129130

src/domains/gps-common/.terraform.lock.hcl

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/domains/gps-common/00_data.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ data "azurerm_virtual_network" "vnet_italy" {
88
resource_group_name = local.vnet_italy_resource_group_name
99
}
1010

11+
data "azurerm_virtual_network" "spoke_data_vnet" {
12+
name = local.spoke_data_vnet_name
13+
resource_group_name = local.hub_spoke_vnet_rg_name
14+
}
15+
1116
data "azurerm_virtual_network" "vnet_italy_cstar_integration" {
1217
name = local.vnet_italy_name
1318
resource_group_name = local.vnet_italy_resource_group_name
Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,31 @@
1+
12
#
23
## Postgres Flexible Server subnet
3-
module "postgres_flexible_itn_snet_replica" {
4-
count = var.geo_replica_enabled ? 1 : 0
5-
source = "./.terraform/modules/__v4__/subnet"
6-
name = "${local.project_replica}-pgres-flexible-snet"
7-
address_prefixes = var.geo_replica_cidr_subnet_postgresql
8-
resource_group_name = data.azurerm_virtual_network.vnet_italy.resource_group_name
9-
virtual_network_name = data.azurerm_virtual_network.vnet_italy.name
10-
service_endpoints = ["Microsoft.Storage"]
11-
private_link_service_network_policies_enabled = true
12-
13-
delegation = {
14-
name = "delegation"
15-
service_delegation = {
16-
name = "Microsoft.DBforPostgreSQL/flexibleServers"
17-
actions = [
18-
"Microsoft.Network/virtualNetworks/subnets/join/action",
19-
]
20-
}
21-
}
4+
module "postgres_flexible_itn_spoke_snet_replica" {
5+
count = var.geo_replica_enabled ? 1 : 0
6+
source = "./.terraform/modules/__v4__/IDH/subnet"
7+
name = "${local.project_replica}-pgres-spoke-flexible-snet"
8+
resource_group_name = data.azurerm_virtual_network.spoke_data_vnet.resource_group_name
9+
virtual_network_name = data.azurerm_virtual_network.spoke_data_vnet.name
10+
service_endpoints = ["Microsoft.Storage"]
11+
12+
env = var.env
13+
idh_resource_tier = "postgres_flexible"
14+
product_name = var.prefix
15+
16+
tags = module.tag_config.tags
2217
}
2318

24-
25-
26-
module "postgresql_gpd_itn_replica_db" {
19+
module "postgresql_gpd_itn_replica_spoke_db" {
2720
source = "./.terraform/modules/__v4__/postgres_flexible_server_replica"
2821
count = var.geo_replica_enabled ? 1 : 0
2922

30-
name = "${local.project_replica}-pgflex"
23+
name = "${local.project_replica}-spoke-pgflex"
3124
resource_group_name = azurerm_resource_group.flex_data[0].name
3225
location = var.location_replica
3326

3427
private_dns_zone_id = var.env_short != "d" ? data.azurerm_private_dns_zone.postgres.id : null
35-
delegated_subnet_id = module.postgres_flexible_itn_snet_replica[0].id
28+
delegated_subnet_id = module.postgres_flexible_itn_spoke_snet_replica[0].id
3629
private_endpoint_enabled = var.pgres_flex_params.private_endpoint_enabled
3730

3831
sku_name = var.pgres_flex_params.sku_name
@@ -54,12 +47,11 @@ module "postgresql_gpd_itn_replica_db" {
5447
tags = module.tag_config.tags
5548
}
5649

57-
5850
resource "azurerm_postgresql_flexible_server_virtual_endpoint" "virtual_endpoint" {
5951
count = var.geo_replica_enabled ? 1 : 0
6052
name = "${local.product}-${var.location_short}-gpd-pgflex-ve"
6153
source_server_id = module.postgres_flexible_server_private_db.id
62-
replica_server_id = module.postgresql_gpd_itn_replica_db[0].id
54+
replica_server_id = module.postgresql_gpd_itn_replica_spoke_db[0].id
6355
type = "ReadWrite"
6456
}
6557

@@ -71,4 +63,3 @@ resource "azurerm_private_dns_cname_record" "cname_record" {
7163
ttl = 300
7264
record = "${azurerm_postgresql_flexible_server_virtual_endpoint.virtual_endpoint[0].name}.writer.postgres.database.azure.com"
7365
}
74-

src/domains/gps-common/99_locals.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ locals {
2020
vnet_name = "${local.product}-vnet"
2121
vnet_resource_group_name = "${local.product}-vnet-rg"
2222

23+
spoke_data_vnet_name = "${local.product}-${var.location_replica_short}-spoke-data-vnet"
24+
hub_spoke_vnet_rg_name = "${local.product}-${var.location_replica_short}-network-hub-spoke-rg"
25+
2326
vnet_italy_name = "${local.product}-itn-vnet"
2427
vnet_italy_cstar_integration_name = "${local.product}-itn-cstar-integration-vnet"
2528
vnet_italy_resource_group_name = "${local.product}-itn-vnet-rg"

0 commit comments

Comments
 (0)