From f6810b71d7726091882de8f80420173fa830e981 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mateusz=20=C5=81api=C5=84ski?=
<51078264+lapson97@users.noreply.github.com>
Date: Tue, 2 Jan 2024 09:11:22 +0100
Subject: [PATCH] GCLOUD2-12605: IPv6/dual-stack support, vrrp ips schema
including (#54)
* IPv6/dual-stack support, vrrp ips schema including
* Included vip ip family in loadbalancer response
* Updated docs
* Used enum values for ip family output
---
docs/data-sources/loadbalancerv2.md | 11 +++++++
docs/resources/lblistener.md | 2 +-
docs/resources/lbpool.md | 2 +-
docs/resources/loadbalancerv2.md | 1 +
gcore/data_source_gcore_loadbalancerv2.go | 37 ++++++++++++++++++++++-
gcore/resource_gcore_loadbalancerv2.go | 18 +++++++++++
go.mod | 2 +-
go.sum | 2 ++
8 files changed, 71 insertions(+), 4 deletions(-)
diff --git a/docs/data-sources/loadbalancerv2.md b/docs/data-sources/loadbalancerv2.md
index 57d9351..367de3a 100644
--- a/docs/data-sources/loadbalancerv2.md
+++ b/docs/data-sources/loadbalancerv2.md
@@ -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))
### Nested Schema for `metadata_read_only`
@@ -67,3 +69,12 @@ Read-Only:
- `key` (String)
- `read_only` (Boolean)
- `value` (String)
+
+
+
+### Nested Schema for `vrrp_ips`
+
+Read-Only:
+
+- `ip_address` (String)
+- `subnet_id` (String)
diff --git a/docs/resources/lblistener.md b/docs/resources/lblistener.md
index b92f089..5682264 100644
--- a/docs/resources/lblistener.md
+++ b/docs/resources/lblistener.md
@@ -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
diff --git a/docs/resources/lbpool.md b/docs/resources/lbpool.md
index 4064188..79daef0 100644
--- a/docs/resources/lbpool.md
+++ b/docs/resources/lbpool.md
@@ -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
diff --git a/docs/resources/loadbalancerv2.md b/docs/resources/loadbalancerv2.md
index d9c68c6..1a93dd4 100644
--- a/docs/resources/loadbalancerv2.md
+++ b/docs/resources/loadbalancerv2.md
@@ -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)
diff --git a/gcore/data_source_gcore_loadbalancerv2.go b/gcore/data_source_gcore_loadbalancerv2.go
index 308fc55..e437cd2 100644
--- a/gcore/data_source_gcore_loadbalancerv2.go
+++ b/gcore/data_source_gcore_loadbalancerv2.go
@@ -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 {
@@ -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,
@@ -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
diff --git a/gcore/resource_gcore_loadbalancerv2.go b/gcore/resource_gcore_loadbalancerv2.go
index edb82d8..84c704a 100644
--- a/gcore/resource_gcore_loadbalancerv2.go
+++ b/gcore/resource_gcore_loadbalancerv2.go
@@ -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"
)
@@ -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,
@@ -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 {
@@ -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())
diff --git a/go.mod b/go.mod
index bf94bc0..1504fe2 100644
--- a/go.mod
+++ b/go.mod
@@ -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
diff --git a/go.sum b/go.sum
index f7b72da..920eeaf 100644
--- a/go.sum
+++ b/go.sum
@@ -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=