Skip to content

Commit 02b9ae5

Browse files
committed
add proxy_protocol_header_enabled to probe; enhance validation; enhance doc
1 parent f40ce18 commit 02b9ae5

5 files changed

Lines changed: 242 additions & 105 deletions

File tree

internal/services/network/application_gateway_data_source.go

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -932,43 +932,54 @@ func dataSourceApplicationGateway() *pluginsdk.Resource {
932932
Computed: true,
933933
Elem: &pluginsdk.Resource{
934934
Schema: map[string]*pluginsdk.Schema{
935-
"name": {
935+
"host": {
936936
Type: pluginsdk.TypeString,
937937
Computed: true,
938938
},
939939

940-
"protocol": {
940+
"id": {
941941
Type: pluginsdk.TypeString,
942942
Computed: true,
943943
},
944944

945-
"path": {
946-
Type: pluginsdk.TypeString,
945+
"interval": {
946+
Type: pluginsdk.TypeInt,
947947
Computed: true,
948948
},
949949

950-
"host": {
951-
Type: pluginsdk.TypeString,
950+
"match": {
951+
Type: pluginsdk.TypeList,
952952
Computed: true,
953-
},
953+
Elem: &pluginsdk.Resource{
954+
Schema: map[string]*pluginsdk.Schema{
955+
"body": {
956+
Type: pluginsdk.TypeString,
957+
Computed: true,
958+
},
954959

955-
"interval": {
956-
Type: pluginsdk.TypeInt,
957-
Computed: true,
960+
"status_code": {
961+
Type: pluginsdk.TypeList,
962+
Computed: true,
963+
Elem: &pluginsdk.Schema{
964+
Type: pluginsdk.TypeString,
965+
},
966+
},
967+
},
968+
},
958969
},
959970

960-
"timeout": {
971+
"minimum_servers": {
961972
Type: pluginsdk.TypeInt,
962973
Computed: true,
963974
},
964975

965-
"unhealthy_threshold": {
966-
Type: pluginsdk.TypeInt,
976+
"name": {
977+
Type: pluginsdk.TypeString,
967978
Computed: true,
968979
},
969980

970-
"port": {
971-
Type: pluginsdk.TypeInt,
981+
"path": {
982+
Type: pluginsdk.TypeString,
972983
Computed: true,
973984
},
974985

@@ -977,34 +988,28 @@ func dataSourceApplicationGateway() *pluginsdk.Resource {
977988
Computed: true,
978989
},
979990

980-
"minimum_servers": {
991+
"port": {
981992
Type: pluginsdk.TypeInt,
982993
Computed: true,
983994
},
984995

985-
"match": {
986-
Type: pluginsdk.TypeList,
996+
"protocol": {
997+
Type: pluginsdk.TypeString,
987998
Computed: true,
988-
Elem: &pluginsdk.Resource{
989-
Schema: map[string]*pluginsdk.Schema{
990-
"body": {
991-
Type: pluginsdk.TypeString,
992-
Computed: true,
993-
},
999+
},
9941000

995-
"status_code": {
996-
Type: pluginsdk.TypeList,
997-
Computed: true,
998-
Elem: &pluginsdk.Schema{
999-
Type: pluginsdk.TypeString,
1000-
},
1001-
},
1002-
},
1003-
},
1001+
"proxy_protocol_header_enabled": {
1002+
Type: pluginsdk.TypeBool,
1003+
Computed: true,
10041004
},
10051005

1006-
"id": {
1007-
Type: pluginsdk.TypeString,
1006+
"timeout": {
1007+
Type: pluginsdk.TypeInt,
1008+
Computed: true,
1009+
},
1010+
1011+
"unhealthy_threshold": {
1012+
Type: pluginsdk.TypeInt,
10081013
Computed: true,
10091014
},
10101015
},

internal/services/network/application_gateway_resource.go

Lines changed: 86 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,9 +1151,16 @@ func resourceApplicationGateway() *pluginsdk.Resource {
11511151
Optional: true,
11521152
Elem: &pluginsdk.Resource{
11531153
Schema: map[string]*pluginsdk.Schema{
1154+
"interval": {
1155+
Type: pluginsdk.TypeInt,
1156+
Required: true,
1157+
ValidateFunc: validation.IntBetween(1, 86400),
1158+
},
1159+
11541160
"name": {
1155-
Type: pluginsdk.TypeString,
1156-
Required: true,
1161+
Type: pluginsdk.TypeString,
1162+
Required: true,
1163+
ValidateFunc: networkValidate.ApplicationGatewayName,
11571164
},
11581165

11591166
"protocol": {
@@ -1167,47 +1174,22 @@ func resourceApplicationGateway() *pluginsdk.Resource {
11671174
}, false),
11681175
},
11691176

1170-
"path": {
1171-
Type: pluginsdk.TypeString,
1172-
Optional: true,
1173-
},
1174-
1175-
"host": {
1176-
Type: pluginsdk.TypeString,
1177-
Optional: true,
1178-
},
1179-
1180-
"interval": {
1181-
Type: pluginsdk.TypeInt,
1182-
Required: true,
1183-
},
1184-
11851177
"timeout": {
1186-
Type: pluginsdk.TypeInt,
1187-
Required: true,
1178+
Type: pluginsdk.TypeInt,
1179+
Required: true,
1180+
ValidateFunc: validation.IntBetween(1, 86400),
11881181
},
11891182

11901183
"unhealthy_threshold": {
1191-
Type: pluginsdk.TypeInt,
1192-
Required: true,
1193-
},
1194-
1195-
"port": {
11961184
Type: pluginsdk.TypeInt,
1197-
Optional: true,
1198-
ValidateFunc: validate.PortNumber,
1199-
},
1200-
1201-
"pick_host_name_from_backend_http_settings": {
1202-
Type: pluginsdk.TypeBool,
1203-
Optional: true,
1204-
Default: false,
1185+
Required: true,
1186+
ValidateFunc: validation.IntBetween(1, 20),
12051187
},
12061188

1207-
"minimum_servers": {
1208-
Type: pluginsdk.TypeInt,
1209-
Optional: true,
1210-
Default: 0,
1189+
"host": {
1190+
Type: pluginsdk.TypeString,
1191+
Optional: true,
1192+
ValidateFunc: validation.StringIsNotEmpty,
12111193
},
12121194

12131195
// lintignore:XS003
@@ -1233,6 +1215,36 @@ func resourceApplicationGateway() *pluginsdk.Resource {
12331215
},
12341216
},
12351217

1218+
"minimum_servers": {
1219+
Type: pluginsdk.TypeInt,
1220+
Optional: true,
1221+
Default: 0,
1222+
},
1223+
1224+
"path": {
1225+
Type: pluginsdk.TypeString,
1226+
Optional: true,
1227+
ValidateFunc: validation.StringStartsWithOneOf("/"),
1228+
},
1229+
1230+
"pick_host_name_from_backend_http_settings": {
1231+
Type: pluginsdk.TypeBool,
1232+
Optional: true,
1233+
Default: false,
1234+
},
1235+
1236+
"port": {
1237+
Type: pluginsdk.TypeInt,
1238+
Optional: true,
1239+
ValidateFunc: validate.PortNumber,
1240+
},
1241+
1242+
"proxy_protocol_header_enabled": {
1243+
Type: pluginsdk.TypeBool,
1244+
Optional: true,
1245+
Default: false,
1246+
},
1247+
12361248
"id": {
12371249
Type: pluginsdk.TypeString,
12381250
Computed: true,
@@ -3630,6 +3642,7 @@ func expandApplicationGatewayProbes(input []interface{}) *[]applicationgateways.
36303642
Timeout: pointer.To(timeout),
36313643
UnhealthyThreshold: pointer.To(unhealthyThreshold),
36323644
PickHostNameFromBackendHTTPSettings: pointer.To(pickHostNameFromBackendHTTPSettings),
3645+
EnableProbeProxyProtocolHeader: pointer.To(v["proxy_protocol_header_enabled"].(bool)),
36333646
},
36343647
}
36353648

@@ -3711,6 +3724,8 @@ func flattenApplicationGatewayProbes(input *[]applicationgateways.ApplicationGat
37113724
output["pick_host_name_from_backend_http_settings"] = *pickHostNameFromBackendHTTPSettings
37123725
}
37133726

3727+
output["proxy_protocol_header_enabled"] = pointer.From(props.EnableProbeProxyProtocolHeader)
3728+
37143729
if minServers := props.MinServers; minServers != nil {
37153730
output["minimum_servers"] = int(*minServers)
37163731
}
@@ -5391,16 +5406,44 @@ func applicationGatewayCustomizeDiff(ctx context.Context, d *pluginsdk.ResourceD
53915406
if v["host_names"].(*pluginsdk.Set).Len() > 0 && strings.EqualFold(v["protocol"].(string), string(applicationgateways.ApplicationGatewayProtocolTcp)) {
53925407
return fmt.Errorf("`host_names` cannot be set when `protocol` is `Tcp` for `listener` %q", v["name"].(string))
53935408
}
5409+
if strings.EqualFold(v["protocol"].(string), string(applicationgateways.ApplicationGatewayProtocolTls)) && v["ssl_certificate_name"].(string) == "" {
5410+
return fmt.Errorf("`ssl_certificate_name` must be set when `protocol` is `Tls` for `listener` %q", v["name"].(string))
5411+
}
53945412
}
53955413

53965414
for _, raw := range d.Get("probe").(*schema.Set).List() {
53975415
v := raw.(map[string]interface{})
5398-
if v["host"].(string) != "" && v["pick_host_name_from_backend_http_settings"].(bool) {
5399-
return fmt.Errorf("only one of `host` or `pick_host_name_from_backend_http_settings` can be set for `probe` %q", v["name"].(string))
5416+
protocol := v["protocol"].(string)
5417+
isHTTPProtocol := strings.EqualFold(protocol, string(applicationgateways.ApplicationGatewayProtocolHTTP)) || strings.EqualFold(protocol, string(applicationgateways.ApplicationGatewayProtocolHTTPS))
5418+
isTcpTlsProtocol := strings.EqualFold(protocol, string(applicationgateways.ApplicationGatewayProtocolTcp)) || strings.EqualFold(protocol, string(applicationgateways.ApplicationGatewayProtocolTls))
5419+
5420+
hasHost := v["host"].(string) != ""
5421+
hasPickHost := v["pick_host_name_from_backend_http_settings"].(bool)
5422+
if isHTTPProtocol && (hasHost == hasPickHost) {
5423+
return fmt.Errorf("exactly one of `host` or `pick_host_name_from_backend_http_settings` must be set when `protocol` is `Http` or `Https` for `probe` %q", v["name"].(string))
5424+
}
5425+
5426+
if isHTTPProtocol && v["path"].(string) == "" {
5427+
return fmt.Errorf("`path` must be specified when `protocol` is `Http` or `Https` for `probe` %q", v["name"].(string))
54005428
}
54015429

5402-
if v["path"].(string) != "" && (strings.EqualFold(v["protocol"].(string), string(applicationgateways.ApplicationGatewayProtocolTcp)) || strings.EqualFold(v["protocol"].(string), string(applicationgateways.ApplicationGatewayProtocolTls))) {
5403-
return fmt.Errorf("`path` cannot be set when `protocol` is `Tcp` or `Tls` for `probe` %q", v["name"].(string))
5430+
if isTcpTlsProtocol {
5431+
hasPath := v["path"].(string) != ""
5432+
matchConfigs := v["match"].([]interface{})
5433+
hasMatch := len(matchConfigs) > 0 && matchConfigs[0] != nil
5434+
if hasHost || hasPickHost || hasPath || hasMatch {
5435+
return fmt.Errorf("`host`, `pick_host_name_from_backend_http_settings`, `path`, and `match` cannot be set when `protocol` is `Tcp` or `Tls` for `probe` %q", v["name"].(string))
5436+
}
5437+
}
5438+
5439+
if v["proxy_protocol_header_enabled"].(bool) && !isTcpTlsProtocol {
5440+
return fmt.Errorf("`proxy_protocol_header_enabled` can only be set when `protocol` is `Tcp` or `Tls` for `probe` %q", v["name"].(string))
5441+
}
5442+
5443+
timeout := v["timeout"].(int)
5444+
interval := v["interval"].(int)
5445+
if timeout > interval {
5446+
return fmt.Errorf("`timeout` must not be greater than `interval` for `probe` %q", v["name"].(string))
54045447
}
54055448
}
54065449

@@ -5564,6 +5607,9 @@ func applicationGatewayProbeHash(v interface{}) int {
55645607
if v, ok := m["minimum_servers"]; ok {
55655608
buf.WriteString(fmt.Sprintf("%d", v.(int)))
55665609
}
5610+
if v, ok := m["proxy_protocol_header_enabled"]; ok {
5611+
buf.WriteString(fmt.Sprintf("%t", v.(bool)))
5612+
}
55675613
if match, ok := m["match"]; ok {
55685614
if attrs := match.([]interface{}); len(attrs) == 1 && attrs[0] != nil {
55695615
attr := attrs[0].(map[string]interface{})

0 commit comments

Comments
 (0)