From 18e620078721f3085fbc78543bf6ea2a648935bf Mon Sep 17 00:00:00 2001 From: Marin Salinas Date: Fri, 20 Mar 2020 12:11:36 -0600 Subject: [PATCH 1/7] feat: virtual_machine resource - omit set ip_endpoint_list when is leaned for nic_list argument --- nutanix/structure.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/nutanix/structure.go b/nutanix/structure.go index bf2a2f331..7926b3baa 100644 --- a/nutanix/structure.go +++ b/nutanix/structure.go @@ -76,10 +76,12 @@ func flattenNicList(nics []*v3.VMNic) []map[string]interface{} { nic["model"] = utils.StringValue(v.Model) var ipEndpointList []map[string]interface{} for _, v1 := range v.IPEndpointList { - ipEndpoint := make(map[string]interface{}) - ipEndpoint["ip"] = utils.StringValue(v1.IP) - ipEndpoint["type"] = utils.StringValue(v1.Type) - ipEndpointList = append(ipEndpointList, ipEndpoint) + if utils.StringValue(v1.Type) != "LEARNED" { + ipEndpoint := make(map[string]interface{}) + ipEndpoint["ip"] = utils.StringValue(v1.IP) + ipEndpoint["type"] = utils.StringValue(v1.Type) + ipEndpointList = append(ipEndpointList, ipEndpoint) + } } nic["ip_endpoint_list"] = ipEndpointList nic["network_function_chain_reference"] = flattenReferenceValues(v.NetworkFunctionChainReference) From 27ab8a8bd973eb72517d581e69091e64142dad7b Mon Sep 17 00:00:00 2001 From: Yannick Struyf Date: Tue, 31 Mar 2020 22:21:33 +0200 Subject: [PATCH 2/7] added nil checking for deviceProperties --- nutanix/resource_nutanix_virtual_machine.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nutanix/resource_nutanix_virtual_machine.go b/nutanix/resource_nutanix_virtual_machine.go index 6c1204d95..09796b0d2 100644 --- a/nutanix/resource_nutanix_virtual_machine.go +++ b/nutanix/resource_nutanix_virtual_machine.go @@ -1935,7 +1935,7 @@ func waitForIPRefreshFunc(client *v3.Client, vmUUID string) resource.StateRefres func CountDiskListCdrom(dl []*v3.VMDisk) (int, error) { counter := 0 for _, v := range dl { - if *v.DeviceProperties.DeviceType == "CDROM" { + if v.DeviceProperties != nil && *v.DeviceProperties.DeviceType == "CDROM" { counter++ } } From 4ec1e639b4c3f2aef30b83027b94157ac43c81da Mon Sep 17 00:00:00 2001 From: Marin Salinas Date: Wed, 1 Apr 2020 10:13:44 -0600 Subject: [PATCH 3/7] fix: add migrate state function to avoid state issues when update the provider --- go.mod | 1 + nutanix/categories_schema_migrate.go | 82 ++++++++++++ nutanix/categories_schema_migrate_test.go | 131 ++++++++++++++++++++ nutanix/resource_nutanix_virtual_machine.go | 7 ++ 4 files changed, 221 insertions(+) create mode 100644 nutanix/categories_schema_migrate.go create mode 100644 nutanix/categories_schema_migrate_test.go diff --git a/go.mod b/go.mod index bc314eb88..8f107d73e 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/nutanix/categories_schema_migrate.go b/nutanix/categories_schema_migrate.go new file mode 100644 index 000000000..e935c15d7 --- /dev/null +++ b/nutanix/categories_schema_migrate.go @@ -0,0 +1,82 @@ +package nutanix + +import ( + "fmt" + "log" + "sort" + "strings" + + "github.com/hashicorp/terraform/terraform" +) + +func resourceNutanixCategoriesMigrateState( + v int, is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) { + switch v { + case 0: + log.Println("[INFO] Found Nutanix State v0; migrating to v1") + return migrateNutanixCategoriesV0toV1(is) + default: + return is, fmt.Errorf("Unexpected schema version: %d", v) + } +} + +func migrateNutanixCategoriesV0toV1(is *terraform.InstanceState) (*terraform.InstanceState, error) { + if is.Empty() || is.Attributes == nil { + log.Println("[DEBUG] Empty InstanceState; nothing to migrate.") + return is, nil + } + + keys := make([]string, 0, len(is.Attributes)) + for k := range is.Attributes { + keys = append(keys, k) + } + + sort.Strings(keys) + + log.Printf("[DEBUG] Attributes before migration: %#v", is.Attributes) + + if l, ok := is.Attributes["categories.%"]; ok && l != "" { + var tempCat []map[string]string + + for _, k := range keys { + v := is.Attributes[k] + + if k == "categories.%" { + is.Attributes["categories.#"] = v + delete(is.Attributes, "categories.%") + continue + } + + if strings.HasPrefix(k, "categories.") { + path := strings.Split(k, ".") + if len(path) != 2 { + return is, fmt.Errorf("found unexpected categories field: %#v", k) + } + + if path[1] == "#" { + continue + } + + log.Printf("[DEBUG] key=%s", k) + + tempCat = append(tempCat, map[string]string{ + "name": path[1], + "value": v, + }) + + delete(is.Attributes, k) + } + } + flattenTempCategories(tempCat, is) + } + log.Printf("[DEBUG] Attributes after migration: %#v", is.Attributes) + return is, nil +} + +func flattenTempCategories(categories []map[string]string, is *terraform.InstanceState) { + for index, category := range categories { + for key, value := range category { + is.Attributes[fmt.Sprintf("categories.%d.%s", index, key)] = value + } + } +} diff --git a/nutanix/categories_schema_migrate_test.go b/nutanix/categories_schema_migrate_test.go new file mode 100644 index 000000000..4e20a28ad --- /dev/null +++ b/nutanix/categories_schema_migrate_test.go @@ -0,0 +1,131 @@ +package nutanix + +import ( + "testing" + + "github.com/hashicorp/terraform/terraform" +) + +func TestResourceNutanixCategoriesteUpgradeV0(t *testing.T) { + cases := map[string]struct { + StateVersion int + Attributes map[string]string + Expected map[string]string + Meta interface{} + }{ + "v0_without_values": { + StateVersion: 0, + Attributes: map[string]string{ + "categories.%": "0", + }, + Expected: map[string]string{ + "categories.#": "0", + }, + }, + "v0_with_values": { + StateVersion: 0, + Attributes: map[string]string{ + "categories.%": "2", + "categories.os_type": "ubuntu", + "categories.os_version": "18.04", + }, + Expected: map[string]string{ + "categories.#": "2", + "categories.0.name": "os_type", + "categories.0.value": "ubuntu", + "categories.1.name": "os_version", + "categories.1.value": "18.04", + }, + }, + "v0_categories_not_set": { + StateVersion: 0, + Attributes: map[string]string{ + "name": "test-name", + }, + Expected: map[string]string{ + "name": "test-name", + }, + }, + "v0_multiple_categories": { + StateVersion: 0, + Attributes: map[string]string{ + "categories.%": "3", + "categories.os_type": "ubuntu", + "categories.os_version": "18.04", + "categories.tier": "application", + "categories.test": "test-value", + }, + Expected: map[string]string{ + "categories.#": "3", + "categories.0.name": "os_type", + "categories.0.value": "ubuntu", + "categories.1.name": "os_version", + "categories.1.value": "18.04", + "categories.2.name": "test", + "categories.2.value": "test-value", + "categories.3.name": "tier", + "categories.3.value": "application", + }, + }, + "v0_already_migrated": { + StateVersion: 0, + Attributes: map[string]string{ + "categories.#": "3", + "categories.0.name": "os_type", + "categories.0.value": "ubuntu", + "categories.1.name": "os_version", + "categories.1.value": "18.04", + "categories.2.name": "tier", + "categories.2.value": "application", + }, + Expected: map[string]string{ + "categories.#": "3", + "categories.0.name": "os_type", + "categories.0.value": "ubuntu", + "categories.1.name": "os_version", + "categories.1.value": "18.04", + "categories.2.name": "tier", + "categories.2.value": "application", + }, + }, + "v0_empty_value": { + StateVersion: 0, + Attributes: map[string]string{ + "categories.%": "3", + "categories.os_type": "", + "categories.os_version": "", + "categories.tier": "", + }, + Expected: map[string]string{ + "categories.#": "3", + "categories.0.name": "os_type", + "categories.0.value": "", + "categories.1.name": "os_version", + "categories.1.value": "", + "categories.2.name": "tier", + "categories.2.value": "", + }, + }, + } + + for tn, tc := range cases { + is := &terraform.InstanceState{ + ID: "i-abc123", + Attributes: tc.Attributes, + } + is, err := resourceNutanixCategoriesMigrateState( + tc.StateVersion, is, tc.Meta) + + if err != nil { + t.Fatalf("bad: %s, err: %#v", tn, err) + } + + for k, v := range tc.Expected { + if is.Attributes[k] != v { + t.Fatalf( + "bad: %s\n\n expected: %#v -> %#v\n got: %#v -> %#v\n in: %#v", + tn, k, v, k, is.Attributes[k], is.Attributes) + } + } + } +} diff --git a/nutanix/resource_nutanix_virtual_machine.go b/nutanix/resource_nutanix_virtual_machine.go index 09796b0d2..457562896 100644 --- a/nutanix/resource_nutanix_virtual_machine.go +++ b/nutanix/resource_nutanix_virtual_machine.go @@ -15,6 +15,7 @@ import ( "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/validation" + "github.com/hashicorp/terraform/terraform" ) var ( @@ -33,6 +34,8 @@ func resourceNutanixVirtualMachine() *schema.Resource { Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, + SchemaVersion: 1, + MigrateState: resourceVirtualMachineInstanceStateUpgradeV0, Schema: map[string]*schema.Schema{ "metadata": { Type: schema.TypeMap, @@ -1941,3 +1944,7 @@ func CountDiskListCdrom(dl []*v3.VMDisk) (int, error) { } return counter, nil } + +func resourceVirtualMachineInstanceStateUpgradeV0(v int, is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) { + return resourceNutanixCategoriesMigrateState(v, is, meta) +} From 787f3717f3d7a0a799d1c9e063edb51de953b9c7 Mon Sep 17 00:00:00 2001 From: Yannick Struyf Date: Wed, 1 Apr 2020 20:45:20 +0200 Subject: [PATCH 4/7] Refactore statefile migrations --- nutanix/categories_schema_migrate.go | 76 +- nutanix/categories_schema_migrate_test.go | 159 +++-- nutanix/resource_nutanix_virtual_machine.go | 739 +++++++++++++++++++- 3 files changed, 836 insertions(+), 138 deletions(-) diff --git a/nutanix/categories_schema_migrate.go b/nutanix/categories_schema_migrate.go index e935c15d7..1a71b7e1a 100644 --- a/nutanix/categories_schema_migrate.go +++ b/nutanix/categories_schema_migrate.go @@ -4,79 +4,49 @@ import ( "fmt" "log" "sort" - "strings" - - "github.com/hashicorp/terraform/terraform" ) -func resourceNutanixCategoriesMigrateState( - v int, is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) { - switch v { - case 0: - log.Println("[INFO] Found Nutanix State v0; migrating to v1") - return migrateNutanixCategoriesV0toV1(is) - default: - return is, fmt.Errorf("Unexpected schema version: %d", v) - } -} - -func migrateNutanixCategoriesV0toV1(is *terraform.InstanceState) (*terraform.InstanceState, error) { - if is.Empty() || is.Attributes == nil { +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 is, nil + return rawState, nil } - keys := make([]string, 0, len(is.Attributes)) - for k := range is.Attributes { + keys := make([]string, 0, len(rawState)) + for k := range rawState { keys = append(keys, k) } sort.Strings(keys) - log.Printf("[DEBUG] Attributes before migration: %#v", is.Attributes) - - if l, ok := is.Attributes["categories.%"]; ok && l != "" { - var tempCat []map[string]string - - for _, k := range keys { - v := is.Attributes[k] + log.Printf("[DEBUG] Attributes before migration: %#v", rawState) - if k == "categories.%" { - is.Attributes["categories.#"] = v - delete(is.Attributes, "categories.%") - continue + if l, ok := rawState["categories"]; ok { + if asserted_l, ok := l.(map[string]interface{}); ok { + c := make([]interface{}, 0) + keys := make([]string, 0, len(asserted_l)) + for k := range asserted_l { + keys = append(keys, k) } - - if strings.HasPrefix(k, "categories.") { - path := strings.Split(k, ".") - if len(path) != 2 { - return is, fmt.Errorf("found unexpected categories field: %#v", k) - } - - if path[1] == "#" { - continue - } - - log.Printf("[DEBUG] key=%s", k) - - tempCat = append(tempCat, map[string]string{ - "name": path[1], - "value": v, + sort.Strings(keys) + for _, name := range keys { + value := asserted_l[name] + c = append(c, map[string]interface{}{ + "name": name, + "value": value.(string), }) - - delete(is.Attributes, k) } + rawState["categories"] = c } - flattenTempCategories(tempCat, is) } - log.Printf("[DEBUG] Attributes after migration: %#v", is.Attributes) - return is, nil + log.Printf("[DEBUG] Attributes after migration: %#v", rawState) + return rawState, nil } -func flattenTempCategories(categories []map[string]string, is *terraform.InstanceState) { +func flattenTempCategories(categories []map[string]string, rawState map[string]interface{}) { for index, category := range categories { for key, value := range category { - is.Attributes[fmt.Sprintf("categories.%d.%s", index, key)] = value + rawState[fmt.Sprintf("categories.%d.%s", index, key)] = value } } } diff --git a/nutanix/categories_schema_migrate_test.go b/nutanix/categories_schema_migrate_test.go index 4e20a28ad..d4e7c08e7 100644 --- a/nutanix/categories_schema_migrate_test.go +++ b/nutanix/categories_schema_migrate_test.go @@ -1,130 +1,127 @@ package nutanix import ( + "reflect" "testing" - - "github.com/hashicorp/terraform/terraform" ) func TestResourceNutanixCategoriesteUpgradeV0(t *testing.T) { cases := map[string]struct { - StateVersion int - Attributes map[string]string - Expected map[string]string - Meta interface{} + Attributes map[string]interface{} + Expected map[string]interface{} + Meta interface{} }{ "v0_without_values": { - StateVersion: 0, - Attributes: map[string]string{ - "categories.%": "0", + Attributes: map[string]interface{}{ + "categories": make(map[string]interface{}), }, - Expected: map[string]string{ - "categories.#": "0", + Expected: map[string]interface{}{ + "categories": make([]interface{}, 0), }, }, "v0_with_values": { - StateVersion: 0, - Attributes: map[string]string{ - "categories.%": "2", - "categories.os_type": "ubuntu", - "categories.os_version": "18.04", + Attributes: map[string]interface{}{ + "categories": map[string]interface{}{ + "os_type": "ubuntu", + "os_version": "18.04", + }, }, - Expected: map[string]string{ - "categories.#": "2", - "categories.0.name": "os_type", - "categories.0.value": "ubuntu", - "categories.1.name": "os_version", - "categories.1.value": "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": { - StateVersion: 0, - Attributes: map[string]string{ + Attributes: map[string]interface{}{ "name": "test-name", }, - Expected: map[string]string{ + Expected: map[string]interface{}{ "name": "test-name", }, }, "v0_multiple_categories": { - StateVersion: 0, - Attributes: map[string]string{ - "categories.%": "3", - "categories.os_type": "ubuntu", - "categories.os_version": "18.04", - "categories.tier": "application", - "categories.test": "test-value", + Attributes: map[string]interface{}{ + "categories": map[string]interface{}{ + "os_type": "ubuntu", + "os_version": "18.04", + "tier": "application", + "test": "test-value", + }, }, - Expected: map[string]string{ - "categories.#": "3", - "categories.0.name": "os_type", - "categories.0.value": "ubuntu", - "categories.1.name": "os_version", - "categories.1.value": "18.04", - "categories.2.name": "test", - "categories.2.value": "test-value", - "categories.3.name": "tier", - "categories.3.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": "test", + "value": "test-value"}, + map[string]interface{}{"name": "tier", + "value": "application"}, + }, }, }, "v0_already_migrated": { - StateVersion: 0, - Attributes: map[string]string{ - "categories.#": "3", - "categories.0.name": "os_type", - "categories.0.value": "ubuntu", - "categories.1.name": "os_version", - "categories.1.value": "18.04", - "categories.2.name": "tier", - "categories.2.value": "application", + 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]string{ - "categories.#": "3", - "categories.0.name": "os_type", - "categories.0.value": "ubuntu", - "categories.1.name": "os_version", - "categories.1.value": "18.04", - "categories.2.name": "tier", - "categories.2.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": { - StateVersion: 0, - Attributes: map[string]string{ - "categories.%": "3", - "categories.os_type": "", - "categories.os_version": "", - "categories.tier": "", + Attributes: map[string]interface{}{ + "categories": map[string]interface{}{ + "os_type": "", + "os_version": "", + "tier": "", + "test": "", + }, }, - Expected: map[string]string{ - "categories.#": "3", - "categories.0.name": "os_type", - "categories.0.value": "", - "categories.1.name": "os_version", - "categories.1.value": "", - "categories.2.name": "tier", - "categories.2.value": "", + 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 := &terraform.InstanceState{ - ID: "i-abc123", - Attributes: tc.Attributes, - } - is, err := resourceNutanixCategoriesMigrateState( - tc.StateVersion, is, tc.Meta) + 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 is.Attributes[k] != v { + 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.Attributes[k], is.Attributes) + tn, k, v, k, is[k], is) } } } diff --git a/nutanix/resource_nutanix_virtual_machine.go b/nutanix/resource_nutanix_virtual_machine.go index 457562896..ec58c199e 100644 --- a/nutanix/resource_nutanix_virtual_machine.go +++ b/nutanix/resource_nutanix_virtual_machine.go @@ -15,7 +15,6 @@ import ( "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/validation" - "github.com/hashicorp/terraform/terraform" ) var ( @@ -35,7 +34,13 @@ func resourceNutanixVirtualMachine() *schema.Resource { State: schema.ImportStatePassthrough, }, SchemaVersion: 1, - MigrateState: resourceVirtualMachineInstanceStateUpgradeV0, + StateUpgraders: []schema.StateUpgrader{ + { + Type: resourceNutanixVirtualMachineInstanceResourceV0().CoreConfigSchema().ImpliedType(), + Upgrade: resourceVirtualMachineInstanceStateUpgradeV0, + Version: 0, + }, + }, Schema: map[string]*schema.Schema{ "metadata": { Type: schema.TypeMap, @@ -1945,6 +1950,732 @@ func CountDiskListCdrom(dl []*v3.VMDisk) (int, error) { return counter, nil } -func resourceVirtualMachineInstanceStateUpgradeV0(v int, is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) { - return resourceNutanixCategoriesMigrateState(v, is, meta) +func resourceVirtualMachineInstanceStateUpgradeV0(is map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + log.Printf("[DEBUG] Entering resourceVirtualMachineInstanceStateUpgradeV0") + return resourceNutanixCategoriesMigrateState(is, meta) +} + +func resourceNutanixVirtualMachineInstanceResourceV0() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "metadata": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "last_update_time": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "creation_time": { + Type: schema.TypeString, + Computed: true, + }, + "spec_version": { + Type: schema.TypeString, + Computed: true, + }, + "spec_hash": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "categories": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + }, + "project_reference": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Required: true, + }, + "uuid": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + }, + }, + }, + "owner_reference": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Required: true, + }, + "uuid": { + Type: schema.TypeString, + Required: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + }, + }, + }, + "api_version": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Required: true, + }, + "description": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "availability_zone_reference": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Required: true, + }, + "uuid": { + Type: schema.TypeString, + Required: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + }, + }, + }, + "cluster_uuid": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringMatch( + regexp.MustCompile( + "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"), + "please see http://developer.nutanix.com/reference/prism_central/v3/api/models/cluster-reference"), + }, + "cluster_name": { + Type: schema.TypeString, + Computed: true, + }, + "state": { + Type: schema.TypeString, + Computed: true, + }, + "host_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "hypervisor_type": { + Type: schema.TypeString, + Computed: true, + }, + "nic_list_status": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "nic_type": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "floating_ip": { + Type: schema.TypeString, + Computed: true, + }, + "model": { + Type: schema.TypeString, + Computed: true, + }, + "network_function_nic_type": { + Type: schema.TypeString, + Computed: true, + }, + "mac_address": { + Type: schema.TypeString, + Computed: true, + }, + "ip_endpoint_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ip": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "network_function_chain_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "subnet_uuid": { + Type: schema.TypeString, + Computed: true, + }, + "subnet_name": { + Type: schema.TypeString, + Computed: true, + }, + "is_connected": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + + // RESOURCES ARGUMENTS + + "num_vnuma_nodes": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "nic_list": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "nic_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "model": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "network_function_nic_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "mac_address": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "ip_endpoint_list": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ip": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + }, + }, + }, + "network_function_chain_reference": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Required: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Required: true, + }, + }, + }, + }, + "subnet_uuid": { + Type: schema.TypeString, + Optional: true, + }, + "subnet_name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "is_connected": { + Type: schema.TypeString, + Optional: true, + Default: "true", + }, + }, + }, + }, + "guest_os_id": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "power_state": { + Type: schema.TypeString, + Computed: true, + }, + "nutanix_guest_tools": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "state": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "ngt_state": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "version": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "iso_mount_state": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "available_version": { + Type: schema.TypeString, + Computed: true, + }, + "guest_os_version": { + Type: schema.TypeString, + Computed: true, + }, + "vss_snapshot_capable": { + Type: schema.TypeString, + Computed: true, + }, + "is_reachable": { + Type: schema.TypeString, + Computed: true, + }, + "vm_mobility_drivers_installed": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "ngt_credentials": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + }, + "ngt_enabled_capability_list": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "num_vcpus_per_socket": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "num_sockets": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "gpu_list": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "frame_buffer_size_mib": { + Type: schema.TypeInt, + Computed: true, + }, + "vendor": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "pci_address": { + Type: schema.TypeString, + Computed: true, + }, + "fraction": { + Type: schema.TypeInt, + Computed: true, + }, + "mode": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "num_virtual_display_heads": { + Type: schema.TypeInt, + Computed: true, + }, + "guest_driver_version": { + Type: schema.TypeString, + Computed: true, + }, + "device_id": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + }, + }, + }, + "parent_reference": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Required: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Required: true, + }, + }, + }, + }, + "memory_size_mib": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "boot_device_order_list": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "boot_device_disk_address": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "device_index": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "adapter_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + }, + }, + }, + "boot_device_mac_address": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "hardware_clock_timezone": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "guest_customization_cloud_init_user_data": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + "guest_customization_cloud_init_meta_data": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + "guest_customization_cloud_init_custom_key_values": { + Type: schema.TypeMap, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Optional: true, + Computed: true, + }, + "guest_customization_is_overridable": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + "guest_customization_sysprep": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + ForceNew: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "install_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "unattend_xml": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + }, + }, + }, + "guest_customization_sysprep_custom_key_values": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + ForceNew: true, + }, + "should_fail_on_script_failure": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + "enable_script_exec": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + "power_state_mechanism": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "vga_console_enabled": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + "disk_list": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "uuid": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "disk_size_bytes": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "disk_size_mib": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "device_properties": { + Type: schema.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "device_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "disk_address": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "device_index": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "adapter_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "data_source_reference": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + }, + }, + }, + "volume_group_reference": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "serial_port_list": { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "index": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "is_connected": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + }, + }, + }, + }, + } } From fc0f74fb11252eda4ee86abe0b31b33e64166ec9 Mon Sep 17 00:00:00 2001 From: Yannick Struyf Date: Wed, 1 Apr 2020 22:00:37 +0200 Subject: [PATCH 5/7] Added categories migration code to all objects --- nutanix/categories_schema_migrate.go | 18 +- nutanix/data_source_nutanix_cluster.go | 598 +++++++++++++- nutanix/data_source_nutanix_clusters.go | 603 +++++++++++++- nutanix/data_source_nutanix_image.go | 211 ++++- ...ta_source_nutanix_network_security_rule.go | 743 +++++++++++++++++- nutanix/data_source_nutanix_subnet.go | 281 ++++++- .../data_source_nutanix_virtual_machine.go | 616 ++++++++++++++- nutanix/resource_nutanix_image.go | 209 +++++ .../resource_nutanix_network_security_rule.go | 436 ++++++++++ nutanix/resource_nutanix_subnet.go | 288 +++++++ 10 files changed, 3982 insertions(+), 21 deletions(-) diff --git a/nutanix/categories_schema_migrate.go b/nutanix/categories_schema_migrate.go index 1a71b7e1a..db96223f1 100644 --- a/nutanix/categories_schema_migrate.go +++ b/nutanix/categories_schema_migrate.go @@ -1,7 +1,6 @@ package nutanix import ( - "fmt" "log" "sort" ) @@ -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), @@ -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 - } - } -} diff --git a/nutanix/data_source_nutanix_cluster.go b/nutanix/data_source_nutanix_cluster.go index c0245f728..baa9ef1b6 100644 --- a/nutanix/data_source_nutanix_cluster.go +++ b/nutanix/data_source_nutanix_cluster.go @@ -2,6 +2,7 @@ package nutanix import ( "fmt" + "log" "strconv" "github.com/hashicorp/terraform/helper/schema" @@ -11,7 +12,15 @@ import ( func dataSourceNutanixCluster() *schema.Resource { return &schema.Resource{ - Read: dataSourceNutanixClusterRead, + Read: dataSourceNutanixClusterRead, + SchemaVersion: 1, + StateUpgraders: []schema.StateUpgrader{ + { + Type: resourceNutanixDatasourceClusterResourceV0().CoreConfigSchema().ImpliedType(), + Upgrade: resourceDatasourceClusterStateUpgradeV0, + Version: 0, + }, + }, Schema: map[string]*schema.Schema{ "cluster_id": { Type: schema.TypeString, @@ -1081,3 +1090,590 @@ func findClusterByName(conn *v3.Client, name string) (*v3.ClusterIntentResponse, return found[0], nil } + +func resourceDatasourceClusterStateUpgradeV0(is map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + log.Printf("[DEBUG] Entering resourceDatasourceClusterStateUpgradeV0") + return resourceNutanixCategoriesMigrateState(is, meta) +} + +func resourceNutanixDatasourceClusterResourceV0() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cluster_id": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ConflictsWith: []string{"name"}, + }, + "metadata": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "last_update_time": { + Type: schema.TypeString, + Computed: true, + }, + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "creation_time": { + Type: schema.TypeString, + Computed: true, + }, + "spec_version": { + Type: schema.TypeString, + Computed: true, + }, + "spec_hash": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "categories": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + }, + "project_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "owner_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "api_version": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ConflictsWith: []string{"cluster_id"}, + }, + + // COMPUTED + "state": { + Type: schema.TypeString, + Computed: true, + }, + "nodes": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ip": { + Type: schema.TypeString, + Computed: true, + }, + "version": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "gpu_driver_version": { + Type: schema.TypeString, + Computed: true, + }, + "client_auth": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "status": { + Type: schema.TypeString, + Computed: true, + }, + "ca_chain": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "authorized_public_key_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "key": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "software_map_ncc": { + Type: schema.TypeMap, + Computed: true, + }, + "software_map_nos": { + Type: schema.TypeMap, + Computed: true, + }, + "encryption_status": { + Type: schema.TypeString, + Computed: true, + }, + "ssl_key_type": { + Type: schema.TypeString, + Computed: true, + }, + "ssl_key_name": { + Type: schema.TypeString, + Computed: true, + }, + "ssl_key_signing_info": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "city": { + Type: schema.TypeString, + Computed: true, + }, + "common_name_suffix": { + Type: schema.TypeString, + Computed: true, + }, + "state": { + Type: schema.TypeString, + Computed: true, + }, + "country_code": { + Type: schema.TypeString, + Computed: true, + }, + "common_name": { + Type: schema.TypeString, + Computed: true, + }, + "organization": { + Type: schema.TypeString, + Computed: true, + }, + "email_address": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "ssl_key_expire_datetime": { + Type: schema.TypeString, + Computed: true, + }, + "service_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "supported_information_verbosity": { + Type: schema.TypeString, + Computed: true, + }, + "certification_signing_info": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "city": { + Type: schema.TypeString, + Computed: true, + }, + "common_name_suffix": { + Type: schema.TypeString, + Computed: true, + }, + "state": { + Type: schema.TypeString, + Computed: true, + }, + "country_code": { + Type: schema.TypeString, + Computed: true, + }, + "common_name": { + Type: schema.TypeString, + Computed: true, + }, + "organization": { + Type: schema.TypeString, + Computed: true, + }, + "email_address": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "operation_mode": { + Type: schema.TypeString, + Computed: true, + }, + "ca_certificate_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ca_name": { + Type: schema.TypeString, + Computed: true, + }, + "certificate": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "enabled_feature_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "is_available": { + Type: schema.TypeBool, + Computed: true, + }, + "build": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "commit_id": { + Type: schema.TypeString, + Computed: true, + }, + "full_version": { + Type: schema.TypeString, + Computed: true, + }, + "commit_date": { + Type: schema.TypeString, + Computed: true, + }, + "version": { + Type: schema.TypeString, + Computed: true, + }, + "short_commit_id": { + Type: schema.TypeString, + Computed: true, + }, + "build_type": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "timezone": { + Type: schema.TypeString, + Computed: true, + }, + "cluster_arch": { + Type: schema.TypeString, + Computed: true, + }, + "management_server_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ip": { + Type: schema.TypeString, + Computed: true, + }, + "drs_enabled": { + Type: schema.TypeBool, + Computed: true, + }, + "status_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "masquerading_port": { + Type: schema.TypeInt, + Computed: true, + }, + "masquerading_ip": { + Type: schema.TypeString, + Computed: true, + }, + "external_ip": { + Type: schema.TypeString, + Computed: true, + }, + "http_proxy_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "credentials": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "username": { + Type: schema.TypeString, + Computed: true, + }, + "password": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "proxy_type_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "address": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ip": { + Type: schema.TypeString, + Computed: true, + }, + "fqdn": { + Type: schema.TypeString, + Computed: true, + }, + "port": { + Type: schema.TypeString, + Computed: true, + }, + "ipv6": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "smtp_server_type": { + Type: schema.TypeString, + Computed: true, + }, + "smtp_server_email_address": { + Type: schema.TypeString, + Computed: true, + }, + "smtp_server_credentials": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "username": { + Type: schema.TypeString, + Computed: true, + }, + "password": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "smtp_server_proxy_type_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "smtp_server_address": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ip": { + Type: schema.TypeString, + Computed: true, + }, + "fqdn": { + Type: schema.TypeString, + Computed: true, + }, + "port": { + Type: schema.TypeString, + Computed: true, + }, + "ipv6": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "ntp_server_ip_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "external_subnet": { + Type: schema.TypeString, + Computed: true, + }, + "external_data_services_ip": { + Type: schema.TypeString, + Computed: true, + }, + "internal_subnet": { + Type: schema.TypeString, + Computed: true, + }, + "domain_server_nameserver": { + Type: schema.TypeString, + Computed: true, + }, + "domain_server_name": { + Type: schema.TypeString, + Computed: true, + }, + "domain_server_credentials": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "username": { + Type: schema.TypeString, + Computed: true, + }, + "password": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "nfs_subnet_whitelist": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "name_server_ip_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "http_proxy_whitelist": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "target": { + Type: schema.TypeString, + Computed: true, + }, + "target_type": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "analysis_vm_efficiency_map": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "bully_vm_num": { + Type: schema.TypeString, + Computed: true, + }, + "constrained_vm_num": { + Type: schema.TypeString, + Computed: true, + }, + "dead_vm_num": { + Type: schema.TypeString, + Computed: true, + }, + "inefficient_vm_num": { + Type: schema.TypeString, + Computed: true, + }, + "overprovisioned_vm_num": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + } +} diff --git a/nutanix/data_source_nutanix_clusters.go b/nutanix/data_source_nutanix_clusters.go index 80858f0b8..feb8c7528 100644 --- a/nutanix/data_source_nutanix_clusters.go +++ b/nutanix/data_source_nutanix_clusters.go @@ -1,6 +1,7 @@ package nutanix import ( + "log" "strconv" "github.com/hashicorp/terraform/helper/resource" @@ -10,8 +11,15 @@ import ( func dataSourceNutanixClusters() *schema.Resource { return &schema.Resource{ - Read: dataSourceNutanixClustersRead, - + Read: dataSourceNutanixClustersRead, + SchemaVersion: 1, + StateUpgraders: []schema.StateUpgrader{ + { + Type: resourceNutanixDatasourceClustersResourceV0().CoreConfigSchema().ImpliedType(), + Upgrade: resourceDatasourceClustersStateUpgradeV0, + Version: 0, + }, + }, Schema: map[string]*schema.Schema{ "api_version": { Type: schema.TypeString, @@ -891,3 +899,594 @@ func dataSourceNutanixClustersRead(d *schema.ResourceData, meta interface{}) err return nil } + +func resourceDatasourceClustersStateUpgradeV0(is map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + log.Printf("[DEBUG] Entering resourceDatasourceClustersStateUpgradeV0") + return resourceNutanixCategoriesMigrateState(is, meta) +} + +func resourceNutanixDatasourceClustersResourceV0() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "api_version": { + Type: schema.TypeString, + Computed: true, + }, + "entities": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "metadata": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "last_update_time": { + Type: schema.TypeString, + Computed: true, + }, + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "creation_time": { + Type: schema.TypeString, + Computed: true, + }, + "spec_version": { + Type: schema.TypeString, + Computed: true, + }, + "spec_hash": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "categories": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + }, + "project_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "owner_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "api_version": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + + // COMPUTED + "state": { + Type: schema.TypeString, + Computed: true, + }, + "nodes": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ip": { + Type: schema.TypeString, + Computed: true, + }, + "version": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "gpu_driver_version": { + Type: schema.TypeString, + Computed: true, + }, + "client_auth": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "status": { + Type: schema.TypeString, + Computed: true, + }, + "ca_chain": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "authorized_public_key_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "key": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "software_map_ncc": { + Type: schema.TypeMap, + Computed: true, + }, + "software_map_nos": { + Type: schema.TypeMap, + Computed: true, + }, + "encryption_status": { + Type: schema.TypeString, + Computed: true, + }, + "ssl_key_type": { + Type: schema.TypeString, + Computed: true, + }, + "ssl_key_name": { + Type: schema.TypeString, + Computed: true, + }, + "ssl_key_signing_info": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "city": { + Type: schema.TypeString, + Computed: true, + }, + "common_name_suffix": { + Type: schema.TypeString, + Computed: true, + }, + "state": { + Type: schema.TypeString, + Computed: true, + }, + "country_code": { + Type: schema.TypeString, + Computed: true, + }, + "common_name": { + Type: schema.TypeString, + Computed: true, + }, + "organization": { + Type: schema.TypeString, + Computed: true, + }, + "email_address": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "ssl_key_expire_datetime": { + Type: schema.TypeString, + Computed: true, + }, + "service_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "supported_information_verbosity": { + Type: schema.TypeString, + Computed: true, + }, + "certification_signing_info": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "city": { + Type: schema.TypeString, + Computed: true, + }, + "common_name_suffix": { + Type: schema.TypeString, + Computed: true, + }, + "state": { + Type: schema.TypeString, + Computed: true, + }, + "country_code": { + Type: schema.TypeString, + Computed: true, + }, + "common_name": { + Type: schema.TypeString, + Computed: true, + }, + "organization": { + Type: schema.TypeString, + Computed: true, + }, + "email_address": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "operation_mode": { + Type: schema.TypeString, + Computed: true, + }, + "ca_certificate_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ca_name": { + Type: schema.TypeString, + Computed: true, + }, + "certificate": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "enabled_feature_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "is_available": { + Type: schema.TypeBool, + Computed: true, + }, + "build": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "commit_id": { + Type: schema.TypeString, + Computed: true, + }, + "full_version": { + Type: schema.TypeString, + Computed: true, + }, + "commit_date": { + Type: schema.TypeString, + Computed: true, + }, + "version": { + Type: schema.TypeString, + Computed: true, + }, + "short_commit_id": { + Type: schema.TypeString, + Computed: true, + }, + "build_type": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "timezone": { + Type: schema.TypeString, + Computed: true, + }, + "cluster_arch": { + Type: schema.TypeString, + Computed: true, + }, + "management_server_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ip": { + Type: schema.TypeString, + Computed: true, + }, + "drs_enabled": { + Type: schema.TypeBool, + Computed: true, + }, + "status_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "masquerading_port": { + Type: schema.TypeInt, + Computed: true, + }, + "masquerading_ip": { + Type: schema.TypeString, + Computed: true, + }, + "external_ip": { + Type: schema.TypeString, + Computed: true, + }, + "http_proxy_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "credentials": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "username": { + Type: schema.TypeString, + Computed: true, + }, + "password": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "proxy_type_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "address": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ip": { + Type: schema.TypeString, + Computed: true, + }, + "fqdn": { + Type: schema.TypeString, + Computed: true, + }, + "port": { + Type: schema.TypeString, + Computed: true, + }, + "ipv6": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "smtp_server_type": { + Type: schema.TypeString, + Computed: true, + }, + "smtp_server_email_address": { + Type: schema.TypeString, + Computed: true, + }, + "smtp_server_credentials": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "username": { + Type: schema.TypeString, + Computed: true, + }, + "password": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "smtp_server_proxy_type_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "smtp_server_address": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ip": { + Type: schema.TypeString, + Computed: true, + }, + "fqdn": { + Type: schema.TypeString, + Computed: true, + }, + "port": { + Type: schema.TypeString, + Computed: true, + }, + "ipv6": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "ntp_server_ip_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "external_subnet": { + Type: schema.TypeString, + Computed: true, + }, + "external_data_services_ip": { + Type: schema.TypeString, + Computed: true, + }, + "internal_subnet": { + Type: schema.TypeString, + Computed: true, + }, + "domain_server_nameserver": { + Type: schema.TypeString, + Computed: true, + }, + "domain_server_name": { + Type: schema.TypeString, + Computed: true, + }, + "domain_server_credentials": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "username": { + Type: schema.TypeString, + Computed: true, + }, + "password": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "nfs_subnet_whitelist": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "name_server_ip_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "http_proxy_whitelist": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "target": { + Type: schema.TypeString, + Computed: true, + }, + "target_type": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "analysis_vm_efficiency_map": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "bully_vm_num": { + Type: schema.TypeString, + Computed: true, + }, + "constrained_vm_num": { + Type: schema.TypeString, + Computed: true, + }, + "dead_vm_num": { + Type: schema.TypeString, + Computed: true, + }, + "inefficient_vm_num": { + Type: schema.TypeString, + Computed: true, + }, + "overprovisioned_vm_num": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + }, + } +} diff --git a/nutanix/data_source_nutanix_image.go b/nutanix/data_source_nutanix_image.go index c9fd78024..72994cc1f 100644 --- a/nutanix/data_source_nutanix_image.go +++ b/nutanix/data_source_nutanix_image.go @@ -2,6 +2,7 @@ package nutanix import ( "fmt" + "log" "github.com/hashicorp/terraform/helper/schema" v3 "github.com/terraform-providers/terraform-provider-nutanix/client/v3" @@ -10,7 +11,15 @@ import ( func dataSourceNutanixImage() *schema.Resource { return &schema.Resource{ - Read: dataSourceNutanixImageRead, + Read: dataSourceNutanixImageRead, + SchemaVersion: 1, + StateUpgraders: []schema.StateUpgrader{ + { + Type: resourceNutanixDatasourceImageInstanceResourceV0().CoreConfigSchema().ImpliedType(), + Upgrade: resourceDatasourceImageInstanceStateUpgradeV0, + Version: 0, + }, + }, Schema: map[string]*schema.Schema{ "image_id": { Type: schema.TypeString, @@ -294,3 +303,203 @@ func findImageByName(conn *v3.Client, name string) (*v3.ImageIntentResponse, err return findImageByUUID(conn, *found[0].Metadata.UUID) } + +func resourceDatasourceImageInstanceStateUpgradeV0(is map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + log.Printf("[DEBUG] Entering resourceDatasourceImageInstanceStateUpgradeV0") + return resourceNutanixCategoriesMigrateState(is, meta) +} + +func resourceNutanixDatasourceImageInstanceResourceV0() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "image_id": { + Type: schema.TypeString, + Optional: true, + ConflictsWith: []string{"image_name"}, + }, + "image_name": { + Type: schema.TypeString, + Optional: true, + ConflictsWith: []string{"image_id"}, + }, + "api_version": { + Type: schema.TypeString, + Computed: true, + }, + "metadata": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "last_update_time": { + Type: schema.TypeString, + Computed: true, + }, + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "creation_time": { + Type: schema.TypeString, + Computed: true, + }, + "spec_version": { + Type: schema.TypeString, + Computed: true, + }, + "spec_hash": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "categories": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + }, + "owner_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "project_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "state": { + Type: schema.TypeString, + Computed: true, + }, + "description": { + Type: schema.TypeString, + Computed: true, + }, + "availability_zone_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "cluster_uuid": { + Type: schema.TypeString, + Computed: true, + }, + "cluster_name": { + Type: schema.TypeString, + Computed: true, + }, + "retrieval_uri_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "image_type": { + Type: schema.TypeString, + Computed: true, + }, + "checksum": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "checksum_algorithm": { + Type: schema.TypeString, + Computed: true, + }, + "checksum_value": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "source_uri": { + Type: schema.TypeString, + Computed: true, + }, + "version": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "product_version": { + Type: schema.TypeString, + Computed: true, + }, + "product_name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "architecture": { + Type: schema.TypeString, + Computed: true, + }, + "size_bytes": { + Type: schema.TypeInt, + Computed: true, + }, + }, + } +} diff --git a/nutanix/data_source_nutanix_network_security_rule.go b/nutanix/data_source_nutanix_network_security_rule.go index 4dad7d8fb..898b9b0ab 100644 --- a/nutanix/data_source_nutanix_network_security_rule.go +++ b/nutanix/data_source_nutanix_network_security_rule.go @@ -12,7 +12,15 @@ import ( func dataSourceNutanixNetworkSecurityRule() *schema.Resource { return &schema.Resource{ - Read: dataSourceNutanixNetworkSecurityRuleRead, + Read: dataSourceNutanixNetworkSecurityRuleRead, + SchemaVersion: 1, + StateUpgraders: []schema.StateUpgrader{ + { + Type: resourceNutanixDatasourceNetworkSecurityRuleResourceV0().CoreConfigSchema().ImpliedType(), + Upgrade: resourceDatasourceNetworkSecurityRuleStateUpgradeV0, + Version: 0, + }, + }, Schema: map[string]*schema.Schema{ "network_security_rule_id": { Type: schema.TypeString, @@ -1088,3 +1096,736 @@ func dataSourceNutanixNetworkSecurityRuleRead(d *schema.ResourceData, meta inter return nil } + +func resourceDatasourceNetworkSecurityRuleStateUpgradeV0(is map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + log.Printf("[DEBUG] Entering resourceDatasourceNetworkSecurityRuleStateUpgradeV0") + return resourceNutanixCategoriesMigrateState(is, meta) +} + +func resourceNutanixDatasourceNetworkSecurityRuleResourceV0() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "network_security_rule_id": { + Type: schema.TypeString, + Required: true, + }, + "api_version": { + Type: schema.TypeString, + Computed: true, + }, + "metadata": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "last_update_time": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "creation_time": { + Type: schema.TypeString, + Computed: true, + }, + "spec_version": { + Type: schema.TypeString, + Computed: true, + }, + "spec_hash": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "categories": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + }, + "owner_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + }, + "uuid": { + Type: schema.TypeString, + }, + "name": { + Type: schema.TypeString, + }, + }, + }, + }, + "project_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + }, + "uuid": { + Type: schema.TypeString, + }, + "name": { + Type: schema.TypeString, + }, + }, + }, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "description": { + Type: schema.TypeString, + Computed: true, + }, + "quarantine_rule_action": { + Type: schema.TypeString, + Computed: true, + }, + "quarantine_rule_outbound_allow_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "protocol": { + Type: schema.TypeString, + Computed: true, + }, + "ip_subnet": { + Type: schema.TypeString, + Computed: true, + }, + "ip_subnet_prefix_length": { + Type: schema.TypeString, + Computed: true, + }, + "tcp_port_range_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "end_port": { + Type: schema.TypeString, + Computed: true, + }, + "start_port": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "udp_port_range_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "end_port": { + Type: schema.TypeInt, + Computed: true, + }, + "start_port": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "filter_kind_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "filter_type": { + Type: schema.TypeString, + Computed: true, + }, + "filter_params": { + Type: schema.TypeSet, + Computed: true, + Set: filterParamsHash, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "values": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + }, + }, + "peer_specification_type": { + Type: schema.TypeString, + Computed: true, + }, + + "expiration_time": { + Type: schema.TypeString, + Computed: true, + }, + "network_function_chain_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + + Computed: true, + }, + }, + }, + }, + "icmp_type_code_list": { + Type: schema.TypeList, + + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "code": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "quarantine_rule_target_group_default_internal_policy": { + Type: schema.TypeString, + Computed: true, + }, + "quarantine_rule_target_group_peer_specification_type": { + Type: schema.TypeString, + Computed: true, + }, + "quarantine_rule_target_group_filter_kind_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "quarantine_rule_target_group_filter_type": { + Type: schema.TypeString, + Computed: true, + }, + "quarantine_rule_target_group_filter_params": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "values": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + }, + }, + "quarantine_rule_inbound_allow_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "protocol": { + Type: schema.TypeString, + Computed: true, + }, + "ip_subnet": { + Type: schema.TypeString, + Computed: true, + }, + "ip_subnet_prefix_length": { + Type: schema.TypeString, + Computed: true, + }, + "tcp_port_range_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "end_port": { + Type: schema.TypeString, + Computed: true, + }, + "start_port": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "udp_port_range_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "end_port": { + Type: schema.TypeInt, + Computed: true, + }, + "start_port": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "filter_kind_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "filter_type": { + Type: schema.TypeString, + Computed: true, + }, + "filter_params": { + Type: schema.TypeSet, + Computed: true, + Set: filterParamsHash, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "values": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + }, + }, + "peer_specification_type": { + Type: schema.TypeString, + Computed: true, + }, + + "expiration_time": { + Type: schema.TypeString, + Computed: true, + }, + "network_function_chain_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "icmp_type_code_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "code": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "app_rule_action": { + Type: schema.TypeString, + Computed: true, + }, + "app_rule_outbound_allow_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "protocol": { + Type: schema.TypeString, + Computed: true, + }, + "ip_subnet": { + Type: schema.TypeString, + Computed: true, + }, + "ip_subnet_prefix_length": { + Type: schema.TypeString, + Computed: true, + }, + "tcp_port_range_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "end_port": { + Type: schema.TypeInt, + Computed: true, + }, + "start_port": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "udp_port_range_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "end_port": { + Type: schema.TypeInt, + Computed: true, + }, + "start_port": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "filter_kind_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "filter_type": { + Type: schema.TypeString, + Computed: true, + }, + "filter_params": { + Type: schema.TypeSet, + Computed: true, + Set: filterParamsHash, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "values": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + }, + }, + "peer_specification_type": { + Type: schema.TypeString, + Computed: true, + }, + + "expiration_time": { + Type: schema.TypeString, + Computed: true, + }, + "network_function_chain_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "icmp_type_code_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "code": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "app_rule_target_group_default_internal_policy": { + Type: schema.TypeString, + Computed: true, + }, + "app_rule_target_group_peer_specification_type": { + Type: schema.TypeString, + Computed: true, + }, + "app_rule_target_group_filter_kind_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "app_rule_target_group_filter_type": { + Type: schema.TypeString, + Computed: true, + }, + "app_rule_target_group_filter_params": { + Type: schema.TypeSet, + Computed: true, + Set: filterParamsHash, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "values": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + }, + }, + "app_rule_inbound_allow_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "protocol": { + Type: schema.TypeString, + Computed: true, + }, + "ip_subnet": { + Type: schema.TypeString, + Computed: true, + }, + "ip_subnet_prefix_length": { + Type: schema.TypeString, + Computed: true, + }, + "tcp_port_range_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "end_port": { + Type: schema.TypeString, + Computed: true, + }, + "start_port": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "udp_port_range_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "end_port": { + Type: schema.TypeInt, + Computed: true, + }, + "start_port": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "filter_kind_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "filter_type": { + Type: schema.TypeString, + Computed: true, + }, + "filter_params": { + Type: schema.TypeSet, + Computed: true, + Set: filterParamsHash, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "values": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + }, + }, + "peer_specification_type": { + Type: schema.TypeString, + Computed: true, + }, + + "expiration_time": { + Type: schema.TypeString, + Computed: true, + }, + "network_function_chain_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "icmp_type_code_list": { + Type: schema.TypeList, + + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "code": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "isolation_rule_action": { + Type: schema.TypeString, + Computed: true, + }, + "isolation_rule_first_entity_filter_kind_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "isolation_rule_first_entity_filter_type": { + Type: schema.TypeString, + Computed: true, + }, + "isolation_rule_first_entity_filter_params": { + Type: schema.TypeSet, + Computed: true, + Set: filterParamsHash, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "values": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + }, + }, + "isolation_rule_second_entity_filter_kind_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "isolation_rule_second_entity_filter_type": { + Type: schema.TypeString, + Computed: true, + }, + "isolation_rule_second_entity_filter_params": { + Type: schema.TypeSet, + Computed: true, + Set: filterParamsHash, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "values": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + }, + }, + }, + } +} diff --git a/nutanix/data_source_nutanix_subnet.go b/nutanix/data_source_nutanix_subnet.go index 7ee1617f8..0d691c583 100644 --- a/nutanix/data_source_nutanix_subnet.go +++ b/nutanix/data_source_nutanix_subnet.go @@ -2,6 +2,7 @@ package nutanix import ( "fmt" + "log" "github.com/hashicorp/terraform/helper/schema" v3 "github.com/terraform-providers/terraform-provider-nutanix/client/v3" @@ -10,7 +11,15 @@ import ( func dataSourceNutanixSubnet() *schema.Resource { return &schema.Resource{ - Read: dataSourceNutanixSubnetRead, + Read: dataSourceNutanixSubnetRead, + SchemaVersion: 1, + StateUpgraders: []schema.StateUpgrader{ + { + Type: resourceNutanixDatasourceSubnetResourceV0().CoreConfigSchema().ImpliedType(), + Upgrade: resourceDatasourceSubnetStateUpgradeV0, + Version: 0, + }, + }, Schema: map[string]*schema.Schema{ "subnet_id": { Type: schema.TypeString, @@ -423,3 +432,273 @@ func dataSourceNutanixSubnetRead(d *schema.ResourceData, meta interface{}) error return nil } + +func resourceDatasourceSubnetStateUpgradeV0(is map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + log.Printf("[DEBUG] Entering resourceDatasourceSubnetStateUpgradeV0") + return resourceNutanixCategoriesMigrateState(is, meta) +} + +func resourceNutanixDatasourceSubnetResourceV0() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "subnet_id": { + Type: schema.TypeString, + Optional: true, + ConflictsWith: []string{"subnet_name"}, + }, + "subnet_name": { + Type: schema.TypeString, + Optional: true, + ConflictsWith: []string{"subnet_id"}, + }, + "api_version": { + Type: schema.TypeString, + Computed: true, + }, + "metadata": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "last_update_time": { + Type: schema.TypeString, + Computed: true, + }, + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "creation_time": { + Type: schema.TypeString, + Computed: true, + }, + "spec_version": { + Type: schema.TypeString, + Computed: true, + }, + "spec_hash": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "categories": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + }, + "owner_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "project_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "state": { + Type: schema.TypeString, + Computed: true, + }, + "description": { + Type: schema.TypeString, + Computed: true, + }, + "availability_zone_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "message_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "message": { + Type: schema.TypeString, + Computed: true, + }, + "reason": { + Type: schema.TypeString, + Computed: true, + }, + "details": { + Type: schema.TypeMap, + Computed: true, + }, + }, + }, + }, + "cluster_uuid": { + Type: schema.TypeString, + Computed: true, + }, + "cluster_name": { + Type: schema.TypeString, + Computed: true, + }, + "vswitch_name": { + Type: schema.TypeString, + Computed: true, + }, + "subnet_type": { + Type: schema.TypeString, + Computed: true, + }, + "default_gateway_ip": { + Type: schema.TypeString, + Computed: true, + }, + "prefix_length": { + Type: schema.TypeInt, + Computed: true, + }, + "subnet_ip": { + Type: schema.TypeString, + Computed: true, + }, + "dhcp_server_address": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ip": { + Type: schema.TypeString, + Computed: true, + }, + "fqdn": { + Type: schema.TypeString, + Computed: true, + }, + "ipv6": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "dhcp_server_address_port": { + Type: schema.TypeInt, + Computed: true, + }, + "ip_config_pool_list_ranges": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "dhcp_options": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "boot_file_name": { + Type: schema.TypeString, + Computed: true, + }, + "domain_name": { + Type: schema.TypeString, + Computed: true, + }, + "tftp_server_name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "dhcp_domain_name_server_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "dhcp_domain_search_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "vlan_id": { + Type: schema.TypeInt, + Computed: true, + }, + "network_function_chain_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + } +} diff --git a/nutanix/data_source_nutanix_virtual_machine.go b/nutanix/data_source_nutanix_virtual_machine.go index e41146edf..720d727cf 100644 --- a/nutanix/data_source_nutanix_virtual_machine.go +++ b/nutanix/data_source_nutanix_virtual_machine.go @@ -2,6 +2,7 @@ package nutanix import ( "fmt" + "log" "strconv" "github.com/terraform-providers/terraform-provider-nutanix/utils" @@ -11,8 +12,15 @@ import ( func dataSourceNutanixVirtualMachine() *schema.Resource { return &schema.Resource{ - Read: dataSourceNutanixVirtualMachineRead, - + Read: dataSourceNutanixVirtualMachineRead, + SchemaVersion: 1, + StateUpgraders: []schema.StateUpgrader{ + { + Type: resourceNutanixDatasourceVirtualMachineInstanceResourceV0().CoreConfigSchema().ImpliedType(), + Upgrade: resourceDatasourceVirtualMachineInstanceStateUpgradeV0, + Version: 0, + }, + }, Schema: map[string]*schema.Schema{ "vm_id": { Type: schema.TypeString, @@ -747,3 +755,607 @@ func dataSourceNutanixVirtualMachineRead(d *schema.ResourceData, meta interface{ return d.Set("disk_list", setDiskList(resp.Status.Resources.DiskList, resp.Status.Resources.GuestCustomization)) } + +func resourceDatasourceVirtualMachineInstanceStateUpgradeV0(is map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + log.Printf("[DEBUG] Entering resourceDatasourceDatasourceVirtualMachineInstanceStateUpgradeV0") + return resourceNutanixCategoriesMigrateState(is, meta) +} + +func resourceNutanixDatasourceVirtualMachineInstanceResourceV0() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "vm_id": { + Type: schema.TypeString, + Required: true, + }, + "metadata": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "last_update_time": { + Type: schema.TypeString, + Computed: true, + }, + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "creation_time": { + Type: schema.TypeString, + Computed: true, + }, + "spec_version": { + Type: schema.TypeString, + Computed: true, + }, + "spec_hash": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "categories": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + }, + "project_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "owner_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "api_version": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "description": { + Type: schema.TypeString, + Computed: true, + }, + "availability_zone_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "cluster_uuid": { + Type: schema.TypeString, + Computed: true, + }, + "cluster_name": { + Type: schema.TypeString, + Computed: true, + }, + // COMPUTED + "message_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "message": { + Type: schema.TypeString, + Computed: true, + }, + "reason": { + Type: schema.TypeString, + Computed: true, + }, + "details": { + Type: schema.TypeMap, + Computed: true, + }, + }, + }, + }, + "state": { + Type: schema.TypeString, + Computed: true, + }, + "host_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "hypervisor_type": { + Type: schema.TypeString, + Computed: true, + }, + + // RESOURCES ARGUMENTS + + "num_vnuma_nodes": { + Type: schema.TypeInt, + Computed: true, + }, + "nic_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "nic_type": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "floating_ip": { + Type: schema.TypeString, + Computed: true, + }, + "model": { + Type: schema.TypeString, + Computed: true, + }, + "network_function_nic_type": { + Type: schema.TypeString, + Computed: true, + }, + "mac_address": { + Type: schema.TypeString, + Computed: true, + }, + "ip_endpoint_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ip": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "network_function_chain_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "subnet_uuid": { + Type: schema.TypeString, + Computed: true, + }, + "subnet_name": { + Type: schema.TypeString, + Computed: true, + }, + "is_connected": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "guest_os_id": { + Type: schema.TypeString, + Computed: true, + }, + "power_state": { + Type: schema.TypeString, + Computed: true, + }, + "nutanix_guest_tools": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "available_version": { + Type: schema.TypeString, + Computed: true, + }, + "ngt_state": { + Type: schema.TypeString, + Computed: true, + }, + "iso_mount_state": { + Type: schema.TypeString, + Computed: true, + }, + "state": { + Type: schema.TypeString, + Computed: true, + }, + "version": { + Type: schema.TypeString, + Computed: true, + }, + "guest_os_version": { + Type: schema.TypeString, + Computed: true, + }, + "vss_snapshot_capable": { + Type: schema.TypeString, //Bool + Computed: true, + }, + "is_reachable": { + Type: schema.TypeString, //Bool + Computed: true, + }, + "vm_mobility_drivers_installed": { + Type: schema.TypeString, //Bool + Computed: true, + }, + }, + }, + }, + "ngt_enabled_capability_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "ngt_credentials": { + Type: schema.TypeMap, + Computed: true, + }, + "num_vcpus_per_socket": { + Type: schema.TypeInt, + Computed: true, + }, + "num_sockets": { + Type: schema.TypeInt, + Computed: true, + }, + "gpu_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "frame_buffer_size_mib": { + Type: schema.TypeInt, + Computed: true, + }, + "vendor": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "pci_address": { + Type: schema.TypeString, + Computed: true, + }, + "fraction": { + Type: schema.TypeInt, + Computed: true, + }, + "mode": { + Type: schema.TypeString, + Computed: true, + }, + "num_virtual_display_heads": { + Type: schema.TypeInt, + Computed: true, + }, + "guest_driver_version": { + Type: schema.TypeString, + Computed: true, + }, + "device_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "parent_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "memory_size_mib": { + Type: schema.TypeInt, + Computed: true, + }, + "boot_device_order_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "boot_device_disk_address": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "device_index": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "adapter_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + }, + }, + }, + "boot_device_mac_address": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "hardware_clock_timezone": { + Type: schema.TypeString, + Computed: true, + }, + "guest_customization_cloud_init_meta_data": { + Type: schema.TypeString, + Computed: true, + }, + "guest_customization_cloud_init_user_data": { + Type: schema.TypeString, + Computed: true, + }, + "guest_customization_cloud_init_custom_key_values": { + Type: schema.TypeMap, + Computed: true, + }, + "guest_customization_is_overridable": { + Type: schema.TypeBool, + Computed: true, + }, + "guest_customization_sysprep": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "install_type": { + Type: schema.TypeString, + Computed: true, + }, + "unattend_xml": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "guest_customization_sysprep_custom_key_values": { + Type: schema.TypeMap, + Computed: true, + }, + "should_fail_on_script_failure": { + Type: schema.TypeBool, + Computed: true, + }, + "enable_script_exec": { + Type: schema.TypeBool, + Computed: true, + }, + "power_state_mechanism": { + Type: schema.TypeString, + Computed: true, + }, + "vga_console_enabled": { + Type: schema.TypeBool, + Computed: true, + }, + "disk_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "disk_size_bytes": { + Type: schema.TypeInt, + Computed: true, + }, + "disk_size_mib": { + Type: schema.TypeInt, + Computed: true, + }, + "device_properties": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "device_type": { + Type: schema.TypeString, + Computed: true, + }, + "disk_address": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "device_index": { + Type: schema.TypeInt, + Computed: true, + }, + "adapter_type": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "data_source_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + + "volume_group_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "serial_port_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "index": { + Type: schema.TypeInt, + Computed: true, + }, + "is_connected": { + Type: schema.TypeBool, + Computed: true, + }, + }, + }, + }, + }, + } +} diff --git a/nutanix/resource_nutanix_image.go b/nutanix/resource_nutanix_image.go index f8d1c233f..bb00cbe65 100644 --- a/nutanix/resource_nutanix_image.go +++ b/nutanix/resource_nutanix_image.go @@ -40,6 +40,14 @@ func resourceNutanixImage() *schema.Resource { Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, + SchemaVersion: 1, + StateUpgraders: []schema.StateUpgrader{ + { + Type: resourceNutanixImageInstanceResourceV0().CoreConfigSchema().ImpliedType(), + Upgrade: resourceImageInstanceStateUpgradeV0, + Version: 0, + }, + }, Schema: map[string]*schema.Schema{ "api_version": { Type: schema.TypeString, @@ -624,3 +632,204 @@ func resourceNutanixImageExists(conn *v3.Client, name string) (*string, error) { } return imageUUID, nil } + +func resourceImageInstanceStateUpgradeV0(is map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + log.Printf("[DEBUG] Entering resourceImageInstanceStateUpgradeV0") + return resourceNutanixCategoriesMigrateState(is, meta) +} + +func resourceNutanixImageInstanceResourceV0() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "api_version": { + Type: schema.TypeString, + Computed: true, + }, + "metadata": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "last_update_time": { + Type: schema.TypeString, + Computed: true, + }, + + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "creation_time": { + Type: schema.TypeString, + Computed: true, + }, + "spec_version": { + Type: schema.TypeString, + Computed: true, + }, + "spec_hash": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "categories": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + }, + "owner_reference": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Optional: true, + }, + "uuid": { + Type: schema.TypeString, + Optional: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + }, + }, + }, + }, + "project_reference": { + Type: schema.TypeMap, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Optional: true, + }, + "uuid": { + Type: schema.TypeString, + Optional: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + }, + }, + }, + }, + "name": { + Type: schema.TypeString, + Required: true, + }, + "state": { + Type: schema.TypeString, + Computed: true, + }, + "description": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "availability_zone_reference": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Required: true, + }, + "uuid": { + Type: schema.TypeString, + Required: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + }, + }, + }, + "cluster_uuid": { + Type: schema.TypeString, + Computed: true, + }, + "cluster_name": { + Type: schema.TypeString, + Computed: true, + }, + "retrieval_uri_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "image_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "checksum": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "checksum_algorithm": { + Type: schema.TypeString, + Required: true, + }, + "checksum_value": { + Type: schema.TypeString, + Required: true, + }, + }, + }, + }, + "source_uri": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "source_path": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "version": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "product_version": { + Type: schema.TypeString, + Required: true, + }, + "product_name": { + Type: schema.TypeString, + Required: true, + }, + }, + }, + }, + "architecture": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "size_bytes": { + Type: schema.TypeInt, + Computed: true, + }, + }, + } +} diff --git a/nutanix/resource_nutanix_network_security_rule.go b/nutanix/resource_nutanix_network_security_rule.go index 59cfe7768..5cad0bd03 100644 --- a/nutanix/resource_nutanix_network_security_rule.go +++ b/nutanix/resource_nutanix_network_security_rule.go @@ -31,6 +31,14 @@ func resourceNutanixNetworkSecurityRule() *schema.Resource { Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, + SchemaVersion: 1, + StateUpgraders: []schema.StateUpgrader{ + { + Type: resourceNutanixSecurityRuleInstanceResourceV0().CoreConfigSchema().ImpliedType(), + Upgrade: resourceSecurityRuleInstanceStateUpgradeV0, + Version: 0, + }, + }, Schema: map[string]*schema.Schema{ "api_version": { Type: schema.TypeString, @@ -1305,3 +1313,431 @@ func portRangeSchema() *schema.Schema { }, } } + +func resourceSecurityRuleInstanceStateUpgradeV0(is map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + log.Printf("[DEBUG] Entering resourceSecurityRuleInstanceStateUpgradeV0") + return resourceNutanixCategoriesMigrateState(is, meta) +} + +func resourceNutanixSecurityRuleInstanceResourceV0() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "api_version": { + Type: schema.TypeString, + Computed: true, + }, + "metadata": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "last_update_time": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "creation_time": { + Type: schema.TypeString, + Computed: true, + }, + "spec_version": { + Type: schema.TypeString, + Computed: true, + }, + "spec_hash": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "categories": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + }, + "owner_reference": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Optional: true, + }, + "uuid": { + Type: schema.TypeString, + Optional: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + }, + }, + }, + }, + "project_reference": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Optional: true, + }, + "uuid": { + Type: schema.TypeString, + Optional: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + }, + }, + }, + }, + "name": { + Type: schema.TypeString, + Required: true, + }, + "description": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "app_rule_action": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "app_rule_outbound_allow_list": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "protocol": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "ip_subnet": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "ip_subnet_prefix_length": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "tcp_port_range_list": portRangeSchema(), + "udp_port_range_list": portRangeSchema(), + "filter_kind_list": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "filter_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "filter_params": { + Type: schema.TypeSet, + Optional: true, + Computed: true, + Set: filterParamsHash, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + }, + "values": { + Type: schema.TypeList, + Required: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + }, + }, + "peer_specification_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + + "expiration_time": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "network_function_chain_reference": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Required: true, + }, + "uuid": { + Type: schema.TypeString, + Required: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + }, + }, + }, + "icmp_type_code_list": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "code": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "app_rule_target_group_default_internal_policy": { + Type: schema.TypeString, + Optional: true, + }, + "app_rule_target_group_peer_specification_type": { + Type: schema.TypeString, + Optional: true, + }, + "app_rule_target_group_filter_kind_list": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "app_rule_target_group_filter_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "app_rule_target_group_filter_params": { + Type: schema.TypeSet, + Optional: true, + Computed: true, + Set: filterParamsHash, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + }, + "values": { + Type: schema.TypeList, + Required: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + }, + }, + "app_rule_inbound_allow_list": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "protocol": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "ip_subnet": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "ip_subnet_prefix_length": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "tcp_port_range_list": portRangeSchema(), + "udp_port_range_list": portRangeSchema(), + "filter_kind_list": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "filter_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "filter_params": { + Type: schema.TypeSet, + Optional: true, + Computed: true, + Set: filterParamsHash, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + }, + "values": { + Type: schema.TypeList, + Required: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + }, + }, + "peer_specification_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + + "expiration_time": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "network_function_chain_reference": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Required: true, + }, + "uuid": { + Type: schema.TypeString, + Required: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + }, + }, + }, + "icmp_type_code_list": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "code": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "isolation_rule_action": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "isolation_rule_first_entity_filter_kind_list": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "isolation_rule_first_entity_filter_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "isolation_rule_first_entity_filter_params": { + Type: schema.TypeSet, + Optional: true, + Computed: true, + Set: filterParamsHash, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + }, + "values": { + Type: schema.TypeList, + Required: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + }, + }, + "isolation_rule_second_entity_filter_kind_list": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "isolation_rule_second_entity_filter_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "isolation_rule_second_entity_filter_params": { + Type: schema.TypeSet, + Optional: true, + Computed: true, + Set: filterParamsHash, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + }, + "values": { + Type: schema.TypeList, + Required: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + }, + }, + }, + } +} diff --git a/nutanix/resource_nutanix_subnet.go b/nutanix/resource_nutanix_subnet.go index 268375b2d..e279cafce 100644 --- a/nutanix/resource_nutanix_subnet.go +++ b/nutanix/resource_nutanix_subnet.go @@ -2,6 +2,7 @@ package nutanix import ( "fmt" + "log" "regexp" "strings" "time" @@ -28,6 +29,14 @@ func resourceNutanixSubnet() *schema.Resource { Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, + SchemaVersion: 1, + StateUpgraders: []schema.StateUpgrader{ + { + Type: resourceNutanixSubnetInstanceResourceV0().CoreConfigSchema().ImpliedType(), + Upgrade: resourceSubnetInstanceStateUpgradeV0, + Version: 0, + }, + }, Schema: map[string]*schema.Schema{ "api_version": { Type: schema.TypeString, @@ -797,3 +806,282 @@ func getSubnetResources(d *schema.ResourceData, subnet *v3.SubnetResources) { subnet.IPConfig = ip } + +func resourceSubnetInstanceStateUpgradeV0(is map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + log.Printf("[DEBUG] Entering resourceSubnetInstanceStateUpgradeV0") + return resourceNutanixCategoriesMigrateState(is, meta) +} + +func resourceNutanixSubnetInstanceResourceV0() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "api_version": { + Type: schema.TypeString, + Computed: true, + }, + "description": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "metadata": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "last_update_time": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "kind": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "creation_time": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "spec_version": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "spec_hash": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + }, + }, + }, + "categories": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + }, + "owner_reference": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Optional: true, + }, + "uuid": { + Type: schema.TypeString, + Optional: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + }, + }, + }, + }, + "project_reference": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Optional: true, + }, + "uuid": { + Type: schema.TypeString, + Optional: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + }, + }, + }, + }, + "name": { + Type: schema.TypeString, + Required: true, + }, + "state": { + Type: schema.TypeString, + Computed: true, + }, + "availability_zone_reference": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Required: true, + }, + "uuid": { + Type: schema.TypeString, + Required: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + }, + }, + }, + "cluster_uuid": { + Type: schema.TypeString, + Required: true, + }, + "cluster_name": { + Type: schema.TypeString, + Computed: true, + }, + "vswitch_name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "subnet_type": { + Type: schema.TypeString, + Required: true, + }, + "default_gateway_ip": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "prefix_length": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "subnet_ip": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "dhcp_server_address": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ip": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "fqdn": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "ipv6": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + }, + }, + }, + "dhcp_server_address_port": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "ip_config_pool_list_ranges": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validation.StringMatch( + regexp.MustCompile( + "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)["+ + " ](?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"), + "please see https://developer.nutanix.com/reference/prism_central/v3/#definitions-ip_pool"), + }, + }, + "dhcp_options": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "boot_file_name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "domain_name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "tftp_server_name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + }, + }, + }, + "dhcp_domain_name_server_list": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "dhcp_domain_search_list": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "vlan_id": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + Computed: true, + }, + "network_function_chain_reference": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Required: true, + }, + "uuid": { + Type: schema.TypeString, + Required: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + }, + }, + }, + }, + } +} From c83a8b93b81b1efe2abc428cfa3a441270e05f45 Mon Sep 17 00:00:00 2001 From: Yannick Struyf Date: Fri, 3 Apr 2020 01:35:24 +0200 Subject: [PATCH 6/7] added cloudinit fix --- nutanix/resource_nutanix_virtual_machine.go | 23 ++++++++++++++++++- .../resource_nutanix_virtual_machine_test.go | 19 --------------- nutanix/structure.go | 16 ++++++++----- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/nutanix/resource_nutanix_virtual_machine.go b/nutanix/resource_nutanix_virtual_machine.go index ec58c199e..04d9f5b96 100644 --- a/nutanix/resource_nutanix_virtual_machine.go +++ b/nutanix/resource_nutanix_virtual_machine.go @@ -21,6 +21,7 @@ var ( vmTimeout = 1 * time.Minute vmDelay = 3 * time.Second vmMinTimeout = 3 * time.Second + IDE = "IDE" ) func resourceNutanixVirtualMachine() *schema.Resource { @@ -1197,7 +1198,7 @@ func resourceNutanixVirtualMachineUpdate(d *schema.ResourceData, meta interface{ if err != nil { return err } - if res.DiskList, err = expandDiskList(d, false); err != nil { + if res.DiskList, err = expandDiskListUpdate(d, response); err != nil { return err } postCdromCount, err := CountDiskListCdrom(res.DiskList) @@ -1658,6 +1659,26 @@ func expandIPAddressList(ipl []interface{}) []*v3.IPAddress { return nil } +func expandDiskListUpdate(d *schema.ResourceData, vm *v3.VMIntentResponse) ([]*v3.VMDisk, error) { + var eDiskList []*v3.VMDisk + var err error + if eDiskList, err = expandDiskList(d, false); err != nil { + return eDiskList, err + } + if vm.Spec != nil && vm.Spec.Resources != nil { + for _, disk := range vm.Spec.Resources.DiskList { + if disk.DeviceProperties != nil && disk.DeviceProperties.DiskAddress != nil { + index := disk.DeviceProperties.DiskAddress.DeviceIndex + adapterType := disk.DeviceProperties.DiskAddress.AdapterType + if *index == 3 && *adapterType == IDE { + eDiskList = append(eDiskList, disk) + } + } + } + } + return eDiskList, nil +} + func expandDiskList(d *schema.ResourceData, isCreation bool) ([]*v3.VMDisk, error) { if v, ok := d.GetOk("disk_list"); ok { dsk := v.([]interface{}) diff --git a/nutanix/resource_nutanix_virtual_machine_test.go b/nutanix/resource_nutanix_virtual_machine_test.go index 36e27b136..24805991e 100644 --- a/nutanix/resource_nutanix_virtual_machine_test.go +++ b/nutanix/resource_nutanix_virtual_machine_test.go @@ -218,13 +218,6 @@ func TestAccNutanixVirtualMachine_CdromGuestCustomisationReboot(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckNutanixVirtualMachineDestroy, Steps: []resource.TestStep{ - { - Config: testAccNutanixVMConfigCdromGuestCustomisationReboot(r), - Check: resource.ComposeTestCheckFunc( - testAccCheckNutanixVirtualMachineExists(resourceName), - ), - ExpectNonEmptyPlan: true, - }, { Config: testAccNutanixVMConfigCdromGuestCustomisationReboot(r), Check: resource.ComposeTestCheckFunc( @@ -249,18 +242,6 @@ func TestAccNutanixVirtualMachine_CloudInitCustomKeyValues(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckNutanixVirtualMachineDestroy, Steps: []resource.TestStep{ - { - Config: testAccNutanixVMConfigCloudInitCustomKeyValues(r), - Check: resource.ComposeTestCheckFunc( - testAccCheckNutanixVirtualMachineExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "hardware_clock_timezone", "UTC"), - resource.TestCheckResourceAttr(resourceName, "power_state", "ON"), - resource.TestCheckResourceAttr(resourceName, "memory_size_mib", "186"), - resource.TestCheckResourceAttr(resourceName, "num_sockets", "1"), - resource.TestCheckResourceAttr(resourceName, "num_vcpus_per_socket", "1"), - ), - ExpectNonEmptyPlan: true, - }, { Config: testAccNutanixVMConfigCloudInitCustomKeyValues(r), Check: resource.ComposeTestCheckFunc( diff --git a/nutanix/structure.go b/nutanix/structure.go index 7926b3baa..6eea9f95a 100644 --- a/nutanix/structure.go +++ b/nutanix/structure.go @@ -105,8 +105,8 @@ func flattenNicList(nics []*v3.VMNic) []map[string]interface{} { func flattenDiskList(disks []*v3.VMDisk) []map[string]interface{} { diskList := make([]map[string]interface{}, 0) if disks != nil { - diskList = make([]map[string]interface{}, len(disks)) - for k, v := range disks { + diskList = make([]map[string]interface{}, 0) + for _, v := range disks { disk := make(map[string]interface{}) disk["uuid"] = utils.StringValue(v.UUID) @@ -117,10 +117,14 @@ func flattenDiskList(disks []*v3.VMDisk) []map[string]interface{} { if v.DeviceProperties != nil { deviceProps = make([]map[string]interface{}, 1) deviceProp := make(map[string]interface{}) - + index := fmt.Sprintf("%d", utils.Int64Value(v.DeviceProperties.DiskAddress.DeviceIndex)) + adapter := v.DeviceProperties.DiskAddress.AdapterType + if index == "3" && *adapter == IDE { + continue + } diskAddress := map[string]interface{}{ - "device_index": fmt.Sprintf("%d", utils.Int64Value(v.DeviceProperties.DiskAddress.DeviceIndex)), - "adapter_type": v.DeviceProperties.DiskAddress.AdapterType, + "device_index": index, + "adapter_type": adapter, } deviceProp["disk_address"] = diskAddress @@ -132,7 +136,7 @@ func flattenDiskList(disks []*v3.VMDisk) []map[string]interface{} { disk["data_source_reference"] = flattenReferenceValues(v.DataSourceReference) disk["volume_group_reference"] = flattenReferenceValues(v.VolumeGroupReference) - diskList[k] = disk + diskList = append(diskList, disk) } } return diskList From 6ebda75e21437659d8385add798e4395785c94a4 Mon Sep 17 00:00:00 2001 From: Yannick Struyf Date: Fri, 3 Apr 2020 20:39:45 +0200 Subject: [PATCH 7/7] modified CPU logic to support modification of number of vcpus per socket --- nutanix/resource_nutanix_virtual_machine.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/nutanix/resource_nutanix_virtual_machine.go b/nutanix/resource_nutanix_virtual_machine.go index 04d9f5b96..5aac4aea5 100644 --- a/nutanix/resource_nutanix_virtual_machine.go +++ b/nutanix/resource_nutanix_virtual_machine.go @@ -922,15 +922,17 @@ func resourceNutanixVirtualMachineRead(d *schema.ResourceData, meta interface{}) b := make([]string, 0) if resp.Status.Resources.BootConfig != nil { - if resp.Status.Resources.BootConfig.BootDevice.DiskAddress != nil { - i := strconv.Itoa(int(utils.Int64Value(resp.Status.Resources.BootConfig.BootDevice.DiskAddress.DeviceIndex))) - diskAddress["device_index"] = i - diskAddress["adapter_type"] = utils.StringValue(resp.Status.Resources.BootConfig.BootDevice.DiskAddress.AdapterType) + if resp.Status.Resources.BootConfig.BootDevice != nil { + if resp.Status.Resources.BootConfig.BootDevice.DiskAddress != nil { + i := strconv.Itoa(int(utils.Int64Value(resp.Status.Resources.BootConfig.BootDevice.DiskAddress.DeviceIndex))) + diskAddress["device_index"] = i + diskAddress["adapter_type"] = utils.StringValue(resp.Status.Resources.BootConfig.BootDevice.DiskAddress.AdapterType) + } + mac = utils.StringValue(resp.Status.Resources.BootConfig.BootDevice.MacAddress) } if resp.Status.Resources.BootConfig.BootDeviceOrderList != nil { b = utils.StringValueSlice(resp.Status.Resources.BootConfig.BootDeviceOrderList) } - mac = utils.StringValue(resp.Status.Resources.BootConfig.BootDevice.MacAddress) } d.Set("boot_device_order_list", b) @@ -1090,7 +1092,7 @@ func resourceNutanixVirtualMachineUpdate(d *schema.ResourceData, meta interface{ if d.HasChange("num_vcpus_per_socket") { o, n := d.GetChange("num_vcpus_per_socket") res.NumVcpusPerSocket = utils.Int64Ptr(int64(n.(int))) - if n.(int) < o.(int) { + if n.(int) < o.(int) || n.(int) > o.(int) { hotPlugChange = false } }