Skip to content

Commit 8eb4d1a

Browse files
google_sql_user: Fixed import where host is an IPv4 CIDR (#11523)
1 parent 615bed6 commit 8eb4d1a

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

mmv1/third_party/terraform/services/sql/resource_sql_user.go

+13
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,19 @@ func resourceSqlUserImporter(d *schema.ResourceData, meta interface{}) ([]*schem
573573
if err := d.Set("name", parts[3]); err != nil {
574574
return nil, fmt.Errorf("Error setting name: %s", err)
575575
}
576+
} else if len(parts) == 5 {
577+
if err := d.Set("project", parts[0]); err != nil {
578+
return nil, fmt.Errorf("Error setting project: %s", err)
579+
}
580+
if err := d.Set("instance", parts[1]); err != nil {
581+
return nil, fmt.Errorf("Error setting instance: %s", err)
582+
}
583+
if err := d.Set("host", fmt.Sprintf("%s/%s", parts[2], parts[3])); err != nil {
584+
return nil, fmt.Errorf("Error setting host: %s", err)
585+
}
586+
if err := d.Set("name", parts[4]); err != nil {
587+
return nil, fmt.Errorf("Error setting name: %s", err)
588+
}
576589
} else {
577590
return nil, fmt.Errorf("Invalid specifier. Expecting {project}/{instance}/{name} for postgres instance and {project}/{instance}/{host}/{name} for MySQL instance")
578591
}

mmv1/third_party/terraform/services/sql/resource_sql_user_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func TestAccSqlUser_mysql(t *testing.T) {
3434
Check: resource.ComposeTestCheckFunc(
3535
testAccCheckGoogleSqlUserExists(t, "google_sql_user.user1"),
3636
testAccCheckGoogleSqlUserExists(t, "google_sql_user.user2"),
37+
testAccCheckGoogleSqlUserExists(t, "google_sql_user.user3"),
3738
),
3839
},
3940
{
@@ -43,6 +44,13 @@ func TestAccSqlUser_mysql(t *testing.T) {
4344
ImportStateVerify: true,
4445
ImportStateVerifyIgnore: []string{"password"},
4546
},
47+
{
48+
ResourceName: "google_sql_user.user3",
49+
ImportStateId: fmt.Sprintf("%s/%s/10.0.0.0/24/admin", envvar.GetTestProjectFromEnv(), instance),
50+
ImportState: true,
51+
ImportStateVerify: true,
52+
ImportStateVerifyIgnore: []string{"password"},
53+
},
4654
},
4755
})
4856
}
@@ -341,6 +349,13 @@ resource "google_sql_user" "user2" {
341349
host = "gmail.com"
342350
password = "hunter2"
343351
}
352+
353+
resource "google_sql_user" "user3" {
354+
name = "admin"
355+
instance = google_sql_database_instance.instance.name
356+
host = "10.0.0.0/24"
357+
password = "hunter3"
358+
}
344359
`, instance, password)
345360
}
346361

0 commit comments

Comments
 (0)