Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ELBv3] ability to change eip bandwidth inopentelekomcloud_lb_loadbalancer_v3 #1991

Merged
merged 4 commits into from Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 34 additions & 0 deletions docs/resources/lb_loadbalancer_v3.md
Expand Up @@ -87,6 +87,40 @@ resource "opentelekomcloud_lb_loadbalancer_v3" "lb_1" {
}
```

#### Assign new bandwidth to EIP without recreating

```hcl
resource "opentelekomcloud_lb_loadbalancer_v3" "loadbalancer_1" {
name = "loadbalancer_1"
router_id = data.opentelekomcloud_vpc_subnet_v1.shared_subnet.vpc_id
network_ids = [data.opentelekomcloud_vpc_subnet_v1.shared_subnet.network_id]

availability_zones = ["eu-de-01"]

public_ip {
ip_type = "5_gray"
bandwidth_name = "lb_band"
bandwidth_size = 10
bandwidth_share_type = "PER"
}

tags = {
muh = "value-create"
kuh = "value-create"
}
}

resource "opentelekomcloud_vpc_bandwidth_v2" "bw" {
name = "lb_band"
size = 20
}

resource "opentelekomcloud_vpc_bandwidth_associate_v2" "associate" {
bandwidth = opentelekomcloud_vpc_bandwidth_v2.bw.id
floating_ips = [opentelekomcloud_lb_loadbalancer_v3.loadbalancer_1.public_ip.0.id]
}
```

## Argument Reference

The following arguments are supported:
Expand Down
Expand Up @@ -15,6 +15,7 @@ import (
)

const resourceLBName = "opentelekomcloud_lb_loadbalancer_v3.loadbalancer_1"
const resourceBWName = "opentelekomcloud_vpc_bandwidth_v2.bw"

func TestAccLBV3LoadBalancer_basic(t *testing.T) {
var lb loadbalancers.LoadBalancer
Expand Down Expand Up @@ -44,7 +45,7 @@ func TestAccLBV3LoadBalancer_basic(t *testing.T) {
})
}

func TestAccLBV3LoadBalancer_eipIDs(t *testing.T) {
func TestAccLBV3LoadBalancer_bandwidth(t *testing.T) {
var lb loadbalancers.LoadBalancer

qts := lbQuotas()
Expand All @@ -57,9 +58,12 @@ func TestAccLBV3LoadBalancer_eipIDs(t *testing.T) {
CheckDestroy: testAccCheckLBV3LoadBalancerDestroy,
Steps: []resource.TestStep{
{
Config: testAccLBV3LoadBalancerEIPs,
Config: testAccLBV3LoadBalancerConfigNewBandwidth,
Check: resource.ComposeTestCheckFunc(
testAccCheckLBV3LoadBalancerExists(resourceLBName, &lb),
resource.TestCheckResourceAttr(resourceLBName, "public_ip.0.bandwidth_share_type", "PER"),
resource.TestCheckResourceAttr(resourceLBName, "public_ip.0.bandwidth_size", "10"),
resource.TestCheckResourceAttr(resourceBWName, "size", "20"),
),
},
},
Expand Down Expand Up @@ -190,21 +194,9 @@ resource "opentelekomcloud_lb_loadbalancer_v3" "loadbalancer_1" {
}
`, common.DataSourceSubnet, env.OS_AVAILABILITY_ZONE)

var testAccLBV3LoadBalancerEIPs = fmt.Sprintf(`
var testAccLBV3LoadBalancerConfigNewBandwidth = fmt.Sprintf(`
%s

resource "opentelekomcloud_vpc_eip_v1" "eip_1" {
publicip {
type = "5_gray"
}
bandwidth {
name = "test"
size = 8
share_type = "PER"
charge_mode = "traffic"
}
}

resource "opentelekomcloud_lb_loadbalancer_v3" "loadbalancer_1" {
name = "loadbalancer_1"
router_id = data.opentelekomcloud_vpc_subnet_v1.shared_subnet.vpc_id
Expand All @@ -213,7 +205,25 @@ resource "opentelekomcloud_lb_loadbalancer_v3" "loadbalancer_1" {
availability_zones = ["%s"]

public_ip {
id = opentelekomcloud_vpc_eip_v1.eip_1.id
ip_type = "5_gray"
bandwidth_name = "lb_band"
bandwidth_size = 10
bandwidth_share_type = "PER"
}

tags = {
muh = "value-create"
kuh = "value-create"
}
}

resource "opentelekomcloud_vpc_bandwidth_v2" "bw" {
name = "lb_band"
size = 20
}

resource "opentelekomcloud_vpc_bandwidth_associate_v2" "associate" {
bandwidth = opentelekomcloud_vpc_bandwidth_v2.bw.id
floating_ips = [opentelekomcloud_lb_loadbalancer_v3.loadbalancer_1.public_ip.0.id]
}
`, common.DataSourceSubnet, env.OS_AVAILABILITY_ZONE)
Expand Up @@ -126,11 +126,18 @@ func ResourceLoadBalancerV3() *schema.Resource {
ForceNew: true,
},
"bandwidth_size": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Type: schema.TypeInt,
Optional: true,
Computed: true,
ForceNew: true,
DiffSuppressOnRefresh: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if old >= new {
return true
}
return false
},
RequiredWith: []string{"public_ip.0.ip_type"},
ForceNew: true,
ValidateFunc: validation.IntBetween(0, 99999),
},
"bandwidth_charge_mode": {
Expand All @@ -143,11 +150,18 @@ func ResourceLoadBalancerV3() *schema.Resource {
}, false),
},
"bandwidth_share_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
DiffSuppressOnRefresh: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if old == "WHOLE" && new == "PER" {
return true
}
return false
},
RequiredWith: []string{"public_ip.0.ip_type"},
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
"PER", "WHOLE",
}, false),
Expand Down
@@ -0,0 +1,4 @@
---
features:
- |
**[ELB]** added suppress functions to size and type to have ability change eip bandwidth in ``opentelekomcloud_lb_loadbalancer_v3`` (`#1991 <https://github.com/opentelekomcloud/terraform-provider-opentelekomcloud/pull/1991>`_)