Skip to content

Commit

Permalink
Merge pull request #511 from terraform-providers/paddy_fix_1.0.0_migr…
Browse files Browse the repository at this point in the history
…ation

Fix compute_instance migration bug.
  • Loading branch information
paddycarver authored Oct 2, 2017
2 parents 302cfda + 33b526a commit 9b573f0
Show file tree
Hide file tree
Showing 3 changed files with 374 additions and 13 deletions.
2 changes: 1 addition & 1 deletion google/resource_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func resourceComputeInstance() *schema.Resource {
Update: resourceComputeInstanceUpdate,
Delete: resourceComputeInstanceDelete,

SchemaVersion: 4,
SchemaVersion: 5,
MigrateState: resourceComputeInstanceMigrateState,

Schema: map[string]*schema.Schema{
Expand Down
31 changes: 24 additions & 7 deletions google/resource_compute_instance_migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,45 @@ func resourceComputeInstanceMigrateState(
return is, nil
}

var err error

switch v {
case 0:
log.Println("[INFO] Found Compute Instance State v0; migrating to v1")
is, err := migrateStateV0toV1(is)
is, err = migrateStateV0toV1(is)
if err != nil {
return is, err
}
fallthrough
case 1:
log.Println("[INFO] Found Compute Instance State v1; migrating to v2")
is, err := migrateStateV1toV2(is)
is, err = migrateStateV1toV2(is)
if err != nil {
return is, err
}
return is, nil
fallthrough
case 2:
log.Println("[INFO] Found Compute Instance State v2; migrating to v3")
is, err := migrateStateV2toV3(is)
is, err = migrateStateV2toV3(is)
if err != nil {
return is, err
}
return is, nil
fallthrough
case 3:
log.Println("[INFO] Found Compute Instance State v3; migrating to v4")
is, err := migrateStateV3toV4(is, meta)
is, err = migrateStateV3toV4(is, meta)
if err != nil {
return is, err
}
return is, nil
fallthrough
case 4:
log.Println("[INFO] Found Compute Instance State v4; migrating to v5")
is, err = migrateStateV4toV5(is, meta)
if err != nil {
return is, err
}
// when adding case 5, make sure to turn this into a fallthrough
return is, err
default:
return is, fmt.Errorf("Unexpected schema version: %d", v)
}
Expand Down Expand Up @@ -274,6 +284,13 @@ func migrateStateV3toV4(is *terraform.InstanceState, meta interface{}) (*terrafo
return is, nil
}

func migrateStateV4toV5(is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) {
if v := is.Attributes["disk.#"]; v != "" {
return migrateStateV3toV4(is, meta)
}
return is, nil
}

func getInstanceFromInstanceState(config *Config, is *terraform.InstanceState) (*compute.Instance, error) {
project, ok := is.Attributes["project"]
if !ok {
Expand Down
Loading

0 comments on commit 9b573f0

Please sign in to comment.