Skip to content

Commit

Permalink
Allow ENTERPRISE_PLUS as default Edition for POSTGRES_16 (GoogleCloud…
Browse files Browse the repository at this point in the history
…Platform#12077)

Co-authored-by: Sarthak Tandon <[email protected]>
  • Loading branch information
2 people authored and BBBmau committed Nov 5, 2024
1 parent 2d8bf57 commit 6b67c05
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,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
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,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 @@ -1755,7 +1781,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 @@ -1805,7 +1831,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 @@ -2681,6 +2707,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 @@ -2691,9 +2730,6 @@ resource "google_sql_database_instance" "instance" {
deletion_protection = false
settings {
tier = "%s"
backup_configuration {
transaction_log_retention_days = 7
}
}
}`, databaseName, tier)
}
Expand All @@ -2709,6 +2745,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 6b67c05

Please sign in to comment.