Skip to content

Commit

Permalink
loadbalancers: Allow resizing without ForceNew. (#606)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsomething committed Apr 26, 2021
1 parent b7abe25 commit 17bdec7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
2 changes: 0 additions & 2 deletions digitalocean/resource_digitalocean_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ func resourceDigitalOceanLoadBalancerV0() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Default: "lb-small",
// Resizing an LB is not currently allowed. If/when that changes, this should be removed/set to false.
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
"lb-small",
"lb-medium",
Expand Down
50 changes: 50 additions & 0 deletions digitalocean/resource_digitalocean_loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,56 @@ func TestAccDigitalOceanLoadbalancer_sslCertByName(t *testing.T) {
})
}

// Load balancers can only be resized once an hour. The initial create counts
// as a "resize" in this context. This test can not perform a resize, but it
// does ensure that the the PUT includes the expected content by checking for
// the failure.
func TestAccDigitalOceanLoadbalancer_resizeExpectedFailure(t *testing.T) {
var loadbalancer godo.LoadBalancer
rInt := acctest.RandInt()

lbConfig := `resource "digitalocean_loadbalancer" "foobar" {
name = "loadbalancer-%d"
region = "nyc3"
size = "%s"
forwarding_rule {
entry_port = 80
entry_protocol = "http"
target_port = 80
target_protocol = "http"
}
healthcheck {
port = 22
protocol = "tcp"
}
}`

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDigitalOceanLoadbalancerDestroy,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(lbConfig, rInt, "lb-small"),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckDigitalOceanLoadbalancerExists("digitalocean_loadbalancer.foobar", &loadbalancer),
resource.TestCheckResourceAttr(
"digitalocean_loadbalancer.foobar", "name", fmt.Sprintf("loadbalancer-%d", rInt)),
resource.TestCheckResourceAttr(
"digitalocean_loadbalancer.foobar", "size", "lb-small"),
),
},
{
Config: fmt.Sprintf(lbConfig, rInt, "lb-large"),
ExpectError: regexp.MustCompile("Load Balancer can only be resized once every hour, last resized at:"),
},
},
})
}

func TestAccDigitalOceanLoadbalancer_multipleRules(t *testing.T) {
var loadbalancer godo.LoadBalancer
rName := randomTestName()
Expand Down

0 comments on commit 17bdec7

Please sign in to comment.