Skip to content

Commit

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

Signed-off-by: Jared Burns <[email protected]>
  • Loading branch information
burnsjared0415 authored and tenthirtyam committed Nov 13, 2024
1 parent 572b660 commit 7b50744
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 19 deletions.
26 changes: 9 additions & 17 deletions internal/cluster/cluster_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,14 +375,13 @@ func FlattenCluster(ctx context.Context, clusterObj *vcf.Cluster, apiClient *vcf
result["vds"] = flattenedVdsSpecs
}

if clusterObj.Hosts != nil {
flattenedHostSpecs, err := getFlattenedHostSpecsForRefs(ctx, *clusterObj.Hosts, apiClient)
if err != nil {
return nil, err
}
result["host"] = flattenedHostSpecs
flattenedHostSpecs, err := getFlattenedHostSpecsForRefs(ctx, clusterObj.Hosts, apiClient)
if err != nil {
return nil, err
}

result["host"] = flattenedHostSpecs

return &result, nil
}

Expand All @@ -404,18 +403,11 @@ func ImportCluster(ctx context.Context, data *schema.ResourceData, apiClient *vc
_ = data.Set("primary_datastore_type", clusterObj.PrimaryDatastoreType)
_ = data.Set("is_default", clusterObj.IsDefault)
_ = data.Set("is_stretched", clusterObj.IsStretched)
if clusterObj.VdsSpecs != nil {
flattenedVdsSpecs := getFlattenedVdsSpecsForRefs(*clusterObj.VdsSpecs)
_ = data.Set("vds", flattenedVdsSpecs)
}
flattenedVdsSpecs := getFlattenedVdsSpecsForRefs(clusterObj.VdsSpecs)
_ = data.Set("vds", flattenedVdsSpecs)

if clusterObj.Hosts != nil {
flattenedHostSpecs, err := getFlattenedHostSpecsForRefs(ctx, *clusterObj.Hosts, apiClient)
if err != nil {
return nil, err
}
_ = data.Set("host", flattenedHostSpecs)
}
flattenedHostSpecs, err := getFlattenedHostSpecsForRefs(ctx, clusterObj.Hosts, apiClient)
_ = data.Set("host", flattenedHostSpecs)

// get all domains and find our cluster to set the "domain_id" attribute, because
// cluster API doesn't provide parent domain ID.
Expand Down
37 changes: 35 additions & 2 deletions internal/cluster/host_spec_subresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,21 @@ func HostSpecSchema() *schema.Resource {
"vmnic": {
Type: schema.TypeList,
Optional: true,
Description: "vmnic configuration for the ESXi host",
Elem: network.VMNicSchema(),
Description: "Physical NIC configuration for the ESXi host",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: "Name of the physical NIC",
},
"mac_address": {
Type: schema.TypeString,
Required: true,
Description: "MAC address of the physical NIC",
},
},
},
},
},
}
Expand All @@ -96,6 +109,26 @@ func FlattenHost(host vcf.Host) *map[string]interface{} {
if len(ipAddresses) > 0 {
result["ip_address"] = ipAddresses[0].IpAddress
}
if len(host.PhysicalNics) > 0 {
var physicalNics []map[string]interface{}
for _, nic := range host.PhysicalNics {
nicMap := make(map[string]interface{})
nicMap["name"] = nic.DeviceName
nicMap["mac_address"] = nic.MacAddress
physicalNics = append(physicalNics, nicMap)
}
result["vmnic"] = physicalNics
}
if len(host.PhysicalNics) > 0 {
var physicalNics []map[string]interface{}
for _, nic := range host.PhysicalNics {
nicMap := make(map[string]interface{})
nicMap["name"] = nic.DeviceName
nicMap["mac_address"] = nic.MacAddress
physicalNics = append(physicalNics, nicMap)
}
result["vmnic"] = physicalNics
}

return &result
}
Expand Down
1 change: 1 addition & 0 deletions internal/provider/data_source_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestAccDataSourceVcfCluster(t *testing.T) {
resource.TestCheckResourceAttrSet("data.vcf_cluster.cluster1", "primary_datastore_type"),
resource.TestCheckResourceAttrSet("data.vcf_cluster.cluster1", "is_default"),
resource.TestCheckResourceAttrSet("data.vcf_cluster.cluster1", "is_stretched"),
resource.TestCheckResourceAttrSet("data.vcf_cluster.cluster1", "vds"),
resource.TestCheckResourceAttrSet("data.vcf_cluster.cluster1", "host.0.id"),
resource.TestCheckResourceAttrSet("data.vcf_cluster.cluster1", "host.0.host_name"),
resource.TestCheckResourceAttrSet("data.vcf_cluster.cluster1", "host.0.ip_address"),
Expand Down
4 changes: 4 additions & 0 deletions internal/provider/resource_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func TestAccResourceVcfClusterCreate(t *testing.T) {
resource.TestCheckResourceAttrSet("vcf_cluster.cluster1", "primary_datastore_type"),
resource.TestCheckResourceAttrSet("vcf_cluster.cluster1", "is_default"),
resource.TestCheckResourceAttrSet("vcf_cluster.cluster1", "is_stretched"),
resource.TestCheckResourceAttrSet("vcf_cluster.cluster1", "vds"),
resource.TestCheckResourceAttrSet("vcf_cluster.cluster1", "host.0.id"),
resource.TestCheckResourceAttrSet("vcf_cluster.cluster1", "host.1.id"),
resource.TestCheckResourceAttrSet("vcf_cluster.cluster1", "host.2.id"),
Expand Down Expand Up @@ -116,6 +117,7 @@ func TestAccResourceVcfClusterFull(t *testing.T) {
resource.TestCheckResourceAttrSet("vcf_cluster.cluster1", "primary_datastore_type"),
resource.TestCheckResourceAttrSet("vcf_cluster.cluster1", "is_default"),
resource.TestCheckResourceAttrSet("vcf_cluster.cluster1", "is_stretched"),
resource.TestCheckResourceAttrSet("vcf_cluster.cluster1", "vds"),
resource.TestCheckResourceAttrSet("vcf_cluster.cluster1", "host.0.id"),
resource.TestCheckResourceAttrSet("vcf_cluster.cluster1", "host.1.id"),
resource.TestCheckResourceAttrSet("vcf_cluster.cluster1", "host.2.id"),
Expand Down Expand Up @@ -151,6 +153,7 @@ func TestAccResourceVcfClusterFull(t *testing.T) {
resource.TestCheckResourceAttrSet("vcf_cluster.cluster1", "primary_datastore_type"),
resource.TestCheckResourceAttrSet("vcf_cluster.cluster1", "is_default"),
resource.TestCheckResourceAttrSet("vcf_cluster.cluster1", "is_stretched"),
resource.TestCheckResourceAttrSet("vcf_cluster.cluster1", "vds"),
resource.TestCheckResourceAttrSet("vcf_cluster.cluster1", "host.0.id"),
resource.TestCheckResourceAttrSet("vcf_cluster.cluster1", "host.1.id"),
resource.TestCheckResourceAttrSet("vcf_cluster.cluster1", "host.2.id"),
Expand Down Expand Up @@ -180,6 +183,7 @@ func TestAccResourceVcfClusterFull(t *testing.T) {
resource.TestCheckResourceAttrSet("vcf_cluster.cluster1", "primary_datastore_type"),
resource.TestCheckResourceAttrSet("vcf_cluster.cluster1", "is_default"),
resource.TestCheckResourceAttrSet("vcf_cluster.cluster1", "is_stretched"),
resource.TestCheckResourceAttrSet("vcf_cluster.cluster1", "vds"),
resource.TestCheckResourceAttrSet("vcf_cluster.cluster1", "host.0.id"),
resource.TestCheckResourceAttrSet("vcf_cluster.cluster1", "host.1.id"),
resource.TestCheckResourceAttrSet("vcf_cluster.cluster1", "host.2.id"),
Expand Down

0 comments on commit 7b50744

Please sign in to comment.