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_server - deprecate ssl_enforcement_enabled and ssl_minimal_tls_version_enforced no longer accpets TLSEnforcementDisabled, TLS1_0 or TLS1_1 as a value in 5.0 #28247

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
56 changes: 38 additions & 18 deletions internal/services/postgres/postgresql_server_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2017-12-01/serversecurityalertpolicies"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/locks"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/postgres/migration"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/postgres/validate"
Expand Down Expand Up @@ -59,7 +60,7 @@ var skuList = []string{
}

func resourcePostgreSQLServer() *pluginsdk.Resource {
return &pluginsdk.Resource{
resource := &pluginsdk.Resource{
Create: resourcePostgreSQLServerCreate,
Read: resourcePostgreSQLServerRead,
Update: resourcePostgreSQLServerUpdate,
Expand Down Expand Up @@ -217,15 +218,12 @@ func resourcePostgreSQLServer() *pluginsdk.Resource {
},

"ssl_minimal_tls_version_enforced": {
Type: pluginsdk.TypeString,
Optional: true,
Default: string(servers.MinimalTlsVersionEnumTLSOneTwo),
ValidateFunc: validation.StringInSlice(servers.PossibleValuesForMinimalTlsVersionEnum(), false),
},

"ssl_enforcement_enabled": {
Type: pluginsdk.TypeBool,
Required: true,
Type: pluginsdk.TypeString,
Optional: true,
Default: string(servers.MinimalTlsVersionEnumTLSOneTwo),
ValidateFunc: validation.StringInSlice([]string{
string(servers.MinimalTlsVersionEnumTLSOneZero),
}, false),
},

"threat_detection_policy": {
Expand Down Expand Up @@ -360,6 +358,22 @@ func resourcePostgreSQLServer() *pluginsdk.Resource {
}),
),
}

if !features.FivePointOhBeta() {
resource.Schema["ssl_minimal_tls_version_enforced"] = &pluginsdk.Schema{
Type: pluginsdk.TypeString,
Optional: true,
Default: string(servers.MinimalTlsVersionEnumTLSOneTwo),
ValidateFunc: validation.StringInSlice(servers.PossibleValuesForMinimalTlsVersionEnum(), false),
}
resource.Schema["ssl_enforcement_enabled"] = &pluginsdk.Schema{
Deprecated: "The `ssl_enforcement_enabled` is deprecated as Azure services will require TLS1.2+ to connect.",
Type: pluginsdk.TypeBool,
Required: true,
}
}

return resource
}

func resourcePostgreSQLServerCreate(d *pluginsdk.ResourceData, meta interface{}) error {
Expand Down Expand Up @@ -403,8 +417,10 @@ func resourcePostgreSQLServerCreate(d *pluginsdk.ResourceData, meta interface{})
}

ssl := servers.SslEnforcementEnumEnabled
if v := d.Get("ssl_enforcement_enabled"); !v.(bool) {
ssl = servers.SslEnforcementEnumDisabled
if !features.FivePointOhBeta() {
if v := d.Get("ssl_enforcement_enabled"); !v.(bool) {
ssl = servers.SslEnforcementEnumDisabled
}
}

tlsMin := servers.MinimalTlsVersionEnum(d.Get("ssl_minimal_tls_version_enforced").(string))
Expand Down Expand Up @@ -622,8 +638,10 @@ func resourcePostgreSQLServerUpdate(d *pluginsdk.ResourceData, meta interface{})
}

ssl := servers.SslEnforcementEnumEnabled
if v := d.Get("ssl_enforcement_enabled"); !v.(bool) {
ssl = servers.SslEnforcementEnumDisabled
if !features.FivePointOhBeta() {
if v := d.Get("ssl_enforcement_enabled"); !v.(bool) {
ssl = servers.SslEnforcementEnumDisabled
}
}

tlsMin := servers.MinimalTlsVersionEnum(d.Get("ssl_minimal_tls_version_enforced").(string))
Expand Down Expand Up @@ -755,11 +773,13 @@ func resourcePostgreSQLServerRead(d *pluginsdk.ResourceData, meta interface{}) e
}
d.Set("public_network_access_enabled", publicNetworkAccess)

sslEnforcement := false
if props.SslEnforcement != nil {
sslEnforcement = *props.SslEnforcement == servers.SslEnforcementEnumEnabled
if !features.FivePointOhBeta() {
sslEnforcement := false
if props.SslEnforcement != nil {
sslEnforcement = *props.SslEnforcement == servers.SslEnforcementEnumEnabled
}
d.Set("ssl_enforcement_enabled", sslEnforcement)
}
d.Set("ssl_enforcement_enabled", sslEnforcement)

if storage := props.StorageProfile; storage != nil {
d.Set("storage_mb", storage.StorageMB)
Expand Down
Loading
Loading