allow cross-project imports for sql user (#2632)

<!-- This change is generated by MagicModules. -->
/cc @danawillow
This commit is contained in:
The Magician 2018-12-12 09:06:36 -08:00 committed by Nathan McKinley
parent 89b95575ea
commit 5fea92fadf
2 changed files with 13 additions and 11 deletions

View File

@ -227,15 +227,17 @@ func resourceSqlUserDelete(d *schema.ResourceData, meta interface{}) error {
func resourceSqlUserImporter(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
parts := strings.Split(d.Id(), "/")
if len(parts) == 2 {
d.Set("instance", parts[0])
d.Set("name", parts[1])
} else if len(parts) == 3 {
d.Set("instance", parts[0])
d.Set("host", parts[1])
if len(parts) == 3 {
d.Set("project", parts[0])
d.Set("instance", parts[1])
d.Set("name", parts[2])
} else if len(parts) == 4 {
d.Set("project", parts[0])
d.Set("instance", parts[1])
d.Set("host", parts[2])
d.Set("name", parts[3])
} else {
return nil, fmt.Errorf("Invalid specifier. Expecting {instance}/{name} for postgres instance and {instance}/{host}/{name} for MySQL instance")
return nil, fmt.Errorf("Invalid specifier. Expecting {project}/{instance}/{name} for postgres instance and {project}/{instance}/{host}/{name} for MySQL instance")
}
return []*schema.ResourceData{d}, nil

View File

@ -62,14 +62,14 @@ Only the arguments listed above are exposed as attributes.
## Import
SQL users for MySQL databases can be imported using the `instance`, `host` and `name`, e.g.
SQL users for MySQL databases can be imported using the `project`, `instance`, `host` and `name`, e.g.
```
$ terraform import google_sql_user.users master-instance/my-domain.com/me
$ terraform import google_sql_user.users my-project/master-instance/my-domain.com/me
```
SQL users for PostgreSQL databases can be imported using the `instance` and `name`, e.g.
SQL users for PostgreSQL databases can be imported using the `project`, `instance` and `name`, e.g.
```
$ terraform import google_sql_user.users master-instance/me
$ terraform import google_sql_user.users my-project/master-instance/me
```