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

Adding the Match parameter to the Probes to check on the response code #1446

Merged
merged 5 commits into from
Jun 28, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
52 changes: 52 additions & 0 deletions azurerm/resource_arm_application_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,29 @@ func resourceArmApplicationGateway() *schema.Resource {
Type: schema.TypeInt,
Required: true,
},

"match": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also add documentation for this block?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"body": {
Type: schema.TypeString,
Optional: true,
Default: "*",
},

"status_code": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given this is a status code, can we make this a TypeInt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

People can specify status codes as ranges also like 200-300.

},
},
},
},
},
},
},
},
Expand Down Expand Up @@ -1162,6 +1185,21 @@ func expandApplicationGatewayProbes(d *schema.ResourceData) *[]network.Applicati
},
}

if matchConfigs := data["match"].([]interface{}); matchConfigs != nil {
match := matchConfigs[0].(map[string]interface{})
matchBody := match["body"].(string)

statusCodes := []string{}
for _, statusCode := range match["status_code"].([]interface{}) {

statusCodes = append(statusCodes, statusCode.(string))
}
setting.ApplicationGatewayProbePropertiesFormat.Match = &network.ApplicationGatewayProbeHealthResponseMatch{
Body: &matchBody,
StatusCodes: &statusCodes,
}
}

backendSettings = append(backendSettings, setting)
}

Expand Down Expand Up @@ -1608,6 +1646,20 @@ func flattenApplicationGatewayProbes(input *[]network.ApplicationGatewayProbe) [
if threshold := props.UnhealthyThreshold; threshold != nil {
settings["unhealthy_threshold"] = int(*threshold)
}

if match := props.Match; match != nil {

matchConfig := map[string]interface{}{
"body": *match.Body,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a potential crash here if body is nil - can we make this:

matchConfig := map[string]interface{}{}
if body := match.Body; body != nil {
  matchConfig["body"] = *body
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Fixed it.

}

statusCodes := make([]interface{}, 0)
for _, status := range *match.StatusCodes {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a potential crash here if the API returns a bad response, can we make this:

if match.StatusCodes != nil {
  for _, status := ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

statusCodes = append(statusCodes, status)
}
matchConfig["status_code"] = statusCodes
settings["match"] = matchConfig
}
}

result = append(result, settings)
Expand Down
10 changes: 10 additions & 0 deletions azurerm/resource_arm_application_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,16 @@ resource "azurerm_application_gateway" "test" {
timeout = 120
interval = 300
unhealthy_threshold = 8
match = {
body = "*"
status_code = [
200,
203,
202,
]
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is an optional block, can we add a test specifically for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a separate test that verifies the presence of Match block in the probe is being set.



}

url_path_map {
Expand Down