Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix breaking change of requiring private_dns_zone_id in azurerm_postgresql_flexible_server #12288

Merged
merged 24 commits into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
networkValidate "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/postgres/parse"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/postgres/validate"
privateDnsValidate "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/privatedns/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/validation"
Expand Down Expand Up @@ -118,6 +119,17 @@ func resourcePostgresqlFlexibleServer() *pluginsdk.Resource {
ValidateFunc: networkValidate.SubnetID,
},

"private_dns_zone_id": {
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
// This is `computed`, because there is a breaking change to require this field when setting vnet.
// For existing fs who don't want to be recreated, they could contact service team to manually migrate to the private dns zone
// We need to ignore the diff when remote is set private dns zone
ForceNew: true,
ValidateFunc: privateDnsValidate.PrivateDnsZoneID,
},

"point_in_time_restore_time_in_utc": {
Type: pluginsdk.TypeString,
Optional: true,
Expand Down Expand Up @@ -350,6 +362,7 @@ func resourcePostgresqlFlexibleServerRead(d *pluginsdk.ResourceData, meta interf
if network := props.Network; network != nil {
d.Set("public_network_access_enabled", network.PublicNetworkAccess == postgresqlflexibleservers.ServerPublicNetworkAccessStateEnabled)
d.Set("delegated_subnet_id", network.DelegatedSubnetResourceID)
d.Set("private_dns_zone_id", network.PrivateDNSZoneArmResourceID)
}

if err := d.Set("maintenance_window", flattenArmServerMaintenanceWindow(props.MaintenanceWindow)); err != nil {
Expand Down Expand Up @@ -458,6 +471,10 @@ func expandArmServerNetwork(d *pluginsdk.ResourceData) *postgresqlflexibleserver
network.DelegatedSubnetResourceID = utils.String(v.(string))
}

if v, ok := d.GetOk("private_dns_zone_id"); ok {
network.PrivateDNSZoneArmResourceID = utils.String(v.(string))
}

return &network
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,18 @@ resource "azurerm_subnet" "test" {
}
}

resource "azurerm_private_dns_zone" "test" {
name = "acc%[2]d.postgres.database.azure.com"
resource_group_name = azurerm_resource_group.test.name
}

resource "azurerm_private_dns_zone_virtual_network_link" "test" {
name = "acctestVnetZone%[2]d.com"
private_dns_zone_name = azurerm_private_dns_zone.test.name
virtual_network_id = azurerm_virtual_network.test.id
resource_group_name = azurerm_resource_group.test.name
}

resource "azurerm_postgresql_flexible_server" "test" {
name = "acctest-fs-%[2]d"
resource_group_name = azurerm_resource_group.test.name
Expand All @@ -302,6 +314,7 @@ resource "azurerm_postgresql_flexible_server" "test" {
backup_retention_days = 7
storage_mb = 32768
delegated_subnet_id = azurerm_subnet.test.id
private_dns_zone_id = azurerm_private_dns_zone.test.id
sku_name = "GP_Standard_D2s_v3"

maintenance_window {
Expand All @@ -313,6 +326,8 @@ resource "azurerm_postgresql_flexible_server" "test" {
tags = {
ENV = "Test"
}

depends_on = [azurerm_private_dns_zone_virtual_network_link.test]
}
`, r.template(data), data.RandomInteger)
}
Expand Down Expand Up @@ -345,6 +360,18 @@ resource "azurerm_subnet" "test" {
}
}

resource "azurerm_private_dns_zone" "test" {
name = "acc%[2]d.postgres.database.azure.com"
resource_group_name = azurerm_resource_group.test.name
}

resource "azurerm_private_dns_zone_virtual_network_link" "test" {
name = "acctestVnetZone%[2]d.com"
private_dns_zone_name = azurerm_private_dns_zone.test.name
virtual_network_id = azurerm_virtual_network.test.id
resource_group_name = azurerm_resource_group.test.name
}

resource "azurerm_postgresql_flexible_server" "test" {
name = "acctest-fs-%[2]d"
resource_group_name = azurerm_resource_group.test.name
Expand All @@ -356,6 +383,7 @@ resource "azurerm_postgresql_flexible_server" "test" {
backup_retention_days = 10
storage_mb = 65536
delegated_subnet_id = azurerm_subnet.test.id
private_dns_zone_id = azurerm_private_dns_zone.test.id
sku_name = "GP_Standard_D2s_v3"

maintenance_window {
Expand All @@ -367,6 +395,8 @@ resource "azurerm_postgresql_flexible_server" "test" {
tags = {
ENV = "Stage"
}

depends_on = [azurerm_private_dns_zone_virtual_network_link.test]
}
`, r.template(data), data.RandomInteger)
}
Expand Down
20 changes: 19 additions & 1 deletion website/docs/r/postgresql_flexible_server.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,33 @@ resource "azurerm_subnet" "example" {
}
}
}
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
}

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 = "psqladminun"
administrator_password = "H@Sh1CoR3!"

storage_mb = 32768

sku_name = "GP_Standard_D4s_v3"
sku_name = "GP_Standard_D4s_v3"
depends_on = [azurerm_private_dns_zone_virtual_network_link.example]

}
```

Expand All @@ -83,6 +97,10 @@ The following arguments are supported:

* `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. Changing this forces a new PostgreSQL Flexible Server to be created.

~> **NOTE:** There will be a breaking change from upstream service at 15th July 2021, the `private_dns_zone_id` will be required when setting a `delegated_subnet_id`. For existing flexible servers who don't want to be recreated, you need to provide the `private_dns_zone_id` to the service team to manually migrate to the specified private dns zone. The `azurerm_private_dns_zone` should end with suffix `.postgres.database.azure.com`.

* `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 `creation_source_server_id` when `create_mode` is `PointInTimeRestore`. Changing this forces a new PostgreSQL Flexible Server to be created.
Expand Down