Skip to content

Commit 9e0628d

Browse files
committed
feat: add d/vra_load_balancer
Adds support for `d/vra_load_balancer`. Signed-off-by: Ryan Johnson <[email protected]>
1 parent 52153d0 commit 9e0628d

File tree

5 files changed

+425
-10
lines changed

5 files changed

+425
-10
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
page_title: "VMware vRealize Automation: vra_load_balancer"
3+
description: |-
4+
Provides a data source for a load balancer resource.
5+
---
6+
7+
# Data Source: vra_load_balancer
8+
9+
Provides a data source to retrieve a `vra_load_balancer`.
10+
11+
## Example Usage
12+
13+
This is an example of how to get a load balancer resource by its id.
14+
15+
```hcl
16+
data "vra_load_balancer" "this" {
17+
id = "load-balancer-id"
18+
}
19+
20+
output "load_balancer_name" {
21+
value = data.vra_load_balancer.this.name
22+
}
23+
24+
## Argument Reference
25+
26+
* `id` - (Required) The id of the load balancer.
27+
28+
## Attribute Reference
29+
30+
* `address` - Primary address allocated or in use by this load balancer. The address could be an in the form of a publicly resolvable DNS name or an IP address.
31+
32+
* `created_at` - Date when the entity was created. The date is in ISO 6801 and UTC.
33+
34+
* `custom_properties` - A set of custom properties that were set on this resource instance. This is a key-value pair where the key is a string and the value can be any string.
35+
36+
* `description` - Description of the load balancer.
37+
38+
* `deployment_id` - The id of the deployment that is associated with this resource.
39+
40+
* `external_id` - External entity Id on the provider side.
41+
42+
* `external_region_id` - The external regionId of the resource.
43+
44+
* `external_zone_id` - The external regionId of the resource.
45+
46+
* `links` - HATEOAS of the entity.
47+
48+
* `name` - Name of the load balancer.
49+
50+
* `organization_id` - The id of the organization this entity belongs to.
51+
52+
* `owner` - Email of the user that owns the entity.
53+
54+
* `project_id` - The id of the project that is associated with this resource.
55+
56+
* `routes` - The load balancer route configuration regarding ports and protocols.
57+
58+
* `algorithm` - Algorithm employed for load balancing.
59+
60+
* `algorithm_parameters` - Parameters need for load balancing algorithm.Use newline to separate multiple parameters.
61+
62+
* `health_check_configuration` - Load balancer health check configuration.
63+
64+
* `healthy_threshold` - Number of consecutive successful checks before considering a particular back-end instance as healthy.
65+
66+
* `http_method` - HTTP or HTTPS method to use when sending a health check request.
67+
68+
* `interval_seconds` - Interval (in seconds) at which the health checks will be performed.
69+
70+
* `passive_monitor` - Enable passive monitor mode. This setting only applies to NSX-T.
71+
72+
* `port` - Port on the back-end instance machine to use for the health check.
73+
74+
* `protocol` - The protocol used for the health check.
75+
76+
* `request_body` - Request body. Used by HTTP, HTTPS, TCP, UDP.
77+
78+
* `response_body` - Expected response body. Used by HTTP, HTTPS, TCP, UDP.
79+
80+
* `timeout_seconds` - Timeout (in seconds) to wait for a response from the back-end instance.
81+
82+
* `unhealthy_threashold` - Number of consecutive check failures before considering a particular back-end instance as unhealthy.
83+
84+
* `urlPath` - URL path on the back-end instance against which a request will be performed for the health check. Useful when the health check protocol is HTTP/HTTPS.
85+
86+
* `member_port` - Member port where the traffic is routed to.
87+
88+
* `member_protocol` - The protocol of the member traffic.
89+
90+
* `port` - Port which the load balancer is listening to.
91+
92+
* `protocol` - The protocol of the incoming load balancer requests.
93+
94+
* `targets` - A list of links to target load balancer pool members. Links can be to either a machine or a machine's network interface.
95+
96+
* `tags` - A set of tag keys and optional values that were set on this resource instance.
97+
* `key` - Tag’s key.
98+
* `value` - Tag’s value.
99+
100+
* `updated_at` - Date when the entity was last updated. The date is ISO 8601 and UTC.

vra/data_source_load_balancer.go

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// © Broadcom. All Rights Reserved.
2+
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+
// SPDX-License-Identifier: MPL-2.0
4+
5+
package vra
6+
7+
import (
8+
"context"
9+
"log"
10+
11+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
12+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
13+
"github.com/vmware/vra-sdk-go/pkg/client/load_balancer"
14+
)
15+
16+
func dataSourceLoadBalancer() *schema.Resource {
17+
return &schema.Resource{
18+
ReadContext: dataSourceLoadBalancerRead,
19+
20+
Schema: map[string]*schema.Schema{
21+
"id": {
22+
Type: schema.TypeString,
23+
Required: true,
24+
},
25+
"name": {
26+
Type: schema.TypeString,
27+
Computed: true,
28+
},
29+
"nics": nicsSchema(false),
30+
"project_id": {
31+
Type: schema.TypeString,
32+
Computed: true,
33+
},
34+
"routes": routesSchema(false),
35+
"custom_properties": {
36+
Type: schema.TypeMap,
37+
Computed: true,
38+
},
39+
"description": {
40+
Type: schema.TypeString,
41+
Computed: true,
42+
},
43+
"deployment_id": {
44+
Type: schema.TypeString,
45+
Computed: true,
46+
},
47+
"internet_facing": {
48+
Type: schema.TypeBool,
49+
Computed: true,
50+
},
51+
"tags": tagsSchema(),
52+
"targets": LoadBalancerTargetSchema(),
53+
"address": {
54+
Type: schema.TypeString,
55+
Computed: true,
56+
},
57+
"created_at": {
58+
Type: schema.TypeString,
59+
Computed: true,
60+
},
61+
"external_id": {
62+
Type: schema.TypeString,
63+
Computed: true,
64+
},
65+
"external_region_id": {
66+
Type: schema.TypeString,
67+
Computed: true,
68+
},
69+
"external_zone_id": {
70+
Type: schema.TypeString,
71+
Computed: true,
72+
},
73+
"links": linksSchema(),
74+
"organization_id": {
75+
Type: schema.TypeString,
76+
Computed: true,
77+
},
78+
"owner": {
79+
Type: schema.TypeString,
80+
Computed: true,
81+
},
82+
"updated_at": {
83+
Type: schema.TypeString,
84+
Computed: true,
85+
},
86+
},
87+
}
88+
}
89+
90+
func dataSourceLoadBalancerRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
91+
apiClient := m.(*Client).apiClient
92+
93+
id := d.Get("id").(string)
94+
resp, err := apiClient.LoadBalancer.GetLoadBalancer(load_balancer.NewGetLoadBalancerParams().WithID(id))
95+
if err != nil {
96+
return diag.FromErr(err)
97+
}
98+
99+
loadBalancer := *resp.Payload
100+
d.SetId(id)
101+
d.Set("address", loadBalancer.Address)
102+
d.Set("created_at", loadBalancer.CreatedAt)
103+
d.Set("custom_properties", loadBalancer.CustomProperties)
104+
d.Set("description", loadBalancer.Description)
105+
d.Set("deployment_id", loadBalancer.DeploymentID)
106+
d.Set("external_id", loadBalancer.ExternalID)
107+
d.Set("external_region_id", loadBalancer.ExternalRegionID)
108+
d.Set("external_zone_id", loadBalancer.ExternalZoneID)
109+
d.Set("name", loadBalancer.Name)
110+
d.Set("organization_id", loadBalancer.OrgID)
111+
d.Set("owner", loadBalancer.Owner)
112+
d.Set("project_id", loadBalancer.ProjectID)
113+
d.Set("updated_at", loadBalancer.UpdatedAt)
114+
115+
if err := d.Set("tags", flattenTags(loadBalancer.Tags)); err != nil {
116+
return diag.Errorf("error setting load balancer tags - error: %v", err)
117+
}
118+
if err := d.Set("routes", flattenRoutes(loadBalancer.Routes)); err != nil {
119+
return diag.Errorf("error setting load balancer routes - error: %v", err)
120+
}
121+
122+
if err := d.Set("links", flattenLinks(loadBalancer.Links)); err != nil {
123+
return diag.Errorf("error setting load balancer links - error: %#v", err)
124+
}
125+
126+
log.Printf("Finished reading the vra_load_balancer data source with id %s", d.Get("id"))
127+
return nil
128+
}

0 commit comments

Comments
 (0)