From 5ac1cf6d4de3f95df18953cd6c817215d9251914 Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Tue, 28 Jan 2025 20:43:13 -0500 Subject: [PATCH] refactor: move to `hcx` package Moves all resources and data sources from the `main` package to the `hcx` package. Signed-off-by: Ryan Johnson --- .../data_source_compute_profile.go | 9 ++- .../data_source_network_backing.go | 7 +-- provider.go => hcx/provider.go | 7 +-- .../resource_activation.go | 21 +++---- .../resource_compute_profile.go | 63 +++++++++---------- .../resource_l2_extension.go | 33 +++++----- .../resource_location.go | 19 +++--- .../resource_network_profile.go | 51 ++++++++------- .../resource_rolemapping.go | 15 +++-- .../resource_service_mesh.go | 37 ++++++----- .../resource_site_pairing.go | 41 ++++++------ resource_sso.go => hcx/resource_sso.go | 33 +++++----- .../resource_vcenter.go | 27 ++++---- resource_vmc.go => hcx/resource_vmc.go | 53 ++++++++-------- main.go | 19 +++++- 15 files changed, 217 insertions(+), 218 deletions(-) rename data_source_compute_profile.go => hcx/data_source_compute_profile.go (85%) rename data_source_network_backing.go => hcx/data_source_network_backing.go (91%) rename provider.go => hcx/provider.go (93%) rename resource_activation.go => hcx/resource_activation.go (87%) rename resource_compute_profile.go => hcx/resource_compute_profile.go (86%) rename resource_l2_extension.go => hcx/resource_l2_extension.go (88%) rename resource_location.go => hcx/resource_location.go (91%) rename resource_network_profile.go => hcx/resource_network_profile.go (88%) rename resource_rolemapping.go => hcx/resource_rolemapping.go (93%) rename resource_service_mesh.go => hcx/resource_service_mesh.go (87%) rename resource_site_pairing.go => hcx/resource_site_pairing.go (87%) rename resource_sso.go => hcx/resource_sso.go (81%) rename resource_vcenter.go => hcx/resource_vcenter.go (85%) rename resource_vmc.go => hcx/resource_vmc.go (83%) diff --git a/data_source_compute_profile.go b/hcx/data_source_compute_profile.go similarity index 85% rename from data_source_compute_profile.go rename to hcx/data_source_compute_profile.go index 3073541..70b09f9 100644 --- a/data_source_compute_profile.go +++ b/hcx/data_source_compute_profile.go @@ -2,14 +2,13 @@ // The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. // SPDX-License-Identifier: MPL-2.0 -package main +package hcx import ( "context" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/vmware/terraform-provider-hcx/hcx" ) // dataSourceComputeProfile defines the data source schema to retrieve information about a compute profile. @@ -36,16 +35,16 @@ func dataSourceComputeProfile() *schema.Resource { func dataSourceComputeProfileRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { var diags diag.Diagnostics - client := m.(*hcx.Client) + client := m.(*Client) - res, err := hcx.GetLocalCloudList(client) + res, err := GetLocalCloudList(client) if err != nil { return diag.FromErr(err) } network := d.Get("name").(string) - cp, err := hcx.GetComputeProfile(client, res.Data.Items[0].EndpointID, network) + cp, err := GetComputeProfile(client, res.Data.Items[0].EndpointID, network) if err != nil { return diag.FromErr(err) diff --git a/data_source_network_backing.go b/hcx/data_source_network_backing.go similarity index 91% rename from data_source_network_backing.go rename to hcx/data_source_network_backing.go index dcda30d..af3ce10 100644 --- a/data_source_network_backing.go +++ b/hcx/data_source_network_backing.go @@ -2,14 +2,13 @@ // The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. // SPDX-License-Identifier: MPL-2.0 -package main +package hcx import ( "context" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/vmware/terraform-provider-hcx/hcx" ) // dataSourceNetworkBacking defines a data source schema to retrieve information about a network backing. @@ -47,13 +46,13 @@ func dataSourceNetworkBacking() *schema.Resource { func dataSourceNetworkBackingRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { var diags diag.Diagnostics - client := m.(*hcx.Client) + client := m.(*Client) network := d.Get("name").(string) vcUUID := d.Get("vcuuid").(string) networkType := d.Get("network_type").(string) - res, err := hcx.GetNetworkBacking(client, vcUUID, network, networkType) + res, err := GetNetworkBacking(client, vcUUID, network, networkType) if err != nil { return diag.FromErr(err) diff --git a/provider.go b/hcx/provider.go similarity index 93% rename from provider.go rename to hcx/provider.go index af42ac6..411222f 100644 --- a/provider.go +++ b/hcx/provider.go @@ -2,7 +2,7 @@ // The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. // SPDX-License-Identifier: MPL-2.0 -package main +package hcx import ( "context" @@ -10,10 +10,9 @@ import ( "github.com/hashicorp/go-cty/cty" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - hcx "github.com/vmware/terraform-provider-hcx/hcx" ) -// Provider - +// Provider returns the schema.Provider object configured with resources, data sources, and schema for the HCX provider. func Provider() *schema.Provider { return &schema.Provider{ Schema: map[string]*schema.Schema{ @@ -95,7 +94,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{} allowUnverifiedSSL := d.Get("allow_unverified_ssl").(bool) vmcToken := d.Get("vmc_token").(string) - c, err := hcx.NewClient(&hcxURL, &username, &password, &adminUsername, &adminPassword, &allowUnverifiedSSL, &vmcToken) + c, err := NewClient(&hcxURL, &username, &password, &adminUsername, &adminPassword, &allowUnverifiedSSL, &vmcToken) if err != nil { return nil, diag.FromErr(err) diff --git a/resource_activation.go b/hcx/resource_activation.go similarity index 87% rename from resource_activation.go rename to hcx/resource_activation.go index 6c0a9eb..dc6cd47 100644 --- a/resource_activation.go +++ b/hcx/resource_activation.go @@ -2,14 +2,13 @@ // The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. // SPDX-License-Identifier: MPL-2.0 -package main +package hcx import ( "context" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/vmware/terraform-provider-hcx/hcx" ) // resourceActivation defines the resource schema for managing activation configurations. @@ -39,16 +38,16 @@ func resourceActivation() *schema.Resource { // resourceActivationCreate creates the activation configuration resource. func resourceActivationCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - client := m.(*hcx.Client) + client := m.(*Client) url := d.Get("url").(string) activationkey := d.Get("activationkey").(string) - body := hcx.ActivateBody{ - Data: hcx.ActivateData{ - Items: []hcx.ActivateDataItem{ + body := ActivateBody{ + Data: ActivateData{ + Items: []ActivateDataItem{ { - Config: hcx.ActivateDataItemConfig{ + Config: ActivateDataItemConfig{ URL: url, ActivationKey: activationkey, }, @@ -58,14 +57,14 @@ func resourceActivationCreate(ctx context.Context, d *schema.ResourceData, m int } // First, check if already activated - res, err := hcx.GetActivate(client) + res, err := GetActivate(client) if err != nil { return diag.FromErr(err) } if len(res.Data.Items) == 0 { // No activation config found - _, err := hcx.PostActivate(client, body) + _, err := PostActivate(client, body) if err != nil { return diag.FromErr(err) @@ -83,9 +82,9 @@ func resourceActivationCreate(ctx context.Context, d *schema.ResourceData, m int func resourceActivationRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { var diags diag.Diagnostics - client := m.(*hcx.Client) + client := m.(*Client) - res, err := hcx.GetActivate(client) + res, err := GetActivate(client) if err != nil { return diag.FromErr(err) } diff --git a/resource_compute_profile.go b/hcx/resource_compute_profile.go similarity index 86% rename from resource_compute_profile.go rename to hcx/resource_compute_profile.go index 324f849..343f605 100644 --- a/resource_compute_profile.go +++ b/hcx/resource_compute_profile.go @@ -2,7 +2,7 @@ // The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. // SPDX-License-Identifier: MPL-2.0 -package main +package hcx import ( "bytes" @@ -13,7 +13,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/vmware/terraform-provider-hcx/hcx" ) // resourceComputeProfile defines the resource schema for managing compute profile configuration. @@ -94,12 +93,12 @@ func resourceComputeProfile() *schema.Resource { // resourceComputeProfileCreate creates the compute profile configuration. func resourceComputeProfileCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - client := m.(*hcx.Client) + client := m.(*Client) name := d.Get("name").(string) cluster := d.Get("cluster").(string) - res, err := hcx.GetVcInventory(client) + res, err := GetVcInventory(client) if err != nil { return diag.FromErr(err) } @@ -121,26 +120,26 @@ func resourceComputeProfileCreate(ctx context.Context, d *schema.ResourceData, m // Get Datastore info datastore := d.Get("datastore").(string) - datastoreFromAPI, err := hcx.GetVcDatastore(client, datastore, res.EntityID, clusterID) + datastoreFromAPI, err := GetVcDatastore(client, datastore, res.EntityID, clusterID) if err != nil { return diag.FromErr(err) } // Get DVS info dvs := d.Get("dvs").(string) - dvsFromAPI, err := hcx.GetVcDvs(client, dvs, res.EntityID, clusterID) + dvsFromAPI, err := GetVcDvs(client, dvs, res.EntityID, clusterID) if err != nil { return diag.FromErr(err) } // Get Services from schema services := d.Get("service").([]interface{}) - servicesFromSchema := []hcx.Service{} + servicesFromSchema := []Service{} for _, j := range services { s := j.(map[string]interface{}) name := s["name"].(string) - sTmp := hcx.Service{ + sTmp := Service{ Name: name, } servicesFromSchema = append(servicesFromSchema, sTmp) @@ -152,40 +151,40 @@ func resourceComputeProfileCreate(ctx context.Context, d *schema.ResourceData, m uplinkNetwork := d.Get("uplink_network").(string) vmotionNetwork := d.Get("vmotion_network").(string) - networksList := []hcx.Network{} - np, err := hcx.GetNetworkProfileByID(client, managementNetwork) + networksList := []Network{} + np, err := GetNetworkProfileByID(client, managementNetwork) if err != nil { return diag.FromErr(err) } managementNetworkName := np.Name managementNetworkID := np.ObjectID - np, err = hcx.GetNetworkProfileByID(client, replicationNetwork) + np, err = GetNetworkProfileByID(client, replicationNetwork) if err != nil { return diag.FromErr(err) } replicationNetworkName := np.Name replicationNetworkID := np.ObjectID - np, err = hcx.GetNetworkProfileByID(client, uplinkNetwork) + np, err = GetNetworkProfileByID(client, uplinkNetwork) if err != nil { return diag.FromErr(err) } uplinkNetworkName := np.Name uplinkNetworkID := np.ObjectID - np, err = hcx.GetNetworkProfileByID(client, vmotionNetwork) + np, err = GetNetworkProfileByID(client, vmotionNetwork) if err != nil { return diag.FromErr(err) } vmotionNetworkName := np.Name vmotionNetworkID := np.ObjectID - netTmp := hcx.Network{ + netTmp := Network{ Name: managementNetworkName, ID: managementNetworkID, Tags: []string{"management"}, - Status: hcx.Status{ + Status: Status{ State: "REALIZED", }, } @@ -203,11 +202,11 @@ func resourceComputeProfileCreate(ctx context.Context, d *schema.ResourceData, m if found { networksList[index].Tags = append(networksList[index].Tags, "replication") } else { - netTmp := hcx.Network{ + netTmp := Network{ Name: replicationNetworkName, ID: replicationNetworkID, Tags: []string{"replication"}, - Status: hcx.Status{ + Status: Status{ State: "REALIZED", }, } @@ -226,11 +225,11 @@ func resourceComputeProfileCreate(ctx context.Context, d *schema.ResourceData, m if found { networksList[index].Tags = append(networksList[index].Tags, "uplink") } else { - netTmp := hcx.Network{ + netTmp := Network{ Name: uplinkNetworkName, ID: uplinkNetworkID, Tags: []string{"uplink"}, - Status: hcx.Status{ + Status: Status{ State: "REALIZED", }, } @@ -249,21 +248,21 @@ func resourceComputeProfileCreate(ctx context.Context, d *schema.ResourceData, m if found { networksList[index].Tags = append(networksList[index].Tags, "vmotion") } else { - netTmp := hcx.Network{ + netTmp := Network{ Name: vmotionNetworkName, ID: vmotionNetworkID, Tags: []string{"vmotion"}, - Status: hcx.Status{ + Status: Status{ State: "REALIZED", }, } networksList = append(networksList, netTmp) } - body := hcx.InsertComputeProfileBody{ + body := InsertComputeProfileBody{ Name: name, Services: servicesFromSchema, - Computes: []hcx.Compute{{ + Computes: []Compute{{ ComputeID: res.EntityID, ComputeType: "VC", ComputeName: res.Name, @@ -271,8 +270,8 @@ func resourceComputeProfileCreate(ctx context.Context, d *schema.ResourceData, m Name: res.Children[0].Name, Type: res.Children[0].EntityType, }}, - DeploymentContainers: hcx.DeploymentContainer{ - Computes: []hcx.Compute{{ + DeploymentContainers: DeploymentContainer{ + Computes: []Compute{{ ComputeID: res.EntityID, ComputeType: "VC", ComputeName: res.Name, @@ -281,7 +280,7 @@ func resourceComputeProfileCreate(ctx context.Context, d *schema.ResourceData, m Type: "ClusterComputeResource", }, }, - Storage: []hcx.Storage{{ + Storage: []Storage{{ ComputeID: res.EntityID, ComputeType: "VC", ComputeName: res.Name, @@ -291,7 +290,7 @@ func resourceComputeProfileCreate(ctx context.Context, d *schema.ResourceData, m }}, }, Networks: networksList, - Switches: []hcx.Switch{{ + Switches: []Switch{{ ComputeID: res.EntityID, MaxMTU: dvsFromAPI.MaxMTU, ID: dvsFromAPI.ID, @@ -305,14 +304,14 @@ func resourceComputeProfileCreate(ctx context.Context, d *schema.ResourceData, m return diag.FromErr(err) } - res2, err := hcx.InsertComputeProfile(client, body) + res2, err := InsertComputeProfile(client, body) if err != nil { return diag.FromErr(err) } // Wait for task completion for { - jr, err := hcx.GetTaskResult(client, res2.Data.InterconnectTaskID) + jr, err := GetTaskResult(client, res2.Data.InterconnectTaskID) if err != nil { return diag.FromErr(err) } @@ -352,16 +351,16 @@ func resourceComputeProfileUpdate(ctx context.Context, d *schema.ResourceData, m func resourceComputeProfileDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { var diags diag.Diagnostics - client := m.(*hcx.Client) + client := m.(*Client) - res, err := hcx.DeleteComputeProfile(client, d.Id()) + res, err := DeleteComputeProfile(client, d.Id()) if err != nil { return diag.FromErr(err) } // Wait for task completion for { - jr, err := hcx.GetTaskResult(client, res.Data.InterconnectTaskID) + jr, err := GetTaskResult(client, res.Data.InterconnectTaskID) if err != nil { return diag.FromErr(err) } diff --git a/resource_l2_extension.go b/hcx/resource_l2_extension.go similarity index 88% rename from resource_l2_extension.go rename to hcx/resource_l2_extension.go index 161d8d4..e3dfe14 100644 --- a/resource_l2_extension.go +++ b/hcx/resource_l2_extension.go @@ -2,7 +2,7 @@ // The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. // SPDX-License-Identifier: MPL-2.0 -package main +package hcx import ( "bytes" @@ -12,7 +12,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/vmware/terraform-provider-hcx/hcx" ) // resourceL2Extension defines the resource schema for managing an L2 extension, enabling extended network configurations. @@ -87,7 +86,7 @@ func resourceL2Extension() *schema.Resource { // resourceComputeProfileCreate creates the L2 extension configuration on the specified service. func resourceL2ExtensionCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - client := m.(*hcx.Client) + client := m.(*Client) sitePairing := d.Get("site_pairing").(map[string]interface{}) vcGUID := sitePairing["local_vc"].(string) @@ -113,7 +112,7 @@ func resourceL2ExtensionCreate(ctx context.Context, d *schema.ResourceData, m in serviceMeshID := d.Get("service_mesh_id").(string) - dvpg, err := hcx.GetNetworkBacking(client, sitePairing["local_endpoint_id"].(string), sourceNetwork, networkType) + dvpg, err := GetNetworkBacking(client, sitePairing["local_endpoint_id"].(string), sourceNetwork, networkType) if err != nil { return diag.FromErr(err) } @@ -121,34 +120,34 @@ func resourceL2ExtensionCreate(ctx context.Context, d *schema.ResourceData, m in applianceID := d.Get("appliance_id").(string) if applianceID == "" { // GET THE FIRST APPLIANCE - appliance, err := hcx.GetAppliance(client, sitePairing["local_endpoint_id"].(string), serviceMeshID) + appliance, err := GetAppliance(client, sitePairing["local_endpoint_id"].(string), serviceMeshID) if err != nil { return diag.FromErr(err) } applianceID = appliance.ApplianceID } - body := hcx.InsertL2ExtensionBody{ + body := InsertL2ExtensionBody{ Gateway: gateway, Netmask: netmask, - DestinationNetwork: hcx.DestinationNetwork{ + DestinationNetwork: DestinationNetwork{ GatewayID: destinationT1, }, DNS: []string{}, - Features: hcx.Features{ + Features: Features{ EgressOptimization: egressOptimization, Mon: mon, }, - SourceAppliance: hcx.SourceAppliance{ + SourceAppliance: SourceAppliance{ ApplianceID: applianceID, }, - SourceNetwork: hcx.SourceNetwork{ + SourceNetwork: SourceNetwork{ NetworkID: dvpg.EntityID, NetworkName: dvpg.Name, NetworkType: dvpg.EntityType, }, VcGUID: vcGUID, - Destination: hcx.Destination{ + Destination: Destination{ EndpointID: destinationEndpointID, EndpointName: destinationEndpointName, EndpointType: destinationEndpointType, @@ -163,7 +162,7 @@ func resourceL2ExtensionCreate(ctx context.Context, d *schema.ResourceData, m in return diag.FromErr(err) } - res2, err := hcx.InsertL2Extension(client, body) + res2, err := InsertL2Extension(client, body) if err != nil { return diag.FromErr(err) @@ -171,7 +170,7 @@ func resourceL2ExtensionCreate(ctx context.Context, d *schema.ResourceData, m in // Wait for job completion for { - jr, err := hcx.GetJobResult(client, res2.ID) + jr, err := GetJobResult(client, res2.ID) if err != nil { return diag.FromErr(err) } @@ -183,7 +182,7 @@ func resourceL2ExtensionCreate(ctx context.Context, d *schema.ResourceData, m in } // Get L2 Extension ID - res3, err := hcx.GetL2Extensions(client, dvpg.Name) + res3, err := GetL2Extensions(client, dvpg.Name) if err != nil { return diag.FromErr(err) } @@ -211,16 +210,16 @@ func resourceL2ExtensionUpdate(ctx context.Context, d *schema.ResourceData, m in func resourceL2ExtensionDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { var diags diag.Diagnostics - client := m.(*hcx.Client) + client := m.(*Client) - res, err := hcx.DeleteL2Extension(client, d.Id()) + res, err := DeleteL2Extension(client, d.Id()) if err != nil { return diag.FromErr(err) } // Wait for job completion for { - jr, err := hcx.GetJobResult(client, res.ID) + jr, err := GetJobResult(client, res.ID) if err != nil { return diag.FromErr(err) } diff --git a/resource_location.go b/hcx/resource_location.go similarity index 91% rename from resource_location.go rename to hcx/resource_location.go index bf5ed45..7fe38bb 100644 --- a/resource_location.go +++ b/hcx/resource_location.go @@ -2,14 +2,13 @@ // The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. // SPDX-License-Identifier: MPL-2.0 -package main +package hcx import ( "context" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/vmware/terraform-provider-hcx/hcx" ) // resourceLocation defines the resource schema for managing the location for an HCX site. @@ -70,9 +69,9 @@ func resourceLocationCreate(ctx context.Context, d *schema.ResourceData, m inter func resourceLocationRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { var diags diag.Diagnostics - client := m.(*hcx.Client) + client := m.(*Client) - resp, err := hcx.GetLocation(client) + resp, err := GetLocation(client) if err != nil { return diag.FromErr(err) } @@ -90,7 +89,7 @@ func resourceLocationRead(ctx context.Context, d *schema.ResourceData, m interfa // resourceLocationUpdate updates the location configuration for an HCX site. func resourceLocationUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - client := m.(*hcx.Client) + client := m.(*Client) city := d.Get("city").(string) country := d.Get("country").(string) @@ -99,7 +98,7 @@ func resourceLocationUpdate(ctx context.Context, d *schema.ResourceData, m inter longitude := d.Get("longitude").(float64) province := d.Get("province").(string) - body := hcx.SetLocationBody{ + body := SetLocationBody{ City: city, Country: country, CityASCII: CityASCII, @@ -108,7 +107,7 @@ func resourceLocationUpdate(ctx context.Context, d *schema.ResourceData, m inter Province: province, } - err := hcx.SetLocation(client, body) + err := SetLocation(client, body) if err != nil { return diag.FromErr(err) } @@ -122,9 +121,9 @@ func resourceLocationUpdate(ctx context.Context, d *schema.ResourceData, m inter func resourceLocationDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { var diags diag.Diagnostics - client := m.(*hcx.Client) + client := m.(*Client) - body := hcx.SetLocationBody{ + body := SetLocationBody{ City: "", Country: "", CityASCII: "", @@ -133,7 +132,7 @@ func resourceLocationDelete(ctx context.Context, d *schema.ResourceData, m inter Province: "", } - err := hcx.SetLocation(client, body) + err := SetLocation(client, body) if err != nil { return diag.FromErr(err) } diff --git a/resource_network_profile.go b/hcx/resource_network_profile.go similarity index 88% rename from resource_network_profile.go rename to hcx/resource_network_profile.go index 2995006..cbe5a89 100644 --- a/resource_network_profile.go +++ b/hcx/resource_network_profile.go @@ -2,7 +2,7 @@ // The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. // SPDX-License-Identifier: MPL-2.0 -package main +package hcx import ( "context" @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/vmware/terraform-provider-hcx/hcx" ) // NetSchema defines the resource schema a network profile. @@ -113,7 +112,7 @@ func resourceNetworkProfile() *schema.Resource { // resourceNetworkProfileCreate creates the network profile configuration. func resourceNetworkProfileCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - client := m.(*hcx.Client) + client := m.(*Client) vmc := d.Get("vmc").(bool) if vmc { @@ -140,7 +139,7 @@ func resourceNetworkProfileCreate(ctx context.Context, d *schema.ResourceData, m return diag.Errorf("VMC switch is not enabled. Network name is mandatory") } networkType := d.Get("network_type").(string) - networkiD, err := hcx.GetNetworkBacking(client, vcLocalEndpointID, networkName.(string), networkType) + networkiD, err := GetNetworkBacking(client, vcLocalEndpointID, networkName.(string), networkType) if err != nil { return diag.FromErr(err) } @@ -148,30 +147,30 @@ func resourceNetworkProfileCreate(ctx context.Context, d *schema.ResourceData, m // Get IP Ranges from schema ipRange := d.Get("ip_range").([]interface{}) - ipr := []hcx.NetworkIPRange{} + ipr := []NetworkIPRange{} for _, j := range ipRange { s := j.(map[string]interface{}) startAddress := s["start_address"].(string) endAddress := s["end_address"].(string) - ipr = append(ipr, hcx.NetworkIPRange{ + ipr = append(ipr, NetworkIPRange{ StartAddress: startAddress, EndAddress: endAddress, }) } - body := hcx.NetworkProfileBody{ + body := NetworkProfileBody{ Name: name, Organization: "DEFAULT", MTU: mtu, - Backings: []hcx.Backing{{ + Backings: []Backing{{ BackingID: networkiD.EntityID, BackingName: networkName.(string), VCenterInstanceUUID: vcUUID, Type: networkType, }, }, - IPScopes: []hcx.IPScope{ + IPScopes: []IPScope{ { DNSSuffix: dnsSuffix, Gateway: gateway, @@ -185,7 +184,7 @@ func resourceNetworkProfileCreate(ctx context.Context, d *schema.ResourceData, m OwnedBySystem: true, } - res, err := hcx.InsertNetworkProfile(client, body) + res, err := InsertNetworkProfile(client, body) if err != nil { return diag.FromErr(err) @@ -193,7 +192,7 @@ func resourceNetworkProfileCreate(ctx context.Context, d *schema.ResourceData, m // Wait for job completion for { - jr, err := hcx.GetJobResult(client, res.Data.JobID) + jr, err := GetJobResult(client, res.Data.JobID) if err != nil { return diag.FromErr(err) } @@ -211,10 +210,10 @@ func resourceNetworkProfileCreate(ctx context.Context, d *schema.ResourceData, m func resourceNetworkProfileRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { var diags diag.Diagnostics - client := m.(*hcx.Client) + client := m.(*Client) name := d.Get("name").(string) - np, err := hcx.GetNetworkProfile(client, name) + np, err := GetNetworkProfile(client, name) if err != nil { return diag.FromErr(err) } @@ -226,7 +225,7 @@ func resourceNetworkProfileRead(ctx context.Context, d *schema.ResourceData, m i // resourceNetworkProfileUpdate updates the network profile configuration. func resourceNetworkProfileUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - client := m.(*hcx.Client) + client := m.(*Client) // Get values from schema vmc := d.Get("vmc").(bool) @@ -249,20 +248,20 @@ func resourceNetworkProfileUpdate(ctx context.Context, d *schema.ResourceData, m // Get IP Ranges from schema ipRange := d.Get("ip_range").([]interface{}) - ipr := []hcx.NetworkIPRange{} + ipr := []NetworkIPRange{} for _, j := range ipRange { s := j.(map[string]interface{}) startAddress := s["start_address"].(string) endAddress := s["end_address"].(string) - ipr = append(ipr, hcx.NetworkIPRange{ + ipr = append(ipr, NetworkIPRange{ StartAddress: startAddress, EndAddress: endAddress, }) } // Read the existing profile - body, err := hcx.GetNetworkProfile(client, name) + body, err := GetNetworkProfile(client, name) if err != nil { return diag.FromErr(err) } @@ -273,12 +272,12 @@ func resourceNetworkProfileUpdate(ctx context.Context, d *schema.ResourceData, m body.Name = name // Get network details - networkID, err := hcx.GetNetworkBacking(client, vcLocalEndpointID, networkName, networkType) + networkID, err := GetNetworkBacking(client, vcLocalEndpointID, networkName, networkType) if err != nil { return diag.FromErr(err) } - body.Backings = []hcx.Backing{{ + body.Backings = []Backing{{ BackingID: networkID.EntityID, BackingName: networkName, VCenterInstanceUUID: vcUUID, @@ -288,7 +287,7 @@ func resourceNetworkProfileUpdate(ctx context.Context, d *schema.ResourceData, m body.MTU = mtu - body.IPScopes = []hcx.IPScope{ + body.IPScopes = []IPScope{ { DNSSuffix: dnsSuffix, Gateway: gateway, @@ -300,7 +299,7 @@ func resourceNetworkProfileUpdate(ctx context.Context, d *schema.ResourceData, m }, } - res, err := hcx.UpdateNetworkProfile(client, body) + res, err := UpdateNetworkProfile(client, body) if err != nil { return diag.FromErr(err) @@ -308,7 +307,7 @@ func resourceNetworkProfileUpdate(ctx context.Context, d *schema.ResourceData, m // Wait for job completion for { - jr, err := hcx.GetJobResult(client, res.Data.JobID) + jr, err := GetJobResult(client, res.Data.JobID) if err != nil { return diag.FromErr(err) } @@ -326,10 +325,10 @@ func resourceNetworkProfileUpdate(ctx context.Context, d *schema.ResourceData, m // schema. func resourceNetworkProfileDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { var diags diag.Diagnostics - var res hcx.NetworkProfileResult + var res NetworkProfileResult var err error - client := m.(*hcx.Client) + client := m.(*Client) //name := d.Get("name").(string) vmc := d.Get("vmc").(bool) @@ -353,7 +352,7 @@ func resourceNetworkProfileDelete(ctx context.Context, d *schema.ResourceData, m */ return diags } else { - res, err = hcx.DeleteNetworkProfile(client, d.Id()) + res, err = DeleteNetworkProfile(client, d.Id()) if err != nil { return diag.FromErr(err) @@ -362,7 +361,7 @@ func resourceNetworkProfileDelete(ctx context.Context, d *schema.ResourceData, m // Wait for job completion for { - jr, err := hcx.GetJobResult(client, res.Data.JobID) + jr, err := GetJobResult(client, res.Data.JobID) if err != nil { return diag.FromErr(err) } diff --git a/resource_rolemapping.go b/hcx/resource_rolemapping.go similarity index 93% rename from resource_rolemapping.go rename to hcx/resource_rolemapping.go index 9c3fdfb..1e0fa9e 100644 --- a/resource_rolemapping.go +++ b/hcx/resource_rolemapping.go @@ -2,14 +2,13 @@ // The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. // SPDX-License-Identifier: MPL-2.0 -package main +package hcx import ( "context" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/vmware/terraform-provider-hcx/hcx" ) // resourceRoleMapping defines the resource schema for managing role mapping configuration. @@ -76,7 +75,7 @@ func resourceRoleMappingRead(ctx context.Context, d *schema.ResourceData, m inte // resourceRoleMappingUpdate updates the role mapping configuration. func resourceRoleMappingUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - client := m.(*hcx.Client) + client := m.(*Client) admin := d.Get("admin").([]interface{}) enterprise := d.Get("enterprise").([]interface{}) @@ -93,7 +92,7 @@ func resourceRoleMappingUpdate(ctx context.Context, d *schema.ResourceData, m in enterpriseGroups = append(enterpriseGroups, tmp["user_group"].(string)) } - body := []hcx.RoleMapping{ + body := []RoleMapping{ { Role: "System Administrator", UserGroups: adminGroups, @@ -108,7 +107,7 @@ func resourceRoleMappingUpdate(ctx context.Context, d *schema.ResourceData, m in json.NewEncoder(buf).Encode(body) return diag.Errorf("%s", buf) */ - _, err := hcx.PutRoleMapping(client, body) + _, err := PutRoleMapping(client, body) if err != nil { return diag.FromErr(err) } @@ -122,8 +121,8 @@ func resourceRoleMappingUpdate(ctx context.Context, d *schema.ResourceData, m in func resourceRoleMappingDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { var diags diag.Diagnostics - client := m.(*hcx.Client) - body := []hcx.RoleMapping{ + client := m.(*Client) + body := []RoleMapping{ { Role: "System Administrator", UserGroups: []string{}, @@ -134,7 +133,7 @@ func resourceRoleMappingDelete(ctx context.Context, d *schema.ResourceData, m in }, } - _, err := hcx.PutRoleMapping(client, body) + _, err := PutRoleMapping(client, body) if err != nil { return diag.FromErr(err) } diff --git a/resource_service_mesh.go b/hcx/resource_service_mesh.go similarity index 87% rename from resource_service_mesh.go rename to hcx/resource_service_mesh.go index 7699392..2561943 100644 --- a/resource_service_mesh.go +++ b/hcx/resource_service_mesh.go @@ -2,7 +2,7 @@ // The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. // SPDX-License-Identifier: MPL-2.0 -package main +package hcx import ( "bytes" @@ -13,7 +13,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/vmware/terraform-provider-hcx/hcx" ) // resourceServiceMesh defines the resource schema for managing service mesh configuration. @@ -110,7 +109,7 @@ func resourceServiceMesh() *schema.Resource { // resourceServiceMeshCreate creates the service mesh configuration. func resourceServiceMeshCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - client := m.(*hcx.Client) + client := m.(*Client) name := d.Get("name").(string) sitePairing := d.Get("site_pairing").(map[string]interface{}) @@ -125,34 +124,34 @@ func resourceServiceMeshCreate(ctx context.Context, d *schema.ResourceData, m in tcpFlowConditioningEnabled := d.Get("tcp_flow_conditioning_enabled").(bool) services := d.Get("service").([]interface{}) - servicesFromSchema := []hcx.Service{} + servicesFromSchema := []Service{} for _, j := range services { s := j.(map[string]interface{}) name := s["name"].(string) - sTmp := hcx.Service{ + sTmp := Service{ Name: name, } servicesFromSchema = append(servicesFromSchema, sTmp) } remoteComputeProfileName := d.Get("remote_compute_profile").(string) - remoteComputeProfile, err := hcx.GetComputeProfile(client, remoteEndpointID, remoteComputeProfileName) + remoteComputeProfile, err := GetComputeProfile(client, remoteEndpointID, remoteComputeProfileName) if err != nil { return diag.FromErr(err) } localComputeProfileName := d.Get("local_compute_profile").(string) - localComputeProfile, err := hcx.GetComputeProfile(client, localEndpointID, localComputeProfileName) + localComputeProfile, err := GetComputeProfile(client, localEndpointID, localComputeProfileName) if err != nil { return diag.FromErr(err) } nbAppliances := d.Get("nb_appliances").(int) - body := hcx.InsertServiceMeshBody{ + body := InsertServiceMeshBody{ Name: name, - ComputeProfiles: []hcx.ComputeProfile{ + ComputeProfiles: []ComputeProfile{ { EndpointID: localEndpointID, EndpointName: localEndpointName, @@ -166,17 +165,17 @@ func resourceServiceMeshCreate(ctx context.Context, d *schema.ResourceData, m in ComputeProfileName: remoteComputeProfile.Name, }, }, - WanoptConfig: hcx.WanoptConfig{ + WanoptConfig: WanoptConfig{ UplinkMaxBandwidth: uplinkMaxBandwidth, }, - TrafficEnggCfg: hcx.TrafficEnggCfg{ + TrafficEnggCfg: TrafficEnggCfg{ IsAppPathResiliencyEnabled: appPathResiliencyEnabled, IsTCPFlowConditioningEnabled: tcpFlowConditioningEnabled, }, Services: servicesFromSchema, - SwitchPairCount: []hcx.SwitchPairCount{ + SwitchPairCount: []SwitchPairCount{ { - Switches: []hcx.Switch{ + Switches: []Switch{ localComputeProfile.Switches[0], remoteComputeProfile.Switches[0], }, @@ -190,7 +189,7 @@ func resourceServiceMeshCreate(ctx context.Context, d *schema.ResourceData, m in return diag.FromErr(err) } - res2, err := hcx.InsertServiceMesh(client, body) + res2, err := InsertServiceMesh(client, body) if err != nil { return diag.FromErr(err) @@ -198,7 +197,7 @@ func resourceServiceMeshCreate(ctx context.Context, d *schema.ResourceData, m in // Wait for task completion for { - jr, err := hcx.GetTaskResult(client, res2.Data.InterconnectID) + jr, err := GetTaskResult(client, res2.Data.InterconnectID) if err != nil { return diag.FromErr(err) } @@ -215,7 +214,7 @@ func resourceServiceMeshCreate(ctx context.Context, d *schema.ResourceData, m in } // Update Appliances ID - appliances, err := hcx.GetAppliances(client, sitePairing["local_endpoint_id"].(string), res2.Data.ServiceMeshID) + appliances, err := GetAppliances(client, sitePairing["local_endpoint_id"].(string), res2.Data.ServiceMeshID) if err != nil { return diag.FromErr(err) } @@ -252,17 +251,17 @@ func resourceServiceMeshUpdate(ctx context.Context, d *schema.ResourceData, m in func resourceServiceMeshDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { var diags diag.Diagnostics - client := m.(*hcx.Client) + client := m.(*Client) force := d.Get("force_delete").(bool) - res, err := hcx.DeleteServiceMesh(client, d.Id(), force) + res, err := DeleteServiceMesh(client, d.Id(), force) if err != nil { return diag.FromErr(err) } // Wait for task completion for { - jr, err := hcx.GetTaskResult(client, res.Data.InterconnectTaskID) + jr, err := GetTaskResult(client, res.Data.InterconnectTaskID) if err != nil { return diag.FromErr(err) } diff --git a/resource_site_pairing.go b/hcx/resource_site_pairing.go similarity index 87% rename from resource_site_pairing.go rename to hcx/resource_site_pairing.go index 1ff9d68..7288ec3 100644 --- a/resource_site_pairing.go +++ b/hcx/resource_site_pairing.go @@ -2,7 +2,7 @@ // The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. // SPDX-License-Identifier: MPL-2.0 -package main +package hcx import ( "context" @@ -11,7 +11,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/vmware/terraform-provider-hcx/hcx" ) // resourceSitePairing defines the resource schema for managing site pairing configuration. @@ -86,21 +85,21 @@ func resourceSitePairing() *schema.Resource { // resourceSitePairingCreate creates the site paring configuration. func resourceSitePairingCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - client := m.(*hcx.Client) + client := m.(*Client) url := d.Get("url").(string) username := d.Get("username").(string) password := d.Get("password").(string) - body := hcx.RemoteCloudConfigBody{ - Remote: hcx.RemoteData{ + body := RemoteCloudConfigBody{ + Remote: RemoteData{ Username: username, Password: password, URL: url, }, } - res, err := hcx.InsertSitePairing(client, body) + res, err := InsertSitePairing(client, body) if err != nil { return diag.FromErr(err) @@ -119,10 +118,10 @@ func resourceSitePairingCreate(ctx context.Context, d *schema.ResourceData, m in if ok { // Add certificate - body := hcx.InsertCertificateBody{ + body := InsertCertificateBody{ Certificate: certificate, } - _, err := hcx.InsertCertificate(client, body) + _, err := InsertCertificate(client, body) if err != nil { return diag.FromErr(err) } @@ -135,7 +134,7 @@ func resourceSitePairingCreate(ctx context.Context, d *schema.ResourceData, m in } if secondTry { - res, err = hcx.InsertSitePairing(client, body) + res, err = InsertSitePairing(client, body) if err != nil { return diag.FromErr(err) } @@ -144,7 +143,7 @@ func resourceSitePairingCreate(ctx context.Context, d *schema.ResourceData, m in // Wait for job completion count := 0 for { - jr, err := hcx.GetJobResult(client, res.Data.JobID) + jr, err := GetJobResult(client, res.Data.JobID) if err != nil { return diag.FromErr(err) } @@ -164,7 +163,7 @@ func resourceSitePairingCreate(ctx context.Context, d *schema.ResourceData, m in } if count > 5 { - res, err = hcx.InsertSitePairing(client, body) + res, err = InsertSitePairing(client, body) if err != nil { return diag.FromErr(err) } @@ -172,7 +171,7 @@ func resourceSitePairingCreate(ctx context.Context, d *schema.ResourceData, m in // Wait for job completion count = 0 for { - jr, err := hcx.GetJobResult(client, res.Data.JobID) + jr, err := GetJobResult(client, res.Data.JobID) if err != nil { return diag.FromErr(err) } @@ -201,24 +200,24 @@ func resourceSitePairingCreate(ctx context.Context, d *schema.ResourceData, m in func resourceSitePairingRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { var diags diag.Diagnostics - client := m.(*hcx.Client) + client := m.(*Client) url := d.Get("url").(string) - res, err := hcx.GetSitePairings(client) + res, err := GetSitePairings(client) for _, item := range res.Data.Items { if item.URL == url { d.SetId(item.EndpointID) - lc, err := hcx.GetLocalContainer(client) + lc, err := GetLocalContainer(client) if err != nil { return diag.FromErr(errors.New("cannot get local container info")) } d.Set("local_vc", lc.VcUUID) - rc, err := hcx.GetRemoteContainer(client) + rc, err := GetRemoteContainer(client) if err != nil { return diag.FromErr(errors.New("cannot get remote container info")) } @@ -227,7 +226,7 @@ func resourceSitePairingRead(ctx context.Context, d *schema.ResourceData, m inte d.Set("remote_resource_name", rc.ResourceName) // Update Remote Cloud Info - res2, err := hcx.GetRemoteCloudList(client) + res2, err := GetRemoteCloudList(client) if err != nil { return diag.FromErr(errors.New("cannot get remote cloud info")) } @@ -239,7 +238,7 @@ func resourceSitePairingRead(ctx context.Context, d *schema.ResourceData, m inte } // Update Local Cloud Info - res3, err := hcx.GetLocalCloudList(client) + res3, err := GetLocalCloudList(client) if err != nil { return diag.FromErr(errors.New("cannot get remote cloud info")) } @@ -266,10 +265,10 @@ func resourceSitePairingUpdate(ctx context.Context, d *schema.ResourceData, m in func resourceSitePairingDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { var diags diag.Diagnostics - client := m.(*hcx.Client) + client := m.(*Client) url := d.Get("url").(string) - _, err := hcx.DeleteSitePairings(client, d.Id()) + _, err := DeleteSitePairings(client, d.Id()) if err != nil { return diag.FromErr(err) @@ -277,7 +276,7 @@ func resourceSitePairingDelete(ctx context.Context, d *schema.ResourceData, m in // Wait for site pairing deletion for { - res, err := hcx.GetSitePairings(client) + res, err := GetSitePairings(client) if err != nil { return diag.FromErr(err) } diff --git a/resource_sso.go b/hcx/resource_sso.go similarity index 81% rename from resource_sso.go rename to hcx/resource_sso.go index 7cdf27b..321b1d4 100644 --- a/resource_sso.go +++ b/hcx/resource_sso.go @@ -2,14 +2,13 @@ // The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. // SPDX-License-Identifier: MPL-2.0 -package main +package hcx import ( "context" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/vmware/terraform-provider-hcx/hcx" ) // resourceSSO defines the resource schema for managing SSO configuration. @@ -38,15 +37,15 @@ func resourceSSO() *schema.Resource { // resourceSSOCreate creates the SSO configuration. func resourceSSOCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - client := m.(*hcx.Client) + client := m.(*Client) url := d.Get("url").(string) - body := hcx.InsertSSOBody{ - Data: hcx.InsertSSOData{ - Items: []hcx.InsertSSODataItem{ + body := InsertSSOBody{ + Data: InsertSSOData{ + Items: []InsertSSODataItem{ { - Config: hcx.InsertSSODataItemConfig{ + Config: InsertSSODataItemConfig{ LookupServiceURL: url, ProviderType: "PSC", }, @@ -56,14 +55,14 @@ func resourceSSOCreate(ctx context.Context, d *schema.ResourceData, m interface{ } // First, check if SSO config is already present - res, err := hcx.GetSSO(client) + res, err := GetSSO(client) if err != nil { return diag.FromErr(err) } if len(res.InsertSSOData.Items) == 0 { // No SSO config found - res, err := hcx.InsertSSO(client, body) + res, err := InsertSSO(client, body) if err != nil { return diag.FromErr(err) @@ -89,15 +88,15 @@ func resourceSSORead(ctx context.Context, d *schema.ResourceData, m interface{}) // resourceSSOUpdate updates the SSO configuration. func resourceSSOUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - client := m.(*hcx.Client) + client := m.(*Client) url := d.Get("url").(string) - body := hcx.InsertSSOBody{ - Data: hcx.InsertSSOData{ - Items: []hcx.InsertSSODataItem{ + body := InsertSSOBody{ + Data: InsertSSOData{ + Items: []InsertSSODataItem{ { - Config: hcx.InsertSSODataItemConfig{ + Config: InsertSSODataItemConfig{ LookupServiceURL: url, UUID: d.Id(), ProviderType: "PSC", @@ -107,7 +106,7 @@ func resourceSSOUpdate(ctx context.Context, d *schema.ResourceData, m interface{ }, } - _, err := hcx.UpdateSSO(client, body) + _, err := UpdateSSO(client, body) if err != nil { return diag.FromErr(err) @@ -120,9 +119,9 @@ func resourceSSOUpdate(ctx context.Context, d *schema.ResourceData, m interface{ func resourceSSODelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { var diags diag.Diagnostics - client := m.(*hcx.Client) + client := m.(*Client) - _, err := hcx.DeleteSSO(client, d.Id()) + _, err := DeleteSSO(client, d.Id()) if err != nil { return diag.FromErr(err) } diff --git a/resource_vcenter.go b/hcx/resource_vcenter.go similarity index 85% rename from resource_vcenter.go rename to hcx/resource_vcenter.go index 8e2b863..d1efc37 100644 --- a/resource_vcenter.go +++ b/hcx/resource_vcenter.go @@ -2,7 +2,7 @@ // The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. // SPDX-License-Identifier: MPL-2.0 -package main +package hcx import ( "context" @@ -12,7 +12,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/vmware/terraform-provider-hcx/hcx" ) // resourcevCenter defines the resource schema for managing vCenter instance configuration. @@ -46,17 +45,17 @@ func resourcevCenter() *schema.Resource { // resourcevCenterCreate creates the vCenter instance configuration. func resourcevCenterCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - client := m.(*hcx.Client) + client := m.(*Client) url := d.Get("url").(string) username := d.Get("username").(string) password := d.Get("password").(string) - body := hcx.InsertvCenterBody{ - Data: hcx.InsertvCenterData{ - Items: []hcx.InsertvCenterDataItem{ + body := InsertvCenterBody{ + Data: InsertvCenterData{ + Items: []InsertvCenterDataItem{ { - Config: hcx.InsertvCenterDataItemConfig{ + Config: InsertvCenterDataItemConfig{ Username: username, Password: b64.StdEncoding.EncodeToString([]byte(password)), URL: url, @@ -66,7 +65,7 @@ func resourcevCenterCreate(ctx context.Context, d *schema.ResourceData, m interf }, } - res, err := hcx.InsertvCenter(client, body) + res, err := InsertvCenter(client, body) if err != nil { return diag.FromErr(err) @@ -75,14 +74,14 @@ func resourcevCenterCreate(ctx context.Context, d *schema.ResourceData, m interf d.SetId(res.InsertvCenterData.Items[0].Config.UUID) // Restart App Daemon - _, err = hcx.AppEngineStop(client) + _, err = AppEngineStop(client) if err != nil { return diag.FromErr(err) } // Wait for App Daemon to be stopped for { - jr, err := hcx.GetAppEngineStatus(client) + jr, err := GetAppEngineStatus(client) if err != nil { return diag.FromErr(err) } @@ -93,14 +92,14 @@ func resourcevCenterCreate(ctx context.Context, d *schema.ResourceData, m interf time.Sleep(5 * time.Second) } - _, err = hcx.AppEngineStart(client) + _, err = AppEngineStart(client) if err != nil { return diag.FromErr(err) } // Wait for App Daemon to be started for { - jr, err := hcx.GetAppEngineStatus(client) + jr, err := GetAppEngineStatus(client) if err != nil { return diag.FromErr(err) } @@ -133,9 +132,9 @@ func resourcevCenterUpdate(ctx context.Context, d *schema.ResourceData, m interf func resourcevCenterDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { var diags diag.Diagnostics - client := m.(*hcx.Client) + client := m.(*Client) - _, err := hcx.DeletevCenter(client, d.Id()) + _, err := DeletevCenter(client, d.Id()) if err != nil { return diag.FromErr(err) } diff --git a/resource_vmc.go b/hcx/resource_vmc.go similarity index 83% rename from resource_vmc.go rename to hcx/resource_vmc.go index 61d81e4..947fa30 100644 --- a/resource_vmc.go +++ b/hcx/resource_vmc.go @@ -2,7 +2,7 @@ // The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. // SPDX-License-Identifier: MPL-2.0 -package main +package hcx import ( "context" @@ -12,7 +12,6 @@ import ( "github.com/hashicorp/go-hclog" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/vmware/terraform-provider-hcx/hcx" ) // resourceVmc defines the resource schema for managing a VMware Cloud on AWS configuration. @@ -56,7 +55,7 @@ func resourceVmc() *schema.Resource { // resourceVmcCreate creates the VMware Cloud on AWS configuration. func resourceVmcCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - client := m.(*hcx.Client) + client := m.(*Client) token := client.Token sddcName := d.Get("sddc_name").(string) @@ -67,21 +66,21 @@ func resourceVmcCreate(ctx context.Context, d *schema.ResourceData, m interface{ } // Authenticate with VMware Cloud Services - accessToken, err := hcx.VmcAuthenticate(token) + accessToken, err := VmcAuthenticate(token) if err != nil { return diag.FromErr(err) } - err = hcx.CloudAuthenticate(client, accessToken) + err = CloudAuthenticate(client, accessToken) if err != nil { return diag.FromErr(err) } - var sddc hcx.SDDC + var sddc SDDC if sddcID != "" { - sddc, err = hcx.GetSddcByID(client, sddcID) + sddc, err = GetSddcByID(client, sddcID) } else { - sddc, err = hcx.GetSddcByName(client, sddcName) + sddc, err = GetSddcByName(client, sddcName) } if err != nil { @@ -94,7 +93,7 @@ func resourceVmcCreate(ctx context.Context, d *schema.ResourceData, m interface{ } // Activate HCX - _, err = hcx.ActivateHcxOnSDDC(client, sddc.ID) + _, err = ActivateHcxOnSDDC(client, sddc.ID) if err != nil { return diag.FromErr(err) } @@ -103,9 +102,9 @@ func resourceVmcCreate(ctx context.Context, d *schema.ResourceData, m interface{ errcount := 0 for { if sddcID != "" { - sddc, err = hcx.GetSddcByID(client, sddcID) + sddc, err = GetSddcByID(client, sddcID) } else { - sddc, err = hcx.GetSddcByName(client, sddcName) + sddc, err = GetSddcByName(client, sddcName) } if err != nil { // Attempt to bypass recurring situation where the HCX API @@ -136,7 +135,7 @@ func resourceVmcCreate(ctx context.Context, d *schema.ResourceData, m interface{ func resourceVmcRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { var diags diag.Diagnostics - client := m.(*hcx.Client) + client := m.(*Client) token := client.Token sddcName := d.Get("sddc_name").(string) @@ -151,12 +150,12 @@ func resourceVmcRead(ctx context.Context, d *schema.ResourceData, m interface{}) } // Authenticate with VMware Cloud Services - accessToken, err := hcx.VmcAuthenticate(token) + accessToken, err := VmcAuthenticate(token) if err != nil { return diag.FromErr(err) } - err = hcx.CloudAuthenticate(client, accessToken) + err = CloudAuthenticate(client, accessToken) if err != nil { return diag.FromErr(err) } @@ -165,11 +164,11 @@ func resourceVmcRead(ctx context.Context, d *schema.ResourceData, m interface{}) log.Printf("[Client inside]: %+v ", client) log.Printf("****************") - var sddc hcx.SDDC + var sddc SDDC if sddcID != "" { - sddc, err = hcx.GetSddcByID(client, sddcID) + sddc, err = GetSddcByID(client, sddcID) } else { - sddc, err = hcx.GetSddcByName(client, sddcName) + sddc, err = GetSddcByName(client, sddcName) } if err != nil { return diag.FromErr(err) @@ -193,35 +192,35 @@ func resourceVmcUpdate(ctx context.Context, d *schema.ResourceData, m interface{ func resourceVmcDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { var diags diag.Diagnostics - client := m.(*hcx.Client) + client := m.(*Client) token := client.Token sddcName := d.Get("sddc_name").(string) sddcID := d.Get("sddc_id").(string) // Authenticate with VMware Cloud Services - accessToken, err := hcx.VmcAuthenticate(token) + accessToken, err := VmcAuthenticate(token) if err != nil { return diag.FromErr(err) } - err = hcx.CloudAuthenticate(client, accessToken) + err = CloudAuthenticate(client, accessToken) if err != nil { return diag.FromErr(err) } - var sddc hcx.SDDC + var sddc SDDC if sddcID != "" { - sddc, err = hcx.GetSddcByID(client, sddcID) + sddc, err = GetSddcByID(client, sddcID) } else { - sddc, err = hcx.GetSddcByName(client, sddcName) + sddc, err = GetSddcByName(client, sddcName) } if err != nil { return diag.FromErr(err) } // Deactivate HCX - _, err = hcx.DeactivateHcxOnSDDC(client, sddc.ID) + _, err = DeactivateHcxOnSDDC(client, sddc.ID) if err != nil { return diag.FromErr(err) } @@ -229,11 +228,11 @@ func resourceVmcDelete(ctx context.Context, d *schema.ResourceData, m interface{ // Wait for task to be completed errcount := 0 for { - var sddc hcx.SDDC + var sddc SDDC if sddcID != "" { - sddc, err = hcx.GetSddcByID(client, sddcID) + sddc, err = GetSddcByID(client, sddcID) } else { - sddc, err = hcx.GetSddcByName(client, sddcName) + sddc, err = GetSddcByName(client, sddcName) } if err != nil { // Attempt to bypass recurring situation where the HCX API diff --git a/main.go b/main.go index 32d4536..3e8fcac 100644 --- a/main.go +++ b/main.go @@ -5,14 +5,27 @@ package main import ( + "flag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/plugin" + "github.com/vmware/terraform-provider-hcx/hcx" ) func main() { - plugin.Serve(&plugin.ServeOpts{ + var debugMode bool + flag.BoolVar(&debugMode, "debug", false, "set to true to run the provider with support for debuggers like delve") + flag.Parse() + + opts := &plugin.ServeOpts{ ProviderFunc: func() *schema.Provider { - return Provider() + return hcx.Provider() }, - }) + } + + if debugMode { + opts.Debug = true + opts.ProviderAddr = "vmware/hcx" + } + + plugin.Serve(opts) }