From db410f494a26a557739a6d7b4958bde74e917638 Mon Sep 17 00:00:00 2001 From: The Magician Date: Tue, 22 Oct 2024 18:52:01 -0700 Subject: [PATCH] Allow ENTERPRISE_PLUS as default Edition for POSTGRES_16 (#12077) (#19977) [upstream:385db4524531105c80b9aaf550da05d749de4ce6] Signed-off-by: Modular Magician --- .changelog/12077.txt | 3 ++ .../sql/resource_sql_database_instance.go | 2 +- .../resource_sql_database_instance_test.go | 49 +++++++++++++++++-- 3 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 .changelog/12077.txt diff --git a/.changelog/12077.txt b/.changelog/12077.txt new file mode 100644 index 00000000000..76c898b3793 --- /dev/null +++ b/.changelog/12077.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +sql: removed the client-side default of `ENTERPRISE` for `edition` in `google_sql_database_instance` so that `edition` is determined by the API when unset. This will cause new instances to use `ENTERPRISE_PLUS` as the default for POSTGRES_16. +``` \ No newline at end of file diff --git a/google/services/sql/resource_sql_database_instance.go b/google/services/sql/resource_sql_database_instance.go index fc16b917167..c9f03c31c94 100644 --- a/google/services/sql/resource_sql_database_instance.go +++ b/google/services/sql/resource_sql_database_instance.go @@ -179,7 +179,7 @@ func ResourceSqlDatabaseInstance() *schema.Resource { "edition": { Type: schema.TypeString, Optional: true, - Default: "ENTERPRISE", + Computed: true, ValidateFunc: validation.StringInSlice([]string{"ENTERPRISE", "ENTERPRISE_PLUS"}, false), Description: `The edition of the instance, can be ENTERPRISE or ENTERPRISE_PLUS.`, }, diff --git a/google/services/sql/resource_sql_database_instance_test.go b/google/services/sql/resource_sql_database_instance_test.go index 40aee1731fc..01c892b9656 100644 --- a/google/services/sql/resource_sql_database_instance_test.go +++ b/google/services/sql/resource_sql_database_instance_test.go @@ -1598,6 +1598,32 @@ func TestAccSQLDatabaseInstance_DenyMaintenancePeriod(t *testing.T) { }) } +func TestAccSQLDatabaseInstance_DefaultEdition(t *testing.T) { + t.Parallel() + databaseName := "tf-test-" + acctest.RandString(t, 10) + databaseVersion := "POSTGRES_16" + enterprisePlusTier := "db-perf-optimized-N-2" + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testGoogleSqlDatabaseInstance_DefaultEdition(databaseName, databaseVersion, enterprisePlusTier), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("google_sql_database_instance.instance", "settings.0.edition", "ENTERPRISE_PLUS"), + ), + }, + { + ResourceName: "google_sql_database_instance.instance", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"deletion_protection"}, + }, + }, + }) +} + func TestAccSqlDatabaseInstance_Edition(t *testing.T) { t.Parallel() enterprisePlusName := "tf-test-enterprise-plus" + acctest.RandString(t, 10) @@ -1757,7 +1783,7 @@ func TestAccSqlDatabaseInstance_Postgres_Edition_Upgrade(t *testing.T) { CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testGoogleSqlDatabaseInstance_EditionConfig_noEdition(editionUpgrade, enterpriseTier), + Config: testGoogleSqlDatabaseInstance_EditionConfig(editionUpgrade, enterpriseTier, "ENTERPRISE"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("google_sql_database_instance.instance", "settings.0.edition", "ENTERPRISE"), ), @@ -1807,7 +1833,7 @@ func TestAccSqlDatabaseInstance_Edition_Downgrade(t *testing.T) { ImportStateVerifyIgnore: []string{"deletion_protection"}, }, { - Config: testGoogleSqlDatabaseInstance_EditionConfig_noEdition(editionDowngrade, enterpriseTier), + Config: testGoogleSqlDatabaseInstance_EditionConfig(editionDowngrade, enterpriseTier, "ENTERPRISE"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("google_sql_database_instance.instance", "settings.0.edition", "ENTERPRISE"), ), @@ -2683,6 +2709,19 @@ resource "google_sql_database_instance" "instance" { }`, databaseName, endDate, startDate, time) } +func testGoogleSqlDatabaseInstance_DefaultEdition(databaseName, databaseVersion, tier string) string { + return fmt.Sprintf(` +resource "google_sql_database_instance" "instance" { + name = "%s" + region = "us-east1" + database_version = "%s" + deletion_protection = false + settings { + tier = "%s" + } +}`, databaseName, databaseVersion, tier) +} + func testGoogleSqlDatabaseInstance_EditionConfig_noEdition(databaseName, tier string) string { return fmt.Sprintf(` @@ -2693,9 +2732,6 @@ resource "google_sql_database_instance" "instance" { deletion_protection = false settings { tier = "%s" - backup_configuration { - transaction_log_retention_days = 7 - } } }`, databaseName, tier) } @@ -2711,6 +2747,9 @@ resource "google_sql_database_instance" "instance" { settings { tier = "%s" edition = "%s" + backup_configuration { + transaction_log_retention_days = 7 + } } }`, databaseName, tier, edition) }