diff --git a/azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_profile.go b/azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_profile.go index 05a7475d8907..435cccd98cee 100644 --- a/azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_profile.go +++ b/azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_profile.go @@ -106,6 +106,24 @@ func resourceArmTrafficManagerProfile() *schema.Resource { }, }, + "custom_header": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + "value": { + Type: schema.TypeString, + Required: true, + }, + }, + }, + }, + "protocol": { Type: schema.TypeString, Required: true, @@ -287,8 +305,11 @@ func expandArmTrafficManagerMonitorConfig(d *schema.ResourceData) *trafficmanage monitorSets := d.Get("monitor_config").([]interface{}) monitor := monitorSets[0].(map[string]interface{}) + customHeaders := expandArmTrafficManagerCustomHeadersConfig(monitor["custom_header"].([]interface{})) + cfg := trafficmanager.MonitorConfig{ Protocol: trafficmanager.MonitorProtocol(monitor["protocol"].(string)), + CustomHeaders: customHeaders, Port: utils.Int64(int64(monitor["port"].(int))), Path: utils.String(monitor["path"].(string)), IntervalInSeconds: utils.Int64(int64(monitor["interval_in_seconds"].(int))), @@ -313,6 +334,45 @@ func expandArmTrafficManagerMonitorConfig(d *schema.ResourceData) *trafficmanage return &cfg } +func expandArmTrafficManagerCustomHeadersConfig(d []interface{}) *[]trafficmanager.MonitorConfigCustomHeadersItem { + if len(d) == 0 || d[0] == nil { + return nil + } + + customHeaders := make([]trafficmanager.MonitorConfigCustomHeadersItem, len(d)) + + for i, v := range d { + ch := v.(map[string]interface{}) + customHeaders[i] = trafficmanager.MonitorConfigCustomHeadersItem{ + Name: utils.String(ch["name"].(string)), + Value: utils.String(ch["value"].(string)), + } + } + + return &customHeaders +} + +func flattenArmTrafficManagerCustomHeadersConfig(input *[]trafficmanager.MonitorConfigCustomHeadersItem) []interface{} { + result := make([]interface{}, 0) + if input == nil { + return result + } + + headers := *input + if len(headers) == 0 { + return result + } + + for _, v := range headers { + header := make(map[string]string, 2) + header["name"] = *v.Name + header["value"] = *v.Value + result = append(result, header) + } + + return result +} + func expandArmTrafficManagerDNSConfig(d *schema.ResourceData) *trafficmanager.DNSConfig { dnsSets := d.Get("dns_config").([]interface{}) dns := dnsSets[0].(map[string]interface{}) @@ -340,6 +400,7 @@ func flattenAzureRMTrafficManagerProfileMonitorConfig(cfg *trafficmanager.Monito result["protocol"] = string(cfg.Protocol) result["port"] = int(*cfg.Port) + result["custom_header"] = flattenArmTrafficManagerCustomHeadersConfig(cfg.CustomHeaders) if cfg.Path != nil { result["path"] = *cfg.Path diff --git a/azurerm/internal/services/trafficmanager/tests/resource_arm_traffic_manager_profile_test.go b/azurerm/internal/services/trafficmanager/tests/resource_arm_traffic_manager_profile_test.go index 4df235b6aee0..aa0e6679d450 100644 --- a/azurerm/internal/services/trafficmanager/tests/resource_arm_traffic_manager_profile_test.go +++ b/azurerm/internal/services/trafficmanager/tests/resource_arm_traffic_manager_profile_test.go @@ -315,6 +315,11 @@ resource "azurerm_traffic_manager_profile" "test" { "301-303", ] + custom_header { + name = "foo" + value = "bar" + } + protocol = "tcp" port = 777 @@ -357,6 +362,11 @@ resource "azurerm_traffic_manager_profile" "test" { "302-304", ] + custom_header { + name = "foo2" + value = "bar2" + } + protocol = "https" port = 442 path = "/" diff --git a/website/docs/r/traffic_manager_profile.html.markdown b/website/docs/r/traffic_manager_profile.html.markdown index afa790a061f1..6e8e23d3fa3d 100644 --- a/website/docs/r/traffic_manager_profile.html.markdown +++ b/website/docs/r/traffic_manager_profile.html.markdown @@ -92,12 +92,20 @@ The `monitor_config` block supports: * `expected_status_code_ranges` - (Optional) A list of status code ranges in the format of `100-101`. +* `custom_header` - (Optional) One or more `custom_header` blocks as defined below. + * `interval_in_seconds` - (Optional) The interval used to check the endpoint health from a Traffic Manager probing agent. You can specify two values here: `30` (normal probing) and `10` (fast probing). The default value is `30`. * `timeout_in_seconds` - (Optional) The amount of time the Traffic Manager probing agent should wait before considering that check a failure when a health check probe is sent to the endpoint. If `interval_in_seconds` is set to `30`, then `timeout_in_seconds` can be between `5` and `10`. The default value is `10`. If `interval_in_seconds` is set to `10`, then valid values are between `5` and `9` and `timeout_in_seconds` is required. * `tolerated_number_of_failures` - (Optional) The number of failures a Traffic Manager probing agent tolerates before marking that endpoint as unhealthy. Valid values are between `0` and `9`. The default value is `3` +A `custom_header` block supports the following: + +* `name` - (Required) The name of the custom header. + +* `value` - (Required) The value of custom header. Applicable for Http and Https protocol. + ## Attributes Reference The following attributes are exported: