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

azurerm_postgresql_flexible_server - mark public_network_access_enabled as optional #25812

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ func resourcePostgresqlFlexibleServer() *pluginsdk.Resource {

"public_network_access_enabled": {
Type: pluginsdk.TypeBool,
Computed: true,
Optional: true,
Default: true,
},

"replication_role": {
Expand Down Expand Up @@ -781,7 +782,7 @@ func resourcePostgresqlFlexibleServerUpdate(d *pluginsdk.ResourceData, meta inte
}
}

if d.HasChange("private_dns_zone_id") {
if d.HasChange("private_dns_zone_id") || d.HasChange("public_network_access_enabled") {
parameters.Properties.Network = expandArmServerNetwork(d)
}

Expand Down Expand Up @@ -978,6 +979,12 @@ func expandArmServerNetwork(d *pluginsdk.ResourceData) *servers.Network {
network.PrivateDnsZoneArmResourceId = utils.String(v.(string))
}

publicNetworkAccessEnabled := servers.ServerPublicNetworkAccessStateEnabled
if !d.Get("public_network_access_enabled").(bool) {
publicNetworkAccessEnabled = servers.ServerPublicNetworkAccessStateDisabled
}
network.PublicNetworkAccess = pointer.To(publicNetworkAccessEnabled)

return &network
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,27 @@ func TestAccPostgresqlFlexibleServer_updateOnlyWithStorageTier(t *testing.T) {
})
}

func TestAccPostgresqlFlexibleServer_publicNetworkAccessEnabled(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_postgresql_flexible_server", "test")
r := PostgresqlFlexibleServerResource{}
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.publicNetworkAccessEnabled(data, false),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("administrator_password", "create_mode"),
{
Config: r.publicNetworkAccessEnabled(data, true),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("administrator_password", "create_mode"),
})
}

func (PostgresqlFlexibleServerResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := servers.ParseFlexibleServerID(state.ID)
if err != nil {
Expand Down Expand Up @@ -781,18 +802,19 @@ resource "azurerm_private_dns_zone_virtual_network_link" "test" {
}

resource "azurerm_postgresql_flexible_server" "test" {
name = "acctest-fs-%[2]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
administrator_login = "adminTerraform"
administrator_password = "QAZwsx123"
version = "13"
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"
zone = "1"
name = "acctest-fs-%[2]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
administrator_login = "adminTerraform"
administrator_password = "QAZwsx123"
version = "13"
backup_retention_days = 7
storage_mb = 32768
delegated_subnet_id = azurerm_subnet.test.id
private_dns_zone_id = azurerm_private_dns_zone.test.id
public_network_access_enabled = false
sku_name = "GP_Standard_D2s_v3"
zone = "1"

high_availability {
mode = "ZoneRedundant"
Expand Down Expand Up @@ -857,19 +879,20 @@ resource "azurerm_private_dns_zone_virtual_network_link" "test" {
}

resource "azurerm_postgresql_flexible_server" "test" {
name = "acctest-fs-%[2]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
administrator_login = "adminTerraform"
administrator_password = "123wsxQAZ"
version = "13"
backup_retention_days = 10
storage_mb = 65536
storage_tier = "P6"
delegated_subnet_id = azurerm_subnet.test.id
private_dns_zone_id = azurerm_private_dns_zone.test.id
sku_name = "GP_Standard_D2s_v3"
zone = "2"
name = "acctest-fs-%[2]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
administrator_login = "adminTerraform"
administrator_password = "123wsxQAZ"
version = "13"
backup_retention_days = 10
storage_mb = 65536
storage_tier = "P6"
delegated_subnet_id = azurerm_subnet.test.id
private_dns_zone_id = azurerm_private_dns_zone.test.id
public_network_access_enabled = false
sku_name = "GP_Standard_D2s_v3"
zone = "2"

high_availability {
mode = "ZoneRedundant"
Expand Down Expand Up @@ -1378,3 +1401,20 @@ resource "azurerm_postgresql_flexible_server" "test" {
}
`, r.template(data), data.RandomInteger, storageMb, storageTier)
}

func (r PostgresqlFlexibleServerResource) publicNetworkAccessEnabled(data acceptance.TestData, publicNetworkAccessEnabled bool) string {
return fmt.Sprintf(`
%s
resource "azurerm_postgresql_flexible_server" "test" {
name = "acctest-fs-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
administrator_login = "adminTerraform"
administrator_password = "QAZwsx123"
version = "12"
sku_name = "GP_Standard_D2s_v3"
zone = "2"
public_network_access_enabled = %t
}
`, r.template(data), data.RandomInteger, publicNetworkAccessEnabled)
}
25 changes: 14 additions & 11 deletions website/docs/r/postgresql_flexible_server.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,16 @@ resource "azurerm_private_dns_zone_virtual_network_link" "example" {
}

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 = "psqladmin"
administrator_password = "H@Sh1CoR3!"
zone = "1"
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
public_network_access_enabled = false
administrator_login = "psqladmin"
administrator_password = "H@Sh1CoR3!"
zone = "1"

storage_mb = 32768
storage_tier = "P30"
Expand Down Expand Up @@ -118,6 +119,10 @@ The following arguments are supported:

~> **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`.

* `public_network_access_enabled` - (Optional) Specifies whether this PostgreSQL Flexible Server is publicly accessible. Defaults to `true`.

-> **Note:** `public_network_access_enabled` must be set to `false` when `delegated_subnet_id` and `private_dns_zone_id` have a value.

* `high_availability` - (Optional) A `high_availability` block as defined below.

* `identity` - (Optional) An `identity` block as defined below.
Expand Down Expand Up @@ -247,8 +252,6 @@ In addition to the Arguments listed above - the following Attributes are exporte

* `fqdn` - The FQDN of the PostgreSQL Flexible Server.

* `public_network_access_enabled` - Is public network access enabled?

## Timeouts

The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions:
Expand Down