Skip to content

Commit

Permalink
Add support for Service Engine Groupp assignment to NSX-T Edge Gateway
Browse files Browse the repository at this point in the history
Signed-off-by: Dainius Serplis <[email protected]>
  • Loading branch information
Didainius committed Nov 8, 2021
1 parent de4dea3 commit d1f38c2
Show file tree
Hide file tree
Showing 11 changed files with 740 additions and 119 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ require (
github.com/kr/pretty v0.2.1
github.com/vmware/go-vcloud-director/v2 v2.14.0-alpha.1
)

replace github.com/vmware/go-vcloud-director/v2 => github.com/Didainius/go-vcloud-director/v2 v2.12.1-0.20211108064041-ca6c651ffe3f
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Didainius/go-vcloud-director/v2 v2.12.1-0.20211108064041-ca6c651ffe3f h1:6jLur7/+Tl6JkEJEn3UMW32ig8cDI27YlbWyluyJmQQ=
github.com/Didainius/go-vcloud-director/v2 v2.12.1-0.20211108064041-ca6c651ffe3f/go.mod h1:poaOwg7CoXO4m9Pv4TVhMpNF1wQQwKzxpdGYTfjzajs=
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=
Expand Down Expand Up @@ -311,8 +313,6 @@ github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaU
github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4=
github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
github.com/vmware/go-vcloud-director/v2 v2.14.0-alpha.1 h1:dKchqU6rPrT77a/zqjyiF7iBq8iFr2NIdDehIhup9WI=
github.com/vmware/go-vcloud-director/v2 v2.14.0-alpha.1/go.mod h1:poaOwg7CoXO4m9Pv4TVhMpNF1wQQwKzxpdGYTfjzajs=
github.com/xanzy/ssh-agent v0.3.0 h1:wUMzuKtKilRgBAD1sUb8gOwwRr2FGoBVumcjoOACClI=
github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
4 changes: 3 additions & 1 deletion vcd/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func testSpecificDataSourceNotFound(t *testing.T, dataSourceName string, vcdClie
t.Skip(`No NSX-T configuration detected or not running as System user`)
case dataSourceName == "vcd_nsxt_alb_controller" || dataSourceName == "vcd_nsxt_alb_cloud" ||
dataSourceName == "vcd_nsxt_alb_importable_cloud" || dataSourceName == "vcd_nsxt_alb_service_engine_group" ||
dataSourceName == "vcd_nsxt_alb_settings":
dataSourceName == "vcd_nsxt_alb_settings" || dataSourceName == "vcd_nsxt_alb_edge_service_engine_group":
skipNoNsxtAlbConfiguration(t)
if !usingSysAdmin() {
t.Skip(`Works only with system admin privileges`)
Expand Down Expand Up @@ -159,6 +159,8 @@ func addMandatoryParams(dataSourceName string, mandatoryFields []string, t *test
return ""
}
templateFields = templateFields + `edge_gateway_id = "` + nsxtEdgeGw.EdgeGateway.ID + `"` + "\n"
case "service_engine_group_id":
templateFields = templateFields + `service_engine_group_id = "does-not-exist"` + "\n"
case "catalog":
templateFields = templateFields + `catalog = "` + testConfig.VCD.Catalog.Name + `"` + "\n"
case "vapp_name":
Expand Down
90 changes: 90 additions & 0 deletions vcd/datasource_vcd_nsxt_alb_edge_service_engine_group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package vcd

import (
"context"
"fmt"
"net/url"

"github.com/vmware/go-vcloud-director/v2/govcd"

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

func datasourceVcdAlbServiceEngineGroupAssignment() *schema.Resource {
return &schema.Resource{
ReadContext: datasourceVcdAlbServiceEngineGroupAssignmentRead,

Schema: map[string]*schema.Schema{
"org": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "The name of organization to use, optional if defined at provider " +
"level. Useful when connected as sysadmin working across different organizations",
},
"vdc": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "The name of VDC to use, optional if defined at provider level",
},
"edge_gateway_id": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Edge Gateway ID in which ALB Service Engine Group should be located",
},
"service_engine_group_id": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Edge Gateway ID in which ALB Service Engine Group should be located",
},
"max_virtual_services": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Description: "Maximum number of virtual services to be used in this Service Engine Group",
},
"reserved_virtual_services": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Description: "Number of reserved virtual services for this Service Engine Group",
},
"deployed_virtual_services": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Description: "Number of reserved deployed virtual services for this Service Engine Group",
},
},
}
}

func datasourceVcdAlbServiceEngineGroupAssignmentRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
vcdClient := meta.(*VCDClient)

edgeGatewayId := d.Get("edge_gateway_id").(string)
serviceEngineGroupId := d.Get("service_engine_group_id")

queryParams := url.Values{}
queryParams.Add("filter", fmt.Sprintf("gatewayRef.id==%s;serviceEngineGroupRef.id==%s", edgeGatewayId, serviceEngineGroupId))

edgeAlbServiceEngineAssignments, err := vcdClient.GetAllAlbServiceEngineGroupAssignments(queryParams)
if err != nil {
return diag.Errorf("error reading ALB Service Engine Group Assignment: %s", err)
}

if len(edgeAlbServiceEngineAssignments) == 0 {
return diag.Errorf("%s", govcd.ErrorEntityNotFound)
}

if len(edgeAlbServiceEngineAssignments) > 1 {
return diag.Errorf("more than one Service Engine Group assignment found (%d)", len(edgeAlbServiceEngineAssignments))
}

setNsxtAlbServiceEngineGroupAssignmentData(d, edgeAlbServiceEngineAssignments[0].NsxtAlbServiceEngineGroupAssignment)

d.SetId(edgeAlbServiceEngineAssignments[0].NsxtAlbServiceEngineGroupAssignment.ID)

return nil
}
Loading

0 comments on commit d1f38c2

Please sign in to comment.