diff --git a/nutanix/categories_schema_migrate.go b/nutanix/categories_schema_migrate.go index e935c15d7..db96223f1 100644 --- a/nutanix/categories_schema_migrate.go +++ b/nutanix/categories_schema_migrate.go @@ -1,82 +1,44 @@ 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 { +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) + log.Printf("[DEBUG] meta: %#v", meta) + log.Printf("[DEBUG] Attributes before migration: %#v", rawState) - 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 l, ok := rawState["categories"]; ok { + if assertedL, ok := l.(map[string]interface{}); ok { + c := make([]interface{}, 0) + keys := make([]string, 0, len(assertedL)) + for k := range assertedL { + keys = append(keys, k) } - - 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 := assertedL[name] + c = append(c, map[string]interface{}{ + "name": name, + "value": value.(string), }) - - 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 + rawState["categories"] = c } } + log.Printf("[DEBUG] Attributes after migration: %#v", rawState) + return rawState, nil } 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/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, + }, + }, + }, + }, + }, + } +} diff --git a/nutanix/resource_nutanix_virtual_machine.go b/nutanix/resource_nutanix_virtual_machine.go index 0d5f2cceb..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, @@ -1938,13 +1943,739 @@ 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++ } } 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, + }, + }, + }, + }, + }, + } }