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

Update google_sql_database and google_sql_user to not do Read actions when instance is not active #11866

Merged
merged 12 commits into from
Oct 17, 2024
Merged
58 changes: 58 additions & 0 deletions mmv1/third_party/terraform/services/sql/resource_sql_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,64 @@ func TestAccSqlUser_mysqlPasswordPolicy(t *testing.T) {
})
}

func TestAccSqlUser_instanceWithActivationPolicy(t *testing.T) {
// Multiple fine-grained resources
acctest.SkipIfVcr(t)
t.Parallel()

instance := fmt.Sprintf("tf-test-%d", acctest.RandInt(t))

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccSqlUserDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testGoogleSqlUser_instanceWithActivationPolicy(instance, "ALWAYS"),
Check: resource.ComposeTestCheckFunc(
testAccCheckGoogleSqlUserExists(t, "google_sql_user.user"),
),
},
// Step 2: Update activation_policy to NEVER
{
Config: testGoogleSqlUser_instanceWithActivationPolicy(instance, "NEVER"),
Check: resource.ComposeTestCheckFunc(
testAccCheckGoogleSqlUserExists(t, "google_sql_user.user"),
),
},
// Step 3: Refresh to verify no errors
{
Config: testGoogleSqlUser_instanceWithActivationPolicy(instance, "NEVER"),
Check: resource.ComposeTestCheckFunc(
testAccCheckGoogleSqlUserExists(t, "google_sql_user.user"),
),
},
SarahFrench marked this conversation as resolved.
Show resolved Hide resolved
SarahFrench marked this conversation as resolved.
Show resolved Hide resolved
SarahFrench marked this conversation as resolved.
Show resolved Hide resolved
},
})
}

func testGoogleSqlUser_instanceWithActivationPolicy(instance, activationPolicy string) string {
return fmt.Sprintf(`
resource "google_sql_database_instance" "test_instance" {
SarahFrench marked this conversation as resolved.
Show resolved Hide resolved
name = "%s"
database_version = "MYSQL_5_7"
region = "us-central1"

SarahFrench marked this conversation as resolved.
Show resolved Hide resolved
settings {
tier = "db-f1-micro"
availability_type = "ZONAL"
activation_policy = "%s"
}
}

resource "google_sql_user" "user" {
name = "admin"
instance = google_sql_database_instance.instance.name
password = "password"
}
`, instance, activationPolicy)
}

func testGoogleSqlUser_mysql(instance, password string) string {
return fmt.Sprintf(`
resource "google_sql_database_instance" "instance" {
Expand Down