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

Deprecate google_sql_database_instance.settings.ip_configuration's require_ssl in favor of ssl_mode #7804

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
3 changes: 3 additions & 0 deletions .changelog/11154.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:deprecation
sql: `settings.ip_configuration.require_ssl` is now deprecated within `google_sql_database_instance`. Please use `settings.ip_configuration.ssl_mode` instead.
```
22 changes: 5 additions & 17 deletions google-beta/services/sql/resource_sql_database_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ var (
ipConfigurationKeys = []string{
"settings.0.ip_configuration.0.authorized_networks",
"settings.0.ip_configuration.0.ipv4_enabled",
"settings.0.ip_configuration.0.require_ssl",
"settings.0.ip_configuration.0.private_network",
"settings.0.ip_configuration.0.allocated_ip_range",
"settings.0.ip_configuration.0.enable_private_path_for_google_cloud_services",
Expand Down Expand Up @@ -438,13 +437,6 @@ is set to true. Defaults to ZONAL.`,
AtLeastOneOf: ipConfigurationKeys,
Description: `Whether this Cloud SQL instance should be assigned a public IPV4 address. At least ipv4_enabled must be enabled or a private_network must be configured.`,
},
"require_ssl": {
Type: schema.TypeBool,
Optional: true,
AtLeastOneOf: ipConfigurationKeys,
Description: `Whether SSL connections over IP are enforced or not. To change this field, also set the corresponding value in ssl_mode if it has been set too.`,
Deprecated: "`require_ssl` will be fully deprecated in a future major release. For now, please use `ssl_mode` with a compatible `require_ssl` value instead.",
},
"private_network": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -493,7 +485,7 @@ is set to true. Defaults to ZONAL.`,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{"ALLOW_UNENCRYPTED_AND_ENCRYPTED", "ENCRYPTED_ONLY", "TRUSTED_CLIENT_CERTIFICATE_REQUIRED"}, false),
Description: `Specify how SSL connection should be enforced in DB connections. This field provides more SSL enforcment options compared to require_ssl. To change this field, also set the correspoding value in require_ssl until next major release.`,
Description: `Specify how SSL connection should be enforced in DB connections.`,
AtLeastOneOf: ipConfigurationKeys,
},
},
Expand Down Expand Up @@ -1386,20 +1378,21 @@ func expandIpConfiguration(configured []interface{}, databaseVersion string) *sq

_ipConfiguration := configured[0].(map[string]interface{})

forceSendFields := []string{"Ipv4Enabled", "RequireSsl"}
forceSendFields := []string{"Ipv4Enabled"}
nullFields := []string{"RequireSsl"}

if !strings.HasPrefix(databaseVersion, "SQLSERVER") {
forceSendFields = append(forceSendFields, "EnablePrivatePathForGoogleCloudServices")
}

return &sqladmin.IpConfiguration{
Ipv4Enabled: _ipConfiguration["ipv4_enabled"].(bool),
RequireSsl: _ipConfiguration["require_ssl"].(bool),
PrivateNetwork: _ipConfiguration["private_network"].(string),
AllocatedIpRange: _ipConfiguration["allocated_ip_range"].(string),
AuthorizedNetworks: expandAuthorizedNetworks(_ipConfiguration["authorized_networks"].(*schema.Set).List()),
EnablePrivatePathForGoogleCloudServices: _ipConfiguration["enable_private_path_for_google_cloud_services"].(bool),
ForceSendFields: forceSendFields,
NullFields: nullFields,
PscConfig: expandPscConfig(_ipConfiguration["psc_config"].(*schema.Set).List()),
SslMode: _ipConfiguration["ssl_mode"].(string),
}
Expand Down Expand Up @@ -2240,8 +2233,8 @@ func flattenIpConfiguration(ipConfiguration *sqladmin.IpConfiguration, d *schema
"ipv4_enabled": ipConfiguration.Ipv4Enabled,
"private_network": ipConfiguration.PrivateNetwork,
"allocated_ip_range": ipConfiguration.AllocatedIpRange,
"require_ssl": ipConfiguration.RequireSsl,
"enable_private_path_for_google_cloud_services": ipConfiguration.EnablePrivatePathForGoogleCloudServices,
"ssl_mode": ipConfiguration.SslMode,
}

if ipConfiguration.AuthorizedNetworks != nil {
Expand All @@ -2252,11 +2245,6 @@ func flattenIpConfiguration(ipConfiguration *sqladmin.IpConfiguration, d *schema
data["psc_config"] = flattenPscConfigs(ipConfiguration.PscConfig)
}

// We store the ssl_mode value only if the customer already uses `ssl_mode`.
if _, ok := d.GetOk("settings.0.ip_configuration.0.ssl_mode"); ok {
data["ssl_mode"] = ipConfiguration.SslMode
}

return []map[string]interface{}{data}
}

Expand Down
19 changes: 7 additions & 12 deletions google-beta/services/sql/resource_sql_database_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2346,9 +2346,8 @@ func TestAccSqlDatabaseInstance_updateSslOptionsForPostgreSQL(t *testing.T) {
// We don't do ImportStateVerify for the ssl_mode because of the implementation. The ssl_mode is expected to be discarded if the local state doesn't have it.
Steps: []resource.TestStep{
{
Config: testGoogleSqlDatabaseInstance_setSslOptionsForPostgreSQL(databaseName, databaseVersion, false, "ALLOW_UNENCRYPTED_AND_ENCRYPTED"),
Config: testGoogleSqlDatabaseInstance_setSslOptionsForPostgreSQL(databaseName, databaseVersion, "ALLOW_UNENCRYPTED_AND_ENCRYPTED"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "settings.0.ip_configuration.0.require_ssl", "false"),
resource.TestCheckResourceAttr(resourceName, "settings.0.ip_configuration.0.ssl_mode", "ALLOW_UNENCRYPTED_AND_ENCRYPTED"),
),
},
Expand All @@ -2359,9 +2358,8 @@ func TestAccSqlDatabaseInstance_updateSslOptionsForPostgreSQL(t *testing.T) {
ImportStateVerifyIgnore: []string{"deletion_protection", "settings.0.ip_configuration.0.ssl_mode"},
},
{
Config: testGoogleSqlDatabaseInstance_setSslOptionsForPostgreSQL(databaseName, databaseVersion, false, "ENCRYPTED_ONLY"),
Config: testGoogleSqlDatabaseInstance_setSslOptionsForPostgreSQL(databaseName, databaseVersion, "ENCRYPTED_ONLY"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "settings.0.ip_configuration.0.require_ssl", "false"),
resource.TestCheckResourceAttr(resourceName, "settings.0.ip_configuration.0.ssl_mode", "ENCRYPTED_ONLY"),
),
},
Expand All @@ -2372,9 +2370,8 @@ func TestAccSqlDatabaseInstance_updateSslOptionsForPostgreSQL(t *testing.T) {
ImportStateVerifyIgnore: []string{"deletion_protection", "settings.0.ip_configuration.0.ssl_mode"},
},
{
Config: testGoogleSqlDatabaseInstance_setSslOptionsForPostgreSQL(databaseName, databaseVersion, true, "TRUSTED_CLIENT_CERTIFICATE_REQUIRED"),
Config: testGoogleSqlDatabaseInstance_setSslOptionsForPostgreSQL(databaseName, databaseVersion, "TRUSTED_CLIENT_CERTIFICATE_REQUIRED"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "settings.0.ip_configuration.0.require_ssl", "true"),
resource.TestCheckResourceAttr(resourceName, "settings.0.ip_configuration.0.ssl_mode", "TRUSTED_CLIENT_CERTIFICATE_REQUIRED"),
),
},
Expand All @@ -2385,9 +2382,8 @@ func TestAccSqlDatabaseInstance_updateSslOptionsForPostgreSQL(t *testing.T) {
ImportStateVerifyIgnore: []string{"deletion_protection", "settings.0.ip_configuration.0.ssl_mode"},
},
{
Config: testGoogleSqlDatabaseInstance_setSslOptionsForPostgreSQL(databaseName, databaseVersion, false, "ALLOW_UNENCRYPTED_AND_ENCRYPTED"),
Config: testGoogleSqlDatabaseInstance_setSslOptionsForPostgreSQL(databaseName, databaseVersion, "ALLOW_UNENCRYPTED_AND_ENCRYPTED"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "settings.0.ip_configuration.0.require_ssl", "false"),
resource.TestCheckResourceAttr(resourceName, "settings.0.ip_configuration.0.ssl_mode", "ALLOW_UNENCRYPTED_AND_ENCRYPTED"),
),
},
Expand All @@ -2401,7 +2397,7 @@ func TestAccSqlDatabaseInstance_updateSslOptionsForPostgreSQL(t *testing.T) {
})
}

func testGoogleSqlDatabaseInstance_setSslOptionsForPostgreSQL(databaseName string, databaseVersion string, requireSsl bool, sslMode string) string {
func testGoogleSqlDatabaseInstance_setSslOptionsForPostgreSQL(databaseName string, databaseVersion string, sslMode string) string {
return fmt.Sprintf(`
resource "google_sql_database_instance" "instance" {
name = "%s"
Expand All @@ -2412,11 +2408,10 @@ resource "google_sql_database_instance" "instance" {
tier = "db-g1-small"
ip_configuration {
ipv4_enabled = true
require_ssl = %t
ssl_mode = "%s"
}
}
}`, databaseName, databaseVersion, requireSsl, sslMode)
}`, databaseName, databaseVersion, sslMode)
}

