Skip to content
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

Add support for HTTP header on resource_iploadbalancing_http_frontend #356

Merged
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
13 changes: 13 additions & 0 deletions ovh/resource_iploadbalancing_http_frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ func resourceIpLoadbalancingHttpFrontend() *schema.Resource {
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"http_header": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"default_farm_id": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -101,6 +106,7 @@ func resourceIpLoadbalancingHttpFrontendCreate(d *schema.ResourceData, meta inte

allowedSources, _ := helpers.StringsFromSchema(d, "allowed_source")
dedicatedIpFo, _ := helpers.StringsFromSchema(d, "dedicated_ipfo")
httpHeader, _ := helpers.StringsFromSchema(d, "http_header")

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

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

httpHeader := make([]string, 0)
httpHeader = append(httpHeader, r.HttpHeader...)

d.Set("allowed_source", allowedSources)
d.Set("dedicated_ipfo", dedicatedIpFos)
d.Set("default_farm_id", r.DefaultFarmId)
Expand All @@ -170,6 +180,7 @@ func resourceIpLoadbalancingHttpFrontendRead(d *schema.ResourceData, meta interf
d.Set("ssl", r.Ssl)
d.Set("zone", r.Zone)
d.Set("redirect_location", r.RedirectLocation)
d.Set("http_header", httpHeader)

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

allowedSources, _ := helpers.StringsFromSchema(d, "allowed_source")
dedicatedIpFo, _ := helpers.StringsFromSchema(d, "dedicated_ipfo")
httpHeader, _ := helpers.StringsFromSchema(d, "http_header")

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

frontend.DefaultFarmId = helpers.GetNilIntPointerFromData(d, "default_farm_id")
Expand Down
1 change: 1 addition & 0 deletions ovh/resource_iploadbalancing_http_frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ resource "ovh_iploadbalancing_http_frontend" "testfrontend" {
zone = "all"
port = "22280,22443"
allowed_source = ["8.8.8.8/32"]
http_header = ["X-Ip-Header %%ci", "X-Port-Header %%cp"]
}
`

Expand Down
1 change: 1 addition & 0 deletions ovh/types_iploadbalancing.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ type IpLoadbalancingHttpFrontend struct {
Ssl bool `json:"ssl"`
RedirectLocation string `json:"redirectLocation,omitempty"`
DisplayName string `json:"displayName,omitempty"`
HttpHeader []string `json:"httpHeader"`
}

type IpLoadbalancingFarmServerCreateOpts struct {
Expand Down
30 changes: 30 additions & 0 deletions website/docs/r/iploadbalancing_http_frontend.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,31 @@ resource "ovh_iploadbalancing_http_frontend" "testfrontend" {
}
```

## Example Usage with HTTP header

```
data "ovh_iploadbalancing" "lb" {
service_name = "ip-1.2.3.4"
state = "ok"
}

resource "ovh_iploadbalancing_http_farm" "farm80" {
service_name = "${data.ovh_iploadbalancing.lb.service_name}"
display_name = "ingress-8080-gra"
zone = "all"
port = 80
}

resource "ovh_iploadbalancing_http_frontend" "testfrontend" {
service_name = "${data.ovh_iploadbalancing.lb.service_name}"
display_name = "ingress-8080-gra"
zone = "all"
port = "80,443"
default_farm_id = "${ovh_iploadbalancing_http_farm.farm80.id}"
http_header = ["X-Ip-Header %%ci", "X-Port-Header %%cp"]
}
```

## Argument Reference

The following arguments are supported:
Expand All @@ -51,12 +76,17 @@ The following arguments are supported:
* `disabled` - Disable your frontend. Default: 'false'
* `ssl` - SSL deciphering. Default: 'false'
* `redirect_location` - Redirection HTTP'
* `http_header` - HTTP headers to add to the frontend. List of string.
scraly marked this conversation as resolved.
Show resolved Hide resolved

## Attributes Reference
scraly marked this conversation as resolved.
Show resolved Hide resolved

The following attributes are exported:

* `id` - Id of your frontend
* `service_name` - See Argument Reference above.
* `port` - See Argument Reference above.
* `zone` - See Argument Reference above.
* `http_header` - See Argument Reference above.
* `display_name` - See Argument Reference above.
* `allowed_source` - See Argument Reference above.
* `dedicated_ipfo` - See Argument Reference above.
Expand Down