Skip to content

Commit fc6cec2

Browse files
authored
Merge pull request #356 from wilfriedroset/dev/wilfriedroset/http-frontend-header
Add support for HTTP header on resource_iploadbalancing_http_frontend
2 parents 973b4e9 + ba48f1e commit fc6cec2

4 files changed

+45
-0
lines changed

ovh/resource_iploadbalancing_http_frontend.go

+13
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ func resourceIpLoadbalancingHttpFrontend() *schema.Resource {
4444
Optional: true,
4545
Elem: &schema.Schema{Type: schema.TypeString},
4646
},
47+
"http_header": {
48+
Type: schema.TypeList,
49+
Optional: true,
50+
Elem: &schema.Schema{Type: schema.TypeString},
51+
},
4752
"default_farm_id": {
4853
Type: schema.TypeInt,
4954
Optional: true,
@@ -101,6 +106,7 @@ func resourceIpLoadbalancingHttpFrontendCreate(d *schema.ResourceData, meta inte
101106

102107
allowedSources, _ := helpers.StringsFromSchema(d, "allowed_source")
103108
dedicatedIpFo, _ := helpers.StringsFromSchema(d, "dedicated_ipfo")
109+
httpHeader, _ := helpers.StringsFromSchema(d, "http_header")
104110

105111
for _, s := range allowedSources {
106112
if err := helpers.ValidateIpBlock(s); err != nil {
@@ -123,6 +129,7 @@ func resourceIpLoadbalancingHttpFrontendCreate(d *schema.ResourceData, meta inte
123129
Ssl: d.Get("ssl").(bool),
124130
RedirectLocation: d.Get("redirect_location").(string),
125131
DisplayName: d.Get("display_name").(string),
132+
HttpHeader: httpHeader,
126133
}
127134

128135
frontend.DefaultFarmId = helpers.GetNilIntPointerFromData(d, "default_farm_id")
@@ -160,6 +167,9 @@ func resourceIpLoadbalancingHttpFrontendRead(d *schema.ResourceData, meta interf
160167
dedicatedIpFos := make([]string, 0)
161168
dedicatedIpFos = append(dedicatedIpFos, r.DedicatedIpFo...)
162169

170+
httpHeader := make([]string, 0)
171+
httpHeader = append(httpHeader, r.HttpHeader...)
172+
163173
d.Set("allowed_source", allowedSources)
164174
d.Set("dedicated_ipfo", dedicatedIpFos)
165175
d.Set("default_farm_id", r.DefaultFarmId)
@@ -170,6 +180,7 @@ func resourceIpLoadbalancingHttpFrontendRead(d *schema.ResourceData, meta interf
170180
d.Set("ssl", r.Ssl)
171181
d.Set("zone", r.Zone)
172182
d.Set("redirect_location", r.RedirectLocation)
183+
d.Set("http_header", httpHeader)
173184

174185
return nil
175186
}
@@ -181,6 +192,7 @@ func resourceIpLoadbalancingHttpFrontendUpdate(d *schema.ResourceData, meta inte
181192

182193
allowedSources, _ := helpers.StringsFromSchema(d, "allowed_source")
183194
dedicatedIpFo, _ := helpers.StringsFromSchema(d, "dedicated_ipfo")
195+
httpHeader, _ := helpers.StringsFromSchema(d, "http_header")
184196

185197
for _, s := range allowedSources {
186198
if err := helpers.ValidateIpBlock(s); err != nil {
@@ -203,6 +215,7 @@ func resourceIpLoadbalancingHttpFrontendUpdate(d *schema.ResourceData, meta inte
203215
Ssl: d.Get("ssl").(bool),
204216
RedirectLocation: d.Get("redirect_location").(string),
205217
DisplayName: d.Get("display_name").(string),
218+
HttpHeader: httpHeader,
206219
}
207220

208221
frontend.DefaultFarmId = helpers.GetNilIntPointerFromData(d, "default_farm_id")

ovh/resource_iploadbalancing_http_frontend_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ resource "ovh_iploadbalancing_http_frontend" "testfrontend" {
159159
zone = "all"
160160
port = "22280,22443"
161161
allowed_source = ["8.8.8.8/32"]
162+
http_header = ["X-Ip-Header %%ci", "X-Port-Header %%cp"]
162163
}
163164
`
164165

ovh/types_iploadbalancing.go

+1
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ type IpLoadbalancingHttpFrontend struct {
514514
Ssl bool `json:"ssl"`
515515
RedirectLocation string `json:"redirectLocation,omitempty"`
516516
DisplayName string `json:"displayName,omitempty"`
517+
HttpHeader []string `json:"httpHeader"`
517518
}
518519

519520
type IpLoadbalancingFarmServerCreateOpts struct {

website/docs/r/iploadbalancing_http_frontend.html.markdown

+30
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,31 @@ resource "ovh_iploadbalancing_http_frontend" "testfrontend" {
3434
}
3535
```
3636

37+
## Example Usage with HTTP header
38+
39+
```
40+
data "ovh_iploadbalancing" "lb" {
41+
service_name = "ip-1.2.3.4"
42+
state = "ok"
43+
}
44+
45+
resource "ovh_iploadbalancing_http_farm" "farm80" {
46+
service_name = "${data.ovh_iploadbalancing.lb.service_name}"
47+
display_name = "ingress-8080-gra"
48+
zone = "all"
49+
port = 80
50+
}
51+
52+
resource "ovh_iploadbalancing_http_frontend" "testfrontend" {
53+
service_name = "${data.ovh_iploadbalancing.lb.service_name}"
54+
display_name = "ingress-8080-gra"
55+
zone = "all"
56+
port = "80,443"
57+
default_farm_id = "${ovh_iploadbalancing_http_farm.farm80.id}"
58+
http_header = ["X-Ip-Header %%ci", "X-Port-Header %%cp"]
59+
}
60+
```
61+
3762
## Argument Reference
3863

3964
The following arguments are supported:
@@ -51,12 +76,17 @@ The following arguments are supported:
5176
* `disabled` - Disable your frontend. Default: 'false'
5277
* `ssl` - SSL deciphering. Default: 'false'
5378
* `redirect_location` - Redirection HTTP'
79+
* `http_header` - HTTP headers to add to the frontend. List of string.
5480

5581
## Attributes Reference
5682

5783
The following attributes are exported:
5884

5985
* `id` - Id of your frontend
86+
* `service_name` - See Argument Reference above.
87+
* `port` - See Argument Reference above.
88+
* `zone` - See Argument Reference above.
89+
* `http_header` - See Argument Reference above.
6090
* `display_name` - See Argument Reference above.
6191
* `allowed_source` - See Argument Reference above.
6292
* `dedicated_ipfo` - See Argument Reference above.

0 commit comments

Comments
 (0)