Skip to content

Commit

Permalink
Add resource to manage solution landing zone [1] (#1251)
Browse files Browse the repository at this point in the history
  • Loading branch information
Didainius authored May 17, 2024
1 parent 69c6eef commit 5be38c1
Show file tree
Hide file tree
Showing 12 changed files with 958 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .changes/v3.13.0/1251-features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* **New Resource:** `vcd_solution_landing_zone` to manage Solution Add-On Landing Zone [GH-1251]
* **New Data Source:** `vcd_solution_landing_zone` to read Solution Add-On Landing Zone [GH-1251]
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/hashicorp/go-version v1.6.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.31.0
github.com/kr/pretty v0.2.1
github.com/vmware/go-vcloud-director/v2 v2.25.0-alpha.2
github.com/vmware/go-vcloud-director/v2 v2.25.0-alpha.3
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IU
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
github.com/vmware/go-vcloud-director/v2 v2.25.0-alpha.2 h1:vNgH4Aare66pe/LZxuwHCxAUHsFmpGKN5fD0XvwgQ/0=
github.com/vmware/go-vcloud-director/v2 v2.25.0-alpha.2/go.mod h1:buylrFJrDJqZlqDQJrR5YS585pzYN+vPLY2a2k4XpLk=
github.com/vmware/go-vcloud-director/v2 v2.25.0-alpha.3 h1:aohdateSUX2kuExNh7QPIe//0sTkCrAXj/E9y7pSYKA=
github.com/vmware/go-vcloud-director/v2 v2.25.0-alpha.3/go.mod h1:NtFFjio08SkxTQH4j1U/SA8fNrh1tLGOhQC7lLNed+w=
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
Expand Down
6 changes: 5 additions & 1 deletion vcd/datasource_not_found_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ func testSpecificDataSourceNotFound(dataSourceName string, vcdClient *VCDClient)
},
{
skipVersionConstraint: "< 37.1",
datasourceName: "vcd_ip_space_custom_quota",
datasourceName: "vcd_ip_space",
},
{
skipVersionConstraint: "< 37.1",
datasourceName: "vcd_solution_landing_zone",
},
{
skipVersionConstraint: "< 37.1",
Expand Down
143 changes: 143 additions & 0 deletions vcd/datasource_vcd_solution_landing_zone.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package vcd

import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dsSlzChildComponent(title string) *schema.Schema {
return &schema.Schema{
Type: schema.TypeSet,
Required: true,
Description: fmt.Sprintf("Details of %s element", title),
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("ID of %s", title),
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Name of %s", title),
},
"is_default": {
Type: schema.TypeBool,
Computed: true,
Description: fmt.Sprintf("Boolean value that marks if this %s should be default", title),
},
"capabilities": {
Type: schema.TypeSet,
Computed: true,
Description: fmt.Sprintf("Set of capabilities for %s", title),
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
}
}

func datasourceVcdSolutionLandingZone() *schema.Resource {
return &schema.Resource{
ReadContext: datasourceVcdSolutionLandingZoneRead,

Schema: map[string]*schema.Schema{
"org": {
Type: schema.TypeString,
Optional: true,
Description: "The name of organization to use, optional if defined at provider " +
"level. Useful when connected as sysadmin working across different organizations",
},
"state": {
Type: schema.TypeString,
Description: "State reports RDE state",
Computed: true,
},
"catalog": {
Type: schema.TypeSet,
Computed: true,
Description: "Catalog definition for storing executable .ISO files",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Description: "ID of catalog",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Catalog Name",
},
"capabilities": {
Type: schema.TypeSet,
Computed: true,
Description: "Capability set for catalog",
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
},

"vdc": {
Type: schema.TypeSet,
Computed: true,
Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Description: "VDC ID",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "VDC Name",
},
"is_default": {
Type: schema.TypeBool,
Computed: true,
Description: "Defines if this VDC should be treated as the default one",
},
"capabilities": {
Type: schema.TypeSet,
Computed: true,
Description: "Set of capabilities of the VDC",
Elem: &schema.Schema{Type: schema.TypeString},
},
"org_vdc_network": dsSlzChildComponent("Org VDC Network"),
"storage_policy": dsSlzChildComponent("Storage Policy"),
"compute_policy": dsSlzChildComponent("Compute Policy"),
},
},
},
},
}
}

func datasourceVcdSolutionLandingZoneRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
vcdClient := meta.(*VCDClient)
if vcdClient.Client.APIVCDMaxVersionIs("< 37.1") {
return diag.Errorf("Solution Landing Zones are supported in VCD 10.4.1+")
}

slz, err := vcdClient.GetExactlyOneSolutionLandingZone()
if err != nil {
return diag.Errorf("error retrieving Solution Landing Zone: %s", err)
}

err = setSlzData(d, slz)
if err != nil {
return diag.Errorf("error storing data to schema: %s", err)
}

// The real ID of Solution Landing Zone is RDE ID
d.SetId(slz.RdeId())

return nil
}
2 changes: 2 additions & 0 deletions vcd/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ var globalDataSourceMap = map[string]*schema.Resource{
"vcd_vm_vgpu_policy": datasourceVcdVmVgpuPolicy(), // 3.11
"vcd_cse_kubernetes_cluster": datasourceVcdCseKubernetesCluster(), // 3.12
"vcd_version": datasourceVcdVersion(), // 3.12
"vcd_solution_landing_zone": datasourceVcdSolutionLandingZone(), // 3.13
}

var globalResourceMap = map[string]*schema.Resource{
Expand Down Expand Up @@ -265,6 +266,7 @@ var globalResourceMap = map[string]*schema.Resource{
"vcd_nsxt_edgegateway_dns": resourceVcdNsxtEdgeGatewayDns(), // 3.11
"vcd_vm_vgpu_policy": resourceVcdVmVgpuPolicy(), // 3.11
"vcd_cse_kubernetes_cluster": resourceVcdCseKubernetesCluster(), // 3.12
"vcd_solution_landing_zone": resourceVcdSolutionLandingZone(), // 3.13
}

// Provider returns a terraform.ResourceProvider.
Expand Down
18 changes: 18 additions & 0 deletions vcd/remove_leftovers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ var alsoDelete = entityList{
{Type: "vcd_vapp", Name: "Vapp-AC-2", Comment: "from vcd.TestAccVcdVappAccessControl-update.tf: Vapp-AC-2"},
{Type: "vcd_vapp", Name: "Vapp-AC-3", Comment: "from vcd.TestAccVcdVappAccessControl-update.tf: Vapp-AC-3"},
{Type: "vcd_org_vdc", Name: "ForInternalDiskTest", Comment: "from vcd.TestAccVcdVmInternalDisk-CreateALl.tf: ForInternalDiskTest"},
{Type: "vcd_solution_landing_zone", Name: "urn:vcloud:type:vmware:solutions_organization:1.0.0", Comment: "Solution Landing Zone"},
}

// isTest is a regular expression that tells if an entity needs to be deleted
Expand Down Expand Up @@ -115,6 +116,23 @@ func removeLeftovers(govcdClient *govcd.VCDClient, verbose bool) error {
}
}

// --------------------------------------------------------------
// Solution Landing Zone (SLZ)
// --------------------------------------------------------------
if govcdClient.Client.IsSysAdmin {
allSlzs, err := govcdClient.GetAllSolutionLandingZones(nil)
if err != nil {
return fmt.Errorf("error retrieving all SLZs: %s", err)
}
for _, slz := range allSlzs {
_ = shouldDeleteEntity(alsoDelete, doNotDelete, slz.DefinedEntity.DefinedEntity.EntityType, "vcd_solution_landing_zone", 0, verbose)
err := slz.Delete()
if err != nil {
return fmt.Errorf("error removing SLZ: %s", err)
}
}
}

// --------------------------------------------------------------
// Provider VDCs
// --------------------------------------------------------------
Expand Down
Loading

0 comments on commit 5be38c1

Please sign in to comment.