Skip to content

Commit

Permalink
Allow ENTERPRISE_PLUS as default Edition for POSTGRES_16 (hashicorp#1…
Browse files Browse the repository at this point in the history
…2077) (hashicorp#19977)

[upstream:385db4524531105c80b9aaf550da05d749de4ce6]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Oct 23, 2024
1 parent 6271874 commit db410f4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .changelog/12077.txt
Original file line number Diff line number Diff line change
@@ -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.
```
2 changes: 1 addition & 1 deletion google/services/sql/resource_sql_database_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
},
Expand Down
49 changes: 44 additions & 5 deletions google/services/sql/resource_sql_database_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"),
),
Expand Down Expand Up @@ -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"),
),
Expand Down Expand Up @@ -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(`
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit db410f4

Please sign in to comment.