Skip to content

Commit 6abac29

Browse files
author
yann degat
committed
r/iplb*: add missing sweepers
1 parent 9738d72 commit 6abac29

7 files changed

+412
-47
lines changed

ovh/resource_ovh_iploadbalancing_http_farm_server_test.go

+70
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package ovh
22

33
import (
44
"fmt"
5+
"log"
56
"os"
7+
"strings"
68
"testing"
9+
"time"
710

811
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
912
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
@@ -130,6 +133,73 @@ resource ovh_iploadbalancing_http_farm_server testacc {
130133
`
131134
)
132135

136+
func init() {
137+
resource.AddTestSweepers("ovh_iploadbalancing_http_farm_server", &resource.Sweeper{
138+
Name: "ovh_iploadbalancing_http_farm_server",
139+
F: testSweepIploadbalancingHttpFarmServer,
140+
})
141+
}
142+
143+
func testSweepIploadbalancingHttpFarmServer(region string) error {
144+
client, err := sharedClientForRegion(region)
145+
if err != nil {
146+
return fmt.Errorf("error getting client: %s", err)
147+
}
148+
149+
iplb := os.Getenv("OVH_IPLB_SERVICE")
150+
if iplb == "" {
151+
log.Print("[DEBUG] OVH_IPLB_SERVICE is not set. No iploadbalancing_vrack_network to sweep")
152+
return nil
153+
}
154+
155+
farms := make([]int64, 0)
156+
if err := client.Get(fmt.Sprintf("/ipLoadbalancing/%s/http/farm", iplb), &farms); err != nil {
157+
return fmt.Errorf("Error calling GET /ipLoadbalancing/%s/http/farm:\n\t %q", iplb, err)
158+
}
159+
160+
if len(farms) == 0 {
161+
log.Print("[DEBUG] No http farm to sweep")
162+
return nil
163+
}
164+
165+
for _, f := range farms {
166+
farm := &IpLoadbalancingFarm{}
167+
168+
if err := client.Get(fmt.Sprintf("/ipLoadbalancing/%s/http/farm/%d", iplb, f), &farm); err != nil {
169+
return fmt.Errorf("Error calling GET /ipLoadbalancing/%s/http/farm/%d:\n\t %q", iplb, f, err)
170+
}
171+
172+
if !strings.HasPrefix(*farm.DisplayName, test_prefix) {
173+
continue
174+
}
175+
176+
servers := make([]int64, 0)
177+
if err := client.Get(fmt.Sprintf("/ipLoadbalancing/%s/http/farm/%d/server", iplb, f), &servers); err != nil {
178+
return fmt.Errorf("Error calling GET /ipLoadbalancing/%s/http/farm/%d/server:\n\t %q", iplb, f, err)
179+
}
180+
181+
if len(servers) == 0 {
182+
log.Printf("[DEBUG] No server to sweep on http farm %s/http/farm/%d", iplb, f)
183+
return nil
184+
}
185+
186+
for _, s := range servers {
187+
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
188+
if err := client.Delete(fmt.Sprintf("/ipLoadbalancing/%s/http/farm/%d/server/%d", iplb, f, s), nil); err != nil {
189+
return resource.RetryableError(err)
190+
}
191+
// Successful delete
192+
return nil
193+
})
194+
if err != nil {
195+
return err
196+
}
197+
}
198+
}
199+
200+
return nil
201+
}
202+
133203
func TestAccIpLoadbalancingHttpFarmServerBasic(t *testing.T) {
134204
displayName := acctest.RandomWithPrefix(test_prefix)
135205
prefix := fmt.Sprintf(

ovh/resource_ovh_iploadbalancing_http_farm_test.go

+61
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package ovh
22

33
import (
44
"fmt"
5+
"log"
56
"os"
7+
"strings"
68
"testing"
9+
"time"
710

811
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
912
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
@@ -28,6 +31,64 @@ resource "ovh_iploadbalancing_http_farm" "testfarm" {
2831
`
2932
)
3033

34+
func init() {
35+
resource.AddTestSweepers("ovh_iploadbalancing_http_farm", &resource.Sweeper{
36+
Name: "ovh_iploadbalancing_http_farm",
37+
Dependencies: []string{
38+
"ovh_iploadbalancing_http_farm_server",
39+
},
40+
F: testSweepIploadbalancingHttpFarm,
41+
})
42+
}
43+
44+
func testSweepIploadbalancingHttpFarm(region string) error {
45+
client, err := sharedClientForRegion(region)
46+
if err != nil {
47+
return fmt.Errorf("error getting client: %s", err)
48+
}
49+
50+
iplb := os.Getenv("OVH_IPLB_SERVICE")
51+
if iplb == "" {
52+
log.Print("[DEBUG] OVH_IPLB_SERVICE is not set. No iploadbalancing_vrack_network to sweep")
53+
return nil
54+
}
55+
56+
farms := make([]int64, 0)
57+
if err := client.Get(fmt.Sprintf("/ipLoadbalancing/%s/http/farm", iplb), &farms); err != nil {
58+
return fmt.Errorf("Error calling /ipLoadbalancing/%s/http/farm:\n\t %q", iplb, err)
59+
}
60+
61+
if len(farms) == 0 {
62+
log.Print("[DEBUG] No http farm to sweep")
63+
return nil
64+
}
65+
66+
for _, f := range farms {
67+
farm := &IpLoadbalancingFarm{}
68+
69+
if err := client.Get(fmt.Sprintf("/ipLoadbalancing/%s/http/farm/%d", iplb, f), &farm); err != nil {
70+
return fmt.Errorf("Error calling /ipLoadbalancing/%s/http/farm/%d:\n\t %q", iplb, f, err)
71+
}
72+
73+
if !strings.HasPrefix(*farm.DisplayName, test_prefix) {
74+
continue
75+
}
76+
77+
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
78+
if err := client.Delete(fmt.Sprintf("/ipLoadbalancing/%s/http/farm/%d", iplb, f), nil); err != nil {
79+
return resource.RetryableError(err)
80+
}
81+
// Successful delete
82+
return nil
83+
})
84+
if err != nil {
85+
return err
86+
}
87+
}
88+
89+
return nil
90+
}
91+
3192
func TestAccIpLoadbalancingHttpFarmBasicCreate(t *testing.T) {
3293
displayName1 := acctest.RandomWithPrefix(test_prefix)
3394
displayName2 := acctest.RandomWithPrefix(test_prefix)

ovh/resource_ovh_iploadbalancing_http_route_rule_test.go

+72-1
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,87 @@ package ovh
22

33
import (
44
"fmt"
5+
"log"
56
"os"
7+
"strings"
68
"testing"
9+
"time"
710

11+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
812
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
913
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
1014
)
1115

16+
func init() {
17+
resource.AddTestSweepers("ovh_iploadbalancing_http_route_rule", &resource.Sweeper{
18+
Name: "ovh_iploadbalancing_http_route_rule",
19+
F: testSweepIploadbalancingHttpRouteRule,
20+
})
21+
}
22+
23+
func testSweepIploadbalancingHttpRouteRule(region string) error {
24+
client, err := sharedClientForRegion(region)
25+
if err != nil {
26+
return fmt.Errorf("error getting client: %s", err)
27+
}
28+
29+
iplb := os.Getenv("OVH_IPLB_SERVICE")
30+
if iplb == "" {
31+
log.Print("[DEBUG] OVH_IPLB_SERVICE is not set. No iploadbalancing_vrack_network to sweep")
32+
return nil
33+
}
34+
35+
routes := make([]int64, 0)
36+
if err := client.Get(fmt.Sprintf("/ipLoadbalancing/%s/http/route", iplb), &routes); err != nil {
37+
return fmt.Errorf("Error calling GET /ipLoadbalancing/%s/http/route:\n\t %q", iplb, err)
38+
}
39+
40+
if len(routes) == 0 {
41+
log.Print("[DEBUG] No http route to sweep")
42+
return nil
43+
}
44+
45+
for _, f := range routes {
46+
route := &IPLoadbalancingRouteHTTP{}
47+
48+
if err := client.Get(fmt.Sprintf("/ipLoadbalancing/%s/http/route/%d", iplb, f), &route); err != nil {
49+
return fmt.Errorf("Error calling GET /ipLoadbalancing/%s/http/route/%d:\n\t %q", iplb, f, err)
50+
}
51+
52+
if !strings.HasPrefix(route.DisplayName, test_prefix) {
53+
continue
54+
}
55+
56+
rules := make([]int64, 0)
57+
if err := client.Get(fmt.Sprintf("/ipLoadbalancing/%s/http/route/%d/rule", iplb, f), &rules); err != nil {
58+
return fmt.Errorf("Error calling GET /ipLoadbalancing/%s/http/route/%d/rule:\n\t %q", iplb, f, err)
59+
}
60+
61+
if len(rules) == 0 {
62+
log.Printf("[DEBUG] No rule to sweep on http route %s/http/route/%d", iplb, f)
63+
return nil
64+
}
65+
66+
for _, s := range rules {
67+
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
68+
if err := client.Delete(fmt.Sprintf("/ipLoadbalancing/%s/http/route/%d/rule/%d", iplb, f, s), nil); err != nil {
69+
return resource.RetryableError(err)
70+
}
71+
// Successful delete
72+
return nil
73+
})
74+
if err != nil {
75+
return err
76+
}
77+
}
78+
}
79+
80+
return nil
81+
}
82+
1283
func TestAccIPLoadbalancingRouteHTTPRuleBasicCreate(t *testing.T) {
1384
serviceName := os.Getenv("OVH_IPLB_SERVICE")
14-
displayName := "Test rule"
85+
displayName := acctest.RandomWithPrefix(test_prefix)
1586
field := "header"
1687
match := "is"
1788
negate := "false"

ovh/resource_ovh_iploadbalancing_http_route_test.go

+62-1
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,78 @@ package ovh
22

33
import (
44
"fmt"
5+
"log"
56
"os"
67
"strings"
78
"testing"
9+
"time"
810

11+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
912
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1013
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
1114
)
1215

16+
func init() {
17+
resource.AddTestSweepers("ovh_iploadbalancing_http_route", &resource.Sweeper{
18+
Name: "ovh_iploadbalancing_http_route",
19+
Dependencies: []string{
20+
"ovh_iploadbalancing_http_route_rule",
21+
},
22+
F: testSweepIploadbalancingHttpRoute,
23+
})
24+
}
25+
26+
func testSweepIploadbalancingHttpRoute(region string) error {
27+
client, err := sharedClientForRegion(region)
28+
if err != nil {
29+
return fmt.Errorf("error getting client: %s", err)
30+
}
31+
32+
iplb := os.Getenv("OVH_IPLB_SERVICE")
33+
if iplb == "" {
34+
log.Print("[DEBUG] OVH_IPLB_SERVICE is not set. No iploadbalancing_vrack_network to sweep")
35+
return nil
36+
}
37+
38+
routes := make([]int64, 0)
39+
if err := client.Get(fmt.Sprintf("/ipLoadbalancing/%s/http/route", iplb), &routes); err != nil {
40+
return fmt.Errorf("Error calling /ipLoadbalancing/%s/http/route:\n\t %q", iplb, err)
41+
}
42+
43+
if len(routes) == 0 {
44+
log.Print("[DEBUG] No http route to sweep")
45+
return nil
46+
}
47+
48+
for _, f := range routes {
49+
route := &IPLoadbalancingRouteHTTP{}
50+
51+
if err := client.Get(fmt.Sprintf("/ipLoadbalancing/%s/http/route/%d", iplb, f), &route); err != nil {
52+
return fmt.Errorf("Error calling /ipLoadbalancing/%s/http/route/%d:\n\t %q", iplb, f, err)
53+
}
54+
55+
if !strings.HasPrefix(route.DisplayName, test_prefix) {
56+
continue
57+
}
58+
59+
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
60+
if err := client.Delete(fmt.Sprintf("/ipLoadbalancing/%s/http/route/%d", iplb, f), nil); err != nil {
61+
return resource.RetryableError(err)
62+
}
63+
// Successful delete
64+
return nil
65+
})
66+
if err != nil {
67+
return err
68+
}
69+
}
70+
71+
return nil
72+
}
73+
1374
func TestAccIPLoadbalancingRouteHTTPBasicCreate(t *testing.T) {
1475
serviceName := os.Getenv("OVH_IPLB_SERVICE")
15-
name := "test-route-redirect-https"
76+
name := acctest.RandomWithPrefix(test_prefix)
1677
weight := "0"
1778
actionStatus := "302"
1879
actionTarget := "https://$${host}$${path}$${arguments}"

0 commit comments

Comments
 (0)