Skip to content

Commit

Permalink
azurerm_traffic_manager_profile - support for custom_header (#… (#5923)
Browse files Browse the repository at this point in the history
(fixes #2187)
  • Loading branch information
jstevans authored Mar 21, 2020
1 parent 1302a9e commit 86565f1
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))),
Expand All @@ -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{})
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ resource "azurerm_traffic_manager_profile" "test" {
"301-303",
]
custom_header {
name = "foo"
value = "bar"
}
protocol = "tcp"
port = 777
Expand Down Expand Up @@ -357,6 +362,11 @@ resource "azurerm_traffic_manager_profile" "test" {
"302-304",
]
custom_header {
name = "foo2"
value = "bar2"
}
protocol = "https"
port = 442
path = "/"
Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/traffic_manager_profile.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 86565f1

Please sign in to comment.