Skip to content

Commit 4f32f53

Browse files
author
yann degat
committed
iplb: fix mandatory attributes handling & testacc
1 parent dd082ad commit 4f32f53

4 files changed

+38
-62
lines changed

ovh/resource_ovh_iploadbalancing_http_farm_server.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type IpLoadbalancingHttpFarmServer struct {
1414
ServerId int `json:"serverId,omitempty"`
1515
FarmId int `json:"farmId,omitempty"`
1616
DisplayName *string `json:"displayName,omitempty"`
17-
Address *string `json:"address"`
17+
Address string `json:"address"`
1818
Cookie *string `json:"cookie,omitempty"`
1919
Port *int `json:"port"`
2020
ProxyProtocolVersion *string `json:"proxyProtocolVersion"`
@@ -23,7 +23,7 @@ type IpLoadbalancingHttpFarmServer struct {
2323
Probe *bool `json:"probe"`
2424
Ssl *bool `json:"ssl"`
2525
Backup *bool `json:"backup"`
26-
Status *string `json:"status"`
26+
Status string `json:"status"`
2727
}
2828

2929
func resourceIpLoadbalancingHttpFarmServer() *schema.Resource {
@@ -122,15 +122,15 @@ func resourceIpLoadbalancingHttpFarmServerCreate(d *schema.ResourceData, meta in
122122

123123
newBackendServer := &IpLoadbalancingHttpFarmServer{
124124
DisplayName: getNilStringPointerFromData(d, "display_name"),
125-
Address: getNilStringPointerFromData(d, "address"),
125+
Address: d.Get("address").(string),
126126
Port: getNilIntPointerFromData(d, "port"),
127127
ProxyProtocolVersion: getNilStringPointerFromData(d, "proxy_protocol_version"),
128128
Chain: getNilStringPointerFromData(d, "chain"),
129129
Weight: getNilIntPointerFromData(d, "weight"),
130130
Probe: getNilBoolPointerFromData(d, "probe"),
131131
Ssl: getNilBoolPointerFromData(d, "ssl"),
132132
Backup: getNilBoolPointerFromData(d, "backup"),
133-
Status: getNilStringPointerFromData(d, "status"),
133+
Status: d.Get("status").(string),
134134
}
135135

136136
service := d.Get("service_name").(string)
@@ -167,7 +167,7 @@ func resourceIpLoadbalancingHttpFarmServerRead(d *schema.ResourceData, meta inte
167167
d.Set("probe", *r.Probe)
168168
d.Set("ssl", *r.Ssl)
169169
d.Set("backup", *r.Backup)
170-
d.Set("address", *r.Address)
170+
d.Set("address", r.Address)
171171
if r.DisplayName != nil {
172172
d.Set("display_name", *r.DisplayName)
173173
}
@@ -182,7 +182,7 @@ func resourceIpLoadbalancingHttpFarmServerRead(d *schema.ResourceData, meta inte
182182
d.Set("chain", *r.Chain)
183183
}
184184
d.Set("weight", *r.Weight)
185-
d.Set("status", *r.Status)
185+
d.Set("status", r.Status)
186186

187187
return nil
188188
}
@@ -192,15 +192,15 @@ func resourceIpLoadbalancingHttpFarmServerUpdate(d *schema.ResourceData, meta in
192192

193193
update := &IpLoadbalancingHttpFarmServer{
194194
DisplayName: getNilStringPointerFromData(d, "display_name"),
195-
Address: getNilStringPointerFromData(d, "address"),
195+
Address: d.Get("address").(string),
196196
Port: getNilIntPointerFromData(d, "port"),
197197
ProxyProtocolVersion: getNilStringPointerFromData(d, "proxy_protocol_version"),
198198
Chain: getNilStringPointerFromData(d, "chain"),
199199
Weight: getNilIntPointerFromData(d, "weight"),
200200
Probe: getNilBoolPointerFromData(d, "probe"),
201201
Ssl: getNilBoolPointerFromData(d, "ssl"),
202202
Backup: getNilBoolPointerFromData(d, "backup"),
203-
Status: getNilStringPointerFromData(d, "status"),
203+
Status: d.Get("status").(string),
204204
}
205205

206206
service := d.Get("service_name").(string)

ovh/resource_ovh_iploadbalancing_http_farm_server_test.go

+11-23
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import (
1414
var TestAccIpLoadbalancingHttpFarmServerPlan = [][]map[string]interface{}{
1515
{
1616
{"Status": "active", "Address": "10.0.0.11", "Port": 80, "Weight": 3, "DisplayName": "testBackendA"},
17-
{"Port": 8080, "Probe": true, "Backup": true},
18-
{"Port": 8080, "Probe": false, "Backup": false, "Weight": 2, "DisplayName": "testBackendB"},
17+
{"Status": "active", "Address": "10.0.0.11", "Port": 8080, "Probe": true, "Backup": true},
18+
{"Status": "active", "Address": "10.0.0.11", "Port": 8080, "Probe": false, "Backup": false, "Weight": 2, "DisplayName": "testBackendB"},
1919
},
2020
{
2121
{"Status": "inactive", "Address": "10.0.0.12", "Port": 80},
22-
{"Port": 8080, "ProxyProtocolVersion": "v2", "Ssl": true},
23-
{"Port": 8080, "ProxyProtocolVersion": "v1", "Ssl": true, "Backup": false},
24-
{"Port": 8080, "ProxyProtocolVersion": nil, "Ssl": true, "Backup": true, "Status": "active"},
22+
{"Status": "active", "Address": "10.0.0.11", "Port": 8080, "ProxyProtocolVersion": "v2", "Ssl": true},
23+
{"Status": "active", "Address": "10.0.0.11", "Port": 8080, "ProxyProtocolVersion": "v1", "Ssl": true, "Backup": false},
24+
{"Status": "active", "Address": "10.0.0.11", "Port": 8080, "ProxyProtocolVersion": nil, "Ssl": true, "Backup": true, "Status": "active"},
2525
},
2626
}
2727

@@ -31,7 +31,7 @@ type TestAccIpLoadbalancingHttpFarmServer struct {
3131
BackendId int `json:"backendId"`
3232
FarmId int `json:"farmId"`
3333
DisplayName *string `json:"displayName"`
34-
Address *string `json:"address"`
34+
Address string `json:"address"`
3535
Cookie *string `json:"cookie"`
3636
Port *int `json:"port"`
3737
ProxyProtocolVersion *string `json:"proxyProtocolVersion"`
@@ -40,7 +40,7 @@ type TestAccIpLoadbalancingHttpFarmServer struct {
4040
Probe *bool `json:"probe"`
4141
Ssl *bool `json:"ssl"`
4242
Backup *bool `json:"backup"`
43-
Status *string `json:"status"`
43+
Status string `json:"status"`
4444
}
4545

4646
type TestAccIpLoadbalancingHttpFarmServerWrapper struct {
@@ -49,18 +49,6 @@ type TestAccIpLoadbalancingHttpFarmServerWrapper struct {
4949

5050
func (w *TestAccIpLoadbalancingHttpFarmServerWrapper) Config() string {
5151
var config bytes.Buffer
52-
var address, status string
53-
if w.Expected.Address == nil {
54-
address = ""
55-
} else {
56-
address = *w.Expected.Address
57-
}
58-
59-
if w.Expected.Status == nil {
60-
status = ""
61-
} else {
62-
status = *w.Expected.Status
63-
}
6452

6553
config.WriteString(fmt.Sprintf(`
6654
resource "ovh_iploadbalancing_http_farm" "testacc" {
@@ -81,8 +69,8 @@ func (w *TestAccIpLoadbalancingHttpFarmServerWrapper) Config() string {
8169
status = "%s"
8270
`, w.Expected.ServiceName,
8371
w.Expected.ServiceName,
84-
address,
85-
status,
72+
w.Expected.Address,
73+
w.Expected.Status,
8674
))
8775

8876
conditionalAttributeString(&config, "display_name", w.Expected.DisplayName)
@@ -137,15 +125,15 @@ type TestAccIpLoadbalancingHttpFarmServerStep struct {
137125

138126
func (w *TestAccIpLoadbalancingHttpFarmServerWrapper) TestStep(c map[string]interface{}) resource.TestStep {
139127
w.Expected.DisplayName = getNilStringPointerFromData(c, "DisplayName")
140-
w.Expected.Address = getNilStringPointerFromData(c, "Address")
128+
w.Expected.Address = c["Address"].(string)
141129
w.Expected.Port = getNilIntPointerFromData(c, "Port")
142130
w.Expected.ProxyProtocolVersion = getNilStringPointerFromData(c, "ProxyProtocolVersion")
143131
w.Expected.Chain = getNilStringPointerFromData(c, "Chain")
144132
w.Expected.Weight = getNilIntPointerFromData(c, "Weight")
145133
w.Expected.Probe = getNilBoolPointerFromData(c, "Probe")
146134
w.Expected.Ssl = getNilBoolPointerFromData(c, "Ssl")
147135
w.Expected.Backup = getNilBoolPointerFromData(c, "Backup")
148-
w.Expected.Status = getNilStringPointerFromData(c, "Status")
136+
w.Expected.Status = c["Status"].(string)
149137

150138
expected := *w.Expected
151139

ovh/resource_ovh_iploadbalancing_tcp_farm_server.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type IpLoadbalancingTcpFarmServer struct {
1414
ServerId int `json:"serverId,omitempty"`
1515
FarmId int `json:"farmId,omitempty"`
1616
DisplayName *string `json:"displayName,omitempty"`
17-
Address *string `json:"address"`
17+
Address string `json:"address"`
1818
Cookie *string `json:"cookie,omitempty"`
1919
Port *int `json:"port"`
2020
ProxyProtocolVersion *string `json:"proxyProtocolVersion"`
@@ -23,7 +23,7 @@ type IpLoadbalancingTcpFarmServer struct {
2323
Probe *bool `json:"probe"`
2424
Ssl *bool `json:"ssl"`
2525
Backup *bool `json:"backup"`
26-
Status *string `json:"status"`
26+
Status string `json:"status"`
2727
}
2828

2929
func resourceIpLoadbalancingTcpFarmServer() *schema.Resource {
@@ -122,15 +122,15 @@ func resourceIpLoadbalancingTcpFarmServerCreate(d *schema.ResourceData, meta int
122122

123123
newBackendServer := &IpLoadbalancingTcpFarmServer{
124124
DisplayName: getNilStringPointerFromData(d, "display_name"),
125-
Address: getNilStringPointerFromData(d, "address"),
125+
Address: d.Get("address").(string),
126126
Port: getNilIntPointerFromData(d, "port"),
127127
ProxyProtocolVersion: getNilStringPointerFromData(d, "proxy_protocol_version"),
128128
Chain: getNilStringPointerFromData(d, "chain"),
129129
Weight: getNilIntPointerFromData(d, "weight"),
130130
Probe: getNilBoolPointerFromData(d, "probe"),
131131
Ssl: getNilBoolPointerFromData(d, "ssl"),
132132
Backup: getNilBoolPointerFromData(d, "backup"),
133-
Status: getNilStringPointerFromData(d, "status"),
133+
Status: d.Get("status").(string),
134134
}
135135

136136
service := d.Get("service_name").(string)
@@ -167,7 +167,7 @@ func resourceIpLoadbalancingTcpFarmServerRead(d *schema.ResourceData, meta inter
167167
d.Set("probe", *r.Probe)
168168
d.Set("ssl", *r.Ssl)
169169
d.Set("backup", *r.Backup)
170-
d.Set("address", *r.Address)
170+
d.Set("address", r.Address)
171171
if r.DisplayName != nil {
172172
d.Set("display_name", *r.DisplayName)
173173
}
@@ -182,7 +182,7 @@ func resourceIpLoadbalancingTcpFarmServerRead(d *schema.ResourceData, meta inter
182182
d.Set("chain", *r.Chain)
183183
}
184184
d.Set("weight", *r.Weight)
185-
d.Set("status", *r.Status)
185+
d.Set("status", r.Status)
186186

187187
return nil
188188
}
@@ -192,15 +192,15 @@ func resourceIpLoadbalancingTcpFarmServerUpdate(d *schema.ResourceData, meta int
192192

193193
update := &IpLoadbalancingTcpFarmServer{
194194
DisplayName: getNilStringPointerFromData(d, "display_name"),
195-
Address: getNilStringPointerFromData(d, "address"),
195+
Address: d.Get("address").(string),
196196
Port: getNilIntPointerFromData(d, "port"),
197197
ProxyProtocolVersion: getNilStringPointerFromData(d, "proxy_protocol_version"),
198198
Chain: getNilStringPointerFromData(d, "chain"),
199199
Weight: getNilIntPointerFromData(d, "weight"),
200200
Probe: getNilBoolPointerFromData(d, "probe"),
201201
Ssl: getNilBoolPointerFromData(d, "ssl"),
202202
Backup: getNilBoolPointerFromData(d, "backup"),
203-
Status: getNilStringPointerFromData(d, "status"),
203+
Status: d.Get("status").(string),
204204
}
205205

206206
service := d.Get("service_name").(string)

ovh/resource_ovh_iploadbalancing_tcp_farm_server_test.go

+11-23
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import (
1414
var TestAccIpLoadbalancingTcpFarmServerPlan = [][]map[string]interface{}{
1515
{
1616
{"Status": "active", "Address": "10.0.0.11", "Port": 80, "Weight": 3, "DisplayName": "testBackendA"},
17-
{"Port": 8080, "Probe": true, "Backup": true},
18-
{"Port": 8080, "Probe": false, "Backup": false, "Weight": 2, "DisplayName": "testBackendB"},
17+
{"Status": "active", "Address": "10.0.0.11", "Port": 8080, "Probe": true, "Backup": true},
18+
{"Status": "active", "Address": "10.0.0.11", "Port": 8080, "Probe": false, "Backup": false, "Weight": 2, "DisplayName": "testBackendB"},
1919
},
2020
{
2121
{"Status": "inactive", "Address": "10.0.0.12", "Port": 80},
22-
{"Port": 8080, "ProxyProtocolVersion": "v2", "Ssl": true},
23-
{"Port": 8080, "ProxyProtocolVersion": "v1", "Ssl": true, "Backup": false},
24-
{"Port": 8080, "ProxyProtocolVersion": nil, "Ssl": true, "Backup": true, "Status": "active"},
22+
{"Status": "inactive", "Address": "10.0.0.12", "Port": 8080, "ProxyProtocolVersion": "v2", "Ssl": true},
23+
{"Status": "inactive", "Address": "10.0.0.12", "Port": 8080, "ProxyProtocolVersion": "v1", "Ssl": true, "Backup": false},
24+
{"Status": "inactive", "Address": "10.0.0.12", "Port": 8080, "ProxyProtocolVersion": nil, "Ssl": true, "Backup": true, "Status": "active"},
2525
},
2626
}
2727

@@ -31,7 +31,7 @@ type TestAccIpLoadbalancingTcpFarmServer struct {
3131
BackendId int `json:"backendId"`
3232
FarmId int `json:"farmId"`
3333
DisplayName *string `json:"displayName"`
34-
Address *string `json:"address"`
34+
Address string `json:"address"`
3535
Cookie *string `json:"cookie"`
3636
Port *int `json:"port"`
3737
ProxyProtocolVersion *string `json:"proxyProtocolVersion"`
@@ -40,7 +40,7 @@ type TestAccIpLoadbalancingTcpFarmServer struct {
4040
Probe *bool `json:"probe"`
4141
Ssl *bool `json:"ssl"`
4242
Backup *bool `json:"backup"`
43-
Status *string `json:"status"`
43+
Status string `json:"status"`
4444
}
4545

4646
type TestAccIpLoadbalancingTcpFarmServerWrapper struct {
@@ -49,18 +49,6 @@ type TestAccIpLoadbalancingTcpFarmServerWrapper struct {
4949

5050
func (w *TestAccIpLoadbalancingTcpFarmServerWrapper) Config() string {
5151
var config bytes.Buffer
52-
var address, status string
53-
if w.Expected.Address == nil {
54-
address = ""
55-
} else {
56-
address = *w.Expected.Address
57-
}
58-
59-
if w.Expected.Status == nil {
60-
status = ""
61-
} else {
62-
status = *w.Expected.Status
63-
}
6452

6553
config.WriteString(fmt.Sprintf(`
6654
resource "ovh_iploadbalancing_tcp_farm" "testacc" {
@@ -81,8 +69,8 @@ func (w *TestAccIpLoadbalancingTcpFarmServerWrapper) Config() string {
8169
status = "%s"
8270
`, w.Expected.ServiceName,
8371
w.Expected.ServiceName,
84-
address,
85-
status,
72+
w.Expected.Address,
73+
w.Expected.Status,
8674
))
8775

8876
conditionalAttributeString(&config, "display_name", w.Expected.DisplayName)
@@ -137,15 +125,15 @@ type TestAccIpLoadbalancingTcpFarmServerStep struct {
137125

138126
func (w *TestAccIpLoadbalancingTcpFarmServerWrapper) TestStep(c map[string]interface{}) resource.TestStep {
139127
w.Expected.DisplayName = getNilStringPointerFromData(c, "DisplayName")
140-
w.Expected.Address = getNilStringPointerFromData(c, "Address")
128+
w.Expected.Address = c["Address"].(string)
141129
w.Expected.Port = getNilIntPointerFromData(c, "Port")
142130
w.Expected.ProxyProtocolVersion = getNilStringPointerFromData(c, "ProxyProtocolVersion")
143131
w.Expected.Chain = getNilStringPointerFromData(c, "Chain")
144132
w.Expected.Weight = getNilIntPointerFromData(c, "Weight")
145133
w.Expected.Probe = getNilBoolPointerFromData(c, "Probe")
146134
w.Expected.Ssl = getNilBoolPointerFromData(c, "Ssl")
147135
w.Expected.Backup = getNilBoolPointerFromData(c, "Backup")
148-
w.Expected.Status = getNilStringPointerFromData(c, "Status")
136+
w.Expected.Status = c["Status"].(string)
149137

150138
expected := *w.Expected
151139

0 commit comments

Comments
 (0)