Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
Signed-off-by: Dainius Serplis <[email protected]>
  • Loading branch information
Didainius committed Nov 14, 2024
1 parent 8cbf89f commit 10bc8ed
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 30 deletions.
4 changes: 2 additions & 2 deletions vcd/datasource_vcd_tm_org_vdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ func datasourceVcdTmVdc() *schema.Resource {

var tmVdcDsZoneResourceAllocation = &schema.Resource{
Schema: map[string]*schema.Schema{
"zone_name": {
"region_zone_name": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("%s Name", labelTmRegionZone),
},
"zone_id": {
"region_zone_id": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("%s ID", labelTmRegionZone),
Expand Down
10 changes: 5 additions & 5 deletions vcd/resource_vcd_tm_org_vdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ func resourceTmVdc() *schema.Resource {

var tmVdcZoneResourceAllocation = &schema.Resource{
Schema: map[string]*schema.Schema{
"zone_name": {
"region_zone_name": {
Type: schema.TypeString,
Computed: true,
Description: "Region Zone Name",
},
"zone_id": {
"region_zone_id": {
Type: schema.TypeString,
Required: true,
Description: "Region Zone ID",
Expand Down Expand Up @@ -181,7 +181,7 @@ func getTmVdcType(_ *VCDClient, d *schema.ResourceData) (*types.TmVdc, error) {
singleZoneMap := singleZone.(map[string]interface{})
singleZoneType := &types.TmVdcZoneResourceAllocation{
Zone: &types.OpenApiReference{
ID: singleZoneMap["zone_id"].(string),
ID: singleZoneMap["region_zone_id"].(string),
},
ResourceAllocation: types.TmVdcResourceAllocation{
CPULimitMHz: singleZoneMap["cpu_limit_mhz"].(int),
Expand Down Expand Up @@ -230,8 +230,8 @@ func setTmVdcData(d *schema.ResourceData, vdc *govcd.TmVdc) error {
for zoneIndex, zone := range vdc.TmVdc.ZoneResourceAllocation {
oneZone := make(map[string]interface{})

oneZone["zone_name"] = zone.Zone.Name
oneZone["zone_id"] = zone.Zone.ID
oneZone["region_zone_name"] = zone.Zone.Name
oneZone["region_zone_id"] = zone.Zone.ID

oneZone["memory_limit_mib"] = zone.ResourceAllocation.MemoryLimitMiB
oneZone["memory_reservation_mib"] = zone.ResourceAllocation.MemoryReservationMiB
Expand Down
57 changes: 43 additions & 14 deletions vcd/resource_vcd_tm_org_vdc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ func TestAccVcdTmOrgVdc(t *testing.T) {

preRequisites := vCenterHcl + nsxManagerHcl + regionHcl

// TODO: TM: There shouldn't be a need to create `preRequisites` separatelly, but region
// creation fails if it is spawned instantly after adding vCenter, therefore this extra step
// give time (with additional 'refresh' and 'refresh storage policies' operations on vCenter)
configText0 := templateFill(preRequisites, params)
params["FuncName"] = t.Name() + "-step0"

configText1 := templateFill(preRequisites+testAccVcdTmOrgVdcStep1, params)
params["FuncName"] = t.Name() + "-step2"
configText2 := templateFill(preRequisites+testAccVcdTmOrgVdcStep2, params)
Expand All @@ -45,31 +51,54 @@ func TestAccVcdTmOrgVdc(t *testing.T) {
return
}

cachedRegionZoneId := &testCachedFieldValue{}

resource.Test(t, resource.TestCase{
ProviderFactories: testAccProviders,
Steps: []resource.TestStep{
{
Config: configText0,
},
{
Config: configText1,
Check: resource.ComposeTestCheckFunc(
cachedRegionZoneId.cacheTestResourceFieldValue("vcd_tm_region_zone.test", "id"),
resource.TestCheckResourceAttrSet("vcd_tm_org_vdc.test", "id"),
// resource.TestCheckResourceAttr("vcd_tm_org.test", "display_name", "terraform-test"),
// resource.TestCheckResourceAttr("vcd_tm_org.test", "description", "terraform test"),
// resource.TestCheckResourceAttr("vcd_tm_org.test", "is_enabled", "true"),
// resource.TestCheckResourceAttr("vcd_tm_org.test", "is_subprovider", "false"),
// resource.TestMatchResourceAttr("vcd_tm_org.test", "managed_by_id", regexp.MustCompile("^urn:vcloud:org:")),
// resource.TestCheckResourceAttr("vcd_tm_org.test", "managed_by_name", "System"),
resource.TestCheckResourceAttr("vcd_tm_org_vdc.test", "is_enabled", "true"),
resource.TestCheckResourceAttr("vcd_tm_org_vdc.test", "status", "READY"),
resource.TestCheckResourceAttrPair("vcd_tm_org_vdc.test", "org_id", "vcd_tm_org.test", "id"),
resource.TestCheckResourceAttrPair("vcd_tm_org_vdc.test", "region_id", "vcd_tm_region.region", "id"),
resource.TestCheckResourceAttr("vcd_tm_org_vdc.test", "supervisor_ids.#", "1"),
resource.TestCheckTypeSetElemAttrPair("vcd_tm_org_vdc.test", "supervisor_ids.*", "data.vcd_tm_supervisor.test", "id"),
resource.TestCheckResourceAttr("vcd_tm_org_vdc.test", "zone_resource_allocations.#", "1"),
resource.TestCheckTypeSetElemNestedAttrs("vcd_tm_org_vdc.test", "zone_resource_allocations.*", map[string]string{
"region_zone_name": "{{.SupervisorZoneName}}",
"cpu_limit_mhz": "2000",
"cpu_reservation_mhz": "100",
"memory_limit_mib": "1024",
"memory_reservation_mib": "512",
}),
),
},
{
Config: configText2,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("vcd_tm_org_vdc.test", "id"),
// resource.TestCheckResourceAttr("vcd_tm_org.test", "display_name", "terraform-test"),
// resource.TestCheckResourceAttr("vcd_tm_org.test", "description", "terraform test"),
// resource.TestCheckResourceAttr("vcd_tm_org.test", "is_enabled", "true"),
// resource.TestCheckResourceAttr("vcd_tm_org.test", "is_subprovider", "false"),
// resource.TestMatchResourceAttr("vcd_tm_org.test", "managed_by_id", regexp.MustCompile("^urn:vcloud:org:")),
// resource.TestCheckResourceAttr("vcd_tm_org.test", "managed_by_name", "System"),
resource.TestCheckResourceAttr("vcd_tm_org_vdc.test", "is_enabled", "true"),
resource.TestCheckResourceAttr("vcd_tm_org_vdc.test", "status", "READY"),
resource.TestCheckResourceAttrPair("vcd_tm_org_vdc.test", "org_id", "vcd_tm_org.test", "id"),
resource.TestCheckResourceAttrPair("vcd_tm_org_vdc.test", "region_id", "vcd_tm_region.region", "id"),
resource.TestCheckResourceAttr("vcd_tm_org_vdc.test", "supervisor_ids.#", "1"),
resource.TestCheckTypeSetElemAttrPair("vcd_tm_org_vdc.test", "supervisor_ids.*", "data.vcd_tm_supervisor.test", "id"),
resource.TestCheckResourceAttr("vcd_tm_org_vdc.test", "zone_resource_allocations.#", "1"),
resource.TestCheckTypeSetElemNestedAttrs("vcd_tm_org_vdc.test", "zone_resource_allocations.*", map[string]string{
"region_zone_name": "{{.SupervisorZoneName}}",
"region_zone_id": cachedRegionZoneId.fieldValue,
"cpu_limit_mhz": "1900",
"cpu_reservation_mhz": "100",
"memory_limit_mib": "1024",
"memory_reservation_mib": "512",
}),
),
},
{
Expand Down Expand Up @@ -112,7 +141,7 @@ resource "vcd_tm_org_vdc" "test" {
region_id = {{.RegionId}}
supervisor_ids = [data.vcd_tm_supervisor.test.id]
zone_resource_allocations {
zone_id = data.vcd_tm_region_zone.test.id
region_zone_id = data.vcd_tm_region_zone.test.id
cpu_limit_mhz = 2000
cpu_reservation_mhz = 100
memory_limit_mib = 1024
Expand Down Expand Up @@ -146,7 +175,7 @@ resource "vcd_tm_org_vdc" "test" {
region_id = {{.RegionId}}
supervisor_ids = [data.vcd_tm_supervisor.test.id]
zone_resource_allocations {
zone_id = data.vcd_tm_region_zone.test.id
region_zone_id = data.vcd_tm_region_zone.test.id
cpu_limit_mhz = 1900
cpu_reservation_mhz = 90
memory_limit_mib = 500
Expand Down
18 changes: 9 additions & 9 deletions website/docs/r/tm_org_vdc.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ resource "vcd_tm_org_vdc" "test" {
region_id = vcd_tm_region.region.id
supervisor_ids = [data.vcd_tm_supervisor.test.id]
zone_resource_allocations {
zone_id = data.vcd_tm_region_zone.test.id
region_zone_id = data.vcd_tm_region_zone.test.id
cpu_limit_mhz = 2000
cpu_reservation_mhz = 100
memory_limit_mib = 1024
Expand All @@ -50,20 +50,20 @@ The following arguments are supported:
* `org_id` - (Required) An Org ID for this Org VDC to be assigned to
* `region_id` - (Required) A Region ID that this Org VDC should be backed by
* `supervisor_ids` - (Required) A set of Supervisor IDs that back this Org VDC. Can be looked up
using [`vcd_tm_supervisor`](/providers/vmware/vcd/latest/docs/data-sources/tm_supervisor) data source.
using [`vcd_tm_supervisor`](/providers/vmware/vcd/latest/docs/data-sources/tm_supervisor) data source
* `zone_resource_allocations` - (Required) A set of Zone Resource Allocation definitions. See [Zone Resource Allocations](#zone-resource-allocations-block)

<a id="zone-resource-allocations-block"></a>
## Zone Resource Allocations

* `zone_id` - Can be looked up
using [`vcd_tm_region_zone`](/providers/vmware/vcd/latest/docs/data-sources/tm_region_zone) data source.
* `cpu_limit_mhz`
* `cpu_reservation_mhz`
* `memory_limit_mib`
* `memory_reservation_mib`
* `region_zone_id` - (Required) Can be looked up using
[`vcd_tm_region_zone`](/providers/vmware/vcd/latest/docs/data-sources/tm_region_zone) data source
* `cpu_limit_mhz` - (Required) Maximum CPU consumption limit in MHz
* `cpu_reservation_mhz` - (Required) Defines reserved CPU capacity in MHz
* `memory_limit_mib` - (Required) Maximum memory consumption limit in MiB
* `memory_reservation_mib` - (Required) Defines reserved memory capacity in Mib

A computed attribute `zone_name` will be set in each `zone_resource_allocations` block.
A computed attribute `region_zone_name` will be set in each `zone_resource_allocations` block.


## Attribute Reference
Expand Down

0 comments on commit 10bc8ed

Please sign in to comment.