Skip to content

Commit

Permalink
feat: Add resource cloudavenue_alb_virtual_service
Browse files Browse the repository at this point in the history
chore: enhancement testacc

feat: Add datasource `cloudavenue_alb_virtual_service`
  • Loading branch information
David MICHENEAU committed Dec 2, 2024
1 parent 540a9e7 commit ec1c2a3
Show file tree
Hide file tree
Showing 27 changed files with 3,014 additions and 412 deletions.
7 changes: 7 additions & 0 deletions .changelog/862.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:feature
`resource/cloudavenue_alb_virtual_service` - New resource for managing ALB virtual service.
```

```release-note:feature
`datasource/cloudavenue_alb_virtual_service` - New datasource to read ALB virtual service.
```
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,6 @@ linters-settings:
"NAT",
"VPN",
"BMS",
"SAML"
"SAML",
"ALB"
]
48 changes: 48 additions & 0 deletions docs/data-sources/alb_virtual_service.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "cloudavenue_alb_virtual_service Data Source - cloudavenue"
subcategory: ""
description: |-
Provides a VMware Cloud Director edge gateway load balancer virtual server data source
---

# cloudavenue_alb_virtual_service (Data Source)

Provides a VMware Cloud Director edge gateway load balancer virtual server data source



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `name` (String) The name of the ALB Virtual Service.

### Optional

- `certificate_id` (String) The ID of the certificate. The certificate must be uploaded to the NSX Advanced Load Balancer before it can be used. The certificate MUST'NT be expired.
- `description` (String) The description of the ALB Virtual Service.
- `edge_gateway_id` (String) The ID of the edge gateway on which the ALB Virtual Service is to be created.
- `edge_gateway_name` (String) The name of the edge gateway on which the ALB Virtual Service is to be created.
- `enabled` (Boolean) Defines if the ALB Virtual Service is enabled.
- `pool_id` (String) The ID of the ALB Server Pool associated.
- `pool_name` (String) The name of the ALB Server Pool associated.

### Read-Only

- `id` (String) The ID of the virtual service.
- `service_engine_group_name` (String) The name of the service Engine Group (Take the first one if not specified).
- `service_ports` (Attributes List) The service port of the ALB Virtual Service. The service port is the port on which the virtual service listens for client traffic. (see [below for nested schema](#nestedatt--service_ports))
- `service_type` (String) .
- `virtual_ip` (String) The virtual IP address of the ALB Virtual Service.

<a id="nestedatt--service_ports"></a>
### Nested Schema for `service_ports`

Read-Only:

- `port_end` (Number) The end port of the service port range. If not specified, only the `port_start` value is used.
- `port_ssl` (Boolean) Defines if the service port is SSL enabled.
- `port_start` (Number) The start port of the service port range or exact port number if `port_end`is not set.
- `port_type` (String) The type of the service port. The different modes that the NSX Advanced Load Balancer supports for handling TCP traffic and various parameters that can be tuned for optimization of the TCP traffic are also detailed here.
114 changes: 114 additions & 0 deletions docs/resources/alb_virtual_service.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
---
page_title: "cloudavenue_alb_virtual_service Resource - cloudavenue"
subcategory: "ALB (Advanced Load Balancer)"
description: |-
Provides a resource to manage ALB Virtual services in CloudAvenue. A virtual service advertises an IP address and ports to the external world and listens for client traffic. When a virtual service receives traffic, it directs it to members in ALB Pool.
---

# cloudavenue_alb_virtual_service (Resource)

Provides a resource to manage ALB Virtual services in CloudAvenue. A virtual service advertises an IP address and ports to the external world and listens for client traffic. When a virtual service receives traffic, it directs it to members in ALB Pool.

## Example Usage

```terraform
data "cloudavenue_edgegateway" "example" {
name = "tn01e02ocb0006205spt101"
}
resource "cloudavenue_alb_pool" "example" {
edge_gateway_id = data.cloudavenue_edgegateway.example.id
name = "albpool-name"
persistence_profile = {
type = "CLIENT_IP"
}
members = [
{
ip_address = "192.168.99.11"
port = "80"
},
{
ip_address = "192.168.10.2"
port = "80"
},
{
ip_address = "192.168.1.3"
port = "80"
}
]
health_monitors = ["TCP"]
}
resource "cloudavenue_alb_virtual_service" "example" {
name = "albvs-name"
description = "description"
edge_gateway_id = data.cloudavenue_edgegateway.example.id
enabled = true
pool_id = cloudavenue_alb_pool.example.id
virtual_ip = "192.168.10.10"
certificate_id = "urn:vcloud:certificateLibraryItem:f9caac3a-2555-477e-ae58-0740687d4daf"
service_type = "HTTPS"
service_ports = [
{
port_start = 443
port_type = "TCP_PROXY"
port_ssl = true
},
{
port_start = 8080
port_type = "TCP_PROXY"
port_ssl = true
},
{
port_start = 8088
port_type = "TCP_PROXY"
port_ssl = true
}
]
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `name` (String) The name of the ALB Virtual Service.
- `service_ports` (Attributes List) The service port of the ALB Virtual Service. The service port is the port on which the virtual service listens for client traffic. (see [below for nested schema](#nestedatt--service_ports))
- `service_type` (String) . Value must be one of: `HTTP` (If you choose "HTTP" you don't need to set the "port_type" and "ssl_enabled" attribute in "service_ports".), `HTTPS` (If you choose "HTTPS", you must provide a certificate ID and you don't need to set the "port_type" attribute in "service_ports".), `L4` (If you choose "L4", you can set a service "port_type" attribute in "service_ports.), `L4_TLS` (If you choose "L4_TLS", you must provide a certificate ID and you can set a service "port_type" attribute in "service_ports.).
- `virtual_ip` (String) The virtual IP address of the ALB Virtual Service.

### Optional

- `certificate_id` (String) The ID of the certificate. The certificate must be uploaded to the NSX Advanced Load Balancer before it can be used. The certificate MUST'NT be expired. If the value of [`<.service_type`](#<.service_type) attribute is one of `L4_TLS` or `HTTPS` this attribute is **REQUIRED**. If the value of [`<.service_ports[*].port_ssl`](#<.service_ports[*].port_ssl) attribute is `true` this attribute is **REQUIRED**.
- `description` (String) The description of the ALB Virtual Service.
- `edge_gateway_id` (String) (ForceNew) The ID of the edge gateway on which the ALB Virtual Service is to be created. Ensure that one and only one attribute from this collection is set : `edge_gateway_name`, `edge_gateway_id`.
- `edge_gateway_name` (String) (ForceNew) The name of the edge gateway on which the ALB Virtual Service is to be created. Ensure that one and only one attribute from this collection is set : `edge_gateway_name`, `edge_gateway_id`.
- `enabled` (Boolean) Defines if the ALB Virtual Service is enabled.
- `pool_id` (String) The ID of the ALB Server Pool associated. Ensure that one and only one attribute from this collection is set : `pool_name`, `pool_id`.
- `pool_name` (String) The name of the ALB Server Pool associated. Ensure that one and only one attribute from this collection is set : `pool_name`, `pool_id`.
- `service_engine_group_name` (String) The name of the service Engine Group (Take the first one if not specified).

### Read-Only

- `id` (String) The ID of the virtual service.

<a id="nestedatt--service_ports"></a>
### Nested Schema for `service_ports`

Required:

- `port_start` (Number) The start port of the service port range or exact port number if `port_end`is not set.

Optional:

- `port_end` (Number) The end port of the service port range. If not specified, only the `port_start` value is used.
- `port_ssl` (Boolean) Defines if the service port is SSL enabled. Value defaults to `false`.
- `port_type` (String) The type of the service port. The different modes that the NSX Advanced Load Balancer supports for handling TCP traffic and various parameters that can be tuned for optimization of the TCP traffic are also detailed here. Value must be one of: `TCP_PROXY` (The TCP proxy terminates client connections to the virtual service, processes the payload, and then opens a new TCP connection to the destination server. Any application data from the client that is destined for a server is forwarded to that server over the new server-side TCP connection. Separating (or proxying) the client-to-server connections enables the NSX Advanced Load Balancer to provide enhanced security, such as TCP protocol sanitization and denial of service (DoS) mitigation.), `TCP_FAST_PATH` (A TCP fast path profile does not proxy TCP connections. It directly connects clients to the destination server and translates the destination virtual service address of the client with the IP address of the chosen destination server. The source IP address of the client can be NATed to the IP address of the SE.), `UDP_FAST_PATH` (NSX Advanced Load Balancer translates the client’s destination virtual service address to the destination server and writes the source IP address of the client to the address of the SE, when forwarding the packet to the server. This ensures that server response traffic traverses symmetrically through the original SE.). If the value of [`service_type`](#service_type) attribute is `L4` this attribute is **REQUIRED**. If the value of [`service_type`](#service_type) attribute is one of `HTTP`, `HTTPS` or `L4_TLS` this attribute is **NULL**. Value defaults to `TCP_PROXY`.

## Import

Import is supported using the following syntax:
```shell
# use the edge_gateway_name.alb_pool_name to import the ALB Pool
terraform import cloudavenue_alb_virtual_service.test edge_gateway_nameOrID.alb_virtual_service_name
```
2 changes: 2 additions & 0 deletions examples/resources/cloudavenue_alb_virtual_service/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# use the edge_gateway_name.alb_pool_name to import the ALB Pool
terraform import cloudavenue_alb_virtual_service.test edge_gateway_nameOrID.alb_virtual_service_name
53 changes: 53 additions & 0 deletions examples/resources/cloudavenue_alb_virtual_service/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
data "cloudavenue_edgegateway" "example" {
name = "tn01e02ocb0006205spt101"
}

resource "cloudavenue_alb_pool" "example" {
edge_gateway_id = data.cloudavenue_edgegateway.example.id
name = "albpool-name"
persistence_profile = {
type = "CLIENT_IP"
}
members = [
{
ip_address = "192.168.99.11"
port = "80"
},
{
ip_address = "192.168.10.2"
port = "80"
},
{
ip_address = "192.168.1.3"
port = "80"
}
]
health_monitors = ["TCP"]
}
resource "cloudavenue_alb_virtual_service" "example" {
name = "albvs-name"
description = "description"
edge_gateway_id = data.cloudavenue_edgegateway.example.id
enabled = true
pool_id = cloudavenue_alb_pool.example.id
virtual_ip = "192.168.10.10"
certificate_id = "urn:vcloud:certificateLibraryItem:f9caac3a-2555-477e-ae58-0740687d4daf"
service_type = "HTTPS"
service_ports = [
{
port_start = 443
port_type = "TCP_PROXY"
port_ssl = true
},
{
port_start = 8080
port_type = "TCP_PROXY"
port_ssl = true
},
{
port_start = 8088
port_type = "TCP_PROXY"
port_ssl = true
}
]
}
2 changes: 1 addition & 1 deletion internal/provider/alb/pool_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var ErrPersistenceProfileIsEmpty = errors.New("persistence profile is empty")
type albPool interface {
GetID() string
GetName() string
GetAlbPool() (*govcd.NsxtAlbPool, error)
GetALBPool() (*govcd.NsxtAlbPool, error)
}

func processMembers(poolMembers []govcdtypes.NsxtAlbPoolMember) (members []member) {
Expand Down
30 changes: 15 additions & 15 deletions internal/provider/alb/pool_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,31 @@ import (
)

var (
_ datasource.DataSource = &albPoolDataSource{}
_ datasource.DataSourceWithConfigure = &albPoolDataSource{}
_ albPool = &albPoolDataSource{}
_ datasource.DataSource = &poolDataSource{}
_ datasource.DataSourceWithConfigure = &poolDataSource{}
_ albPool = &poolDataSource{}
)

func NewAlbPoolDataSource() datasource.DataSource {
return &albPoolDataSource{}
func NewPoolDataSource() datasource.DataSource {
return &poolDataSource{}
}

type albPoolDataSource struct {
type poolDataSource struct {
client *client.CloudAvenue
org org.Org
edgegw edgegw.BaseEdgeGW
albPool base
}

func (d *albPoolDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
func (d *poolDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_" + categoryName + "_pool"
}

func (d *albPoolDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
func (d *poolDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = albPoolSchema().GetDataSource(ctx)
}

func (d *albPoolDataSource) Init(ctx context.Context, dm *albPoolModel) (diags diag.Diagnostics) {
func (d *poolDataSource) Init(ctx context.Context, dm *albPoolModel) (diags diag.Diagnostics) {
d.albPool = base{
name: dm.Name.ValueString(),
id: dm.ID.ValueString(),
Expand All @@ -58,7 +58,7 @@ func (d *albPoolDataSource) Init(ctx context.Context, dm *albPoolModel) (diags d
return
}

func (d *albPoolDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
func (d *poolDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
// Prevent panic if the provider has not been configured.
if req.ProviderData == nil {
return
Expand All @@ -78,7 +78,7 @@ func (d *albPoolDataSource) Configure(ctx context.Context, req datasource.Config
d.client = client
}

func (d *albPoolDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
func (d *poolDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
defer metrics.New("data.cloudavenue_alb_pool", d.client.GetOrgName(), metrics.Read)()

var (
Expand All @@ -98,7 +98,7 @@ func (d *albPoolDataSource) Read(ctx context.Context, req datasource.ReadRequest
}

// Get albPool.
albPool, err := d.GetAlbPool()
albPool, err := d.GetALBPool()
if err != nil {
resp.Diagnostics.AddError("Unable to find ALB Pool", err.Error())
return
Expand Down Expand Up @@ -145,17 +145,17 @@ func (d *albPoolDataSource) Read(ctx context.Context, req datasource.ReadRequest
}

// GetID returns the ID of the albPool.
func (d *albPoolDataSource) GetID() string {
func (d *poolDataSource) GetID() string {
return d.albPool.id
}

// GetName returns the name of the albPool.
func (d *albPoolDataSource) GetName() string {
func (d *poolDataSource) GetName() string {
return d.albPool.name
}

// GetAlbPool returns the govcd.NsxtAlbPool.
func (d *albPoolDataSource) GetAlbPool() (*govcd.NsxtAlbPool, error) {
func (d *poolDataSource) GetALBPool() (*govcd.NsxtAlbPool, error) {
if d.GetID() != "" {
return d.client.Vmware.GetAlbPoolById(d.GetID())
}
Expand Down
Loading

0 comments on commit ec1c2a3

Please sign in to comment.