Skip to content

Commit

Permalink
Merge pull request #42 from Cox-Automotive/defect22103_revised
Browse files Browse the repository at this point in the history
 Updates state migrator to follow HashiCorp recommendations
  • Loading branch information
webbbarker committed Feb 5, 2019
2 parents 9c14255 + ae610e2 commit 5a91fdd
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions resource_alks_iamrole.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,24 @@ func populateResourceDataFromRole(role *alks.IamRoleResponse, d *schema.Resource
func migrateState(version int, state *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) {
switch version {
case 0:
state.Attributes["enable_alks_access"] = "false"
return state, nil
log.Println("[INFO] Found Instance State v0, migrating to v1")
return migrateV0toV1(state)
default:
return state, fmt.Errorf("Unrecognized version '%q' in schema for instance of ALKS IAM role", version)
return state, fmt.Errorf("Unrecognized version '%d' in schema for instance of ALKS IAM role '%s'", version, state.Attributes["name"])
}
}

func migrateV0toV1(state *terraform.InstanceState) (*terraform.InstanceState, error) {
if state.Empty() {
log.Println("[DEBUG] Empty InstanceState, nothing to migrate")
return state, nil
}

if _, ok := state.Attributes["enable_alks_access"]; !ok {
log.Printf("[DEBUG] Attributes before migration: %#v", state.Attributes)
state.Attributes["enable_alks_access"] = "false"
log.Printf("[DEBUG] Attributes after migration: %#v", state.Attributes)
}

return state, nil
}

0 comments on commit 5a91fdd

Please sign in to comment.