Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compute_instance migration bug. #511

Merged
merged 2 commits into from
Oct 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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