github.com/koding/terraform@v0.6.4-0.20170608090606-5d7e0339779d/builtin/providers/google/resource_sql_user_migrate.go (about)

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