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

azurerm_traffic_manager_profile - support for custom_header (#2187) #5923

Merged
merged 13 commits into from
Mar 21, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,25 @@ func resourceArmTrafficManagerProfile() *schema.Resource {
},
},

"custom_headers": {
Type: schema.TypeList,
jstevans marked this conversation as resolved.
Show resolved Hide resolved
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
DiffSuppressFunc: suppress.CaseDifference,
jstevans marked this conversation as resolved.
Show resolved Hide resolved
},
"value": {
Type: schema.TypeString,
Required: true,
},
},
},
},

"protocol": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -287,8 +306,11 @@ func expandArmTrafficManagerMonitorConfig(d *schema.ResourceData) *trafficmanage
monitorSets := d.Get("monitor_config").([]interface{})
monitor := monitorSets[0].(map[string]interface{})

customHeaders := expandArmTrafficManagerCustomHeadersConfig(monitor["custom_headers"].([]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 +335,41 @@ 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{} {
headers := *input
result := make([]interface{}, 0)
if len(headers) == 0 || headers == nil {
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 +397,7 @@ func flattenAzureRMTrafficManagerProfileMonitorConfig(cfg *trafficmanager.Monito

result["protocol"] = string(cfg.Protocol)
result["port"] = int(*cfg.Port)
result["custom_headers"] = flattenArmTrafficManagerCustomHeadersConfig(cfg.CustomHeaders)

if cfg.Path != nil {
result["path"] = *cfg.Path
Expand Down