Skip to content

Commit

Permalink
azurerm_application_gateway: fix panic in backend and prob pick hostn…
Browse files Browse the repository at this point in the history
…ame validation (#3438)
  • Loading branch information
katbyte authored May 15, 2019
1 parent 5f7ac4f commit 36ce9cc
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions azurerm/resource_arm_application_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -1147,28 +1147,30 @@ func resourceArmApplicationGatewayCreateUpdate(d *schema.ResourceData, meta inte
}

for _, backendHttpSettings := range *backendHTTPSettingsCollection {
backendHttpSettingsProperties := *backendHttpSettings.ApplicationGatewayBackendHTTPSettingsPropertiesFormat
if backendHttpSettingsProperties.HostName != nil {
hostName := *backendHttpSettingsProperties.HostName
pick := *backendHttpSettingsProperties.PickHostNameFromBackendAddress
if props := backendHttpSettings.ApplicationGatewayBackendHTTPSettingsPropertiesFormat; props != nil {
if props.HostName == nil || props.PickHostNameFromBackendAddress == nil {
continue
}

if hostName != "" && pick {
if *props.HostName != "" && *props.PickHostNameFromBackendAddress {
return fmt.Errorf("Only one of `host_name` or `pick_host_name_from_backend_address` can be set")
}
}
}

for _, probe := range *probes {
probeProperties := *probe.ApplicationGatewayProbePropertiesFormat
host := *probeProperties.Host
pick := *probeProperties.PickHostNameFromBackendHTTPSettings
if props := probe.ApplicationGatewayProbePropertiesFormat; props != nil {
if props.Host == nil || props.PickHostNameFromBackendHTTPSettings == nil {
continue
}

if host == "" && !pick {
return fmt.Errorf("One of `host` or `pick_host_name_from_backend_http_settings` must be set")
}
if *props.Host == "" && !*props.PickHostNameFromBackendHTTPSettings {
return fmt.Errorf("One of `host` or `pick_host_name_from_backend_http_settings` must be set")
}

if host != "" && pick {
return fmt.Errorf("Only one of `host` or `pick_host_name_from_backend_http_settings` can be set")
if *props.Host != "" && *props.PickHostNameFromBackendHTTPSettings {
return fmt.Errorf("Only one of `host` or `pick_host_name_from_backend_http_settings` can be set")
}
}
}

Expand Down

0 comments on commit 36ce9cc

Please sign in to comment.