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

added cloudinit fix #108

Closed
9 changes: 9 additions & 0 deletions client/v3/v3_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ type VMResources struct {
// NICs attached to the VM.
NicList []*VMNic `json:"nic_list,omitempty"`

// Number of threads per core
NumThreads *int64 `json:"num_threads_per_core,omitempty"`

// Number of vCPU sockets.
NumSockets *int64 `json:"num_sockets,omitempty"`

Expand Down Expand Up @@ -836,6 +839,9 @@ type ImageResources struct {

// The image version
Version *ImageVersionResources `json:"version,omitempty"`

// Reference to the source image such as 'vm_disk
DataSourceReference *Reference `json:"data_source_reference,omitempty"`
}

// Image An intentful representation of a image spec
Expand Down Expand Up @@ -1620,6 +1626,9 @@ type Metadata struct {
OwnerReference *Reference `json:"owner_reference,omitempty"`
Categories map[string]string `json:"categories,omitempty"`
Name *string `json:"name,omitempty"`

// Applied on Prism Central only. Indicate whether force to translate the spec of the fanout request to fit the target cluster API schema.
ShouldForceTranslate *bool `json:"should_force_translate,omitempty"`
}

// NetworkSecurityRuleIntentInput An intentful representation of a network_security_rule
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module github.com/terraform-providers/terraform-provider-nutanix

require (
github.com/gogo/protobuf v1.2.0
github.com/golang/protobuf v1.3.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/terraform v0.12.3
Expand Down
44 changes: 44 additions & 0 deletions nutanix/categories_schema_migrate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package nutanix

import (
"log"
"sort"
)

func resourceNutanixCategoriesMigrateState(rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
if len(rawState) == 0 || rawState == nil {
log.Println("[DEBUG] Empty InstanceState; nothing to migrate.")
return rawState, nil
}

keys := make([]string, 0, len(rawState))
for k := range rawState {
keys = append(keys, k)
}

sort.Strings(keys)

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

if l, ok := rawState["categories"]; ok {
if assertedL, ok := l.(map[string]interface{}); ok {
c := make([]interface{}, 0)
keys := make([]string, 0, len(assertedL))
for k := range assertedL {
keys = append(keys, k)
}
sort.Strings(keys)
for _, name := range keys {
value := assertedL[name]
c = append(c, map[string]interface{}{
"name": name,
"value": value.(string),
})
}
rawState["categories"] = c
}
}
log.Printf("[DEBUG] Attributes after migration: %#v", rawState)
return rawState, nil
}
128 changes: 128 additions & 0 deletions nutanix/categories_schema_migrate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package nutanix

import (
"reflect"
"testing"
)

func TestResourceNutanixCategoriesteUpgradeV0(t *testing.T) {
cases := map[string]struct {
Attributes map[string]interface{}
Expected map[string]interface{}
Meta interface{}
}{
"v0_without_values": {
Attributes: map[string]interface{}{
"categories": make(map[string]interface{}),
},
Expected: map[string]interface{}{
"categories": make([]interface{}, 0),
},
},
"v0_with_values": {
Attributes: map[string]interface{}{
"categories": map[string]interface{}{
"os_type": "ubuntu",
"os_version": "18.04",
},
},
Expected: map[string]interface{}{

"categories": []interface{}{
map[string]interface{}{"name": "os_type", "value": "ubuntu"},
map[string]interface{}{"name": "os_version", "value": "18.04"},
},
},
},
"v0_categories_not_set": {
Attributes: map[string]interface{}{
"name": "test-name",
},
Expected: map[string]interface{}{
"name": "test-name",
},
},
"v0_multiple_categories": {
Attributes: map[string]interface{}{
"categories": map[string]interface{}{
"os_type": "ubuntu",
"os_version": "18.04",
"tier": "application",
"test": "test-value",
},
},
Expected: map[string]interface{}{
"categories": []interface{}{
map[string]interface{}{"name": "os_type",
"value": "ubuntu"},
map[string]interface{}{"name": "os_version",
"value": "18.04"},
map[string]interface{}{"name": "test",
"value": "test-value"},
map[string]interface{}{"name": "tier",
"value": "application"},
},
},
},
"v0_already_migrated": {
Attributes: map[string]interface{}{
"categories": []interface{}{
map[string]interface{}{"name": "os_type",
"value": "ubuntu"},
map[string]interface{}{"name": "os_version",
"value": "18.04"},
map[string]interface{}{"name": "tier",
"value": "application"},
},
},
Expected: map[string]interface{}{
"categories": []interface{}{
map[string]interface{}{"name": "os_type",
"value": "ubuntu"},
map[string]interface{}{"name": "os_version",
"value": "18.04"},
map[string]interface{}{"name": "tier",
"value": "application"},
},
},
},
"v0_empty_value": {
Attributes: map[string]interface{}{
"categories": map[string]interface{}{
"os_type": "",
"os_version": "",
"tier": "",
"test": "",
},
},
Expected: map[string]interface{}{
"categories": []interface{}{
map[string]interface{}{"name": "os_type",
"value": ""},
map[string]interface{}{"name": "os_version",
"value": ""},
map[string]interface{}{"name": "test",
"value": ""},
map[string]interface{}{"name": "tier",
"value": ""},
},
},
},
}

for tn, tc := range cases {
is, err := resourceNutanixCategoriesMigrateState(tc.Attributes, tc.Meta)

if err != nil {
t.Fatalf("bad: %s, err: %#v", tn, err)
}

for k, v := range tc.Expected {
if !reflect.DeepEqual(is[k], v) {
t.Fatalf(
"bad: %s\n\n expected: %#v -> %#v\n got: %#v -> %#v\n in: %#v",
tn, k, v, k, is[k], is)
}
}
}
}
Loading