Skip to content

Commit

Permalink
GCLOUD2-17284: Add preferred_connectivity field for lb operations (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
lapson97 authored Jan 16, 2025
1 parent 14393f3 commit 3d471a1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
6 changes: 6 additions & 0 deletions gcore/data_source_gcore_loadbalancerv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ func dataSourceLoadBalancerV2() *schema.Resource {
Optional: true,
ValidateFunc: validation.StringInSlice(types.IPFamilyType("").StringList(), false),
},
"preferred_connectivity": &schema.Schema{
Type: schema.TypeString,
Description: fmt.Sprintf("Available values are '%s', '%s'", types.PreferredConnectivityL2, types.PreferredConnectivityL3),
Computed: true,
},
"metadata_k": &schema.Schema{
Type: schema.TypeString,
Description: "Metadata string of the load balancer.",
Expand Down Expand Up @@ -200,6 +205,7 @@ func dataSourceLoadBalancerV2Read(ctx context.Context, d *schema.ResourceData, m
d.Set("vip_port_id", lb.VipPortID)
d.Set("vrrp_ips", vrrpIps)
d.Set("vip_ip_family", lb.VipIPFamilyType)
d.Set("preferred_connectivity", lb.PreferredConnectivity)

log.Println("[DEBUG] Finish LoadBalancer reading")
return diags
Expand Down
32 changes: 23 additions & 9 deletions gcore/resource_gcore_loadbalancerv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ func resourceLoadBalancerV2() *schema.Resource {
return diag.Errorf("wrong type %s, available values are '%s', '%s', '%s'", v, types.IPv4IPFamilyType, types.IPv6IPFamilyType, types.DualStackIPFamilyType)
},
},
"preferred_connectivity": &schema.Schema{
Type: schema.TypeString,
Description: fmt.Sprintf("Available values are '%s', '%s'", types.PreferredConnectivityL2, types.PreferredConnectivityL3),
Optional: true,
},
"last_updated": &schema.Schema{
Type: schema.TypeString,
Description: "Datetime when load balancer was updated at the last time.",
Expand Down Expand Up @@ -190,11 +195,12 @@ func resourceLoadBalancerV2Create(ctx context.Context, d *schema.ResourceData, m
}

opts := loadbalancers.CreateOpts{
Name: d.Get("name").(string),
VipNetworkID: d.Get("vip_network_id").(string),
VipSubnetID: d.Get("vip_subnet_id").(string),
VipPortID: d.Get("vip_port_id").(string),
VIPIPFamily: types.IPFamilyType(d.Get("vip_ip_family").(string)),
Name: d.Get("name").(string),
VipNetworkID: d.Get("vip_network_id").(string),
VipSubnetID: d.Get("vip_subnet_id").(string),
VipPortID: d.Get("vip_port_id").(string),
VIPIPFamily: types.IPFamilyType(d.Get("vip_ip_family").(string)),
PreferredConnectivity: types.PreferredConnectivityType(d.Get("preferred_connectivity").(string)),
}

if metadataRaw, ok := d.GetOk("metadata_map"); ok {
Expand Down Expand Up @@ -265,6 +271,7 @@ func resourceLoadBalancerV2Read(ctx context.Context, d *schema.ResourceData, m i
d.Set("vip_port_id", lb.VipPortID)
d.Set("vrrp_ips", lb.VrrpIPs)
d.Set("vip_ip_family", lb.VipIPFamilyType)
d.Set("preferred_connectivity", lb.PreferredConnectivity)

if lb.VipAddress != nil {
d.Set("vip_address", lb.VipAddress.String())
Expand Down Expand Up @@ -310,11 +317,18 @@ func resourceLoadBalancerV2Update(ctx context.Context, d *schema.ResourceData, m
return diag.FromErr(err)
}

var change bool
updateOpts := loadbalancers.UpdateOpts{}
if d.HasChange("name") {
opts := loadbalancers.UpdateOpts{
Name: d.Get("name").(string),
}
_, err = loadbalancers.Update(client, d.Id(), opts).Extract()
updateOpts.Name = d.Get("name").(string)
change = true
}
if d.HasChange("preferred_connectivity") {
updateOpts.PreferredConnectivity = d.Get("preferred_connectivity").(types.PreferredConnectivityType)
change = true
}
if change {
_, err = loadbalancers.Update(client, d.Id(), updateOpts).Extract()
if err != nil {
return diag.FromErr(err)
}
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.9
github.com/G-Core/gcore-storage-sdk-go v0.1.34
github.com/G-Core/gcorelabscdn-go v1.0.25
github.com/G-Core/gcorelabscloud-go v0.8.13
github.com/G-Core/gcorelabscloud-go v0.8.17
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
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ github.com/G-Core/gcorelabscdn-go v1.0.23 h1:mn/2BaqiBLux0k9/UDZ2OFMk+uCLTxO+1fL
github.com/G-Core/gcorelabscdn-go v1.0.23/go.mod h1:iSGXaTvZBzDHQW+rKFS918BgFVpONcyLEijwh8WsXpE=
github.com/G-Core/gcorelabscdn-go v1.0.25 h1:OS2uTmth12GzWw2tLeUFh4n9TUOie+gmE0e2cdg0EYk=
github.com/G-Core/gcorelabscdn-go v1.0.25/go.mod h1:iSGXaTvZBzDHQW+rKFS918BgFVpONcyLEijwh8WsXpE=
github.com/G-Core/gcorelabscloud-go v0.8.12 h1:qT8rrtSCXT+ol1g4zrl5JzWG+8IicHWCn7+U96tdlj4=
github.com/G-Core/gcorelabscloud-go v0.8.12/go.mod h1:13Z1USxlxPbDFuYQyWqfNexlk4kUvOYTXbnvV/Z1lZo=
github.com/G-Core/gcorelabscloud-go v0.8.13 h1:MpaT3owpIfbLP3EPZW+NDuxQfezN7FK6b+4VV0WILP8=
github.com/G-Core/gcorelabscloud-go v0.8.13/go.mod h1:13Z1USxlxPbDFuYQyWqfNexlk4kUvOYTXbnvV/Z1lZo=
github.com/G-Core/gcorelabscloud-go v0.8.17 h1:8411GSyVogvmIzQrqbzBhRxLXy86/0el+aJWSQjBMzE=
github.com/G-Core/gcorelabscloud-go v0.8.17/go.mod h1:13Z1USxlxPbDFuYQyWqfNexlk4kUvOYTXbnvV/Z1lZo=
github.com/Kunde21/markdownfmt/v3 v3.1.0 h1:KiZu9LKs+wFFBQKhrZJrFZwtLnCCWJahL+S+E/3VnM0=
github.com/Kunde21/markdownfmt/v3 v3.1.0/go.mod h1:tPXN1RTyOzJwhfHoon9wUr4HGYmWgVxSQN6VBJDkrVc=
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
Expand Down

0 comments on commit 3d471a1

Please sign in to comment.