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

feat(lb): add support for http_filter_option #1229

Merged
merged 5 commits into from
Apr 22, 2022
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
18 changes: 17 additions & 1 deletion docs/resources/lb_frontend.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ resource "scaleway_lb_frontend" "frontend01" {
invert = "true"
}
}

# Allow upstream http requests that have an HTTP header "foo" that matches "bar"
acl {
action {
type = "allow"
}

match {
http_filter = "http_header_match"
http_filter_value = "foo"
http_value_option = "bar"
}
}
}
```

Expand Down Expand Up @@ -148,9 +161,12 @@ The following arguments are supported:

- `http_filter` - (Optional) The HTTP filter to match. This filter is supported only if your backend protocol has an HTTP forward protocol.
It extracts the request's URL path, which starts at the first slash and ends before the question mark (without the host part).
Possible values are: `acl_http_filter_none`, `path_begin`, `path_end` or `regex`.
Possible values are: `acl_http_filter_none`, `path_begin`, `path_end`, `http_header_match` or `regex`.

- `http_filter_value` - (Optional) A list of possible values to match for the given HTTP filter.
Keep in mind that in the case of `http_header_match` the HTTP header field name is case-insensitive.

- `http_value_option` - (Optional) If you have `http_filter` at `http_header_match`, you can use this field to filter on the HTTP header's value.

- `invert` - (Optional) If set to `true`, the condition will be of type "unless".

Expand Down
18 changes: 10 additions & 8 deletions scaleway/helpers_lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,11 @@ func expandLbACLAction(raw interface{}) *lbSDK.ACLAction {
func flattenLbACLMatch(match *lbSDK.ACLMatch) interface{} {
return []map[string]interface{}{
{
"ip_subnet": flattenSliceStringPtr(match.IPSubnet),
"http_filter": match.HTTPFilter.String(),
"http_filter_value": flattenSliceStringPtr(match.HTTPFilterValue),
"invert": match.Invert,
"ip_subnet": flattenSliceStringPtr(match.IPSubnet),
"http_filter": match.HTTPFilter.String(),
"http_filter_value": flattenSliceStringPtr(match.HTTPFilterValue),
"http_filter_option": match.HTTPFilterOption,
"invert": match.Invert,
},
}
}
Expand All @@ -232,10 +233,11 @@ func expandLbACLMatch(raw interface{}) *lbSDK.ACLMatch {
}

return &lbSDK.ACLMatch{
IPSubnet: ipSubnet,
HTTPFilter: lbSDK.ACLHTTPFilter(rawMap["http_filter"].(string)),
HTTPFilterValue: expandSliceStringPtr(rawMap["http_filter_value"].([]interface{})),
Invert: rawMap["invert"].(bool),
IPSubnet: ipSubnet,
HTTPFilter: lbSDK.ACLHTTPFilter(rawMap["http_filter"].(string)),
HTTPFilterValue: expandSliceStringPtr(rawMap["http_filter_value"].([]interface{})),
HTTPFilterOption: expandStringPtr(rawMap["http_filter_option"].(string)),
Invert: rawMap["invert"].(bool),
}
}

Expand Down
22 changes: 22 additions & 0 deletions scaleway/resource_lb_acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ func TestAccScalewayLbAcl_Basic(t *testing.T) {
type = "deny"
}
}

acl {
match {
ip_subnet = ["0.0.0.0/0"]
http_filter = "http_header_match"
http_filter_value = ["example.com"]
http_filter_option = "host"
}

action {
type = "allow"
}
}
}
`,
Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -139,6 +152,15 @@ func TestAccScalewayLbAcl_Basic(t *testing.T) {
},
Action: &lbSDK.ACLAction{Type: lbSDK.ACLActionTypeDeny},
},
{
Match: &lbSDK.ACLMatch{
IPSubnet: scw.StringSlicePtr([]string{"0.0.0.0/0"}),
HTTPFilter: lbSDK.ACLHTTPFilterHTTPHeaderMatch,
HTTPFilterValue: scw.StringSlicePtr([]string{"example.com"}),
HTTPFilterOption: scw.StringPtr("host"),
},
Action: &lbSDK.ACLAction{Type: lbSDK.ACLActionTypeAllow},
},
}),
),
},
Expand Down
6 changes: 6 additions & 0 deletions scaleway/resource_lb_frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func resourceScalewayLbFrontend() *schema.Resource {
lbSDK.ACLHTTPFilterPathBegin.String(),
lbSDK.ACLHTTPFilterPathEnd.String(),
lbSDK.ACLHTTPFilterRegex.String(),
lbSDK.ACLHTTPFilterHTTPHeaderMatch.String(),
}, false),
Description: "The HTTP filter to match",
},
Expand All @@ -146,6 +147,11 @@ func resourceScalewayLbFrontend() *schema.Resource {
Type: schema.TypeString,
},
},
"http_filter_option": {
Type: schema.TypeString,
Optional: true,
Description: "You can use this field with http_header_match acl type to set the header name to filter",
},
"invert": {
Type: schema.TypeBool,
Optional: true,
Expand Down
Loading