Skip to content

Commit

Permalink
Add support for Service Engine Group assignment to NSX-T Edge Gateway (
Browse files Browse the repository at this point in the history
…#738)

This PR adds resource and datasource to manage NSX-T ALB Service Engine Group assignment to Edge Gateways. It is named quite lengthy vcd_nsxt_alb_edgegateway_service_engine_group, but should reflect that this resource handle Service Engine Group assignments to Edge gateways as opposed to resource vcd_nsxt_alb_service_engine_group defining Service Engine Groups for provider in general.
  • Loading branch information
Didainius authored Nov 19, 2021
1 parent 4c429e5 commit 72cb07a
Show file tree
Hide file tree
Showing 14 changed files with 790 additions and 132 deletions.
4 changes: 4 additions & 0 deletions .changes/v3.5.0/738-features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* **New Resource:** `vcd_nsxt_alb_edgegateway_service_engine_group` for managing NSX-T ALB Service Engine Groups
assignments to Edge Gateways [GH-738]
* **New Data source:** `vcd_nsxt_alb_edgegateway_service_engine_group` for reading NSX-T ALB Service Engine Groups
assignments to Edge Gateways [GH-738]
5 changes: 2 additions & 3 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# These owners will be the default owners for everything in the repo. Unless a later match takes
# precedence, @lvirbalas, @dataclouder, and @Didainius will be requested for review when someone
# opens a pull request.
* @lvirbalas @dataclouder @Didainius
# precedence all these users will be requested for review when someone opens a pull request.
* @lvirbalas @dataclouder @Didainius @vbauzysvmware
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Terraform vCloud Director Provider
Terraform VMware Cloud Director Provider
==================

The official Terraform provider for [VMware vCloud Director](https://www.vmware.com/products/vcloud-director.html)
The official Terraform provider for [VMware Cloud Director](https://www.vmware.com/products/cloud-director.html)

- Documentation of the latest binary release available at https://www.terraform.io/docs/providers/vcd/index.html
- Documentation of the latest binary release available at https://registry.terraform.io/providers/vmware/vcd/latest/docs
- This project is using [go-vcloud-director](https://github.com/vmware/go-vcloud-director) Golang SDK for making API calls to vCD
- Join through [VMware {code}](https://code.vmware.com/) to [![Chat](https://img.shields.io/badge/chat-on%20slack-brightgreen.svg)](https://vmwarecode.slack.com/messages/CBBBXVB16) in #vcd-terraform-dev channel

Expand All @@ -13,8 +13,9 @@ Part of Terraform
- Website: https://www.terraform.io
- [![Gitter chat](https://badges.gitter.im/hashicorp-terraform/Lobby.png)](https://gitter.im/hashicorp-terraform/Lobby)
- Mailing list: [Google Groups](http://groups.google.com/group/terraform-tool)
- [Hashicorp Discuss](https://discuss.hashicorp.com/c/terraform-core/27)

<img src="https://cdn.rawgit.com/hashicorp/terraform-website/master/content/source/assets/images/logo-hashicorp.svg" width="600px">
<img src="https://www.datocms-assets.com/2885/1629941242-logo-terraform-main.svg" width="600px">

Requirements
------------
Expand All @@ -24,9 +25,10 @@ Requirements

Building The Provider (the modules way)
--------------------------------------
**Note.** You *only* need to build the provider plugin if you want to *develop* it. Refer to [documentation](https://www.terraform.io/docs/providers/vcd/) for using it. Terraform will
automatically download officially released binaries of this provider plugin on the first run of
`terraform init` command.
**Note.** You *only* need to build the provider plugin if you want to *develop* it. Refer to
[documentation](https://registry.terraform.io/providers/vmware/vcd/latest/docs) for using it. Terraform will
automatically download officially released binaries of this provider plugin on the first run of `terraform init`
command.

Starting with version 2.1 provider started using [Go modules](https://github.com/golang/go/wiki/Modules)
This means that it is no longer necessary to be in GOPATH.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ require (
github.com/hashicorp/go-version v1.3.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.7.0
github.com/kr/pretty v0.2.1
github.com/vmware/go-vcloud-director/v2 v2.14.0-alpha.2
github.com/vmware/go-vcloud-director/v2 v2.14.0-alpha.4
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ 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.2 h1:yg3+XMstvuGAMe1tc7qkqQ55tN8e2x7SOTAiUMBidyA=
github.com/vmware/go-vcloud-director/v2 v2.14.0-alpha.2/go.mod h1:2BS1yw61VN34WI0/nUYoInFvBc3Zcuf84d4ESiAAl68=
github.com/vmware/go-vcloud-director/v2 v2.14.0-alpha.4 h1:onOig+mUHFd3fcFsRNYW0W/rMd4EWXV+rVS0NBAiFPM=
github.com/vmware/go-vcloud-director/v2 v2.14.0-alpha.4/go.mod h1:2BS1yw61VN34WI0/nUYoInFvBc3Zcuf84d4ESiAAl68=
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_edgegateway_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
88 changes: 88 additions & 0 deletions vcd/datasource_vcd_nsxt_alb_edgegateway_service_engine_group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
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 datasourceVcdAlbEdgeGatewayServiceEngineGroup() *schema.Resource {
return &schema.Resource{
ReadContext: datasourceVcdAlbEdgeGatewayServiceEngineGroupRead,

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 datasourceVcdAlbEdgeGatewayServiceEngineGroupRead(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 to Edge Gateway: %s", err)
}

if len(edgeAlbServiceEngineAssignments) == 0 {
return diag.FromErr(govcd.ErrorEntityNotFound)
}

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

setAlbServiceEngineGroupAssignmentData(d, edgeAlbServiceEngineAssignments[0].NsxtAlbServiceEngineGroupAssignment)
d.SetId(edgeAlbServiceEngineAssignments[0].NsxtAlbServiceEngineGroupAssignment.ID)
return nil
}
Loading

0 comments on commit 72cb07a

Please sign in to comment.