Skip to content

Commit

Permalink
fix: missing vds info with r/cluster import
Browse files Browse the repository at this point in the history
Draft to address missing `vds` info with `r/cluster` import.

Signed-off-by: Jared Burns <jared.burns@broadcom.com>
  • Loading branch information
burnsjared0415 authored and tenthirtyam committed Aug 21, 2024
1 parent 94a68df commit 25b1826
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 7 deletions.
54 changes: 52 additions & 2 deletions internal/cluster/cluster_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,17 @@ func ImportCluster(ctx context.Context, data *schema.ResourceData, apiClient *cl
WithTimeout(constants.DefaultVcfApiCallTimeout)
getClusterParams.ID = clusterId
clusterResult, err := apiClient.Clusters.GetCluster(getClusterParams)

Check failure on line 392 in internal/cluster/cluster_operations.go

View workflow job for this annotation

GitHub Actions / Build

ineffectual assignment to err (ineffassign)
vdsParams := &clusters.GetVdsesParams{
ClusterID: clusterId,
Context: ctx,
}

vdsResult, err := apiClient.Clusters.GetVdses(vdsParams)
if err != nil {
return nil, err
}

clusterObj := clusterResult.Payload

data.SetId(clusterObj.ID)
Expand All @@ -400,8 +408,50 @@ func ImportCluster(ctx context.Context, data *schema.ResourceData, apiClient *cl
_ = data.Set("primary_datastore_type", clusterObj.PrimaryDatastoreType)
_ = data.Set("is_default", clusterObj.IsDefault)
_ = data.Set("is_stretched", clusterObj.IsStretched)
flattenedVdsSpecs := getFlattenedVdsSpecsForRefs(clusterObj.VdsSpecs)
_ = data.Set("vds", flattenedVdsSpecs)

vdsList := make([]map[string]interface{}, len(vdsResult.Payload))
for i, vds := range vdsResult.Payload {
portGroups := make([]map[string]interface{}, len(vds.PortGroups))
for j, pg := range vds.PortGroups {
portGroups[j] = map[string]interface{}{
"name": pg.Name,
"transport_type": pg.TransportType,
"port_binding_type": pg.PortBindingType,
"vlan_id": pg.VlanID,
"active_uplinks": pg.ActiveUplinks,
"standby_uplinks": pg.StandbyUplinks,
}
}

niocBandwidthAllocations := make([]map[string]interface{}, len(vds.NiocBandwidthAllocations))
for k, nioc := range vds.NiocBandwidthAllocations {
niocBandwidthAllocations[k] = map[string]interface{}{
"type": nioc.Type,
"nioc_traffic_resource_allocation": []map[string]interface{}{
{
"shares_info": []map[string]interface{}{
{
"shares": nioc.NiocTrafficResourceAllocation.SharesInfo.Shares,
"level": nioc.NiocTrafficResourceAllocation.SharesInfo.Level,
},
},
},
},
}
}

vdsList[i] = map[string]interface{}{
"id": vds.ID,
"name": vds.Name,
"is_used_by_nsxt": vds.IsUsedByNSXT,
"mtu": vds.Mtu,
"port_groups": portGroups,
"nioc_bandwidth_allocations": niocBandwidthAllocations,
"version": vds.Version,
}
}

data.Set("vds", vdsList)

Check failure on line 455 in internal/cluster/cluster_operations.go

View workflow job for this annotation

GitHub Actions / Build

Error return value of `data.Set` is not checked (errcheck)
flattenedHostSpecs, err := getFlattenedHostSpecsForRefs(ctx, clusterObj.Hosts, apiClient)
if err != nil {
Expand Down
106 changes: 101 additions & 5 deletions internal/provider/data_source_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/vmware/terraform-provider-vcf/internal/api_client"
"github.com/vmware/terraform-provider-vcf/internal/cluster"
"github.com/vmware/terraform-provider-vcf/internal/network"
)

func DataSourceCluster() *schema.Resource {
Expand Down Expand Up @@ -46,10 +45,107 @@ func DataSourceCluster() *schema.Resource {
Elem: cluster.HostSpecSchema(),
},
"vds": {
Type: schema.TypeList,
Computed: true,
Description: "vSphere Distributed Switches to add to the Cluster",
Elem: network.VdsSchema(),
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"is_used_by_nsxt": {
Type: schema.TypeBool,
Computed: true,
},
"mtu": {
Type: schema.TypeInt,
Computed: true,
},
"port_groups": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},
"transport_type": {
Type: schema.TypeString,
Computed: true,
},
"port_binding_type": {
Type: schema.TypeString,
Computed: true,
},
"vlan_id": {
Type: schema.TypeInt,
Computed: true,
},
"active_uplinks": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"standby_uplinks": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"nioc_bandwidth_allocations": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Computed: true,
},
"nioc_traffic_resource_allocation": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"shares_info": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"shares": {
Type: schema.TypeInt,
Computed: true,
},
"level": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
},
Optional: true,
},
},
},
},
"version": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"primary_datastore_name": {
Type: schema.TypeString,
Expand Down

0 comments on commit 25b1826

Please sign in to comment.