Skip to content

add Iplb missing sweepers #171

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

Merged
merged 1 commit into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions ovh/resource_ovh_iploadbalancing_http_farm_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package ovh

import (
"fmt"
"log"
"os"
"strings"
"testing"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand Down Expand Up @@ -130,6 +133,73 @@ resource ovh_iploadbalancing_http_farm_server testacc {
`
)

func init() {
resource.AddTestSweepers("ovh_iploadbalancing_http_farm_server", &resource.Sweeper{
Name: "ovh_iploadbalancing_http_farm_server",
F: testSweepIploadbalancingHttpFarmServer,
})
}

func testSweepIploadbalancingHttpFarmServer(region string) error {
client, err := sharedClientForRegion(region)
if err != nil {
return fmt.Errorf("error getting client: %s", err)
}

iplb := os.Getenv("OVH_IPLB_SERVICE")
if iplb == "" {
log.Print("[DEBUG] OVH_IPLB_SERVICE is not set. No iploadbalancing_vrack_network to sweep")
return nil
}

farms := make([]int64, 0)
if err := client.Get(fmt.Sprintf("/ipLoadbalancing/%s/http/farm", iplb), &farms); err != nil {
return fmt.Errorf("Error calling GET /ipLoadbalancing/%s/http/farm:\n\t %q", iplb, err)
}

if len(farms) == 0 {
log.Print("[DEBUG] No http farm to sweep")
return nil
}

for _, f := range farms {
farm := &IpLoadbalancingFarm{}

if err := client.Get(fmt.Sprintf("/ipLoadbalancing/%s/http/farm/%d", iplb, f), &farm); err != nil {
return fmt.Errorf("Error calling GET /ipLoadbalancing/%s/http/farm/%d:\n\t %q", iplb, f, err)
}

if !strings.HasPrefix(*farm.DisplayName, test_prefix) {
continue
}

servers := make([]int64, 0)
if err := client.Get(fmt.Sprintf("/ipLoadbalancing/%s/http/farm/%d/server", iplb, f), &servers); err != nil {
return fmt.Errorf("Error calling GET /ipLoadbalancing/%s/http/farm/%d/server:\n\t %q", iplb, f, err)
}

if len(servers) == 0 {
log.Printf("[DEBUG] No server to sweep on http farm %s/http/farm/%d", iplb, f)
return nil
}

for _, s := range servers {
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
if err := client.Delete(fmt.Sprintf("/ipLoadbalancing/%s/http/farm/%d/server/%d", iplb, f, s), nil); err != nil {
return resource.RetryableError(err)
}
// Successful delete
return nil
})
if err != nil {
return err
}
}
}

return nil
}

func TestAccIpLoadbalancingHttpFarmServerBasic(t *testing.T) {
displayName := acctest.RandomWithPrefix(test_prefix)
prefix := fmt.Sprintf(
Expand Down
61 changes: 61 additions & 0 deletions ovh/resource_ovh_iploadbalancing_http_farm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package ovh

import (
"fmt"
"log"
"os"
"strings"
"testing"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand All @@ -28,6 +31,64 @@ resource "ovh_iploadbalancing_http_farm" "testfarm" {
`
)

func init() {
resource.AddTestSweepers("ovh_iploadbalancing_http_farm", &resource.Sweeper{
Name: "ovh_iploadbalancing_http_farm",
Dependencies: []string{
"ovh_iploadbalancing_http_farm_server",
},
F: testSweepIploadbalancingHttpFarm,
})
}

func testSweepIploadbalancingHttpFarm(region string) error {
client, err := sharedClientForRegion(region)
if err != nil {
return fmt.Errorf("error getting client: %s", err)
}

iplb := os.Getenv("OVH_IPLB_SERVICE")
if iplb == "" {
log.Print("[DEBUG] OVH_IPLB_SERVICE is not set. No iploadbalancing_vrack_network to sweep")
return nil
}

farms := make([]int64, 0)
if err := client.Get(fmt.Sprintf("/ipLoadbalancing/%s/http/farm", iplb), &farms); err != nil {
return fmt.Errorf("Error calling /ipLoadbalancing/%s/http/farm:\n\t %q", iplb, err)
}

if len(farms) == 0 {
log.Print("[DEBUG] No http farm to sweep")
return nil
}

for _, f := range farms {
farm := &IpLoadbalancingFarm{}

if err := client.Get(fmt.Sprintf("/ipLoadbalancing/%s/http/farm/%d", iplb, f), &farm); err != nil {
return fmt.Errorf("Error calling /ipLoadbalancing/%s/http/farm/%d:\n\t %q", iplb, f, err)
}

if !strings.HasPrefix(*farm.DisplayName, test_prefix) {
continue
}

err = resource.Retry(5*time.Minute, func() *resource.RetryError {
if err := client.Delete(fmt.Sprintf("/ipLoadbalancing/%s/http/farm/%d", iplb, f), nil); err != nil {
return resource.RetryableError(err)
}
// Successful delete
return nil
})
if err != nil {
return err
}
}

return nil
}

func TestAccIpLoadbalancingHttpFarmBasicCreate(t *testing.T) {
displayName1 := acctest.RandomWithPrefix(test_prefix)
displayName2 := acctest.RandomWithPrefix(test_prefix)
Expand Down
73 changes: 72 additions & 1 deletion ovh/resource_ovh_iploadbalancing_http_route_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,87 @@ package ovh

import (
"fmt"
"log"
"os"
"strings"
"testing"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func init() {
resource.AddTestSweepers("ovh_iploadbalancing_http_route_rule", &resource.Sweeper{
Name: "ovh_iploadbalancing_http_route_rule",
F: testSweepIploadbalancingHttpRouteRule,
})
}

func testSweepIploadbalancingHttpRouteRule(region string) error {
client, err := sharedClientForRegion(region)
if err != nil {
return fmt.Errorf("error getting client: %s", err)
}

iplb := os.Getenv("OVH_IPLB_SERVICE")
if iplb == "" {
log.Print("[DEBUG] OVH_IPLB_SERVICE is not set. No iploadbalancing_vrack_network to sweep")
return nil
}

routes := make([]int64, 0)
if err := client.Get(fmt.Sprintf("/ipLoadbalancing/%s/http/route", iplb), &routes); err != nil {
return fmt.Errorf("Error calling GET /ipLoadbalancing/%s/http/route:\n\t %q", iplb, err)
}

if len(routes) == 0 {
log.Print("[DEBUG] No http route to sweep")
return nil
}

for _, f := range routes {
route := &IPLoadbalancingRouteHTTP{}

if err := client.Get(fmt.Sprintf("/ipLoadbalancing/%s/http/route/%d", iplb, f), &route); err != nil {
return fmt.Errorf("Error calling GET /ipLoadbalancing/%s/http/route/%d:\n\t %q", iplb, f, err)
}

if !strings.HasPrefix(route.DisplayName, test_prefix) {
continue
}

rules := make([]int64, 0)
if err := client.Get(fmt.Sprintf("/ipLoadbalancing/%s/http/route/%d/rule", iplb, f), &rules); err != nil {
return fmt.Errorf("Error calling GET /ipLoadbalancing/%s/http/route/%d/rule:\n\t %q", iplb, f, err)
}

if len(rules) == 0 {
log.Printf("[DEBUG] No rule to sweep on http route %s/http/route/%d", iplb, f)
return nil
}

for _, s := range rules {
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
if err := client.Delete(fmt.Sprintf("/ipLoadbalancing/%s/http/route/%d/rule/%d", iplb, f, s), nil); err != nil {
return resource.RetryableError(err)
}
// Successful delete
return nil
})
if err != nil {
return err
}
}
}

return nil
}

func TestAccIPLoadbalancingRouteHTTPRuleBasicCreate(t *testing.T) {
serviceName := os.Getenv("OVH_IPLB_SERVICE")
displayName := "Test rule"
displayName := acctest.RandomWithPrefix(test_prefix)
field := "header"
match := "is"
negate := "false"
Expand Down
63 changes: 62 additions & 1 deletion ovh/resource_ovh_iploadbalancing_http_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,78 @@ package ovh

import (
"fmt"
"log"
"os"
"strings"
"testing"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func init() {
resource.AddTestSweepers("ovh_iploadbalancing_http_route", &resource.Sweeper{
Name: "ovh_iploadbalancing_http_route",
Dependencies: []string{
"ovh_iploadbalancing_http_route_rule",
},
F: testSweepIploadbalancingHttpRoute,
})
}

func testSweepIploadbalancingHttpRoute(region string) error {
client, err := sharedClientForRegion(region)
if err != nil {
return fmt.Errorf("error getting client: %s", err)
}

iplb := os.Getenv("OVH_IPLB_SERVICE")
if iplb == "" {
log.Print("[DEBUG] OVH_IPLB_SERVICE is not set. No iploadbalancing_vrack_network to sweep")
return nil
}

routes := make([]int64, 0)
if err := client.Get(fmt.Sprintf("/ipLoadbalancing/%s/http/route", iplb), &routes); err != nil {
return fmt.Errorf("Error calling /ipLoadbalancing/%s/http/route:\n\t %q", iplb, err)
}

if len(routes) == 0 {
log.Print("[DEBUG] No http route to sweep")
return nil
}

for _, f := range routes {
route := &IPLoadbalancingRouteHTTP{}

if err := client.Get(fmt.Sprintf("/ipLoadbalancing/%s/http/route/%d", iplb, f), &route); err != nil {
return fmt.Errorf("Error calling /ipLoadbalancing/%s/http/route/%d:\n\t %q", iplb, f, err)
}

if !strings.HasPrefix(route.DisplayName, test_prefix) {
continue
}

err = resource.Retry(5*time.Minute, func() *resource.RetryError {
if err := client.Delete(fmt.Sprintf("/ipLoadbalancing/%s/http/route/%d", iplb, f), nil); err != nil {
return resource.RetryableError(err)
}
// Successful delete
return nil
})
if err != nil {
return err
}
}

return nil
}

func TestAccIPLoadbalancingRouteHTTPBasicCreate(t *testing.T) {
serviceName := os.Getenv("OVH_IPLB_SERVICE")
name := "test-route-redirect-https"
name := acctest.RandomWithPrefix(test_prefix)
weight := "0"
actionStatus := "302"
actionTarget := "https://$${host}$${path}$${arguments}"
Expand Down
Loading