-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Service Engine Group assignment to NSX-T Edge Gateway (…
…#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
Showing
14 changed files
with
790 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
vcd/datasource_vcd_nsxt_alb_edgegateway_service_engine_group.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.