From a994161e0f763417c5b51c936258c242473e3395 Mon Sep 17 00:00:00 2001 From: Sanket Phansekar Date: Thu, 16 Jan 2025 20:32:28 +0530 Subject: [PATCH 1/8] feat: update vmware service with latest api specs --- examples/ibm-vmware/README.md | 10 +- ibm/service/vmware/README.md | 4 +- .../vmware/data_source_ibm_vmaas_vdc.go | 206 ++++++---- .../vmware/data_source_ibm_vmaas_vdc_test.go | 278 ++++++++++++- ibm/service/vmware/resource_ibm_vmaas_vdc.go | 287 +++++++++----- .../vmware/resource_ibm_vmaas_vdc_test.go | 372 ++++++++++++++++++ website/docs/d/vmaas_vdc.html.markdown | 27 +- website/docs/r/vmaas_vdc.html.markdown | 11 +- 8 files changed, 994 insertions(+), 201 deletions(-) diff --git a/examples/ibm-vmware/README.md b/examples/ibm-vmware/README.md index 5574a7243d..1104bf4c9f 100644 --- a/examples/ibm-vmware/README.md +++ b/examples/ibm-vmware/README.md @@ -1,6 +1,6 @@ -# Examples for VMware as a Service API +# Examples for VMware Cloud Foundation as a Service API -These examples illustrate how to use the resources and data sources associated with VMware as a Service API. +These examples illustrate how to use the resources and data sources associated with VMware Cloud Foundation as a Service API. The following resources are supported: * ibm_vmaas_vdc @@ -20,7 +20,7 @@ $ terraform apply Run `terraform destroy` when you don't need these resources. -## VMware as a Service API resources +## VMware Cloud Foundation as a Service API resources ### Resource: ibm_vmaas_vdc @@ -62,11 +62,12 @@ resource "ibm_vmaas_vdc" "vmaas_vdc_instance" { | edges | The VMware NSX-T networking edges deployed on the virtual data center (VDC). NSX-T edges are used for bridging virtualization networking to the physical public-internet and IBM private networking. | | status_reasons | Information about why the request to create the virtual data center (VDC) cannot be completed. | | ordered_at | The time that the virtual data center (VDC) is ordered. | +| org_href | The URL of the organization that owns the VDC. | | org_name | The name of the VMware Cloud Director organization that contains this virtual data center (VDC). VMware Cloud Director organizations are used to create strong boundaries between VDCs. There is a complete isolation of user administration, networking, workloads, and VMware Cloud Director catalogs between different Director organizations. | | status | Determines the state of the virtual data center. | | type | Determines whether this virtual data center is in a single-tenant or multitenant Cloud Director site. | -## VMware as a Service API data sources +## VMware Cloud Foundation as a Service API data sources ### Data source: ibm_vmaas_vdc @@ -98,6 +99,7 @@ data "ibm_vmaas_vdc" "vmaas_vdc_instance" { | status_reasons | Information about why the request to create the virtual data center (VDC) cannot be completed. | | name | A human readable ID for the virtual data center (VDC). | | ordered_at | The time that the virtual data center (VDC) is ordered. | +| org_href | The URL of the organization that owns the VDC. | | org_name | The name of the VMware Cloud Director organization that contains this virtual data center (VDC). VMware Cloud Director organizations are used to create strong boundaries between VDCs. There is a complete isolation of user administration, networking, workloads, and VMware Cloud Director catalogs between different Director organizations. | | ram | The RAM usage limit on the virtual data center (VDC) in GB (1024^3 bytes). Supported for VDCs deployed on a multitenant Cloud Director site. This property is applicable when the resource pool type is reserved. | | status | Determines the state of the virtual data center. | diff --git a/ibm/service/vmware/README.md b/ibm/service/vmware/README.md index bcca29a597..eaeaf865de 100644 --- a/ibm/service/vmware/README.md +++ b/ibm/service/vmware/README.md @@ -7,5 +7,5 @@ This area is primarily for IBM provider contributors and maintainers. For inform * [Find out about contributing](../../../CONTRIBUTING.md) to the IBM provider! * IBM Provider Docs: [Home](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs) * IBM Provider Docs: [One of the resources](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/vmaas_vdc) -* IBM API Docs: [IBM API Docs for VMware as a Service](https://cloud.ibm.com/apidocs/vmware-service) -* IBM SDK: [IBM SDK for VMware as a Service ](https://github.com/IBM/appconfiguration-go-admin-sdk/tree/master/vmwarev1) +* IBM API Docs: [IBM API Docs for VMware Cloud Foundation as a Service](https://cloud.ibm.com/apidocs/vmware-service) +* IBM SDK: [IBM SDK for VMware Cloud Foundation as a Service ](https://github.com/IBM/appconfiguration-go-admin-sdk/tree/master/vmwarev1) diff --git a/ibm/service/vmware/data_source_ibm_vmaas_vdc.go b/ibm/service/vmware/data_source_ibm_vmaas_vdc.go index 6a46efbe2f..004a0db013 100644 --- a/ibm/service/vmware/data_source_ibm_vmaas_vdc.go +++ b/ibm/service/vmware/data_source_ibm_vmaas_vdc.go @@ -1,6 +1,10 @@ // Copyright IBM Corp. 2024 All Rights Reserved. // Licensed under the Mozilla Public License v2.0 +/* + * IBM OpenAPI Terraform Generator Version: 3.98.0-8be2046a-20241205-162752 +*/ + package vmware import ( @@ -13,6 +17,7 @@ import ( "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" + "github.com/IBM/go-sdk-core/v5/core" "github.com/IBM/vmware-go-sdk/vmwarev1" ) @@ -122,6 +127,19 @@ func DataSourceIbmVmaasVdc() *schema.Resource { Type: schema.TypeString, }, }, + "private_ips": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "The private IP addresses assigned to the edge.", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "private_only": &schema.Schema{ + Type: schema.TypeBool, + Computed: true, + Description: "Indicates whether the edge is private only. The default value is True for a private Cloud Director site and False for a public Cloud Director site.", + }, "size": &schema.Schema{ Type: schema.TypeString, Computed: true, @@ -222,6 +240,11 @@ func DataSourceIbmVmaasVdc() *schema.Resource { Computed: true, Description: "Determines the state of the IBM Transit Gateway based on its connections.", }, + "region": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The region where the IBM Transit Gateway is deployed.", + }, }, }, }, @@ -272,6 +295,11 @@ func DataSourceIbmVmaasVdc() *schema.Resource { Computed: true, Description: "The time that the virtual data center (VDC) is ordered.", }, + "org_href": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The URL of the organization that owns the VDC.", + }, "org_name": &schema.Schema{ Type: schema.TypeString, Computed: true, @@ -314,7 +342,9 @@ func DataSourceIbmVmaasVdc() *schema.Resource { func dataSourceIbmVmaasVdcRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { vmwareClient, err := meta.(conns.ClientSession).VmwareV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_vmaas_vdc", "read", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } getVdcOptions := &vmwarev1.GetVdcOptions{} @@ -324,130 +354,137 @@ func dataSourceIbmVmaasVdcRead(context context.Context, d *schema.ResourceData, getVdcOptions.SetAcceptLanguage(d.Get("accept_language").(string)) } - vDC, response, err := vmwareClient.GetVdcWithContext(context, getVdcOptions) + vDC, _, err := vmwareClient.GetVdcWithContext(context, getVdcOptions) if err != nil { - log.Printf("[DEBUG] GetVdcWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetVdcWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetVdcWithContext failed: %s", err.Error()), "(Data) ibm_vmaas_vdc", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } - d.SetId(fmt.Sprintf("%s", *getVdcOptions.ID)) + d.SetId(*getVdcOptions.ID) if err = d.Set("href", vDC.Href); err != nil { - return diag.FromErr(fmt.Errorf("Error setting href: %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting href: %s", err), "(Data) ibm_vmaas_vdc", "read", "set-href").GetDiag() } - if err = d.Set("provisioned_at", flex.DateTimeToString(vDC.ProvisionedAt)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting provisioned_at: %s", err)) + if !core.IsNil(vDC.ProvisionedAt) { + if err = d.Set("provisioned_at", flex.DateTimeToString(vDC.ProvisionedAt)); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting provisioned_at: %s", err), "(Data) ibm_vmaas_vdc", "read", "set-provisioned_at").GetDiag() + } } - if err = d.Set("cpu", flex.IntValue(vDC.Cpu)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting cpu: %s", err)) + if !core.IsNil(vDC.Cpu) { + if err = d.Set("cpu", flex.IntValue(vDC.Cpu)); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting cpu: %s", err), "(Data) ibm_vmaas_vdc", "read", "set-cpu").GetDiag() + } } if err = d.Set("crn", vDC.Crn); err != nil { - return diag.FromErr(fmt.Errorf("Error setting crn: %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting crn: %s", err), "(Data) ibm_vmaas_vdc", "read", "set-crn").GetDiag() } - if err = d.Set("deleted_at", flex.DateTimeToString(vDC.DeletedAt)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting deleted_at: %s", err)) + if !core.IsNil(vDC.DeletedAt) { + if err = d.Set("deleted_at", flex.DateTimeToString(vDC.DeletedAt)); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting deleted_at: %s", err), "(Data) ibm_vmaas_vdc", "read", "set-deleted_at").GetDiag() + } } directorSite := []map[string]interface{}{} - if vDC.DirectorSite != nil { - modelMap, err := dataSourceIbmVmaasVdcVDCDirectorSiteToMap(vDC.DirectorSite) - if err != nil { - return diag.FromErr(err) - } - directorSite = append(directorSite, modelMap) + directorSiteMap, err := DataSourceIbmVmaasVdcVDCDirectorSiteToMap(vDC.DirectorSite) + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_vmaas_vdc", "read", "director_site-to-map").GetDiag() } + directorSite = append(directorSite, directorSiteMap) if err = d.Set("director_site", directorSite); err != nil { - return diag.FromErr(fmt.Errorf("Error setting director_site %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting director_site: %s", err), "(Data) ibm_vmaas_vdc", "read", "set-director_site").GetDiag() } edges := []map[string]interface{}{} - if vDC.Edges != nil { - for _, modelItem := range vDC.Edges { - modelMap, err := dataSourceIbmVmaasVdcEdgeToMap(&modelItem) - if err != nil { - return diag.FromErr(err) - } - edges = append(edges, modelMap) + for _, edgesItem := range vDC.Edges { + edgesItemMap, err := DataSourceIbmVmaasVdcEdgeToMap(&edgesItem) // #nosec G601 + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_vmaas_vdc", "read", "edges-to-map").GetDiag() } + edges = append(edges, edgesItemMap) } if err = d.Set("edges", edges); err != nil { - return diag.FromErr(fmt.Errorf("Error setting edges %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting edges: %s", err), "(Data) ibm_vmaas_vdc", "read", "set-edges").GetDiag() } statusReasons := []map[string]interface{}{} - if vDC.StatusReasons != nil { - for _, modelItem := range vDC.StatusReasons { - modelMap, err := dataSourceIbmVmaasVdcStatusReasonToMap(&modelItem) - if err != nil { - return diag.FromErr(err) - } - statusReasons = append(statusReasons, modelMap) + for _, statusReasonsItem := range vDC.StatusReasons { + statusReasonsItemMap, err := DataSourceIbmVmaasVdcStatusReasonToMap(&statusReasonsItem) // #nosec G601 + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_vmaas_vdc", "read", "status_reasons-to-map").GetDiag() } + statusReasons = append(statusReasons, statusReasonsItemMap) } if err = d.Set("status_reasons", statusReasons); err != nil { - return diag.FromErr(fmt.Errorf("Error setting status_reasons %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting status_reasons: %s", err), "(Data) ibm_vmaas_vdc", "read", "set-status_reasons").GetDiag() } if err = d.Set("name", vDC.Name); err != nil { - return diag.FromErr(fmt.Errorf("Error setting name: %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting name: %s", err), "(Data) ibm_vmaas_vdc", "read", "set-name").GetDiag() } if err = d.Set("ordered_at", flex.DateTimeToString(vDC.OrderedAt)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting ordered_at: %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting ordered_at: %s", err), "(Data) ibm_vmaas_vdc", "read", "set-ordered_at").GetDiag() + } + + if err = d.Set("org_href", vDC.OrgHref); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting org_href: %s", err), "(Data) ibm_vmaas_vdc", "read", "set-org_href").GetDiag() } if err = d.Set("org_name", vDC.OrgName); err != nil { - return diag.FromErr(fmt.Errorf("Error setting org_name: %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting org_name: %s", err), "(Data) ibm_vmaas_vdc", "read", "set-org_name").GetDiag() } - if err = d.Set("ram", flex.IntValue(vDC.Ram)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting ram: %s", err)) + if !core.IsNil(vDC.Ram) { + if err = d.Set("ram", flex.IntValue(vDC.Ram)); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting ram: %s", err), "(Data) ibm_vmaas_vdc", "read", "set-ram").GetDiag() + } } if err = d.Set("status", vDC.Status); err != nil { - return diag.FromErr(fmt.Errorf("Error setting status: %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting status: %s", err), "(Data) ibm_vmaas_vdc", "read", "set-status").GetDiag() } if err = d.Set("type", vDC.Type); err != nil { - return diag.FromErr(fmt.Errorf("Error setting type: %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting type: %s", err), "(Data) ibm_vmaas_vdc", "read", "set-type").GetDiag() } if err = d.Set("fast_provisioning_enabled", vDC.FastProvisioningEnabled); err != nil { - return diag.FromErr(fmt.Errorf("Error setting fast_provisioning_enabled: %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting fast_provisioning_enabled: %s", err), "(Data) ibm_vmaas_vdc", "read", "set-fast_provisioning_enabled").GetDiag() } if err = d.Set("rhel_byol", vDC.RhelByol); err != nil { - return diag.FromErr(fmt.Errorf("Error setting rhel_byol: %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting rhel_byol: %s", err), "(Data) ibm_vmaas_vdc", "read", "set-rhel_byol").GetDiag() } if err = d.Set("windows_byol", vDC.WindowsByol); err != nil { - return diag.FromErr(fmt.Errorf("Error setting windows_byol: %s", err)) + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting windows_byol: %s", err), "(Data) ibm_vmaas_vdc", "read", "set-windows_byol").GetDiag() } return nil } -func dataSourceIbmVmaasVdcVDCDirectorSiteToMap(model *vmwarev1.VDCDirectorSite) (map[string]interface{}, error) { +func DataSourceIbmVmaasVdcVDCDirectorSiteToMap(model *vmwarev1.VDCDirectorSite) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["id"] = model.ID - pvdcMap, err := dataSourceIbmVmaasVdcDirectorSitePVDCToMap(model.Pvdc) + modelMap["id"] = *model.ID + pvdcMap, err := DataSourceIbmVmaasVdcDirectorSitePVDCToMap(model.Pvdc) if err != nil { return modelMap, err } modelMap["pvdc"] = []map[string]interface{}{pvdcMap} - modelMap["url"] = model.URL + modelMap["url"] = *model.URL return modelMap, nil } -func dataSourceIbmVmaasVdcDirectorSitePVDCToMap(model *vmwarev1.DirectorSitePVDC) (map[string]interface{}, error) { +func DataSourceIbmVmaasVdcDirectorSitePVDCToMap(model *vmwarev1.DirectorSitePVDC) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["id"] = model.ID + modelMap["id"] = *model.ID if model.ProviderType != nil { - providerTypeMap, err := dataSourceIbmVmaasVdcVDCProviderTypeToMap(model.ProviderType) + providerTypeMap, err := DataSourceIbmVmaasVdcVDCProviderTypeToMap(model.ProviderType) if err != nil { return modelMap, err } @@ -456,68 +493,71 @@ func dataSourceIbmVmaasVdcDirectorSitePVDCToMap(model *vmwarev1.DirectorSitePVDC return modelMap, nil } -func dataSourceIbmVmaasVdcVDCProviderTypeToMap(model *vmwarev1.VDCProviderType) (map[string]interface{}, error) { +func DataSourceIbmVmaasVdcVDCProviderTypeToMap(model *vmwarev1.VDCProviderType) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["name"] = model.Name + modelMap["name"] = *model.Name return modelMap, nil } -func dataSourceIbmVmaasVdcEdgeToMap(model *vmwarev1.Edge) (map[string]interface{}, error) { +func DataSourceIbmVmaasVdcEdgeToMap(model *vmwarev1.Edge) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["id"] = model.ID + modelMap["id"] = *model.ID modelMap["public_ips"] = model.PublicIps - if model.Size != nil { - modelMap["size"] = model.Size + modelMap["private_ips"] = model.PrivateIps + if model.PrivateOnly != nil { + modelMap["private_only"] = *model.PrivateOnly } - modelMap["status"] = model.Status + modelMap["size"] = *model.Size + modelMap["status"] = *model.Status transitGateways := []map[string]interface{}{} for _, transitGatewaysItem := range model.TransitGateways { - transitGatewaysItemMap, err := dataSourceIbmVmaasVdcTransitGatewayToMap(&transitGatewaysItem) + transitGatewaysItemMap, err := DataSourceIbmVmaasVdcTransitGatewayToMap(&transitGatewaysItem) // #nosec G601 if err != nil { return modelMap, err } transitGateways = append(transitGateways, transitGatewaysItemMap) } modelMap["transit_gateways"] = transitGateways - modelMap["type"] = model.Type - modelMap["version"] = model.Version + modelMap["type"] = *model.Type + modelMap["version"] = *model.Version return modelMap, nil } -func dataSourceIbmVmaasVdcTransitGatewayToMap(model *vmwarev1.TransitGateway) (map[string]interface{}, error) { +func DataSourceIbmVmaasVdcTransitGatewayToMap(model *vmwarev1.TransitGateway) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["id"] = model.ID + modelMap["id"] = *model.ID connections := []map[string]interface{}{} for _, connectionsItem := range model.Connections { - connectionsItemMap, err := dataSourceIbmVmaasVdcTransitGatewayConnectionToMap(&connectionsItem) + connectionsItemMap, err := DataSourceIbmVmaasVdcTransitGatewayConnectionToMap(&connectionsItem) // #nosec G601 if err != nil { return modelMap, err } connections = append(connections, connectionsItemMap) } modelMap["connections"] = connections - modelMap["status"] = model.Status + modelMap["status"] = *model.Status + modelMap["region"] = *model.Region return modelMap, nil } -func dataSourceIbmVmaasVdcTransitGatewayConnectionToMap(model *vmwarev1.TransitGatewayConnection) (map[string]interface{}, error) { +func DataSourceIbmVmaasVdcTransitGatewayConnectionToMap(model *vmwarev1.TransitGatewayConnection) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["name"] = model.Name + modelMap["name"] = *model.Name if model.TransitGatewayConnectionName != nil { - modelMap["transit_gateway_connection_name"] = model.TransitGatewayConnectionName + modelMap["transit_gateway_connection_name"] = *model.TransitGatewayConnectionName } - modelMap["status"] = model.Status + modelMap["status"] = *model.Status if model.LocalGatewayIp != nil { - modelMap["local_gateway_ip"] = model.LocalGatewayIp + modelMap["local_gateway_ip"] = *model.LocalGatewayIp } if model.RemoteGatewayIp != nil { - modelMap["remote_gateway_ip"] = model.RemoteGatewayIp + modelMap["remote_gateway_ip"] = *model.RemoteGatewayIp } if model.LocalTunnelIp != nil { - modelMap["local_tunnel_ip"] = model.LocalTunnelIp + modelMap["local_tunnel_ip"] = *model.LocalTunnelIp } if model.RemoteTunnelIp != nil { - modelMap["remote_tunnel_ip"] = model.RemoteTunnelIp + modelMap["remote_tunnel_ip"] = *model.RemoteTunnelIp } if model.LocalBgpAsn != nil { modelMap["local_bgp_asn"] = flex.IntValue(model.LocalBgpAsn) @@ -525,19 +565,19 @@ func dataSourceIbmVmaasVdcTransitGatewayConnectionToMap(model *vmwarev1.TransitG if model.RemoteBgpAsn != nil { modelMap["remote_bgp_asn"] = flex.IntValue(model.RemoteBgpAsn) } - modelMap["network_account_id"] = model.NetworkAccountID - modelMap["network_type"] = model.NetworkType - modelMap["base_network_type"] = model.BaseNetworkType - modelMap["zone"] = model.Zone + modelMap["network_account_id"] = *model.NetworkAccountID + modelMap["network_type"] = *model.NetworkType + modelMap["base_network_type"] = *model.BaseNetworkType + modelMap["zone"] = *model.Zone return modelMap, nil } -func dataSourceIbmVmaasVdcStatusReasonToMap(model *vmwarev1.StatusReason) (map[string]interface{}, error) { +func DataSourceIbmVmaasVdcStatusReasonToMap(model *vmwarev1.StatusReason) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["code"] = model.Code - modelMap["message"] = model.Message + modelMap["code"] = *model.Code + modelMap["message"] = *model.Message if model.MoreInfo != nil { - modelMap["more_info"] = model.MoreInfo + modelMap["more_info"] = *model.MoreInfo } return modelMap, nil } diff --git a/ibm/service/vmware/data_source_ibm_vmaas_vdc_test.go b/ibm/service/vmware/data_source_ibm_vmaas_vdc_test.go index 2977ebc942..5b44df1f47 100644 --- a/ibm/service/vmware/data_source_ibm_vmaas_vdc_test.go +++ b/ibm/service/vmware/data_source_ibm_vmaas_vdc_test.go @@ -1,6 +1,10 @@ // Copyright IBM Corp. 2024 All Rights Reserved. // Licensed under the Mozilla Public License v2.0 +/* + * IBM OpenAPI Terraform Generator Version: 3.98.0-8be2046a-20241205-162752 + */ + package vmware_test import ( @@ -10,7 +14,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/terraform-provider-ibm/ibm/service/vmware" + acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" + "github.com/IBM/go-sdk-core/v5/core" + "github.com/IBM/vmware-go-sdk/vmwarev1" + "github.com/stretchr/testify/assert" ) func TestAccIbmVmaasVdcDataSourceBasic(t *testing.T) { @@ -35,6 +44,7 @@ func TestAccIbmVmaasVdcDataSourceBasic(t *testing.T) { resource.TestCheckResourceAttrSet("data.ibm_vmaas_vdc.vmaas_vdc_instance", "status_reasons.#"), resource.TestCheckResourceAttrSet("data.ibm_vmaas_vdc.vmaas_vdc_instance", "name"), resource.TestCheckResourceAttrSet("data.ibm_vmaas_vdc.vmaas_vdc_instance", "ordered_at"), + resource.TestCheckResourceAttrSet("data.ibm_vmaas_vdc.vmaas_vdc_instance", "org_href"), resource.TestCheckResourceAttrSet("data.ibm_vmaas_vdc.vmaas_vdc_instance", "org_name"), resource.TestCheckResourceAttrSet("data.ibm_vmaas_vdc.vmaas_vdc_instance", "status"), resource.TestCheckResourceAttrSet("data.ibm_vmaas_vdc.vmaas_vdc_instance", "type"), @@ -68,7 +78,7 @@ func TestAccIbmVmaasVdcDataSourceAllArgs(t *testing.T) { resource.TestCheckResourceAttrSet("data.ibm_vmaas_vdc.vmaas_vdc_instance", "id"), resource.TestCheckResourceAttrSet("data.ibm_vmaas_vdc.vmaas_vdc_instance", "vmaas_vdc_id"), resource.TestCheckResourceAttrSet("data.ibm_vmaas_vdc.vmaas_vdc_instance", "href"), - resource.TestCheckResourceAttrSet("data.ibm_vmaas_vdc.vmaas_vdc_instance", "provisioned_at"), + // resource.TestCheckResourceAttrSet("data.ibm_vmaas_vdc.vmaas_vdc_instance", "provisioned_at"), resource.TestCheckResourceAttrSet("data.ibm_vmaas_vdc.vmaas_vdc_instance", "cpu"), resource.TestCheckResourceAttrSet("data.ibm_vmaas_vdc.vmaas_vdc_instance", "crn"), // resource.TestCheckResourceAttrSet("data.ibm_vmaas_vdc.vmaas_vdc_instance", "deleted_at"), @@ -76,6 +86,7 @@ func TestAccIbmVmaasVdcDataSourceAllArgs(t *testing.T) { resource.TestCheckResourceAttrSet("data.ibm_vmaas_vdc.vmaas_vdc_instance", "edges.#"), /* resource.TestCheckResourceAttrSet("data.ibm_vmaas_vdc.vmaas_vdc_instance", "edges.0.id"), + resource.TestCheckResourceAttrSet("data.ibm_vmaas_vdc.vmaas_vdc_instance", "edges.0.private_only"), resource.TestCheckResourceAttrSet("data.ibm_vmaas_vdc.vmaas_vdc_instance", "edges.0.size"), resource.TestCheckResourceAttrSet("data.ibm_vmaas_vdc.vmaas_vdc_instance", "edges.0.status"), resource.TestCheckResourceAttrSet("data.ibm_vmaas_vdc.vmaas_vdc_instance", "edges.0.type"), @@ -89,6 +100,7 @@ func TestAccIbmVmaasVdcDataSourceAllArgs(t *testing.T) { */ resource.TestCheckResourceAttrSet("data.ibm_vmaas_vdc.vmaas_vdc_instance", "name"), resource.TestCheckResourceAttrSet("data.ibm_vmaas_vdc.vmaas_vdc_instance", "ordered_at"), + resource.TestCheckResourceAttrSet("data.ibm_vmaas_vdc.vmaas_vdc_instance", "org_href"), resource.TestCheckResourceAttrSet("data.ibm_vmaas_vdc.vmaas_vdc_instance", "org_name"), resource.TestCheckResourceAttrSet("data.ibm_vmaas_vdc.vmaas_vdc_instance", "ram"), resource.TestCheckResourceAttrSet("data.ibm_vmaas_vdc.vmaas_vdc_instance", "status"), @@ -115,8 +127,8 @@ func testAccCheckIbmVmaasVdcDataSourceConfigBasic(ds_id string, ds_pvdc_id strin } } name = "%s" - } - + } + data "ibm_vmaas_vdc" "vmaas_vdc_instance" { vmaas_vdc_id = ibm_vmaas_vdc.vmaas_vdc_instance.id } @@ -148,3 +160,263 @@ func testAccCheckIbmVmaasVdcDataSourceConfig(vDCCpu string, ds_id string, ds_pvd } `, vDCCpu, ds_id, ds_pvdc_id, vDCName, vDCRam, vDCFastProvisioningEnabled, vDCRhelByol, vDCWindowsByol) } + +func TestDataSourceIbmVmaasVdcVDCDirectorSiteToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + vdcProviderTypeModel := make(map[string]interface{}) + vdcProviderTypeModel["name"] = "paygo" + + directorSitePvdcModel := make(map[string]interface{}) + directorSitePvdcModel["id"] = "pvdc_id" + directorSitePvdcModel["provider_type"] = []map[string]interface{}{vdcProviderTypeModel} + + model := make(map[string]interface{}) + model["id"] = "testString" + model["pvdc"] = []map[string]interface{}{directorSitePvdcModel} + model["url"] = "testString" + + assert.Equal(t, result, model) + } + + vdcProviderTypeModel := new(vmwarev1.VDCProviderType) + vdcProviderTypeModel.Name = core.StringPtr("paygo") + + directorSitePvdcModel := new(vmwarev1.DirectorSitePVDC) + directorSitePvdcModel.ID = core.StringPtr("pvdc_id") + directorSitePvdcModel.ProviderType = vdcProviderTypeModel + + model := new(vmwarev1.VDCDirectorSite) + model.ID = core.StringPtr("testString") + model.Pvdc = directorSitePvdcModel + model.URL = core.StringPtr("testString") + + result, err := vmware.DataSourceIbmVmaasVdcVDCDirectorSiteToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIbmVmaasVdcDirectorSitePVDCToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + vdcProviderTypeModel := make(map[string]interface{}) + vdcProviderTypeModel["name"] = "paygo" + + model := make(map[string]interface{}) + model["id"] = "pvdc_id" + model["provider_type"] = []map[string]interface{}{vdcProviderTypeModel} + + assert.Equal(t, result, model) + } + + vdcProviderTypeModel := new(vmwarev1.VDCProviderType) + vdcProviderTypeModel.Name = core.StringPtr("paygo") + + model := new(vmwarev1.DirectorSitePVDC) + model.ID = core.StringPtr("pvdc_id") + model.ProviderType = vdcProviderTypeModel + + result, err := vmware.DataSourceIbmVmaasVdcDirectorSitePVDCToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIbmVmaasVdcVDCProviderTypeToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["name"] = "paygo" + + assert.Equal(t, result, model) + } + + model := new(vmwarev1.VDCProviderType) + model.Name = core.StringPtr("paygo") + + result, err := vmware.DataSourceIbmVmaasVdcVDCProviderTypeToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIbmVmaasVdcEdgeToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + transitGatewayConnectionModel := make(map[string]interface{}) + transitGatewayConnectionModel["name"] = "testString" + transitGatewayConnectionModel["transit_gateway_connection_name"] = "testString" + transitGatewayConnectionModel["status"] = "pending" + transitGatewayConnectionModel["local_gateway_ip"] = "testString" + transitGatewayConnectionModel["remote_gateway_ip"] = "testString" + transitGatewayConnectionModel["local_tunnel_ip"] = "testString" + transitGatewayConnectionModel["remote_tunnel_ip"] = "testString" + transitGatewayConnectionModel["local_bgp_asn"] = int(1) + transitGatewayConnectionModel["remote_bgp_asn"] = int(1) + transitGatewayConnectionModel["network_account_id"] = "testString" + transitGatewayConnectionModel["network_type"] = "testString" + transitGatewayConnectionModel["base_network_type"] = "testString" + transitGatewayConnectionModel["zone"] = "testString" + + transitGatewayModel := make(map[string]interface{}) + transitGatewayModel["id"] = "testString" + transitGatewayModel["connections"] = []map[string]interface{}{transitGatewayConnectionModel} + transitGatewayModel["status"] = "pending" + transitGatewayModel["region"] = "testString" + + model := make(map[string]interface{}) + model["id"] = "testString" + model["public_ips"] = []string{"testString"} + model["private_ips"] = []string{"testString"} + model["private_only"] = true + model["size"] = "medium" + model["status"] = "creating" + model["transit_gateways"] = []map[string]interface{}{transitGatewayModel} + model["type"] = "performance" + model["version"] = "testString" + + assert.Equal(t, result, model) + } + + transitGatewayConnectionModel := new(vmwarev1.TransitGatewayConnection) + transitGatewayConnectionModel.Name = core.StringPtr("testString") + transitGatewayConnectionModel.TransitGatewayConnectionName = core.StringPtr("testString") + transitGatewayConnectionModel.Status = core.StringPtr("pending") + transitGatewayConnectionModel.LocalGatewayIp = core.StringPtr("testString") + transitGatewayConnectionModel.RemoteGatewayIp = core.StringPtr("testString") + transitGatewayConnectionModel.LocalTunnelIp = core.StringPtr("testString") + transitGatewayConnectionModel.RemoteTunnelIp = core.StringPtr("testString") + transitGatewayConnectionModel.LocalBgpAsn = core.Int64Ptr(int64(1)) + transitGatewayConnectionModel.RemoteBgpAsn = core.Int64Ptr(int64(1)) + transitGatewayConnectionModel.NetworkAccountID = core.StringPtr("testString") + transitGatewayConnectionModel.NetworkType = core.StringPtr("testString") + transitGatewayConnectionModel.BaseNetworkType = core.StringPtr("testString") + transitGatewayConnectionModel.Zone = core.StringPtr("testString") + + transitGatewayModel := new(vmwarev1.TransitGateway) + transitGatewayModel.ID = core.StringPtr("testString") + transitGatewayModel.Connections = []vmwarev1.TransitGatewayConnection{*transitGatewayConnectionModel} + transitGatewayModel.Status = core.StringPtr("pending") + transitGatewayModel.Region = core.StringPtr("testString") + + model := new(vmwarev1.Edge) + model.ID = core.StringPtr("testString") + model.PublicIps = []string{"testString"} + model.PrivateIps = []string{"testString"} + model.PrivateOnly = core.BoolPtr(true) + model.Size = core.StringPtr("medium") + model.Status = core.StringPtr("creating") + model.TransitGateways = []vmwarev1.TransitGateway{*transitGatewayModel} + model.Type = core.StringPtr("performance") + model.Version = core.StringPtr("testString") + + result, err := vmware.DataSourceIbmVmaasVdcEdgeToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIbmVmaasVdcTransitGatewayToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + transitGatewayConnectionModel := make(map[string]interface{}) + transitGatewayConnectionModel["name"] = "testString" + transitGatewayConnectionModel["transit_gateway_connection_name"] = "testString" + transitGatewayConnectionModel["status"] = "pending" + transitGatewayConnectionModel["local_gateway_ip"] = "testString" + transitGatewayConnectionModel["remote_gateway_ip"] = "testString" + transitGatewayConnectionModel["local_tunnel_ip"] = "testString" + transitGatewayConnectionModel["remote_tunnel_ip"] = "testString" + transitGatewayConnectionModel["local_bgp_asn"] = int(1) + transitGatewayConnectionModel["remote_bgp_asn"] = int(1) + transitGatewayConnectionModel["network_account_id"] = "testString" + transitGatewayConnectionModel["network_type"] = "testString" + transitGatewayConnectionModel["base_network_type"] = "testString" + transitGatewayConnectionModel["zone"] = "testString" + + model := make(map[string]interface{}) + model["id"] = "testString" + model["connections"] = []map[string]interface{}{transitGatewayConnectionModel} + model["status"] = "pending" + model["region"] = "testString" + + assert.Equal(t, result, model) + } + + transitGatewayConnectionModel := new(vmwarev1.TransitGatewayConnection) + transitGatewayConnectionModel.Name = core.StringPtr("testString") + transitGatewayConnectionModel.TransitGatewayConnectionName = core.StringPtr("testString") + transitGatewayConnectionModel.Status = core.StringPtr("pending") + transitGatewayConnectionModel.LocalGatewayIp = core.StringPtr("testString") + transitGatewayConnectionModel.RemoteGatewayIp = core.StringPtr("testString") + transitGatewayConnectionModel.LocalTunnelIp = core.StringPtr("testString") + transitGatewayConnectionModel.RemoteTunnelIp = core.StringPtr("testString") + transitGatewayConnectionModel.LocalBgpAsn = core.Int64Ptr(int64(1)) + transitGatewayConnectionModel.RemoteBgpAsn = core.Int64Ptr(int64(1)) + transitGatewayConnectionModel.NetworkAccountID = core.StringPtr("testString") + transitGatewayConnectionModel.NetworkType = core.StringPtr("testString") + transitGatewayConnectionModel.BaseNetworkType = core.StringPtr("testString") + transitGatewayConnectionModel.Zone = core.StringPtr("testString") + + model := new(vmwarev1.TransitGateway) + model.ID = core.StringPtr("testString") + model.Connections = []vmwarev1.TransitGatewayConnection{*transitGatewayConnectionModel} + model.Status = core.StringPtr("pending") + model.Region = core.StringPtr("testString") + + result, err := vmware.DataSourceIbmVmaasVdcTransitGatewayToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIbmVmaasVdcTransitGatewayConnectionToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["name"] = "testString" + model["transit_gateway_connection_name"] = "testString" + model["status"] = "pending" + model["local_gateway_ip"] = "testString" + model["remote_gateway_ip"] = "testString" + model["local_tunnel_ip"] = "testString" + model["remote_tunnel_ip"] = "testString" + model["local_bgp_asn"] = int(1) + model["remote_bgp_asn"] = int(1) + model["network_account_id"] = "testString" + model["network_type"] = "testString" + model["base_network_type"] = "testString" + model["zone"] = "testString" + + assert.Equal(t, result, model) + } + + model := new(vmwarev1.TransitGatewayConnection) + model.Name = core.StringPtr("testString") + model.TransitGatewayConnectionName = core.StringPtr("testString") + model.Status = core.StringPtr("pending") + model.LocalGatewayIp = core.StringPtr("testString") + model.RemoteGatewayIp = core.StringPtr("testString") + model.LocalTunnelIp = core.StringPtr("testString") + model.RemoteTunnelIp = core.StringPtr("testString") + model.LocalBgpAsn = core.Int64Ptr(int64(1)) + model.RemoteBgpAsn = core.Int64Ptr(int64(1)) + model.NetworkAccountID = core.StringPtr("testString") + model.NetworkType = core.StringPtr("testString") + model.BaseNetworkType = core.StringPtr("testString") + model.Zone = core.StringPtr("testString") + + result, err := vmware.DataSourceIbmVmaasVdcTransitGatewayConnectionToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIbmVmaasVdcStatusReasonToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["code"] = "insufficent_cpu" + model["message"] = "testString" + model["more_info"] = "testString" + + assert.Equal(t, result, model) + } + + model := new(vmwarev1.StatusReason) + model.Code = core.StringPtr("insufficent_cpu") + model.Message = core.StringPtr("testString") + model.MoreInfo = core.StringPtr("testString") + + result, err := vmware.DataSourceIbmVmaasVdcStatusReasonToMap(model) + assert.Nil(t, err) + checkResult(result) +} diff --git a/ibm/service/vmware/resource_ibm_vmaas_vdc.go b/ibm/service/vmware/resource_ibm_vmaas_vdc.go index 8a5864440e..e4a404f92a 100644 --- a/ibm/service/vmware/resource_ibm_vmaas_vdc.go +++ b/ibm/service/vmware/resource_ibm_vmaas_vdc.go @@ -1,6 +1,10 @@ // Copyright IBM Corp. 2024 All Rights Reserved. // Licensed under the Mozilla Public License v2.0 +/* + * IBM OpenAPI Terraform Generator Version: 3.98.0-8be2046a-20241205-162752 + */ + package vmware import ( @@ -157,6 +161,18 @@ func ResourceIbmVmaasVdc() *schema.Resource { Description: "The public IP addresses assigned to the edge.", Elem: &schema.Schema{Type: schema.TypeString}, }, + "private_ips": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "The private IP addresses assigned to the edge.", + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "private_only": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + Computed: true, + Description: "Indicates whether the edge is private only. The default value is True for a private Cloud Director site and False for a public Cloud Director site.", + }, "size": &schema.Schema{ Type: schema.TypeString, Computed: true, @@ -191,6 +207,7 @@ func ResourceIbmVmaasVdc() *schema.Resource { }, "transit_gateway_connection_name": &schema.Schema{ Type: schema.TypeString, + Optional: true, Computed: true, Description: "The user-defined name of the connection created on the IBM Transit Gateway.", }, @@ -201,31 +218,37 @@ func ResourceIbmVmaasVdc() *schema.Resource { }, "local_gateway_ip": &schema.Schema{ Type: schema.TypeString, + Optional: true, Computed: true, Description: "Local gateway IP address for the connection.", }, "remote_gateway_ip": &schema.Schema{ Type: schema.TypeString, + Optional: true, Computed: true, Description: "Remote gateway IP address for the connection.", }, "local_tunnel_ip": &schema.Schema{ Type: schema.TypeString, + Optional: true, Computed: true, Description: "Local tunnel IP address for the connection.", }, "remote_tunnel_ip": &schema.Schema{ Type: schema.TypeString, + Optional: true, Computed: true, Description: "Remote tunnel IP address for the connection.", }, "local_bgp_asn": &schema.Schema{ Type: schema.TypeInt, + Optional: true, Computed: true, Description: "Local network BGP ASN for the connection.", }, "remote_bgp_asn": &schema.Schema{ Type: schema.TypeInt, + Optional: true, Computed: true, Description: "Remote network BGP ASN for the connection.", }, @@ -257,6 +280,11 @@ func ResourceIbmVmaasVdc() *schema.Resource { Computed: true, Description: "Determines the state of the IBM Transit Gateway based on its connections.", }, + "region": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The region where the IBM Transit Gateway is deployed.", + }, }, }, }, @@ -291,6 +319,7 @@ func ResourceIbmVmaasVdc() *schema.Resource { }, "more_info": &schema.Schema{ Type: schema.TypeString, + Optional: true, Computed: true, Description: "A URL that links to a page with more information about this error.", }, @@ -302,6 +331,11 @@ func ResourceIbmVmaasVdc() *schema.Resource { Computed: true, Description: "The time that the virtual data center (VDC) is ordered.", }, + "org_href": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The URL of the organization that owns the VDC.", + }, "org_name": &schema.Schema{ Type: schema.TypeString, Computed: true, @@ -367,21 +401,23 @@ func ResourceIbmVmaasVdcValidator() *validate.ResourceValidator { func resourceIbmVmaasVdcCreate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { vmwareClient, err := meta.(conns.ClientSession).VmwareV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_vmaas_vdc", "create", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } createVdcOptions := &vmwarev1.CreateVdcOptions{} createVdcOptions.SetName(d.Get("name").(string)) - directorSiteModel, err := resourceIbmVmaasVdcMapToVDCDirectorSitePrototype(d.Get("director_site.0").(map[string]interface{})) + directorSiteModel, err := ResourceIbmVmaasVdcMapToVDCDirectorSitePrototype(d.Get("director_site.0").(map[string]interface{})) if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_vmaas_vdc", "create", "parse-director_site").GetDiag() } createVdcOptions.SetDirectorSite(directorSiteModel) if _, ok := d.GetOk("edge"); ok { - edgeModel, err := resourceIbmVmaasVdcMapToVDCEdgePrototype(d.Get("edge.0").(map[string]interface{})) + edgeModel, err := ResourceIbmVmaasVdcMapToVDCEdgePrototype(d.Get("edge.0").(map[string]interface{})) if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_vmaas_vdc", "create", "parse-edge").GetDiag() } createVdcOptions.SetEdge(edgeModel) } @@ -389,9 +425,9 @@ func resourceIbmVmaasVdcCreate(context context.Context, d *schema.ResourceData, createVdcOptions.SetFastProvisioningEnabled(d.Get("fast_provisioning_enabled").(bool)) } if _, ok := d.GetOk("resource_group"); ok { - resourceGroupModel, err := resourceIbmVmaasVdcMapToResourceGroupIdentity(d.Get("resource_group.0").(map[string]interface{})) + resourceGroupModel, err := ResourceIbmVmaasVdcMapToResourceGroupIdentity(d.Get("resource_group.0").(map[string]interface{})) if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_vmaas_vdc", "create", "parse-resource_group").GetDiag() } createVdcOptions.SetResourceGroup(resourceGroupModel) } @@ -411,10 +447,11 @@ func resourceIbmVmaasVdcCreate(context context.Context, d *schema.ResourceData, createVdcOptions.SetAcceptLanguage(d.Get("accept_language").(string)) } - vdc, response, err := vmwareClient.CreateVdcWithContext(context, createVdcOptions) + vdc, _, err := vmwareClient.CreateVdcWithContext(context, createVdcOptions) if err != nil { - log.Printf("[DEBUG] CreateVdcWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("CreateVdcWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("CreateVdcWithContext failed: %s", err.Error()), "ibm_vmaas_vdc", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(*vdc.ID) @@ -432,12 +469,17 @@ func resourceIbmVmaasVdcCreate(context context.Context, d *schema.ResourceData, func resourceIbmVmaasVdcRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { vmwareClient, err := meta.(conns.ClientSession).VmwareV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_vmaas_vdc", "read", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } getVdcOptions := &vmwarev1.GetVdcOptions{} getVdcOptions.SetID(d.Id()) + if _, ok := d.GetOk("accept_language"); ok { + getVdcOptions.SetAcceptLanguage(d.Get("accept_language").(string)) + } vdc, response, err := vmwareClient.GetVdcWithContext(context, getVdcOptions) if err != nil { @@ -445,94 +487,116 @@ func resourceIbmVmaasVdcRead(context context.Context, d *schema.ResourceData, me d.SetId("") return nil } - log.Printf("[DEBUG] GetVdcWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetVdcWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetVdcWithContext failed: %s", err.Error()), "ibm_vmaas_vdc", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if !core.IsNil(vdc.Cpu) { if err = d.Set("cpu", flex.IntValue(vdc.Cpu)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting cpu: %s", err)) + err = fmt.Errorf("Error setting cpu: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_vmaas_vdc", "read", "set-cpu").GetDiag() } } - directorSiteMap, err := resourceIbmVmaasVdcVDCDirectorSiteToMap(vdc.DirectorSite) + directorSiteMap, err := ResourceIbmVmaasVdcVDCDirectorSiteToMap(vdc.DirectorSite) if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_vmaas_vdc", "read", "director_site-to-map").GetDiag() } if err = d.Set("director_site", []map[string]interface{}{directorSiteMap}); err != nil { - return diag.FromErr(fmt.Errorf("Error setting director_site: %s", err)) + err = fmt.Errorf("Error setting director_site: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_vmaas_vdc", "read", "set-director_site").GetDiag() } if err = d.Set("name", vdc.Name); err != nil { - return diag.FromErr(fmt.Errorf("Error setting name: %s", err)) + err = fmt.Errorf("Error setting name: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_vmaas_vdc", "read", "set-name").GetDiag() } if !core.IsNil(vdc.Ram) { if err = d.Set("ram", flex.IntValue(vdc.Ram)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting ram: %s", err)) + err = fmt.Errorf("Error setting ram: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_vmaas_vdc", "read", "set-ram").GetDiag() } } if !core.IsNil(vdc.FastProvisioningEnabled) { if err = d.Set("fast_provisioning_enabled", vdc.FastProvisioningEnabled); err != nil { - return diag.FromErr(fmt.Errorf("Error setting fast_provisioning_enabled: %s", err)) + err = fmt.Errorf("Error setting fast_provisioning_enabled: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_vmaas_vdc", "read", "set-fast_provisioning_enabled").GetDiag() } } if !core.IsNil(vdc.RhelByol) { if err = d.Set("rhel_byol", vdc.RhelByol); err != nil { - return diag.FromErr(fmt.Errorf("Error setting rhel_byol: %s", err)) + err = fmt.Errorf("Error setting rhel_byol: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_vmaas_vdc", "read", "set-rhel_byol").GetDiag() } } if !core.IsNil(vdc.WindowsByol) { if err = d.Set("windows_byol", vdc.WindowsByol); err != nil { - return diag.FromErr(fmt.Errorf("Error setting windows_byol: %s", err)) + err = fmt.Errorf("Error setting windows_byol: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_vmaas_vdc", "read", "set-windows_byol").GetDiag() } } if err = d.Set("href", vdc.Href); err != nil { - return diag.FromErr(fmt.Errorf("Error setting href: %s", err)) + err = fmt.Errorf("Error setting href: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_vmaas_vdc", "read", "set-href").GetDiag() } if !core.IsNil(vdc.ProvisionedAt) { if err = d.Set("provisioned_at", flex.DateTimeToString(vdc.ProvisionedAt)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting provisioned_at: %s", err)) + err = fmt.Errorf("Error setting provisioned_at: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_vmaas_vdc", "read", "set-provisioned_at").GetDiag() } } if err = d.Set("crn", vdc.Crn); err != nil { - return diag.FromErr(fmt.Errorf("Error setting crn: %s", err)) + err = fmt.Errorf("Error setting crn: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_vmaas_vdc", "read", "set-crn").GetDiag() } if !core.IsNil(vdc.DeletedAt) { if err = d.Set("deleted_at", flex.DateTimeToString(vdc.DeletedAt)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting deleted_at: %s", err)) + err = fmt.Errorf("Error setting deleted_at: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_vmaas_vdc", "read", "set-deleted_at").GetDiag() } } edges := []map[string]interface{}{} for _, edgesItem := range vdc.Edges { - edgesItemMap, err := resourceIbmVmaasVdcEdgeToMap(&edgesItem) + edgesItemMap, err := ResourceIbmVmaasVdcEdgeToMap(&edgesItem) // #nosec G601 if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_vmaas_vdc", "read", "edges-to-map").GetDiag() } edges = append(edges, edgesItemMap) } if err = d.Set("edges", edges); err != nil { - return diag.FromErr(fmt.Errorf("Error setting edges: %s", err)) + err = fmt.Errorf("Error setting edges: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_vmaas_vdc", "read", "set-edges").GetDiag() } statusReasons := []map[string]interface{}{} for _, statusReasonsItem := range vdc.StatusReasons { - statusReasonsItemMap, err := resourceIbmVmaasVdcStatusReasonToMap(&statusReasonsItem) + statusReasonsItemMap, err := ResourceIbmVmaasVdcStatusReasonToMap(&statusReasonsItem) // #nosec G601 if err != nil { - return diag.FromErr(err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_vmaas_vdc", "read", "status_reasons-to-map").GetDiag() } statusReasons = append(statusReasons, statusReasonsItemMap) } if err = d.Set("status_reasons", statusReasons); err != nil { - return diag.FromErr(fmt.Errorf("Error setting status_reasons: %s", err)) + err = fmt.Errorf("Error setting status_reasons: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_vmaas_vdc", "read", "set-status_reasons").GetDiag() } if err = d.Set("ordered_at", flex.DateTimeToString(vdc.OrderedAt)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting ordered_at: %s", err)) + err = fmt.Errorf("Error setting ordered_at: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_vmaas_vdc", "read", "set-ordered_at").GetDiag() + } + if err = d.Set("org_href", vdc.OrgHref); err != nil { + err = fmt.Errorf("Error setting org_href: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_vmaas_vdc", "read", "set-org_href").GetDiag() } if err = d.Set("org_name", vdc.OrgName); err != nil { - return diag.FromErr(fmt.Errorf("Error setting org_name: %s", err)) + err = fmt.Errorf("Error setting org_name: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_vmaas_vdc", "read", "set-org_name").GetDiag() } if err = d.Set("status", vdc.Status); err != nil { - return diag.FromErr(fmt.Errorf("Error setting status: %s", err)) + err = fmt.Errorf("Error setting status: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_vmaas_vdc", "read", "set-status").GetDiag() } if err = d.Set("type", vdc.Type); err != nil { - return diag.FromErr(fmt.Errorf("Error setting type: %s", err)) + err = fmt.Errorf("Error setting type: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_vmaas_vdc", "read", "set-type").GetDiag() } return nil @@ -541,7 +605,9 @@ func resourceIbmVmaasVdcRead(context context.Context, d *schema.ResourceData, me func resourceIbmVmaasVdcUpdate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { vmwareClient, err := meta.(conns.ClientSession).VmwareV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_vmaas_vdc", "update", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } updateVdcOptions := &vmwarev1.UpdateVdcOptions{} @@ -572,11 +638,16 @@ func resourceIbmVmaasVdcUpdate(context context.Context, d *schema.ResourceData, } if hasChange { - updateVdcOptions.VDCPatch, _ = patchVals.AsPatch() - _, response, err := vmwareClient.UpdateVdcWithContext(context, updateVdcOptions) + // Fields with `nil` values are omitted from the generic map, + // so we need to re-add them to support removing arguments + // in merge-patch operations sent to the service. + updateVdcOptions.VDCPatch = ResourceIbmVmaasVdcVDCPatchAsPatch(patchVals, d) + + _, _, err = vmwareClient.UpdateVdcWithContext(context, updateVdcOptions) if err != nil { - log.Printf("[DEBUG] UpdateVdcWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("UpdateVdcWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("UpdateVdcWithContext failed: %s", err.Error()), "ibm_vmaas_vdc", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } @@ -593,17 +664,23 @@ func resourceIbmVmaasVdcUpdate(context context.Context, d *schema.ResourceData, func resourceIbmVmaasVdcDelete(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { vmwareClient, err := meta.(conns.ClientSession).VmwareV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_vmaas_vdc", "delete", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } deleteVdcOptions := &vmwarev1.DeleteVdcOptions{} deleteVdcOptions.SetID(d.Id()) + if _, ok := d.GetOk("accept_language"); ok { + deleteVdcOptions.SetAcceptLanguage(d.Get("accept_language").(string)) + } - vdcDelete, response, err := vmwareClient.DeleteVdcWithContext(context, deleteVdcOptions) + vdcDelete, _, err := vmwareClient.DeleteVdcWithContext(context, deleteVdcOptions) if err != nil { - log.Printf("[DEBUG] DeleteVdcWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("DeleteVdcWithContext failed %s\n%s", err, response)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("DeleteVdcWithContext failed: %s", err.Error()), "ibm_vmaas_vdc", "delete") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if waitForVdcStatus { @@ -618,10 +695,10 @@ func resourceIbmVmaasVdcDelete(context context.Context, d *schema.ResourceData, return nil } -func resourceIbmVmaasVdcMapToVDCDirectorSitePrototype(modelMap map[string]interface{}) (*vmwarev1.VDCDirectorSitePrototype, error) { +func ResourceIbmVmaasVdcMapToVDCDirectorSitePrototype(modelMap map[string]interface{}) (*vmwarev1.VDCDirectorSitePrototype, error) { model := &vmwarev1.VDCDirectorSitePrototype{} model.ID = core.StringPtr(modelMap["id"].(string)) - PvdcModel, err := resourceIbmVmaasVdcMapToDirectorSitePVDC(modelMap["pvdc"].([]interface{})[0].(map[string]interface{})) + PvdcModel, err := ResourceIbmVmaasVdcMapToDirectorSitePVDC(modelMap["pvdc"].([]interface{})[0].(map[string]interface{})) if err != nil { return model, err } @@ -629,11 +706,11 @@ func resourceIbmVmaasVdcMapToVDCDirectorSitePrototype(modelMap map[string]interf return model, nil } -func resourceIbmVmaasVdcMapToDirectorSitePVDC(modelMap map[string]interface{}) (*vmwarev1.DirectorSitePVDC, error) { +func ResourceIbmVmaasVdcMapToDirectorSitePVDC(modelMap map[string]interface{}) (*vmwarev1.DirectorSitePVDC, error) { model := &vmwarev1.DirectorSitePVDC{} model.ID = core.StringPtr(modelMap["id"].(string)) if modelMap["provider_type"] != nil && len(modelMap["provider_type"].([]interface{})) > 0 { - ProviderTypeModel, err := resourceIbmVmaasVdcMapToVDCProviderType(modelMap["provider_type"].([]interface{})[0].(map[string]interface{})) + ProviderTypeModel, err := ResourceIbmVmaasVdcMapToVDCProviderType(modelMap["provider_type"].([]interface{})[0].(map[string]interface{})) if err != nil { return model, err } @@ -642,44 +719,47 @@ func resourceIbmVmaasVdcMapToDirectorSitePVDC(modelMap map[string]interface{}) ( return model, nil } -func resourceIbmVmaasVdcMapToVDCProviderType(modelMap map[string]interface{}) (*vmwarev1.VDCProviderType, error) { +func ResourceIbmVmaasVdcMapToVDCProviderType(modelMap map[string]interface{}) (*vmwarev1.VDCProviderType, error) { model := &vmwarev1.VDCProviderType{} model.Name = core.StringPtr(modelMap["name"].(string)) return model, nil } -func resourceIbmVmaasVdcMapToVDCEdgePrototype(modelMap map[string]interface{}) (*vmwarev1.VDCEdgePrototype, error) { +func ResourceIbmVmaasVdcMapToVDCEdgePrototype(modelMap map[string]interface{}) (*vmwarev1.VDCEdgePrototype, error) { model := &vmwarev1.VDCEdgePrototype{} if modelMap["size"] != nil && modelMap["size"].(string) != "" { model.Size = core.StringPtr(modelMap["size"].(string)) } model.Type = core.StringPtr(modelMap["type"].(string)) + if modelMap["private_only"] != nil { + model.PrivateOnly = core.BoolPtr(modelMap["private_only"].(bool)) + } return model, nil } -func resourceIbmVmaasVdcMapToResourceGroupIdentity(modelMap map[string]interface{}) (*vmwarev1.ResourceGroupIdentity, error) { +func ResourceIbmVmaasVdcMapToResourceGroupIdentity(modelMap map[string]interface{}) (*vmwarev1.ResourceGroupIdentity, error) { model := &vmwarev1.ResourceGroupIdentity{} model.ID = core.StringPtr(modelMap["id"].(string)) return model, nil } -func resourceIbmVmaasVdcVDCDirectorSiteToMap(model *vmwarev1.VDCDirectorSite) (map[string]interface{}, error) { +func ResourceIbmVmaasVdcVDCDirectorSiteToMap(model *vmwarev1.VDCDirectorSite) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["id"] = model.ID - pvdcMap, err := resourceIbmVmaasVdcDirectorSitePVDCToMap(model.Pvdc) + modelMap["id"] = *model.ID + pvdcMap, err := ResourceIbmVmaasVdcDirectorSitePVDCToMap(model.Pvdc) if err != nil { return modelMap, err } modelMap["pvdc"] = []map[string]interface{}{pvdcMap} - modelMap["url"] = model.URL + modelMap["url"] = *model.URL return modelMap, nil } -func resourceIbmVmaasVdcDirectorSitePVDCToMap(model *vmwarev1.DirectorSitePVDC) (map[string]interface{}, error) { +func ResourceIbmVmaasVdcDirectorSitePVDCToMap(model *vmwarev1.DirectorSitePVDC) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["id"] = model.ID + modelMap["id"] = *model.ID if model.ProviderType != nil { - providerTypeMap, err := resourceIbmVmaasVdcVDCProviderTypeToMap(model.ProviderType) + providerTypeMap, err := ResourceIbmVmaasVdcVDCProviderTypeToMap(model.ProviderType) if err != nil { return modelMap, err } @@ -688,68 +768,71 @@ func resourceIbmVmaasVdcDirectorSitePVDCToMap(model *vmwarev1.DirectorSitePVDC) return modelMap, nil } -func resourceIbmVmaasVdcVDCProviderTypeToMap(model *vmwarev1.VDCProviderType) (map[string]interface{}, error) { +func ResourceIbmVmaasVdcVDCProviderTypeToMap(model *vmwarev1.VDCProviderType) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["name"] = model.Name + modelMap["name"] = *model.Name return modelMap, nil } -func resourceIbmVmaasVdcEdgeToMap(model *vmwarev1.Edge) (map[string]interface{}, error) { +func ResourceIbmVmaasVdcEdgeToMap(model *vmwarev1.Edge) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["id"] = model.ID + modelMap["id"] = *model.ID modelMap["public_ips"] = model.PublicIps - if model.Size != nil { - modelMap["size"] = model.Size + modelMap["private_ips"] = model.PrivateIps + if model.PrivateOnly != nil { + modelMap["private_only"] = *model.PrivateOnly } - modelMap["status"] = model.Status + modelMap["size"] = *model.Size + modelMap["status"] = *model.Status transitGateways := []map[string]interface{}{} for _, transitGatewaysItem := range model.TransitGateways { - transitGatewaysItemMap, err := resourceIbmVmaasVdcTransitGatewayToMap(&transitGatewaysItem) + transitGatewaysItemMap, err := ResourceIbmVmaasVdcTransitGatewayToMap(&transitGatewaysItem) // #nosec G601 if err != nil { return modelMap, err } transitGateways = append(transitGateways, transitGatewaysItemMap) } modelMap["transit_gateways"] = transitGateways - modelMap["type"] = model.Type - modelMap["version"] = model.Version + modelMap["type"] = *model.Type + modelMap["version"] = *model.Version return modelMap, nil } -func resourceIbmVmaasVdcTransitGatewayToMap(model *vmwarev1.TransitGateway) (map[string]interface{}, error) { +func ResourceIbmVmaasVdcTransitGatewayToMap(model *vmwarev1.TransitGateway) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["id"] = model.ID + modelMap["id"] = *model.ID connections := []map[string]interface{}{} for _, connectionsItem := range model.Connections { - connectionsItemMap, err := resourceIbmVmaasVdcTransitGatewayConnectionToMap(&connectionsItem) + connectionsItemMap, err := ResourceIbmVmaasVdcTransitGatewayConnectionToMap(&connectionsItem) // #nosec G601 if err != nil { return modelMap, err } connections = append(connections, connectionsItemMap) } modelMap["connections"] = connections - modelMap["status"] = model.Status + modelMap["status"] = *model.Status + modelMap["region"] = *model.Region return modelMap, nil } -func resourceIbmVmaasVdcTransitGatewayConnectionToMap(model *vmwarev1.TransitGatewayConnection) (map[string]interface{}, error) { +func ResourceIbmVmaasVdcTransitGatewayConnectionToMap(model *vmwarev1.TransitGatewayConnection) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["name"] = model.Name + modelMap["name"] = *model.Name if model.TransitGatewayConnectionName != nil { - modelMap["transit_gateway_connection_name"] = model.TransitGatewayConnectionName + modelMap["transit_gateway_connection_name"] = *model.TransitGatewayConnectionName } - modelMap["status"] = model.Status + modelMap["status"] = *model.Status if model.LocalGatewayIp != nil { - modelMap["local_gateway_ip"] = model.LocalGatewayIp + modelMap["local_gateway_ip"] = *model.LocalGatewayIp } if model.RemoteGatewayIp != nil { - modelMap["remote_gateway_ip"] = model.RemoteGatewayIp + modelMap["remote_gateway_ip"] = *model.RemoteGatewayIp } if model.LocalTunnelIp != nil { - modelMap["local_tunnel_ip"] = model.LocalTunnelIp + modelMap["local_tunnel_ip"] = *model.LocalTunnelIp } if model.RemoteTunnelIp != nil { - modelMap["remote_tunnel_ip"] = model.RemoteTunnelIp + modelMap["remote_tunnel_ip"] = *model.RemoteTunnelIp } if model.LocalBgpAsn != nil { modelMap["local_bgp_asn"] = flex.IntValue(model.LocalBgpAsn) @@ -757,19 +840,45 @@ func resourceIbmVmaasVdcTransitGatewayConnectionToMap(model *vmwarev1.TransitGat if model.RemoteBgpAsn != nil { modelMap["remote_bgp_asn"] = flex.IntValue(model.RemoteBgpAsn) } - modelMap["network_account_id"] = model.NetworkAccountID - modelMap["network_type"] = model.NetworkType - modelMap["base_network_type"] = model.BaseNetworkType - modelMap["zone"] = model.Zone + modelMap["network_account_id"] = *model.NetworkAccountID + modelMap["network_type"] = *model.NetworkType + modelMap["base_network_type"] = *model.BaseNetworkType + modelMap["zone"] = *model.Zone return modelMap, nil } -func resourceIbmVmaasVdcStatusReasonToMap(model *vmwarev1.StatusReason) (map[string]interface{}, error) { +func ResourceIbmVmaasVdcStatusReasonToMap(model *vmwarev1.StatusReason) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - modelMap["code"] = model.Code - modelMap["message"] = model.Message + modelMap["code"] = *model.Code + modelMap["message"] = *model.Message if model.MoreInfo != nil { - modelMap["more_info"] = model.MoreInfo + modelMap["more_info"] = *model.MoreInfo } return modelMap, nil } + +func ResourceIbmVmaasVdcVDCPatchAsPatch(patchVals *vmwarev1.VDCPatch, d *schema.ResourceData) map[string]interface{} { + patch, _ := patchVals.AsPatch() + var path string + + path = "cpu" + if _, exists := d.GetOk(path); d.HasChange(path) && !exists { + patch["cpu"] = nil + } else if !exists { + delete(patch, "cpu") + } + path = "fast_provisioning_enabled" + if _, exists := d.GetOk(path); d.HasChange(path) && !exists { + patch["fast_provisioning_enabled"] = nil + } else if !exists { + delete(patch, "fast_provisioning_enabled") + } + path = "ram" + if _, exists := d.GetOk(path); d.HasChange(path) && !exists { + patch["ram"] = nil + } else if !exists { + delete(patch, "ram") + } + + return patch +} diff --git a/ibm/service/vmware/resource_ibm_vmaas_vdc_test.go b/ibm/service/vmware/resource_ibm_vmaas_vdc_test.go index 52bec2cf4c..ad8ccc3be2 100644 --- a/ibm/service/vmware/resource_ibm_vmaas_vdc_test.go +++ b/ibm/service/vmware/resource_ibm_vmaas_vdc_test.go @@ -11,9 +11,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/terraform-provider-ibm/ibm/service/vmware" + acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM/go-sdk-core/v5/core" "github.com/IBM/vmware-go-sdk/vmwarev1" + "github.com/stretchr/testify/assert" ) func TestAccIbmVmaasVdcBasic(t *testing.T) { @@ -189,3 +193,371 @@ func testAccCheckIbmVmaasVdcDestroy(s *terraform.State) error { return nil } + +func TestResourceIbmVmaasVdcVDCDirectorSiteToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + vdcProviderTypeModel := make(map[string]interface{}) + vdcProviderTypeModel["name"] = "paygo" + + directorSitePvdcModel := make(map[string]interface{}) + directorSitePvdcModel["id"] = "pvdc_id" + directorSitePvdcModel["provider_type"] = []map[string]interface{}{vdcProviderTypeModel} + + model := make(map[string]interface{}) + model["id"] = "testString" + model["pvdc"] = []map[string]interface{}{directorSitePvdcModel} + model["url"] = "testString" + + assert.Equal(t, result, model) + } + + vdcProviderTypeModel := new(vmwarev1.VDCProviderType) + vdcProviderTypeModel.Name = core.StringPtr("paygo") + + directorSitePvdcModel := new(vmwarev1.DirectorSitePVDC) + directorSitePvdcModel.ID = core.StringPtr("pvdc_id") + directorSitePvdcModel.ProviderType = vdcProviderTypeModel + + model := new(vmwarev1.VDCDirectorSite) + model.ID = core.StringPtr("testString") + model.Pvdc = directorSitePvdcModel + model.URL = core.StringPtr("testString") + + result, err := vmware.ResourceIbmVmaasVdcVDCDirectorSiteToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIbmVmaasVdcDirectorSitePVDCToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + vdcProviderTypeModel := make(map[string]interface{}) + vdcProviderTypeModel["name"] = "paygo" + + model := make(map[string]interface{}) + model["id"] = "pvdc_id" + model["provider_type"] = []map[string]interface{}{vdcProviderTypeModel} + + assert.Equal(t, result, model) + } + + vdcProviderTypeModel := new(vmwarev1.VDCProviderType) + vdcProviderTypeModel.Name = core.StringPtr("paygo") + + model := new(vmwarev1.DirectorSitePVDC) + model.ID = core.StringPtr("pvdc_id") + model.ProviderType = vdcProviderTypeModel + + result, err := vmware.ResourceIbmVmaasVdcDirectorSitePVDCToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIbmVmaasVdcVDCProviderTypeToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["name"] = "paygo" + + assert.Equal(t, result, model) + } + + model := new(vmwarev1.VDCProviderType) + model.Name = core.StringPtr("paygo") + + result, err := vmware.ResourceIbmVmaasVdcVDCProviderTypeToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIbmVmaasVdcEdgeToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + transitGatewayConnectionModel := make(map[string]interface{}) + transitGatewayConnectionModel["name"] = "testString" + transitGatewayConnectionModel["transit_gateway_connection_name"] = "testString" + transitGatewayConnectionModel["status"] = "pending" + transitGatewayConnectionModel["local_gateway_ip"] = "testString" + transitGatewayConnectionModel["remote_gateway_ip"] = "testString" + transitGatewayConnectionModel["local_tunnel_ip"] = "testString" + transitGatewayConnectionModel["remote_tunnel_ip"] = "testString" + transitGatewayConnectionModel["local_bgp_asn"] = int(1) + transitGatewayConnectionModel["remote_bgp_asn"] = int(1) + transitGatewayConnectionModel["network_account_id"] = "testString" + transitGatewayConnectionModel["network_type"] = "testString" + transitGatewayConnectionModel["base_network_type"] = "testString" + transitGatewayConnectionModel["zone"] = "testString" + + transitGatewayModel := make(map[string]interface{}) + transitGatewayModel["id"] = "testString" + transitGatewayModel["connections"] = []map[string]interface{}{transitGatewayConnectionModel} + transitGatewayModel["status"] = "pending" + transitGatewayModel["region"] = "testString" + + model := make(map[string]interface{}) + model["id"] = "testString" + model["public_ips"] = []string{"testString"} + model["private_ips"] = []string{"testString"} + model["private_only"] = true + model["size"] = "medium" + model["status"] = "creating" + model["transit_gateways"] = []map[string]interface{}{transitGatewayModel} + model["type"] = "performance" + model["version"] = "testString" + + assert.Equal(t, result, model) + } + + transitGatewayConnectionModel := new(vmwarev1.TransitGatewayConnection) + transitGatewayConnectionModel.Name = core.StringPtr("testString") + transitGatewayConnectionModel.TransitGatewayConnectionName = core.StringPtr("testString") + transitGatewayConnectionModel.Status = core.StringPtr("pending") + transitGatewayConnectionModel.LocalGatewayIp = core.StringPtr("testString") + transitGatewayConnectionModel.RemoteGatewayIp = core.StringPtr("testString") + transitGatewayConnectionModel.LocalTunnelIp = core.StringPtr("testString") + transitGatewayConnectionModel.RemoteTunnelIp = core.StringPtr("testString") + transitGatewayConnectionModel.LocalBgpAsn = core.Int64Ptr(int64(1)) + transitGatewayConnectionModel.RemoteBgpAsn = core.Int64Ptr(int64(1)) + transitGatewayConnectionModel.NetworkAccountID = core.StringPtr("testString") + transitGatewayConnectionModel.NetworkType = core.StringPtr("testString") + transitGatewayConnectionModel.BaseNetworkType = core.StringPtr("testString") + transitGatewayConnectionModel.Zone = core.StringPtr("testString") + + transitGatewayModel := new(vmwarev1.TransitGateway) + transitGatewayModel.ID = core.StringPtr("testString") + transitGatewayModel.Connections = []vmwarev1.TransitGatewayConnection{*transitGatewayConnectionModel} + transitGatewayModel.Status = core.StringPtr("pending") + transitGatewayModel.Region = core.StringPtr("testString") + + model := new(vmwarev1.Edge) + model.ID = core.StringPtr("testString") + model.PublicIps = []string{"testString"} + model.PrivateIps = []string{"testString"} + model.PrivateOnly = core.BoolPtr(true) + model.Size = core.StringPtr("medium") + model.Status = core.StringPtr("creating") + model.TransitGateways = []vmwarev1.TransitGateway{*transitGatewayModel} + model.Type = core.StringPtr("performance") + model.Version = core.StringPtr("testString") + + result, err := vmware.ResourceIbmVmaasVdcEdgeToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIbmVmaasVdcTransitGatewayToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + transitGatewayConnectionModel := make(map[string]interface{}) + transitGatewayConnectionModel["name"] = "testString" + transitGatewayConnectionModel["transit_gateway_connection_name"] = "testString" + transitGatewayConnectionModel["status"] = "pending" + transitGatewayConnectionModel["local_gateway_ip"] = "testString" + transitGatewayConnectionModel["remote_gateway_ip"] = "testString" + transitGatewayConnectionModel["local_tunnel_ip"] = "testString" + transitGatewayConnectionModel["remote_tunnel_ip"] = "testString" + transitGatewayConnectionModel["local_bgp_asn"] = int(1) + transitGatewayConnectionModel["remote_bgp_asn"] = int(1) + transitGatewayConnectionModel["network_account_id"] = "testString" + transitGatewayConnectionModel["network_type"] = "testString" + transitGatewayConnectionModel["base_network_type"] = "testString" + transitGatewayConnectionModel["zone"] = "testString" + + model := make(map[string]interface{}) + model["id"] = "testString" + model["connections"] = []map[string]interface{}{transitGatewayConnectionModel} + model["status"] = "pending" + model["region"] = "testString" + + assert.Equal(t, result, model) + } + + transitGatewayConnectionModel := new(vmwarev1.TransitGatewayConnection) + transitGatewayConnectionModel.Name = core.StringPtr("testString") + transitGatewayConnectionModel.TransitGatewayConnectionName = core.StringPtr("testString") + transitGatewayConnectionModel.Status = core.StringPtr("pending") + transitGatewayConnectionModel.LocalGatewayIp = core.StringPtr("testString") + transitGatewayConnectionModel.RemoteGatewayIp = core.StringPtr("testString") + transitGatewayConnectionModel.LocalTunnelIp = core.StringPtr("testString") + transitGatewayConnectionModel.RemoteTunnelIp = core.StringPtr("testString") + transitGatewayConnectionModel.LocalBgpAsn = core.Int64Ptr(int64(1)) + transitGatewayConnectionModel.RemoteBgpAsn = core.Int64Ptr(int64(1)) + transitGatewayConnectionModel.NetworkAccountID = core.StringPtr("testString") + transitGatewayConnectionModel.NetworkType = core.StringPtr("testString") + transitGatewayConnectionModel.BaseNetworkType = core.StringPtr("testString") + transitGatewayConnectionModel.Zone = core.StringPtr("testString") + + model := new(vmwarev1.TransitGateway) + model.ID = core.StringPtr("testString") + model.Connections = []vmwarev1.TransitGatewayConnection{*transitGatewayConnectionModel} + model.Status = core.StringPtr("pending") + model.Region = core.StringPtr("testString") + + result, err := vmware.ResourceIbmVmaasVdcTransitGatewayToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIbmVmaasVdcTransitGatewayConnectionToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["name"] = "testString" + model["transit_gateway_connection_name"] = "testString" + model["status"] = "pending" + model["local_gateway_ip"] = "testString" + model["remote_gateway_ip"] = "testString" + model["local_tunnel_ip"] = "testString" + model["remote_tunnel_ip"] = "testString" + model["local_bgp_asn"] = int(1) + model["remote_bgp_asn"] = int(1) + model["network_account_id"] = "testString" + model["network_type"] = "testString" + model["base_network_type"] = "testString" + model["zone"] = "testString" + + assert.Equal(t, result, model) + } + + model := new(vmwarev1.TransitGatewayConnection) + model.Name = core.StringPtr("testString") + model.TransitGatewayConnectionName = core.StringPtr("testString") + model.Status = core.StringPtr("pending") + model.LocalGatewayIp = core.StringPtr("testString") + model.RemoteGatewayIp = core.StringPtr("testString") + model.LocalTunnelIp = core.StringPtr("testString") + model.RemoteTunnelIp = core.StringPtr("testString") + model.LocalBgpAsn = core.Int64Ptr(int64(1)) + model.RemoteBgpAsn = core.Int64Ptr(int64(1)) + model.NetworkAccountID = core.StringPtr("testString") + model.NetworkType = core.StringPtr("testString") + model.BaseNetworkType = core.StringPtr("testString") + model.Zone = core.StringPtr("testString") + + result, err := vmware.ResourceIbmVmaasVdcTransitGatewayConnectionToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIbmVmaasVdcStatusReasonToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["code"] = "insufficent_cpu" + model["message"] = "testString" + model["more_info"] = "testString" + + assert.Equal(t, result, model) + } + + model := new(vmwarev1.StatusReason) + model.Code = core.StringPtr("insufficent_cpu") + model.Message = core.StringPtr("testString") + model.MoreInfo = core.StringPtr("testString") + + result, err := vmware.ResourceIbmVmaasVdcStatusReasonToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIbmVmaasVdcMapToVDCDirectorSitePrototype(t *testing.T) { + checkResult := func(result *vmwarev1.VDCDirectorSitePrototype) { + vdcProviderTypeModel := new(vmwarev1.VDCProviderType) + vdcProviderTypeModel.Name = core.StringPtr("paygo") + + directorSitePvdcModel := new(vmwarev1.DirectorSitePVDC) + directorSitePvdcModel.ID = core.StringPtr("pvdc_id") + directorSitePvdcModel.ProviderType = vdcProviderTypeModel + + model := new(vmwarev1.VDCDirectorSitePrototype) + model.ID = core.StringPtr("site_id") + model.Pvdc = directorSitePvdcModel + + assert.Equal(t, result, model) + } + + vdcProviderTypeModel := make(map[string]interface{}) + vdcProviderTypeModel["name"] = "paygo" + + directorSitePvdcModel := make(map[string]interface{}) + directorSitePvdcModel["id"] = "pvdc_id" + directorSitePvdcModel["provider_type"] = []interface{}{vdcProviderTypeModel} + + model := make(map[string]interface{}) + model["id"] = "site_id" + model["pvdc"] = []interface{}{directorSitePvdcModel} + + result, err := vmware.ResourceIbmVmaasVdcMapToVDCDirectorSitePrototype(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIbmVmaasVdcMapToDirectorSitePVDC(t *testing.T) { + checkResult := func(result *vmwarev1.DirectorSitePVDC) { + vdcProviderTypeModel := new(vmwarev1.VDCProviderType) + vdcProviderTypeModel.Name = core.StringPtr("paygo") + + model := new(vmwarev1.DirectorSitePVDC) + model.ID = core.StringPtr("pvdc_id") + model.ProviderType = vdcProviderTypeModel + + assert.Equal(t, result, model) + } + + vdcProviderTypeModel := make(map[string]interface{}) + vdcProviderTypeModel["name"] = "paygo" + + model := make(map[string]interface{}) + model["id"] = "pvdc_id" + model["provider_type"] = []interface{}{vdcProviderTypeModel} + + result, err := vmware.ResourceIbmVmaasVdcMapToDirectorSitePVDC(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIbmVmaasVdcMapToVDCProviderType(t *testing.T) { + checkResult := func(result *vmwarev1.VDCProviderType) { + model := new(vmwarev1.VDCProviderType) + model.Name = core.StringPtr("paygo") + + assert.Equal(t, result, model) + } + + model := make(map[string]interface{}) + model["name"] = "paygo" + + result, err := vmware.ResourceIbmVmaasVdcMapToVDCProviderType(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIbmVmaasVdcMapToVDCEdgePrototype(t *testing.T) { + checkResult := func(result *vmwarev1.VDCEdgePrototype) { + model := new(vmwarev1.VDCEdgePrototype) + model.Size = core.StringPtr("medium") + model.Type = core.StringPtr("performance") + model.PrivateOnly = core.BoolPtr(true) + + assert.Equal(t, result, model) + } + + model := make(map[string]interface{}) + model["size"] = "medium" + model["type"] = "performance" + model["private_only"] = true + + result, err := vmware.ResourceIbmVmaasVdcMapToVDCEdgePrototype(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIbmVmaasVdcMapToResourceGroupIdentity(t *testing.T) { + checkResult := func(result *vmwarev1.ResourceGroupIdentity) { + model := new(vmwarev1.ResourceGroupIdentity) + model.ID = core.StringPtr("some_resourcegroupid") + + assert.Equal(t, result, model) + } + + model := make(map[string]interface{}) + model["id"] = "some_resourcegroupid" + + result, err := vmware.ResourceIbmVmaasVdcMapToResourceGroupIdentity(model) + assert.Nil(t, err) + checkResult(result) +} diff --git a/website/docs/d/vmaas_vdc.html.markdown b/website/docs/d/vmaas_vdc.html.markdown index 3867afeaf2..46e4d96f96 100644 --- a/website/docs/d/vmaas_vdc.html.markdown +++ b/website/docs/d/vmaas_vdc.html.markdown @@ -3,7 +3,7 @@ layout: "ibm" page_title: "IBM : ibm_vmaas_vdc" description: |- Get information about vmaas_vdc -subcategory: "VMware as a Service API" +subcategory: "VMware Cloud Foundation as a Service API" --- # ibm_vmaas_vdc @@ -35,11 +35,8 @@ After your data source is created, you can read values from the following attrib * `id` - The unique identifier of the vmaas_vdc. * `cpu` - (Integer) The vCPU usage limit on the virtual data center (VDC). Supported for VDCs deployed on a multitenant Cloud Director site. This property is applicable when the resource pool type is reserved. * Constraints: The maximum value is `2000`. The minimum value is `0`. - * `crn` - (String) A unique ID for the virtual data center (VDC) in IBM Cloud. - * `deleted_at` - (String) The time that the virtual data center (VDC) is deleted. - * `director_site` - (List) The Cloud Director site in which to deploy the virtual data center (VDC). Nested schema for **director_site**: * `id` - (String) A unique ID for the Cloud Director site. @@ -52,13 +49,15 @@ Nested schema for **director_site**: * `name` - (String) The name of the resource pool type. * Constraints: Allowable values are: `paygo`, `on_demand`, `reserved`. * `url` - (String) The URL of the VMware Cloud Director tenant portal where this virtual data center (VDC) can be managed. - * `edges` - (List) The VMware NSX-T networking edges deployed on the virtual data center (VDC). NSX-T edges are used for bridging virtualization networking to the physical public-internet and IBM private networking. * Constraints: The maximum length is `128` items. The minimum length is `0` items. Nested schema for **edges**: * `id` - (String) A unique ID for the edge. + * `private_ips` - (List) The private IP addresses assigned to the edge. + * Constraints: The maximum length is `128` items. The minimum length is `0` items. + * `private_only` - (Boolean) Indicates whether the edge is private only. The default value is True for a private Cloud Director site and False for a public Cloud Director site. * `public_ips` - (List) The public IP addresses assigned to the edge. - * Constraints: The maximum length is `256` items. The minimum length is `1` item. + * Constraints: The maximum length is `256` items. The minimum length is `0` items. * `size` - (String) The size of the edge.The size can be specified only for performance edges. Larger sizes require more capacity from the Cloud Director site in which the virtual data center (VDC) was created to be deployed. * Constraints: Allowable values are: `medium`, `large`, `extra_large`. * `status` - (String) Determines the state of the edge. @@ -71,12 +70,14 @@ Nested schema for **edges**: Nested schema for **connections**: * `base_network_type` - (String) The type of the network that the unbound GRE tunnel is targeting. Only "classic" is supported. * `local_bgp_asn` - (Integer) Local network BGP ASN for the connection. + * Constraints: The maximum value is `4294967294`. The minimum value is `1`. * `local_gateway_ip` - (String) Local gateway IP address for the connection. * `local_tunnel_ip` - (String) Local tunnel IP address for the connection. * `name` - (String) The autogenerated name for this connection. * `network_account_id` - (String) The ID of the account that owns the connected network. * `network_type` - (String) The type of the network that is connected through this connection. Only "unbound_gre_tunnel" is supported. * `remote_bgp_asn` - (Integer) Remote network BGP ASN for the connection. + * Constraints: The maximum value is `4294967294`. The minimum value is `1`. * `remote_gateway_ip` - (String) Remote gateway IP address for the connection. * `remote_tunnel_ip` - (String) Remote tunnel IP address for the connection. * `status` - (String) Determines the state of the connection. @@ -84,32 +85,24 @@ Nested schema for **edges**: * `transit_gateway_connection_name` - (String) The user-defined name of the connection created on the IBM Transit Gateway. * `zone` - (String) The location of the connection. * `id` - (String) A unique ID for an IBM Transit Gateway. + * `region` - (String) The region where the IBM Transit Gateway is deployed. * `status` - (String) Determines the state of the IBM Transit Gateway based on its connections. * Constraints: Allowable values are: `pending`, `creating`, `ready_to_use`, `deleting`. * `type` - (String) The type of edge to be deployed.Efficiency edges allow for multiple VDCs to share some edge resources. Performance edges do not share resources between VDCs. * Constraints: Allowable values are: `performance`, `efficiency`. * `version` - (String) The edge version. - * `fast_provisioning_enabled` - (Boolean) Determines whether this virtual data center has fast provisioning enabled or not. - * `href` - (String) The URL of this virtual data center (VDC). - * `name` - (String) A human readable ID for the virtual data center (VDC). - * `ordered_at` - (String) The time that the virtual data center (VDC) is ordered. - +* `org_href` - (String) The URL of the organization that owns the VDC. * `org_name` - (String) The name of the VMware Cloud Director organization that contains this virtual data center (VDC). VMware Cloud Director organizations are used to create strong boundaries between VDCs. There is a complete isolation of user administration, networking, workloads, and VMware Cloud Director catalogs between different Director organizations. - * `provisioned_at` - (String) The time that the virtual data center (VDC) is provisioned and available to use. - * `ram` - (Integer) The RAM usage limit on the virtual data center (VDC) in GB (1024^3 bytes). Supported for VDCs deployed on a multitenant Cloud Director site. This property is applicable when the resource pool type is reserved. * Constraints: The maximum value is `40960`. The minimum value is `0`. - * `rhel_byol` - (Boolean) Indicates if the RHEL VMs will be using the license from IBM or the customer will use their own license (BYOL). - * `status` - (String) Determines the state of the virtual data center. * Constraints: Allowable values are: `creating`, `ready_to_use`, `modifying`, `deleting`, `deleted`, `failed`. - * `status_reasons` - (List) Information about why the request to create the virtual data center (VDC) cannot be completed. * Constraints: The maximum length is `128` items. The minimum length is `0` items. Nested schema for **status_reasons**: @@ -117,9 +110,7 @@ Nested schema for **status_reasons**: * Constraints: Allowable values are: `insufficent_cpu`, `insufficent_ram`, `insufficent_cpu_and_ram`. * `message` - (String) A message that describes why the error ocurred. * `more_info` - (String) A URL that links to a page with more information about this error. - * `type` - (String) Determines whether this virtual data center is in a single-tenant or multitenant Cloud Director site. * Constraints: Allowable values are: `single_tenant`, `multitenant`. - * `windows_byol` - (Boolean) Indicates if the Microsoft Windows VMs will be using the license from IBM or the customer will use their own license (BYOL). diff --git a/website/docs/r/vmaas_vdc.html.markdown b/website/docs/r/vmaas_vdc.html.markdown index fb8102064f..6b19553388 100644 --- a/website/docs/r/vmaas_vdc.html.markdown +++ b/website/docs/r/vmaas_vdc.html.markdown @@ -3,7 +3,7 @@ layout: "ibm" page_title: "IBM : ibm_vmaas_vdc" description: |- Manages vmaas_vdc. -subcategory: "VMware as a Service API" +subcategory: "VMware Cloud Foundation as a Service API" --- # ibm_vmaas_vdc @@ -67,8 +67,11 @@ After your resource is created, you can read values from the listed arguments an * Constraints: The maximum length is `128` items. The minimum length is `0` items. Nested schema for **edges**: * `id` - (String) A unique ID for the edge. + * `private_ips` - (List) The private IP addresses assigned to the edge. + * Constraints: The maximum length is `128` items. The minimum length is `0` items. + * `private_only` - (Boolean) Indicates whether the edge is private only. The default value is True for a private Cloud Director site and False for a public Cloud Director site. * `public_ips` - (List) The public IP addresses assigned to the edge. - * Constraints: The maximum length is `256` items. The minimum length is `1` item. + * Constraints: The maximum length is `256` items. The minimum length is `0` items. * `size` - (String) The size of the edge.The size can be specified only for performance edges. Larger sizes require more capacity from the Cloud Director site in which the virtual data center (VDC) was created to be deployed. * Constraints: Allowable values are: `medium`, `large`, `extra_large`. * `status` - (String) Determines the state of the edge. @@ -81,12 +84,14 @@ Nested schema for **edges**: Nested schema for **connections**: * `base_network_type` - (String) The type of the network that the unbound GRE tunnel is targeting. Only "classic" is supported. * `local_bgp_asn` - (Integer) Local network BGP ASN for the connection. + * Constraints: The maximum value is `4294967294`. The minimum value is `1`. * `local_gateway_ip` - (String) Local gateway IP address for the connection. * `local_tunnel_ip` - (String) Local tunnel IP address for the connection. * `name` - (String) The autogenerated name for this connection. * `network_account_id` - (String) The ID of the account that owns the connected network. * `network_type` - (String) The type of the network that is connected through this connection. Only "unbound_gre_tunnel" is supported. * `remote_bgp_asn` - (Integer) Remote network BGP ASN for the connection. + * Constraints: The maximum value is `4294967294`. The minimum value is `1`. * `remote_gateway_ip` - (String) Remote gateway IP address for the connection. * `remote_tunnel_ip` - (String) Remote tunnel IP address for the connection. * `status` - (String) Determines the state of the connection. @@ -94,6 +99,7 @@ Nested schema for **edges**: * `transit_gateway_connection_name` - (String) The user-defined name of the connection created on the IBM Transit Gateway. * `zone` - (String) The location of the connection. * `id` - (String) A unique ID for an IBM Transit Gateway. + * `region` - (String) The region where the IBM Transit Gateway is deployed. * `status` - (String) Determines the state of the IBM Transit Gateway based on its connections. * Constraints: Allowable values are: `pending`, `creating`, `ready_to_use`, `deleting`. * `type` - (String) The type of edge to be deployed.Efficiency edges allow for multiple VDCs to share some edge resources. Performance edges do not share resources between VDCs. @@ -101,6 +107,7 @@ Nested schema for **edges**: * `version` - (String) The edge version. * `href` - (String) The URL of this virtual data center (VDC). * `ordered_at` - (String) The time that the virtual data center (VDC) is ordered. +* `org_href` - (String) The URL of the organization that owns the VDC. * `org_name` - (String) The name of the VMware Cloud Director organization that contains this virtual data center (VDC). VMware Cloud Director organizations are used to create strong boundaries between VDCs. There is a complete isolation of user administration, networking, workloads, and VMware Cloud Director catalogs between different Director organizations. * `provisioned_at` - (String) The time that the virtual data center (VDC) is provisioned and available to use. * `status` - (String) Determines the state of the virtual data center. From 5d4ec125774ee95a703bf4e46a15eb2e5fe47c93 Mon Sep 17 00:00:00 2001 From: Sanket Phansekar Date: Thu, 16 Jan 2025 21:55:25 +0530 Subject: [PATCH 2/8] fix: update go.mod file with latest vmware-go-sdk --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 12921f5e7b..3340f30fc6 100644 --- a/go.mod +++ b/go.mod @@ -41,7 +41,7 @@ require ( github.com/IBM/schematics-go-sdk v0.3.0 github.com/IBM/sds-go-sdk v0.0.4 github.com/IBM/secrets-manager-go-sdk/v2 v2.0.7 - github.com/IBM/vmware-go-sdk v0.1.2 + github.com/IBM/vmware-go-sdk v0.1.3 github.com/IBM/vpc-beta-go-sdk v0.8.0 github.com/IBM/vpc-go-sdk v0.64.0 github.com/ScaleFT/sshkeys v0.0.0-20200327173127-6142f742bca5 diff --git a/go.sum b/go.sum index 74dacf8d07..fd306356a3 100644 --- a/go.sum +++ b/go.sum @@ -174,6 +174,8 @@ github.com/IBM/secrets-manager-go-sdk/v2 v2.0.7 h1:5lKt1rHuKaAaiZtbPfsF8dgiko/gG github.com/IBM/secrets-manager-go-sdk/v2 v2.0.7/go.mod h1:RglK3v6CPe3T1myRtQCD6z+nBygXvNJwufAon0qcZok= github.com/IBM/vmware-go-sdk v0.1.2 h1:5lKWFyInWz9e2hwGsoFTEoLa1jYkD30SReN0fQ10w9M= github.com/IBM/vmware-go-sdk v0.1.2/go.mod h1:2UGPBJju3jiv5VKKBBm9a5L6bzF/aJdKOKAzJ7HaOjA= +github.com/IBM/vmware-go-sdk v0.1.3 h1:uJL3kwzM0jAKsT6Gj9tE5xT9SZBVXVaJvZdxrSMx8b8= +github.com/IBM/vmware-go-sdk v0.1.3/go.mod h1:OyQKRInGGsBaOyE5LIZCqH7b1DZ01BvIYa8BgGy+wWo= github.com/IBM/vpc-beta-go-sdk v0.8.0 h1:cEPpv4iw3Ba5W2d0AWg3TIbKeJ8y1nPuUuibR5Jt9eE= github.com/IBM/vpc-beta-go-sdk v0.8.0/go.mod h1:hORgIyTFRzXrZIK9IohaWmCRBBlYiDRagsufi7M6akE= github.com/IBM/vpc-go-sdk v0.64.0 h1:0x2jakapXxXYTTr0EdrwuXa6h0couSK+FTDGxd8jChA= From fb223c89c6a62d9922e1759147727c70b63cbbcb Mon Sep 17 00:00:00 2001 From: Sanket Phansekar Date: Fri, 17 Jan 2025 10:36:17 +0530 Subject: [PATCH 3/8] fix: add config and refactor --- ibm/conns/config.go | 41 ++++++++++--------- .../vmware/data_source_ibm_vmaas_vdc.go | 2 +- .../vmware/data_source_ibm_vmaas_vdc_test.go | 2 +- .../vmware/resource_ibm_vmaas_vdc_test.go | 2 +- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/ibm/conns/config.go b/ibm/conns/config.go index ef09b51336..635c5800df 100644 --- a/ibm/conns/config.go +++ b/ibm/conns/config.go @@ -668,7 +668,7 @@ type clientSession struct { mqcloudClient *mqcloudv1.MqcloudV1 mqcloudClientErr error - // VMware as a Service + // VMware Cloud Foundation as a Service vmwareClient *vmwarev1.VmwareV1 vmwareClientErr error @@ -3560,25 +3560,28 @@ func (c *Config) ClientSession() (interface{}, error) { session.mqcloudClientErr = fmt.Errorf("Error occurred while configuringMQaaS service: %q", err) } - // VMware as a Service - // Construct the service options. - vmwareURL := ContructEndpoint(fmt.Sprintf("api.%s.vmware", c.Region), cloudEndpoint+"/v1") - vmwareClientOptions := &vmwarev1.VmwareV1Options{ - Authenticator: authenticator, - URL: EnvFallBack([]string{"VMWARE_URL"}, vmwareURL), - } + // VMware Cloud Foundation as a Service + // Construct an instance of the 'VMware Cloud Foundation as a Service API' service. + if session.vmwareClientErr == nil { + // Construct the service options. + vmwareURL := ContructEndpoint(fmt.Sprintf("api.%s.vmware", c.Region), cloudEndpoint+"/v1") + vmwareClientOptions := &vmwarev1.VmwareV1Options{ + Authenticator: authenticator, + URL: EnvFallBack([]string{"VMWARE_URL"}, vmwareURL), + } - // Construct the service client. - session.vmwareClient, err = vmwarev1.NewVmwareV1(vmwareClientOptions) - if err == nil { - // Enable retries for API calls - session.vmwareClient.Service.EnableRetries(c.RetryCount, c.RetryDelay) - // Add custom header for analytics - session.vmwareClient.SetDefaultHeaders(gohttp.Header{ - "X-Original-User-Agent": {fmt.Sprintf("terraform-provider-ibm/%s", version.Version)}, - }) - } else { - session.vmwareClientErr = fmt.Errorf("Error occurred while configuring VMware as a Service API service: %q", err) + // Construct the service client. + session.vmwareClient, err = vmwarev1.NewVmwareV1(vmwareClientOptions) + if err == nil { + // Enable retries for API calls + session.vmwareClient.Service.EnableRetries(c.RetryCount, c.RetryDelay) + // Add custom header for analytics + session.vmwareClient.SetDefaultHeaders(gohttp.Header{ + "X-Original-User-Agent": {fmt.Sprintf("terraform-provider-ibm/%s", version.Version)}, + }) + } else { + session.vmwareClientErr = fmt.Errorf("Error occurred while constructing 'VMware Cloud Foundation as a Service API' service client: %q", err) + } } // Construct the service options. diff --git a/ibm/service/vmware/data_source_ibm_vmaas_vdc.go b/ibm/service/vmware/data_source_ibm_vmaas_vdc.go index 004a0db013..58e0b185f6 100644 --- a/ibm/service/vmware/data_source_ibm_vmaas_vdc.go +++ b/ibm/service/vmware/data_source_ibm_vmaas_vdc.go @@ -3,7 +3,7 @@ /* * IBM OpenAPI Terraform Generator Version: 3.98.0-8be2046a-20241205-162752 -*/ + */ package vmware diff --git a/ibm/service/vmware/data_source_ibm_vmaas_vdc_test.go b/ibm/service/vmware/data_source_ibm_vmaas_vdc_test.go index 5b44df1f47..9536d328c8 100644 --- a/ibm/service/vmware/data_source_ibm_vmaas_vdc_test.go +++ b/ibm/service/vmware/data_source_ibm_vmaas_vdc_test.go @@ -14,7 +14,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/terraform-provider-ibm/ibm/service/vmware" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/vmware" acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" "github.com/IBM/go-sdk-core/v5/core" diff --git a/ibm/service/vmware/resource_ibm_vmaas_vdc_test.go b/ibm/service/vmware/resource_ibm_vmaas_vdc_test.go index ad8ccc3be2..d75d2004f2 100644 --- a/ibm/service/vmware/resource_ibm_vmaas_vdc_test.go +++ b/ibm/service/vmware/resource_ibm_vmaas_vdc_test.go @@ -11,7 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - "github.com/terraform-provider-ibm/ibm/service/vmware" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/vmware" acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" From f3bc0328b7bfd4b9adeead73538676aea8184617 Mon Sep 17 00:00:00 2001 From: Sanket Phansekar Date: Mon, 20 Jan 2025 17:03:21 +0530 Subject: [PATCH 4/8] refactor: fix go.mod file --- go.sum | 2 -- 1 file changed, 2 deletions(-) diff --git a/go.sum b/go.sum index fd306356a3..9a17c61532 100644 --- a/go.sum +++ b/go.sum @@ -172,8 +172,6 @@ github.com/IBM/sds-go-sdk v0.0.4 h1:zkkqDzc+TgFYU/BK4Oknv8cMBXJ08WKUu7yKCyzslvE= github.com/IBM/sds-go-sdk v0.0.4/go.mod h1:HcqZfsgKMqfFxbU1RcRfF934ls+vQY97oXPGPSoIWPg= github.com/IBM/secrets-manager-go-sdk/v2 v2.0.7 h1:5lKt1rHuKaAaiZtbPfsF8dgiko/gGbVgreiut3zU128= github.com/IBM/secrets-manager-go-sdk/v2 v2.0.7/go.mod h1:RglK3v6CPe3T1myRtQCD6z+nBygXvNJwufAon0qcZok= -github.com/IBM/vmware-go-sdk v0.1.2 h1:5lKWFyInWz9e2hwGsoFTEoLa1jYkD30SReN0fQ10w9M= -github.com/IBM/vmware-go-sdk v0.1.2/go.mod h1:2UGPBJju3jiv5VKKBBm9a5L6bzF/aJdKOKAzJ7HaOjA= github.com/IBM/vmware-go-sdk v0.1.3 h1:uJL3kwzM0jAKsT6Gj9tE5xT9SZBVXVaJvZdxrSMx8b8= github.com/IBM/vmware-go-sdk v0.1.3/go.mod h1:OyQKRInGGsBaOyE5LIZCqH7b1DZ01BvIYa8BgGy+wWo= github.com/IBM/vpc-beta-go-sdk v0.8.0 h1:cEPpv4iw3Ba5W2d0AWg3TIbKeJ8y1nPuUuibR5Jt9eE= From 8513f58f526c28b6623a67777040de0cf4f991eb Mon Sep 17 00:00:00 2001 From: Sanket Phansekar Date: Fri, 24 Jan 2025 10:31:15 +0530 Subject: [PATCH 5/8] docs: shorten service name --- website/docs/d/vmaas_vdc.html.markdown | 2 +- website/docs/r/vmaas_vdc.html.markdown | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/website/docs/d/vmaas_vdc.html.markdown b/website/docs/d/vmaas_vdc.html.markdown index 46e4d96f96..f55e4a39b9 100644 --- a/website/docs/d/vmaas_vdc.html.markdown +++ b/website/docs/d/vmaas_vdc.html.markdown @@ -3,7 +3,7 @@ layout: "ibm" page_title: "IBM : ibm_vmaas_vdc" description: |- Get information about vmaas_vdc -subcategory: "VMware Cloud Foundation as a Service API" +subcategory: "VCF as a Service API" --- # ibm_vmaas_vdc diff --git a/website/docs/r/vmaas_vdc.html.markdown b/website/docs/r/vmaas_vdc.html.markdown index 6b19553388..4f02a486c6 100644 --- a/website/docs/r/vmaas_vdc.html.markdown +++ b/website/docs/r/vmaas_vdc.html.markdown @@ -3,7 +3,7 @@ layout: "ibm" page_title: "IBM : ibm_vmaas_vdc" description: |- Manages vmaas_vdc. -subcategory: "VMware Cloud Foundation as a Service API" +subcategory: "VCF as a Service API" --- # ibm_vmaas_vdc From a8721690f2ee5ba9002773545376510a4373e264 Mon Sep 17 00:00:00 2001 From: Sanket Phansekar Date: Fri, 24 Jan 2025 10:31:41 +0530 Subject: [PATCH 6/8] refactor: update variable name with prefix IBMCLOUD --- ibm/conns/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ibm/conns/config.go b/ibm/conns/config.go index 635c5800df..7bd053fd7e 100644 --- a/ibm/conns/config.go +++ b/ibm/conns/config.go @@ -3567,7 +3567,7 @@ func (c *Config) ClientSession() (interface{}, error) { vmwareURL := ContructEndpoint(fmt.Sprintf("api.%s.vmware", c.Region), cloudEndpoint+"/v1") vmwareClientOptions := &vmwarev1.VmwareV1Options{ Authenticator: authenticator, - URL: EnvFallBack([]string{"VMWARE_URL"}, vmwareURL), + URL: EnvFallBack([]string{"IBMCLOUD_VMWARE_URL"}, vmwareURL), } // Construct the service client. From cd4f27195de737e980155f6a2b1254e1628edd0f Mon Sep 17 00:00:00 2001 From: Sanket Phansekar Date: Fri, 24 Jan 2025 10:32:07 +0530 Subject: [PATCH 7/8] refactor: remove optional for computed property --- ibm/service/vmware/resource_ibm_vmaas_vdc.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/ibm/service/vmware/resource_ibm_vmaas_vdc.go b/ibm/service/vmware/resource_ibm_vmaas_vdc.go index e4a404f92a..f3e969a99c 100644 --- a/ibm/service/vmware/resource_ibm_vmaas_vdc.go +++ b/ibm/service/vmware/resource_ibm_vmaas_vdc.go @@ -169,7 +169,6 @@ func ResourceIbmVmaasVdc() *schema.Resource { }, "private_only": &schema.Schema{ Type: schema.TypeBool, - Optional: true, Computed: true, Description: "Indicates whether the edge is private only. The default value is True for a private Cloud Director site and False for a public Cloud Director site.", }, @@ -207,7 +206,6 @@ func ResourceIbmVmaasVdc() *schema.Resource { }, "transit_gateway_connection_name": &schema.Schema{ Type: schema.TypeString, - Optional: true, Computed: true, Description: "The user-defined name of the connection created on the IBM Transit Gateway.", }, @@ -218,37 +216,31 @@ func ResourceIbmVmaasVdc() *schema.Resource { }, "local_gateway_ip": &schema.Schema{ Type: schema.TypeString, - Optional: true, Computed: true, Description: "Local gateway IP address for the connection.", }, "remote_gateway_ip": &schema.Schema{ Type: schema.TypeString, - Optional: true, Computed: true, Description: "Remote gateway IP address for the connection.", }, "local_tunnel_ip": &schema.Schema{ Type: schema.TypeString, - Optional: true, Computed: true, Description: "Local tunnel IP address for the connection.", }, "remote_tunnel_ip": &schema.Schema{ Type: schema.TypeString, - Optional: true, Computed: true, Description: "Remote tunnel IP address for the connection.", }, "local_bgp_asn": &schema.Schema{ Type: schema.TypeInt, - Optional: true, Computed: true, Description: "Local network BGP ASN for the connection.", }, "remote_bgp_asn": &schema.Schema{ Type: schema.TypeInt, - Optional: true, Computed: true, Description: "Remote network BGP ASN for the connection.", }, @@ -319,7 +311,6 @@ func ResourceIbmVmaasVdc() *schema.Resource { }, "more_info": &schema.Schema{ Type: schema.TypeString, - Optional: true, Computed: true, Description: "A URL that links to a page with more information about this error.", }, From 3cd39ea368ba53bed5086ddce8fbbfe96cb232ee Mon Sep 17 00:00:00 2001 From: Sanket Phansekar Date: Fri, 24 Jan 2025 21:55:01 +0530 Subject: [PATCH 8/8] feat: add to subcategory list --- website/allowed-subcategories.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/website/allowed-subcategories.txt b/website/allowed-subcategories.txt index b6fcbeee6d..80989ea231 100644 --- a/website/allowed-subcategories.txt +++ b/website/allowed-subcategories.txt @@ -45,4 +45,5 @@ Secrets Manager Security and Compliance Center Transit Gateway Usage Reports +VCF as a Service VPC infrastructure