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

Fix TestAccSqlUser_postgresIAM by using a real IAM user #10731

Merged
merged 3 commits into from
May 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ 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))
const iamUser = "[email protected]"
acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
Expand All @@ -149,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"},
Expand Down Expand Up @@ -404,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"
Expand All @@ -422,19 +422,19 @@ 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]
name = "admin"
depends_on = [time_sleep.wait_60_seconds]
name = "%s"
instance = google_sql_database_instance.instance.name
type = "CLOUD_IAM_USER"
}
`, instance)
`, instance, iamUser)
}

func testGoogleSqlUser_postgresAbandon(instance, name string) string {
Expand Down