Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resource to manage solution landing zone [1] #1251

Merged
merged 13 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 zones [GH-1251]
* **New Data Source:** `vcd_solution_landing_zone` to read solution add-on landing zones [GH-1251]
dataclouder marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,5 @@ require (
google.golang.org/grpc v1.60.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)

replace github.com/vmware/go-vcloud-director/v2 => github.com/Didainius/go-vcloud-director/v2 v2.17.0-alpha.2.0.20240507112434-a7d21821fbd3
Didainius marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
github.com/Didainius/go-vcloud-director/v2 v2.17.0-alpha.2.0.20240507112434-a7d21821fbd3 h1:saQXT3mWz8vjMae+GBP14Nzfcy+8n1xN91WAbiw6Xlg=
github.com/Didainius/go-vcloud-director/v2 v2.17.0-alpha.2.0.20240507112434-a7d21821fbd3/go.mod h1:NtFFjio08SkxTQH4j1U/SA8fNrh1tLGOhQC7lLNed+w=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 h1:kkhsdkhsCvIsutKu5zLMgWtgh9YxGCNAw8Ad8hjwfYg=
Expand Down Expand Up @@ -142,8 +144,6 @@ 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.24.0 h1:IjHISp/1Nk4bxtcA5Hx34w6J2haN/Hq66amw9XvTL54=
github.com/vmware/go-vcloud-director/v2 v2.24.0/go.mod h1:NyNcb2ymhrzwv4GyYXyYOm1NbqRwGNxDWn90AtWniXc=
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: "",
adambarreiro marked this conversation as resolved.
Show resolved Hide resolved
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: "Shows is the member is enabled or not",
lvirbalas marked this conversation as resolved.
Show resolved Hide resolved
},
"capabilities": {
Type: schema.TypeSet,
Computed: true,
Description: "",
adambarreiro marked this conversation as resolved.
Show resolved Hide resolved
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.Id())

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
Loading