Skip to content

Commit

Permalink
GCLOUD2-12605: IPv6/dual-stack support, vrrp ips schema including (#54)
Browse files Browse the repository at this point in the history
* IPv6/dual-stack support, vrrp ips schema including

* Included vip ip family in loadbalancer response

* Updated docs

* Used enum values for ip family output
  • Loading branch information
lapson97 authored Jan 2, 2024
1 parent 1aec39b commit f6810b7
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 4 deletions.
11 changes: 11 additions & 0 deletions docs/data-sources/loadbalancerv2.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ output "view" {
- `id` (String) The ID of this resource.
- `metadata_read_only` (List of Object) (see [below for nested schema](#nestedatt--metadata_read_only))
- `vip_address` (String)
- `vip_ip_family` (String)
- `vip_port_id` (String)
- `vrrp_ips` (List of Object) (see [below for nested schema](#nestedatt--vrrp_ips))

<a id="nestedatt--metadata_read_only"></a>
### Nested Schema for `metadata_read_only`
Expand All @@ -67,3 +69,12 @@ Read-Only:
- `key` (String)
- `read_only` (Boolean)
- `value` (String)


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

Read-Only:

- `ip_address` (String)
- `subnet_id` (String)
2 changes: 1 addition & 1 deletion docs/resources/lblistener.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ resource "gcore_lblistener" "listener" {

- `loadbalancer_id` (String)
- `name` (String)
- `protocol` (String) Available values is 'HTTP', 'HTTPS', 'TCP', 'UDP', 'TERMINATED_HTTPS'
- `protocol` (String) Available values are 'HTTP', 'HTTPS', 'TCP', 'UDP', 'TERMINATED_HTTPS', 'PROMETHEUS'
- `protocol_port` (Number)

### Optional
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/lbpool.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ resource "gcore_lbpool" "pl" {

- `lb_algorithm` (String) Available values is 'ROUND_ROBIN', 'LEAST_CONNECTIONS', 'SOURCE_IP', 'SOURCE_IP_PORT'
- `name` (String)
- `protocol` (String) Available values is 'HTTP' (currently work, other do not work on ed-8), 'HTTPS', 'TCP', 'UDP'
- `protocol` (String) Available values are 'HTTP' (currently work, other do not work on ed-8), 'HTTPS', 'TCP', 'UDP', 'PROXY'

### Optional

Expand Down
1 change: 1 addition & 0 deletions docs/resources/loadbalancerv2.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ resource "gcore_loadbalancerv2" "lb" {
- `region_id` (Number)
- `region_name` (String)
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
- `vip_ip_family` (String) Available values are 'ipv4', 'ipv6', 'dual'
- `vip_network_id` (String) Note: add all created `gcore_subnet` resources within the network with this id to the `depends_on` to be sure that `gcore_loadbalancerv2` will be destroyed first
- `vip_subnet_id` (String)

Expand Down
37 changes: 36 additions & 1 deletion gcore/data_source_gcore_loadbalancerv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package gcore

import (
"context"
"github.com/G-Core/gcorelabscloud-go/gcore/utils"
"log"

"github.com/G-Core/gcorelabscloud-go/gcore/utils"

"github.com/G-Core/gcorelabscloud-go/gcore/loadbalancer/v1/loadbalancers"
"github.com/G-Core/gcorelabscloud-go/gcore/loadbalancer/v1/types"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

func dataSourceLoadBalancerV2() *schema.Resource {
Expand Down Expand Up @@ -60,6 +63,28 @@ func dataSourceLoadBalancerV2() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"vrrp_ips": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ip_address": {
Type: schema.TypeString,
Computed: true,
},
"subnet_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"vip_ip_family": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Optional: true,
ValidateFunc: validation.StringInSlice(types.IPFamilyType("").StringList(), false),
},
"metadata_k": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -142,12 +167,22 @@ func dataSourceLoadBalancerV2Read(ctx context.Context, d *schema.ResourceData, m
return diag.Errorf("load balancer with name %s not found", name)
}

vrrpIps := make([]map[string]string, len(lb.VrrpIPs))
for i, vrrpIp := range lb.VrrpIPs {
v := map[string]string{"subnet_id": "", "ip_address": ""}
v["subnet_id"] = vrrpIp.SubnetID
v["ip_address"] = vrrpIp.IpAddress.String()
vrrpIps[i] = v
}

d.SetId(lb.ID)
d.Set("project_id", lb.ProjectID)
d.Set("region_id", lb.RegionID)
d.Set("name", lb.Name)
d.Set("vip_address", lb.VipAddress.String())
d.Set("vip_port_id", lb.VipPortID)
d.Set("vrrp_ips", vrrpIps)
d.Set("vip_ip_family", lb.VipIPFamilyType)

log.Println("[DEBUG] Finish LoadBalancer reading")
return diags
Expand Down
18 changes: 18 additions & 0 deletions gcore/resource_gcore_loadbalancerv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"time"

"github.com/G-Core/gcorelabscloud-go/gcore/loadbalancer/v1/loadbalancers"
"github.com/G-Core/gcorelabscloud-go/gcore/loadbalancer/v1/types"
"github.com/G-Core/gcorelabscloud-go/gcore/task/v1/tasks"
"github.com/G-Core/gcorelabscloud-go/gcore/utils"
"github.com/G-Core/gcorelabscloud-go/gcore/utils/metadata/v1/metadata"
"github.com/hashicorp/go-cty/cty"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down Expand Up @@ -109,6 +111,19 @@ func resourceLoadBalancerV2() *schema.Resource {
Description: "Load balancer Port ID",
Computed: true,
},
"vip_ip_family": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: fmt.Sprintf("Available values are '%s', '%s', '%s'", types.IPv4IPFamilyType, types.IPv6IPFamilyType, types.DualStackIPFamilyType),
ValidateDiagFunc: func(val interface{}, key cty.Path) diag.Diagnostics {
v := val.(string)
switch types.IPFamilyType(v) {
case types.IPv4IPFamilyType, types.IPv6IPFamilyType, types.DualStackIPFamilyType:
return diag.Diagnostics{}
}
return diag.Errorf("wrong type %s, available values are '%s', '%s', '%s'", v, types.IPv4IPFamilyType, types.IPv6IPFamilyType, types.DualStackIPFamilyType)
},
},
"last_updated": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -160,6 +175,7 @@ func resourceLoadBalancerV2Create(ctx context.Context, d *schema.ResourceData, m
Name: d.Get("name").(string),
VipNetworkID: d.Get("vip_network_id").(string),
VipSubnetID: d.Get("vip_subnet_id").(string),
VIPIPFamily: types.IPFamilyType(d.Get("vip_ip_family").(string)),
}

if metadataRaw, ok := d.GetOk("metadata_map"); ok {
Expand Down Expand Up @@ -224,6 +240,8 @@ func resourceLoadBalancerV2Read(ctx context.Context, d *schema.ResourceData, m i
d.Set("name", lb.Name)
d.Set("flavor", lb.Flavor.FlavorName)
d.Set("vip_port_id", lb.VipPortID)
d.Set("vrrp_ips", lb.VrrpIPs)
d.Set("vip_ip_family", lb.VipIPFamilyType)

if lb.VipAddress != nil {
d.Set("vip_address", lb.VipAddress.String())
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/G-Core/gcore-dns-sdk-go v0.2.7-0.20230801110428-99ef24b50d4d
github.com/G-Core/gcore-storage-sdk-go v0.1.34
github.com/G-Core/gcorelabscdn-go v1.0.1
github.com/G-Core/gcorelabscloud-go v0.6.15
github.com/G-Core/gcorelabscloud-go v0.6.18
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-sdk/v2 v2.27.0
github.com/mitchellh/mapstructure v1.5.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ github.com/G-Core/gcorelabscloud-go v0.6.2 h1:oCo3yurVnGKZLkRuQ7GVQK1LuLFEjq3mFW
github.com/G-Core/gcorelabscloud-go v0.6.2/go.mod h1:13Z1USxlxPbDFuYQyWqfNexlk4kUvOYTXbnvV/Z1lZo=
github.com/G-Core/gcorelabscloud-go v0.6.15 h1:lyzUPvQy7/KM0n4ErKpM4BpJA0iKrv82pHAimWfxNwA=
github.com/G-Core/gcorelabscloud-go v0.6.15/go.mod h1:13Z1USxlxPbDFuYQyWqfNexlk4kUvOYTXbnvV/Z1lZo=
github.com/G-Core/gcorelabscloud-go v0.6.18 h1:6Hw4H5fDNeawV9jkR5jhn0m8Z2lVMPZgRyuyzb2yivU=
github.com/G-Core/gcorelabscloud-go v0.6.18/go.mod h1:13Z1USxlxPbDFuYQyWqfNexlk4kUvOYTXbnvV/Z1lZo=
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc=
Expand Down

0 comments on commit f6810b7

Please sign in to comment.