forked from ovh/terraform-provider-ovh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport_iploadbalancing_http_farm_server_test.go
78 lines (71 loc) · 2.29 KB
/
import_iploadbalancing_http_farm_server_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package ovh
import (
"fmt"
"os"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)
const (
testAccIpLoadbalancingHttpFarmServerConfig = `
data "ovh_iploadbalancing" "iplb" {
service_name = "%s"
}
resource "ovh_iploadbalancing_http_farm" "testfarm" {
service_name = data.ovh_iploadbalancing.iplb.id
display_name = "%s"
port = "%d"
zone = "%s"
balance = "roundrobin"
probe {
interval = 30
type = "oco"
}
}
resource "ovh_iploadbalancing_http_farm_server" "testfarmserver" {
service_name = data.ovh_iploadbalancing.iplb.id
farm_id = ovh_iploadbalancing_http_farm.testfarm.id
display_name = "%s"
probe = "true"
proxy_protocol_version = "v1"
status = "active"
address = "%s"
}
`
)
func TestAccIpLoadbalancingHttpFarmServer_importBasic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheckIpLoadbalancing(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccIpLoadbalancingHttpFarmServerConfig_basic,
},
{
ResourceName: "ovh_iploadbalancing_http_farm_server.testfarmserver",
ImportState: true,
ImportStateVerify: true,
ImportStateIdFunc: testAccIpLoadbalancingHttpFarmServerImportId("ovh_iploadbalancing_http_farm_server.testfarmserver"),
},
},
})
}
func testAccIpLoadbalancingHttpFarmServerImportId(resourceName string) resource.ImportStateIdFunc {
return func(s *terraform.State) (string, error) {
testFarmServer, ok := s.RootModule().Resources[resourceName]
if !ok {
return "", fmt.Errorf("ovh_ip_loadbalancing_http_farm not found: %s", resourceName)
}
return fmt.Sprintf(
"%s/%s/%s",
testFarmServer.Primary.Attributes["service_name"],
testFarmServer.Primary.Attributes["farm_id"],
testFarmServer.Primary.Attributes["id"],
), nil
}
}
// an OVH IPv4 is required for servers
// ping.ovh.net ip is used for test purposes
var httpServerAddress = "198.27.92.1"
var testAccIpLoadbalancingHttpFarmServerConfig_basic = fmt.Sprintf(testAccIpLoadbalancingHttpFarmServerConfig,
os.Getenv("OVH_IPLB_SERVICE"), "testfarm", 12345, "all", "testserver", httpServerAddress)