forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresource_sql_user_migrate.go
39 lines (32 loc) · 972 Bytes
/
resource_sql_user_migrate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package google
import (
"fmt"
"log"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)
func resourceSqlUserMigrateState(
v int, is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) {
if is.Empty() {
log.Println("[DEBUG] Empty InstanceState; nothing to migrate.")
return is, nil
}
switch v {
case 0:
log.Println("[INFO] Found Google Sql User State v0; migrating to v1")
is, err := migrateSqlUserStateV0toV1(is)
if err != nil {
return is, err
}
return is, nil
default:
return is, fmt.Errorf("Unexpected schema version: %d", v)
}
}
func migrateSqlUserStateV0toV1(is *terraform.InstanceState) (*terraform.InstanceState, error) {
log.Printf("[DEBUG] Attributes before migration: %#v", is.Attributes)
name := is.Attributes["name"]
instance := is.Attributes["instance"]
is.ID = fmt.Sprintf("%s/%s", instance, name)
log.Printf("[DEBUG] Attributes after migration: %#v", is.Attributes)
return is, nil
}