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 12 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 @@ -110,15 +110,16 @@ resource "azurerm_resource_group" "test" {
}

resource "azurerm_postgresql_flexible_server" "test" {
name = "acctest-fs-%[1]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
administrator_login = "adminTerraform"
administrator_password = "QAZwsx123"
storage_mb = 32768
version = "12"
sku_name = "GP_Standard_D2s_v3"
zone = "2"
name = "acctest-fs-%[1]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
administrator_login = "adminTerraform"
administrator_password = "QAZwsx123"
storage_mb = 32768
version = "12"
sku_name = "GP_Standard_D2s_v3"
zone = "2"
public_network_access_enabled = true

authentication {
active_directory_auth_enabled = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,16 @@ resource "azurerm_resource_group" "test" {
}

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"
storage_mb = 32768
version = "12"
sku_name = "GP_Standard_D2s_v3"
zone = "2"
name = "acctest-fs-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
administrator_login = "adminTerraform"
administrator_password = "QAZwsx123"
storage_mb = 32768
version = "12"
sku_name = "GP_Standard_D2s_v3"
zone = "2"
public_network_access_enabled = true
}

resource "azurerm_postgresql_flexible_server_configuration" "test" {
Expand Down
13 changes: 11 additions & 2 deletions internal/services/postgres/postgresql_flexible_server_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func resourcePostgresqlFlexibleServer() *pluginsdk.Resource {

"public_network_access_enabled": {
Type: pluginsdk.TypeBool,
Computed: true,
Optional: true,
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to be a breaking change for existing users? as it will now set everyone to false whenthe default iirc is true?

as such we should make it optional + computed to account for existing resources + users changing the default outside terraform

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. When user created the resource without delegated_subnet_id, private_dns_zone_id and public_network_access_enabled using old AzureRM version and then user upgraded to new AzureRM version, tf plan would cause difference if public_network_access_enabled isn't set in the tf config. Though there is TF difference but it's expected since service API would return the default value true for public_network_access_enabled when delegated_subnet_id and private_dns_zone_id aren't set.

OK. I will use optional + computed. Then the existing resources wouldn't be impacted anymore.


"replication_role": {
Expand Down Expand Up @@ -767,7 +767,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 @@ -964,6 +964,15 @@ func expandArmServerNetwork(d *pluginsdk.ResourceData) *servers.Network {
network.PrivateDnsZoneArmResourceId = utils.String(v.(string))
}

// `d.GetOk()` cannot identify if the bool property `public_network_access_enabled` is set or not in the tf config since d.GetOk() always returns `false` when `public_network_access_enabled` is set to `false` and `public_network_access_enabled` isn't set in the tf config
if !pluginsdk.IsExplicitlyNullInConfig(d, "public_network_access_enabled") {
publicNetworkAccessEnabled := servers.ServerPublicNetworkAccessStateDisabled
if d.Get("public_network_access_enabled").(bool) {
publicNetworkAccessEnabled = servers.ServerPublicNetworkAccessStateEnabled
}
network.PublicNetworkAccess = pointer.To(publicNetworkAccessEnabled)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By defaulting this in the Read we can just pull from the config:

Suggested change
// `d.GetOk()` cannot identify if the bool property `public_network_access_enabled` is set or not in the tf config since d.GetOk() always returns `false` when `public_network_access_enabled` is set to `false` and `public_network_access_enabled` isn't set in the tf config
if !pluginsdk.IsExplicitlyNullInConfig(d, "public_network_access_enabled") {
publicNetworkAccessEnabled := servers.ServerPublicNetworkAccessStateDisabled
if d.Get("public_network_access_enabled").(bool) {
publicNetworkAccessEnabled = servers.ServerPublicNetworkAccessStateEnabled
}
network.PublicNetworkAccess = pointer.To(publicNetworkAccessEnabled)
}
// `d.GetOk()` cannot identify if the bool property `public_network_access_enabled` is set or not in the tf config since d.GetOk() always returns `false` when `public_network_access_enabled` is set to `false` and `public_network_access_enabled` isn't set in the tf config
publicNetworkAccessEnabled := servers.ServerPublicNetworkAccessStateEnabled
if !d.Get("public_network_access_enabled").(bool) {
publicNetworkAccessEnabled = servers.ServerPublicNetworkAccessStateDisabled
}
network.PublicNetworkAccess = pointer.To(publicNetworkAccessEnabled)

Note: since the Azure API defaults this to true today, we'll also need to update the Read function to account for this too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I above mentioned, I assume that we can't simply hard-code the default value for public_network_access_enabled. So I may not apply this suggestion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated


return &network
}

Expand Down