Skip to content

Commit

Permalink
first acctest adjustment and panic fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Aris van Ommeren committed Apr 2, 2021
1 parent 9a854a1 commit 67b36cc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
35 changes: 19 additions & 16 deletions azurerm/internal/services/web/app_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2029,24 +2029,27 @@ func flattenHeaders(input map[string][]string) []interface{} {
return append(output, headers)
}

func expandHeaders(input []interface{}) map[string][]string {
func expandHeaders(input interface{}) map[string][]string {
output := make(map[string][]string)
if input == nil || input[0] == nil {
return output
}

val := input[0].(map[string]interface{})
if raw := val["x_forwarded_host"].(*schema.Set).List(); len(raw) > 0 {
output["x-forwarded-host"] = *utils.ExpandStringSlice(raw)
}
if raw := val["x_forwarded_for"].(*schema.Set).List(); len(raw) > 0 {
output["x-forwarded-for"] = *utils.ExpandStringSlice(raw)
}
if raw := val["x_azure_fdid"].(*schema.Set).List(); len(raw) > 0 {
output["x-azure-fdid"] = *utils.ExpandStringSlice(raw)
}
if raw := val["x_fd_health_probe"].(*schema.Set).List(); len(raw) > 0 {
output["x-fd-healthprobe"] = *utils.ExpandStringSlice(raw)
for _, r := range input.([]interface{}) {
if r == nil {
continue
}

val := r.(map[string]interface{})
if raw := val["x_forwarded_host"].(*schema.Set).List(); len(raw) > 0 {
output["x-forwarded-host"] = *utils.ExpandStringSlice(raw)
}
if raw := val["x_forwarded_for"].(*schema.Set).List(); len(raw) > 0 {
output["x-forwarded-for"] = *utils.ExpandStringSlice(raw)
}
if raw := val["x_azure_fdid"].(*schema.Set).List(); len(raw) > 0 {
output["x-azure-fdid"] = *utils.ExpandStringSlice(raw)
}
if raw := val["x_fd_health_probe"].(*schema.Set).List(); len(raw) > 0 {
output["x-fd-healthprobe"] = *utils.ExpandStringSlice(raw)
}
}

return output
Expand Down
16 changes: 16 additions & 0 deletions azurerm/internal/services/web/app_service_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,16 @@ func TestAccAppService_completeIpRestriction(t *testing.T) {
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.name").HasValue("test-restriction"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.priority").HasValue("123"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.action").HasValue("Allow"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_forwarded_for.#").HasValue("2"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_forwarded_for.0").HasValue("2002::1234:abcd:ffff:c0a8:101/64"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_forwarded_for.1").HasValue("9.9.9.9/32"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_azure_fdid.#").HasValue("1"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_azure_fdid.0").HasValue("55ce4ed1-4b06-4bf1-b40e-4638452104da"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_fd_health_probe.#").HasValue("8"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_fd_health_probe.0").HasValue("1"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_fd_health_probe.7").HasValue("8"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_forwarded_host.#").HasValue("1"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_forwarded_host.0").HasValue("example.com"),
),
},
data.ImportStep(),
Expand Down Expand Up @@ -2774,6 +2784,12 @@ resource "azurerm_app_service" "test" {
name = "test-restriction"
priority = 123
action = "Allow"
headers {
x_azure_fdid = ["55ce4ed1-4b06-4bf1-b40e-4638452104da"]
x_fd_health_probe = ["1", "2", "3", "4", "5", "6", "7", "8"]
x_forwarded_for = ["9.9.9.9/32", "2002::1234:abcd:ffff:c0a8:101/64"]
x_forwarded_host = ["example.com"]
}
}
}
}
Expand Down

0 comments on commit 67b36cc

Please sign in to comment.