Skip to content

Commit

Permalink
Added categories migration code to all objects
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickstruyf3 committed Apr 1, 2020
1 parent a6f1a1e commit e53bfa1
Show file tree
Hide file tree
Showing 10 changed files with 3,982 additions and 21 deletions.
18 changes: 5 additions & 13 deletions nutanix/categories_schema_migrate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package nutanix

import (
"fmt"
"log"
"sort"
)
Expand All @@ -19,18 +18,19 @@ func resourceNutanixCategoriesMigrateState(rawState map[string]interface{}, meta

sort.Strings(keys)

log.Printf("[DEBUG] meta: %#v", meta)
log.Printf("[DEBUG] Attributes before migration: %#v", rawState)

if l, ok := rawState["categories"]; ok {
if asserted_l, ok := l.(map[string]interface{}); ok {
if assertedL, ok := l.(map[string]interface{}); ok {
c := make([]interface{}, 0)
keys := make([]string, 0, len(asserted_l))
for k := range asserted_l {
keys := make([]string, 0, len(assertedL))
for k := range assertedL {
keys = append(keys, k)
}
sort.Strings(keys)
for _, name := range keys {
value := asserted_l[name]
value := assertedL[name]
c = append(c, map[string]interface{}{
"name": name,
"value": value.(string),
Expand All @@ -42,11 +42,3 @@ func resourceNutanixCategoriesMigrateState(rawState map[string]interface{}, meta
log.Printf("[DEBUG] Attributes after migration: %#v", rawState)
return rawState, nil
}

func flattenTempCategories(categories []map[string]string, rawState map[string]interface{}) {
for index, category := range categories {
for key, value := range category {
rawState[fmt.Sprintf("categories.%d.%s", index, key)] = value
}
}
}
Loading

0 comments on commit e53bfa1

Please sign in to comment.