func testAccSqlDatabaseInstance_sqlMysqlInstancePvpExample(context map[string]interface{}) string {
Expand Down Expand Up @@ -2500,7 +2495,7 @@ resource "google_sql_database_instance" "instance" {
collation = "Polish_CI_AS"
ip_configuration {
ipv4_enabled = true
require_ssl = true
ssl_mode = "ENCRYPTED_ONLY"
}
}
}
Expand Down
7 changes: 1 addition & 6 deletions website/docs/r/sql_database_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,7 @@ Specifying a network enables private IP.
At least `ipv4_enabled` must be enabled or a `private_network` must be configured.
This setting can be updated, but it cannot be removed after it is set.

* `require_ssl` - (Optional, Deprecated) Whether SSL connections over IP are enforced or not. To change this field, also set the corresponding value in `ssl_mode`. It will be fully deprecated in a future major release. For now, please use `ssl_mode` with a compatible `require_ssl` value instead.

* `ssl_mode` - (Optional) Specify how SSL connection should be enforced in DB connections. This field provides more SSL enforcment options compared to `require_ssl`. To change this field, also set the correspoding value in `require_ssl`.
* For PostgreSQL instances, the value pairs are listed in the [API reference doc](https://cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/instances#ipconfiguration) for `ssl_mode` field.
* For MySQL instances, use the same value pairs as the PostgreSQL instances.
* For SQL Server instances, set it to `ALLOW_UNENCRYPTED_AND_ENCRYPTED` when `require_ssl=false` and `ENCRYPTED_ONLY` otherwise.
* `ssl_mode` - (Optional) Specify how SSL connection should be enforced in DB connections.

* `allocated_ip_range` - (Optional) The name of the allocated ip range for the private ip CloudSQL instance. For example: "google-managed-services-default". If set, the instance ip will be created in the allocated range. The range name must comply with [RFC 1035](https://datatracker.ietf.org/doc/html/rfc1035). Specifically, the name must be 1-63 characters long and match the regular expression [a-z]([-a-z0-9]*[a-z0-9])?.

Expand Down