From e2f57c6c3226f4e88fbab4ac86eb734ddaeee90f Mon Sep 17 00:00:00 2001 From: Scott Mitchell Date: Fri, 17 May 2024 17:18:30 +0000 Subject: [PATCH 1/3] Fix TestAccSqlUser_postgresIAM by using an IAM user that actually exists --- .../services/sql/resource_sql_user_test.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/mmv1/third_party/terraform/services/sql/resource_sql_user_test.go b/mmv1/third_party/terraform/services/sql/resource_sql_user_test.go index dac6798be896..4295f7162285 100644 --- a/mmv1/third_party/terraform/services/sql/resource_sql_user_test.go +++ b/mmv1/third_party/terraform/services/sql/resource_sql_user_test.go @@ -136,7 +136,6 @@ func TestAccSqlUser_postgres(t *testing.T) { } func TestAccSqlUser_postgresIAM(t *testing.T) { - t.Skipf("Skipping test %s due to https://github.com/hashicorp/terraform-provider-google/issues/16704", t.Name()) t.Parallel() instance := fmt.Sprintf("tf-test-%d", acctest.RandInt(t)) @@ -428,9 +427,17 @@ resource "time_sleep" "wait_30_seconds" { create_duration = "30s" } +data "google_project" "project" {} + +resource "google_project_iam_member" "iam_user" { + project = data.google_project.project.project_id + role = "roles/cloudsql.instanceUser" + member = "user:admin@hashicorptest.com" +} + resource "google_sql_user" "user" { - depends_on = [time_sleep.wait_30_seconds] - name = "admin" + depends_on = [time_sleep.wait_30_seconds, google_project_iam_member.iam_user] + name = "admin@hashicorptest.com" instance = google_sql_database_instance.instance.name type = "CLOUD_IAM_USER" } From c8a5dbe28df34d27b03545a25f3f1bb82bfe906b Mon Sep 17 00:00:00 2001 From: Scott Mitchell Date: Tue, 21 May 2024 19:07:04 +0000 Subject: [PATCH 2/3] Update import statement to use properly qualified user --- .../services/sql/resource_sql_user_test.go | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/mmv1/third_party/terraform/services/sql/resource_sql_user_test.go b/mmv1/third_party/terraform/services/sql/resource_sql_user_test.go index 4295f7162285..cb87c9e0712a 100644 --- a/mmv1/third_party/terraform/services/sql/resource_sql_user_test.go +++ b/mmv1/third_party/terraform/services/sql/resource_sql_user_test.go @@ -139,6 +139,7 @@ func TestAccSqlUser_postgresIAM(t *testing.T) { t.Parallel() instance := fmt.Sprintf("tf-test-%d", acctest.RandInt(t)) + const iamUser = "admin@hashicorptest.com" acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), @@ -148,14 +149,14 @@ func TestAccSqlUser_postgresIAM(t *testing.T) { CheckDestroy: testAccSqlUserDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testGoogleSqlUser_postgresIAM(instance), + Config: testGoogleSqlUser_postgresIAM(instance, iamUser), Check: resource.ComposeTestCheckFunc( testAccCheckGoogleSqlUserExists(t, "google_sql_user.user"), ), }, { ResourceName: "google_sql_user.user", - ImportStateId: fmt.Sprintf("%s/%s/admin", envvar.GetTestProjectFromEnv(), instance), + ImportStateId: fmt.Sprintf("%s/%s/%s", envvar.GetTestProjectFromEnv(), instance, iamUser), ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"password"}, @@ -403,7 +404,7 @@ resource "google_sql_user" "user" { `, instance, password) } -func testGoogleSqlUser_postgresIAM(instance string) string { +func testGoogleSqlUser_postgresIAM(instance, iamUser string) string { return fmt.Sprintf(` resource "google_sql_database_instance" "instance" { name = "%s" @@ -427,21 +428,13 @@ resource "time_sleep" "wait_30_seconds" { create_duration = "30s" } -data "google_project" "project" {} - -resource "google_project_iam_member" "iam_user" { - project = data.google_project.project.project_id - role = "roles/cloudsql.instanceUser" - member = "user:admin@hashicorptest.com" -} - resource "google_sql_user" "user" { - depends_on = [time_sleep.wait_30_seconds, google_project_iam_member.iam_user] - name = "admin@hashicorptest.com" + depends_on = [time_sleep.wait_30_seconds] + name = "%s" instance = google_sql_database_instance.instance.name type = "CLOUD_IAM_USER" } -`, instance) +`, instance, iamUser) } func testGoogleSqlUser_postgresAbandon(instance, name string) string { From 9835e2c1383e2ec6294e042dee25c1e799bfb47b Mon Sep 17 00:00:00 2001 From: Scott Mitchell Date: Tue, 21 May 2024 21:06:48 +0000 Subject: [PATCH 3/3] increase sleep to 60s --- .../terraform/services/sql/resource_sql_user_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mmv1/third_party/terraform/services/sql/resource_sql_user_test.go b/mmv1/third_party/terraform/services/sql/resource_sql_user_test.go index cb87c9e0712a..527179d03961 100644 --- a/mmv1/third_party/terraform/services/sql/resource_sql_user_test.go +++ b/mmv1/third_party/terraform/services/sql/resource_sql_user_test.go @@ -422,14 +422,14 @@ resource "google_sql_database_instance" "instance" { } # TODO: Remove with resolution of https://github.com/hashicorp/terraform-provider-google/issues/14233 -resource "time_sleep" "wait_30_seconds" { +resource "time_sleep" "wait_60_seconds" { depends_on = [google_sql_database_instance.instance] - create_duration = "30s" + create_duration = "60s" } resource "google_sql_user" "user" { - depends_on = [time_sleep.wait_30_seconds] + depends_on = [time_sleep.wait_60_seconds] name = "%s" instance = google_sql_database_instance.instance.name type = "CLOUD_IAM_USER"