-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Region, Supervisor and Supervisor Zones (#1348)
- Loading branch information
Showing
25 changed files
with
996 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
* **New Resource:** `vcd_vcenter` to manage vCenter servers [GH-1343] | ||
* **New Resource:** `vcd_vcenter` to manage vCenter servers [GH-1343, GH-1348] | ||
* **New Resource:** `vcd_nsxt_manager` to manage NSX-T Managers [GH-1343] |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
* **New Resource:** `vcd_tm_region` to manage Regions [GH-1348] | ||
* **New Data Source:** `vcd_tm_region` to read Regions [GH-1348] | ||
* **New Data Source:** `vcd_tm_supervisor` to read Supervisors [GH-1348] | ||
* **New Data Source:** `vcd_tm_supervisor_zone` to read Supervisor Zones [GH-1348] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package vcd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/vmware/go-vcloud-director/v3/govcd" | ||
"github.com/vmware/go-vcloud-director/v3/types/v56" | ||
) | ||
|
||
func datasourceVcdTmRegion() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: datasourceVcdTmRegionRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: fmt.Sprintf("%s name", labelTmRegion), | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: fmt.Sprintf("%s description", labelTmRegion), | ||
}, | ||
"is_enabled": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
Description: fmt.Sprintf("Defines whether the %s is enabled or not", labelTmRegion), | ||
}, | ||
"nsx_manager_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "NSX Manager ID", | ||
}, | ||
"cpu_capacity_mhz": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "CPU Capacity in MHz", | ||
}, | ||
"cpu_reservation_capacity_mhz": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "CPU reservation in MHz", | ||
}, | ||
"memory_capacity_mib": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "Memory capacity in MiB", | ||
}, | ||
"memory_reservation_capacity_mib": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "Memory reservation in MiB", | ||
}, | ||
"status": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: fmt.Sprintf("Status of the %s", labelTmRegion), | ||
}, | ||
"supervisor_ids": { | ||
Type: schema.TypeSet, | ||
Computed: true, | ||
Description: fmt.Sprintf("A set of supervisor IDs used in this %s", labelTmRegion), | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
"storage_policy_names": { | ||
Type: schema.TypeSet, | ||
Computed: true, | ||
Description: "A set of storage policies", | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func datasourceVcdTmRegionRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
vcdClient := meta.(*VCDClient) | ||
c := crudConfig[*govcd.Region, types.Region]{ | ||
entityLabel: labelTmRegion, | ||
getEntityFunc: vcdClient.GetRegionByName, | ||
stateStoreFunc: setRegionData, | ||
} | ||
return readDatasource(ctx, d, meta, c) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package vcd | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/vmware/go-vcloud-director/v3/types/v56" | ||
) | ||
|
||
func datasourceVcdTmSupervisor() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: datasourceVcdTmSupervisorRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Name of the Supervisor", | ||
}, | ||
"vcenter_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Parent vCenter ID", | ||
}, | ||
"region_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Parent Region ID", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func datasourceVcdTmSupervisorRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
vcdClient := meta.(*VCDClient) | ||
|
||
s, err := vcdClient.GetSupervisorByNameAndVcenterId(d.Get("name").(string), d.Get("vcenter_id").(string)) | ||
if err != nil { | ||
return diag.Errorf("error getting Supervisor: %s", err) | ||
} | ||
|
||
err = setSupervisorData(d, s.Supervisor) | ||
if err != nil { | ||
return diag.Errorf("error storing Supervisor data: %s", err) | ||
} | ||
|
||
d.SetId(s.Supervisor.SupervisorID) | ||
|
||
return nil | ||
} | ||
|
||
func setSupervisorData(d *schema.ResourceData, s *types.Supervisor) error { | ||
vCenterId := "" | ||
if s.VirtualCenter != nil { | ||
vCenterId = s.VirtualCenter.ID | ||
} | ||
dSet(d, "vcenter_id", vCenterId) | ||
|
||
regionId := "" | ||
if s.Region != nil { | ||
regionId = s.Region.ID | ||
} | ||
|
||
dSet(d, "region_id", regionId) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package vcd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/vmware/go-vcloud-director/v3/govcd" | ||
) | ||
|
||
const labelSupervisorZone = "Supervisor Zone" | ||
|
||
func datasourceVcdTmSupervisorZone() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: datasourceVcdTmSupervisorZoneRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"supervisor_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "ID of the Supervisor", | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: fmt.Sprintf("Name of the %s", labelSupervisorZone), | ||
}, | ||
"vcenter_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Parent vCenter ID", | ||
}, | ||
"region_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Parent Region ID", | ||
}, | ||
"cpu_capacity_mhz": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "CPU Capacity in MHz", | ||
}, | ||
"cpu_used_mhz": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "CPU used in MHz", | ||
}, | ||
"memory_capacity_mib": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "Memory capacity in MiB", | ||
}, | ||
"memory_used_mib": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "Memory used in MiB", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func datasourceVcdTmSupervisorZoneRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
vcdClient := meta.(*VCDClient) | ||
|
||
s, err := vcdClient.GetSupervisorById(d.Get("supervisor_id").(string)) | ||
if err != nil { | ||
return diag.Errorf("error getting Supervisor: %s", err) | ||
} | ||
|
||
sz, err := s.GetSupervisorZoneByName(d.Get("name").(string)) | ||
if err != nil { | ||
return diag.Errorf("error getting Supervisor Zone '%s': %s", d.Get("name").(string), err) | ||
} | ||
|
||
err = setSupervisorZoneData(d, sz) | ||
if err != nil { | ||
return diag.Errorf("error storing Supervisor data: %s", err) | ||
} | ||
|
||
d.SetId(sz.SupervisorZone.ID) | ||
|
||
return nil | ||
} | ||
|
||
func setSupervisorZoneData(d *schema.ResourceData, s *govcd.SupervisorZone) error { | ||
if s == nil { | ||
return fmt.Errorf("error") | ||
} | ||
vCenterId := "" | ||
if s.SupervisorZone.VirtualCenter != nil { | ||
vCenterId = s.SupervisorZone.VirtualCenter.ID | ||
} | ||
dSet(d, "vcenter_id", vCenterId) | ||
dSet(d, "name", s.SupervisorZone.Name) | ||
supervisorId := "" | ||
if s.SupervisorZone.Supervisor != nil { | ||
supervisorId = s.SupervisorZone.Supervisor.ID | ||
} | ||
dSet(d, "supervisor_id", supervisorId) | ||
|
||
regionId := "" | ||
if s.SupervisorZone.Region != nil { | ||
regionId = s.SupervisorZone.Region.ID | ||
} | ||
dSet(d, "region_id", regionId) | ||
dSet(d, "cpu_capacity_mhz", s.SupervisorZone.TotalCPUCapacityMHz) | ||
dSet(d, "cpu_used_mhz", s.SupervisorZone.CpuUsedMHz) | ||
dSet(d, "memory_capacity_mib", s.SupervisorZone.TotalMemoryCapacityMiB) | ||
dSet(d, "memory_used_mib", s.SupervisorZone.MemoryUsedMiB) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.