From 465d09e1ca42a58f9d7ff99f2962d7b769e46ee0 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Thu, 9 Jan 2020 15:06:02 -0800 Subject: [PATCH 01/33] Port PR to new code base --- azurerm/internal/services/frontdoor/helper.go | 91 +++++++++++++++++++ .../frontdoor/resource_arm_front_door.go | 39 ++++---- .../internal/services/frontdoor/validate.go | 10 +- website/docs/r/front_door.html.markdown | 54 +++++------ 4 files changed, 147 insertions(+), 47 deletions(-) diff --git a/azurerm/internal/services/frontdoor/helper.go b/azurerm/internal/services/frontdoor/helper.go index 8dc1e23e2493..6b2aad654dff 100644 --- a/azurerm/internal/services/frontdoor/helper.go +++ b/azurerm/internal/services/frontdoor/helper.go @@ -2,9 +2,11 @@ package frontdoor import ( "fmt" + "net/url" "strings" "github.com/Azure/azure-sdk-for-go/services/frontdoor/mgmt/2019-04-01/frontdoor" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" ) func VerifyBackendPoolExists(backendPoolName string, backendPools []interface{}) error { @@ -201,3 +203,92 @@ func FlattenFrontendEndpointLinkSlice(input *[]frontdoor.FrontendEndpointLink) [ } return result } + +// ParseAzureResourceIDLowerPath converts a long-form Azure Resource Manager ID +// into a ResourceID. We make assumptions about the structure of URLs, +// which is obviously not good, but the best thing available given the +// SDK. I had to normalize the key casing of Path because the Front Door API +// via Portal does not have consistent casing within the resource, for example: +// +// In the backendPools block the casing of the HealthProbeSettings is (notice the lowercase 'h'): +// portal-front-door/ -> healthProbeSettings/healthProbeSettings-1571100669337 +// +// but in the HealthProbeSettings block the casing of the HealthProbeSettings is (notice the uppercase 'H'):: +// portal-front-door/ -> HealthProbeSettings/healthProbeSettings-1571100669337 +// +// so if I need to parse the name of the resource from its ID string I would be +// unable to do so with the current implementation so I normalize the key into +// a known format so I can reliable parse the ID string. +// +// Link to issue: https://github.com/Azure/azure-sdk-for-go/issues/6762 +func ParseAzureResourceIDLowerPath(id string) (*azure.ResourceID, error) { + idURL, err := url.ParseRequestURI(id) + if err != nil { + return nil, fmt.Errorf("Cannot parse Azure ID: %s", err) + } + + path := idURL.Path + + path = strings.TrimPrefix(path, "/") + path = strings.TrimSuffix(path, "/") + + components := strings.Split(path, "/") + + // We should have an even number of key-value pairs. + if len(components)%2 != 0 { + return nil, fmt.Errorf("The number of path segments is not divisible by 2 in %q", path) + } + + var subscriptionID string + + // Put the constituent key-value pairs into a map + componentMap := make(map[string]string, len(components)/2) + for current := 0; current < len(components); current += 2 { + key := strings.ToLower(components[current]) + value := components[current+1] + + // Check key/value for empty strings. + if key == "" || value == "" { + return nil, fmt.Errorf("Key/Value cannot be empty strings. Key: '%s', Value: '%s'", key, value) + } + + // Catch the subscriptionID before it can be overwritten by another "subscriptions" + // value in the ID which is the case for the Service Bus subscription resource + if key == "subscriptions" && subscriptionID == "" { + subscriptionID = value + } else { + componentMap[key] = value + } + } + + // Build up a ResourceID from the map + idObj := &azure.ResourceID{} + idObj.Path = componentMap + + if subscriptionID != "" { + idObj.SubscriptionID = subscriptionID + } else { + return nil, fmt.Errorf("No subscription ID found in: %q", path) + } + + if resourceGroup, ok := componentMap["resourceGroups"]; ok { + idObj.ResourceGroup = resourceGroup + delete(componentMap, "resourceGroups") + } else { + // Some Azure APIs are weird and provide things in lower case... + // However it's not clear whether the casing of other elements in the URI + // matter, so we explicitly look for that case here. + if resourceGroup, ok := componentMap["resourcegroups"]; ok { + idObj.ResourceGroup = resourceGroup + delete(componentMap, "resourcegroups") + } + } + + // It is OK not to have a provider in the case of a resource group + if provider, ok := componentMap["providers"]; ok { + idObj.Provider = provider + delete(componentMap, "providers") + } + + return idObj, nil +} diff --git a/azurerm/internal/services/frontdoor/resource_arm_front_door.go b/azurerm/internal/services/frontdoor/resource_arm_front_door.go index 3e382e256d59..a10d1b692931 100644 --- a/azurerm/internal/services/frontdoor/resource_arm_front_door.go +++ b/azurerm/internal/services/frontdoor/resource_arm_front_door.go @@ -3,6 +3,7 @@ package frontdoor import ( "fmt" "log" + "strings" "time" "github.com/Azure/azure-sdk-for-go/services/frontdoor/mgmt/2019-04-01/frontdoor" @@ -172,11 +173,12 @@ func resourceArmFrontDoor() *schema.Resource { Required: true, ValidateFunc: ValidateBackendPoolRoutingRuleName, }, + // Remove default value for #4461 "cache_use_dynamic_compression": { Type: schema.TypeBool, Optional: true, - Default: false, }, + // Remove default value for #4461 "cache_query_parameter_strip_directive": { Type: schema.TypeString, Optional: true, @@ -184,12 +186,12 @@ func resourceArmFrontDoor() *schema.Resource { string(frontdoor.StripAll), string(frontdoor.StripNone), }, false), - Default: string(frontdoor.StripNone), }, "custom_forwarding_path": { Type: schema.TypeString, Optional: true, }, + // Added Portal Default value for #4627 "forwarding_protocol": { Type: schema.TypeString, Optional: true, @@ -198,7 +200,7 @@ func resourceArmFrontDoor() *schema.Resource { string(frontdoor.HTTPSOnly), string(frontdoor.MatchRequest), }, false), - Default: string(frontdoor.MatchRequest), + Default: string(frontdoor.HTTPSOnly), }, }, }, @@ -596,7 +598,7 @@ func resourceArmFrontDoorRead(d *schema.ResourceData, meta interface{}) error { ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := ParseAzureResourceIDLowerPath(d.Id()) if err != nil { return err } @@ -668,7 +670,7 @@ func resourceArmFrontDoorDelete(d *schema.ResourceData, meta interface{}) error ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := ParseAzureResourceIDLowerPath(d.Id()) if err != nil { return err } @@ -1050,20 +1052,9 @@ func expandArmFrontDoorForwardingConfiguration(input []interface{}, frontDoorPat customForwardingPath := v["custom_forwarding_path"].(string) forwardingProtocol := v["forwarding_protocol"].(string) + backendPoolName := v["backend_pool_name"].(string) cacheUseDynamicCompression := v["cache_use_dynamic_compression"].(bool) cacheQueryParameterStripDirective := v["cache_query_parameter_strip_directive"].(string) - backendPoolName := v["backend_pool_name"].(string) - - useDynamicCompression := frontdoor.DynamicCompressionEnabledDisabled - - if cacheUseDynamicCompression { - useDynamicCompression = frontdoor.DynamicCompressionEnabledEnabled - } - - cacheConfiguration := &frontdoor.CacheConfiguration{ - QueryParameterStripDirective: frontdoor.Query(cacheQueryParameterStripDirective), - DynamicCompression: useDynamicCompression, - } backend := &frontdoor.SubResource{ ID: utils.String(frontDoorPath + "/BackendPools/" + backendPoolName), @@ -1071,11 +1062,19 @@ func expandArmFrontDoorForwardingConfiguration(input []interface{}, frontDoorPat forwardingConfiguration := frontdoor.ForwardingConfiguration{ ForwardingProtocol: frontdoor.ForwardingProtocol(forwardingProtocol), - CacheConfiguration: cacheConfiguration, BackendPool: backend, OdataType: frontdoor.OdataTypeMicrosoftAzureFrontDoorModelsFrontdoorForwardingConfiguration, } + // Per the portal, if you enable the cache the cache_query_parameter_strip_directive + // is then a required attribute else the CacheConfiguration type is null + if cacheUseDynamicCompression { + forwardingConfiguration.CacheConfiguration = &frontdoor.CacheConfiguration{ + DynamicCompression: frontdoor.DynamicCompressionEnabledEnabled, + QueryParameterStripDirective: frontdoor.Query(cacheQueryParameterStripDirective), + } + } + if customForwardingPath != "" { forwardingConfiguration.CustomForwardingPath = utils.String(customForwardingPath) } @@ -1409,11 +1408,11 @@ func flattenArmFrontDoorSubResource(input *frontdoor.SubResource, resourceType s name := "" if id := input.ID; id != nil { - aid, err := azure.ParseAzureResourceID(*id) + aid, err := ParseAzureResourceIDLowerPath(*id) if err != nil { return "" } - name = aid.Path[resourceType] + name = aid.Path[strings.ToLower(resourceType)] } return name diff --git a/azurerm/internal/services/frontdoor/validate.go b/azurerm/internal/services/frontdoor/validate.go index 007a0ce96cdc..6a38df599011 100644 --- a/azurerm/internal/services/frontdoor/validate.go +++ b/azurerm/internal/services/frontdoor/validate.go @@ -65,9 +65,17 @@ func ValidateFrontdoorSettings(d *schema.ResourceDiff) error { if err := VerifyBackendPoolExists(fc["backend_pool_name"].(string), backendPools); err != nil { return fmt.Errorf(`"routing_rule":%q is invalid. %+v`, routingRuleName, err) } + + // Check 3. validate if the cache_query_parameter_strip_directive is defined + // that the cache_use_dynamic_compression is set to true + if cacheQueryParameterStripDirective := fc["cache_query_parameter_strip_directive"].(string); cacheQueryParameterStripDirective != "" { + if !fc["cache_use_dynamic_compression"].(bool) { + return fmt.Errorf(`"routing_rule": %q is invalid. "cache_use_dynamic_compression" must be set to "true" if the "cache_query_parameter_strip_directive" attribute is defined`, routingRuleName) + } + } } - // Check 3. validate that each routing rule frontend_endpoints are actually defined in the resource schema + // Check 4. validate that each routing rule frontend_endpoints are actually defined in the resource schema if routingRuleFrontends := routingRule["frontend_endpoints"].([]interface{}); len(routingRuleFrontends) > 0 { if err := VerifyRoutingRuleFrontendEndpoints(routingRuleFrontends, configFrontendEndpoints); err != nil { return fmt.Errorf(`"routing_rule":%q %+v`, routingRuleName, err) diff --git a/website/docs/r/front_door.html.markdown b/website/docs/r/front_door.html.markdown index 1fe5c035f5c1..27b9de0aa0ad 100644 --- a/website/docs/r/front_door.html.markdown +++ b/website/docs/r/front_door.html.markdown @@ -70,11 +70,11 @@ resource "azurerm_frontdoor" "example" { The following arguments are supported: -* `name` - (Required) Name of the Front Door which is globally unique. Changing this forces a new resource to be created. +* `name` - (Required) Specifies the name of the `Front Door` service. Changing this forces a new resource to be created. -* `resource_group_name` - (Required) Name of the Resource group within the Azure subscription. Changing this forces a new resource to be created. +* `resource_group_name` - (Required) Specifies the name of the Resource Group in which the `Front Door` service should exist. Changing this forces a new resource to be created. -* `location` - (Required) Resource location. Changing this forces a new resource to be created. +* `location` - (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. * `backend_pool` - (Required) A `backend_pool` block as defined below. @@ -82,29 +82,29 @@ The following arguments are supported: * `backend_pool_load_balancing` - (Required) A `backend_pool_load_balancing` block as defined below. -* `enforce_backend_pools_certificate_name_check` - (Required) Whether to enforce certificate name check on HTTPS requests to all backend pools. No effect on non-HTTPS requests. Permitted values are `true` or `false`. +* `enforce_backend_pools_certificate_name_check` - (Required) Enforce certificate name check on `HTTPS` requests to all backend pools, this setting will have no effect on `HTTP` requests. Permitted values are `true` or `false`. -* `load_balancer_enabled` - (Optional) Operational status of the Front Door load balancer. Permitted values are `true` or `false` Defaults to `true`. +* `load_balancer_enabled` - (Optional) Operational status of the `Front Door` load balancer. Permitted values are `true` or `false` Defaults to `true`. -* `friendly_name` - (Optional) A friendly name for the Front Door service. +* `friendly_name` - (Optional) A friendly name for the `Front Door` service. * `frontend_endpoint` - (Required) A `frontend_endpoint` block as defined below. * `routing_rule` - (Required) A `routing_rule` block as defined below. -* `tags` - (Optional) Resource tags. +* `tags` - (Optional) A mapping of tags to assign to the resource. --- The `backend_pool` block supports the following: -* `name` - (Required) The name of the `Backend Pool`. +* `name` - (Required) Specifies the name of the name of the `Backend Pool`. * `backend` - (Required) A `backend` block as defined below. -* `load_balancing_name` - (Required) The name property of the `backend_pool_load_balancing` block whithin this resource to use for the `Backend Pool`. +* `load_balancing_name` - (Required) Specifies the name of the `backend_pool_load_balancing` block whithin this resource to use for this `Backend Pool`. -* `health_probe_name` - (Required) The name property of a `backend_pool_health_probe` block whithin this resource to use for the `Backend Pool`. +* `health_probe_name` - (Required) Specifies the name of the `backend_pool_health_probe` block whithin this resource to use for this `Backend Pool`. --- @@ -126,35 +126,37 @@ The `backend` block supports the following: The `frontend_endpoint` block supports the following: -* `name` - (Required) The name of the Frontend Endpoint. +* `name` - (Required) Specifies the name of the `frontend_endpoint`. -* `host_name` - (Required) The host name of the Frontend Endpoint. Must be a domain name. - -* `custom_https_provisioning_enabled` - (Required) Whether to allow HTTPS protocol for a custom domain that's associated with Front Door to ensure sensitive data is delivered securely via TLS/SSL encryption when sent across the internet. Valid options are `true` or `false`. +* `host_name` - (Required) Specifies the host name of the `frontend_endpoint`. Must be a domain name. * `session_affinity_enabled` - (Optional) Whether to allow session affinity on this host. Valid options are `true` or `false` Defaults to `false`. * `session_affinity_ttl_seconds` - (Optional) The TTL to use in seconds for session affinity, if applicable. Defaults to `0`. +* `custom_https_provisioning_enabled` - (Required) Whether to allow HTTPS protocol for a custom domain that's associated with Front Door to ensure sensitive data is delivered securely via TLS/SSL encryption when sent across the internet. Valid options are `true` or `false`. + +* `custom_https_configuration` - (Optional) A `custom_https_configuration` block as defined below. This block is required if the `custom_https_provisioning_enabled` is set to `true`. + * `web_application_firewall_policy_link_id` - (Optional) Defines the Web Application Firewall policy `ID` for each host. --- The `backend_pool_health_probe` block supports the following: -* `name` - (Required) The name of the Azure Front Door Backend Health Probe. +* `name` - (Required) Specifies the name of the `backend_pool_health_probe`. -* `path` - (Optional) The path to use for the Backend Health Probe. Default is `/`. +* `path` - (Optional) The path to use for the `backend_pool_health_probe`. Default is `/`. -* `protocol` - (Optional) Protocol scheme to use for the Backend Health Probe. Defaults to `Http`. +* `protocol` - (Optional) Protocol scheme to use for the `backend_pool_health_probe`. Defaults to `Http`. -* `interval_in_seconds` - (Optional) The number of seconds between health probes. Defaults to `120`. +* `interval_in_seconds` - (Optional) The number of seconds between the `backend_pool_health_probe` probes. Defaults to `120`. --- The `backend_pool_load_balancing` block supports the following: -* `name` - (Required) The name of the Azure Front Door Backend Load Balancer. +* `name` - (Required) Specifies the name of the `backend_pool_load_balancing`. * `sample_size` - (Optional) The number of samples to consider for load balancing decisions. Defaults to `4`. @@ -166,7 +168,7 @@ The `backend_pool_load_balancing` block supports the following: The `routing_rule` block supports the following: -* `name` - (Required) The name of the Front Door Backend Routing Rule. +* `name` - (Required) Specifies the name of the `routing_rule`. * `frontend_endpoints` - (Required) The names of the `frontend_endpoint` blocks whithin this resource to associate with this `routing_rule`. @@ -184,15 +186,15 @@ The `routing_rule` block supports the following: The `forwarding_configuration` block supports the following: -* `backend_pool_name` - (Required) The name of the Front Door Backend Pool. +* `backend_pool_name` - (Required) Specifies the name of the `backend_pool` to forward the incoming traffic to. -* `cache_use_dynamic_compression` - (Optional) Whether to use dynamic compression when caching. Valid options are `true` or `false`. Defaults to `true`. +* `cache_use_dynamic_compression` - (Optional) Whether to use dynamic compression when caching. Valid options are `true` or `false`. Defaults to `false`. -* `cache_query_parameter_strip_directive` - (Optional) Defines cache behavior in releation to query string parameters. Valid options are `StripAll` or `StripNone`. Defaults to `StripNone` +* `cache_query_parameter_strip_directive` - (Optional) Defines cache behavior in releation to query string parameters. Valid options are `StripAll` or `StripNone`. * `custom_forwarding_path` - (Optional) Path to use when constructing the request to forward to the backend. This functions as a URL Rewrite. Default behavior preserves the URL path. -* `forwarding_protocol` - (Optional) Protocol to use when redirecting. Valid options are `HttpOnly`, `HttpsOnly`, or `MatchRequest`. Defaults to `MatchRequest`. +* `forwarding_protocol` - (Optional) Protocol to use when redirecting. Valid options are `HTTPOnly`, `HTTPSOnly`, or `MatchRequest`. Defaults to `HTTPSOnly`. --- @@ -200,7 +202,7 @@ The `redirect_configuration` block supports the following: * `custom_host` - (Optional) Set this to change the URL for the redirection. -* `redirect_protocol` - (Optional) Protocol to use when redirecting. Valid options are `HttpOnly`, `HttpsOnly`, `MatchRequest`. Defaults to `MatchRequest` +* `redirect_protocol` - (Optional) Protocol to use when redirecting. Valid options are `HTTPOnly`, `HTTPSOnly`, `MatchRequest`. Defaults to `MatchRequest` * `redirect_type` - (Optional) Status code for the redirect. Valida options are `Moved`, `Found`, `TemporaryRedirect`, `PermanentRedirect`. Defaults to `Found` @@ -218,7 +220,7 @@ The `custom_https_configuration` block supports the following: The following attributes are only valid if `certificate_source` is set to `AzureKeyVault`: -* `azure_key_vault_certificate_vault_id` - (Required) The `id` of the Key Vault containing the SSL certificate. +* `azure_key_vault_certificate_vault_id` - (Required) The `ID` of the Key Vault containing the SSL certificate. * `azure_key_vault_certificate_secret_name` - (Required) The name of the Key Vault secret representing the full certificate PFX. From 4904a2026f0ba300d6ad3e7b6a24a7438ff7eaa3 Mon Sep 17 00:00:00 2001 From: WS <20408400+WodansSon@users.noreply.github.com> Date: Mon, 13 Jan 2020 15:24:50 -0800 Subject: [PATCH 02/33] Update website/docs/r/front_door.html.markdown Co-Authored-By: Tom Harvey --- website/docs/r/front_door.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/front_door.html.markdown b/website/docs/r/front_door.html.markdown index 27b9de0aa0ad..2b529fefdca3 100644 --- a/website/docs/r/front_door.html.markdown +++ b/website/docs/r/front_door.html.markdown @@ -70,7 +70,7 @@ resource "azurerm_frontdoor" "example" { The following arguments are supported: -* `name` - (Required) Specifies the name of the `Front Door` service. Changing this forces a new resource to be created. +* `name` - (Required) Specifies the name of the Front Door service. Changing this forces a new resource to be created. * `resource_group_name` - (Required) Specifies the name of the Resource Group in which the `Front Door` service should exist. Changing this forces a new resource to be created. From f62f456856bbffef67f43be0c13343d47123c9c8 Mon Sep 17 00:00:00 2001 From: WS <20408400+WodansSon@users.noreply.github.com> Date: Mon, 13 Jan 2020 15:25:09 -0800 Subject: [PATCH 03/33] Update website/docs/r/front_door.html.markdown Co-Authored-By: Tom Harvey --- website/docs/r/front_door.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/front_door.html.markdown b/website/docs/r/front_door.html.markdown index 2b529fefdca3..2eb2ada31cdd 100644 --- a/website/docs/r/front_door.html.markdown +++ b/website/docs/r/front_door.html.markdown @@ -72,7 +72,7 @@ The following arguments are supported: * `name` - (Required) Specifies the name of the Front Door service. Changing this forces a new resource to be created. -* `resource_group_name` - (Required) Specifies the name of the Resource Group in which the `Front Door` service should exist. Changing this forces a new resource to be created. +* `resource_group_name` - (Required) Specifies the name of the Resource Group in which the Front Door service should exist. Changing this forces a new resource to be created. * `location` - (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. From c85c9c13fb5ed7f0f39d2e018995f92448dca81a Mon Sep 17 00:00:00 2001 From: WS <20408400+WodansSon@users.noreply.github.com> Date: Mon, 13 Jan 2020 15:25:40 -0800 Subject: [PATCH 04/33] Update website/docs/r/front_door.html.markdown Co-Authored-By: Tom Harvey --- website/docs/r/front_door.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/front_door.html.markdown b/website/docs/r/front_door.html.markdown index 2eb2ada31cdd..b2a380678829 100644 --- a/website/docs/r/front_door.html.markdown +++ b/website/docs/r/front_door.html.markdown @@ -156,7 +156,7 @@ The `backend_pool_health_probe` block supports the following: The `backend_pool_load_balancing` block supports the following: -* `name` - (Required) Specifies the name of the `backend_pool_load_balancing`. +* `name` - (Required) Specifies the name of the Load Balancer. * `sample_size` - (Optional) The number of samples to consider for load balancing decisions. Defaults to `4`. From cfe157dcd01d4306c3e428f5fd4b48507d1eb716 Mon Sep 17 00:00:00 2001 From: WS <20408400+WodansSon@users.noreply.github.com> Date: Mon, 13 Jan 2020 15:25:52 -0800 Subject: [PATCH 05/33] Update website/docs/r/front_door.html.markdown Co-Authored-By: Tom Harvey --- website/docs/r/front_door.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/front_door.html.markdown b/website/docs/r/front_door.html.markdown index b2a380678829..3ed9b2916ab8 100644 --- a/website/docs/r/front_door.html.markdown +++ b/website/docs/r/front_door.html.markdown @@ -186,7 +186,7 @@ The `routing_rule` block supports the following: The `forwarding_configuration` block supports the following: -* `backend_pool_name` - (Required) Specifies the name of the `backend_pool` to forward the incoming traffic to. +* `backend_pool_name` - (Required) Specifies the name of the Backend Pool to forward the incoming traffic to. * `cache_use_dynamic_compression` - (Optional) Whether to use dynamic compression when caching. Valid options are `true` or `false`. Defaults to `false`. From ff57240bc939dcad8428bfa39087cc4f90810a18 Mon Sep 17 00:00:00 2001 From: WS <20408400+WodansSon@users.noreply.github.com> Date: Mon, 13 Jan 2020 15:26:33 -0800 Subject: [PATCH 06/33] Update website/docs/r/front_door.html.markdown Co-Authored-By: Tom Harvey --- website/docs/r/front_door.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/front_door.html.markdown b/website/docs/r/front_door.html.markdown index 3ed9b2916ab8..99d8ba26df12 100644 --- a/website/docs/r/front_door.html.markdown +++ b/website/docs/r/front_door.html.markdown @@ -220,7 +220,7 @@ The `custom_https_configuration` block supports the following: The following attributes are only valid if `certificate_source` is set to `AzureKeyVault`: -* `azure_key_vault_certificate_vault_id` - (Required) The `ID` of the Key Vault containing the SSL certificate. +* `azure_key_vault_certificate_vault_id` - (Required) The ID of the Key Vault containing the SSL certificate. * `azure_key_vault_certificate_secret_name` - (Required) The name of the Key Vault secret representing the full certificate PFX. From d9aecd846cd07354cb1742e261a6dc7fcdd93398 Mon Sep 17 00:00:00 2001 From: WS <20408400+WodansSon@users.noreply.github.com> Date: Mon, 13 Jan 2020 15:27:04 -0800 Subject: [PATCH 07/33] Update website/docs/r/front_door.html.markdown Co-Authored-By: Tom Harvey --- website/docs/r/front_door.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/front_door.html.markdown b/website/docs/r/front_door.html.markdown index 99d8ba26df12..db2d39a10187 100644 --- a/website/docs/r/front_door.html.markdown +++ b/website/docs/r/front_door.html.markdown @@ -168,7 +168,7 @@ The `backend_pool_load_balancing` block supports the following: The `routing_rule` block supports the following: -* `name` - (Required) Specifies the name of the `routing_rule`. +* `name` - (Required) Specifies the name of the Routing Rule. * `frontend_endpoints` - (Required) The names of the `frontend_endpoint` blocks whithin this resource to associate with this `routing_rule`. From 17c05f69cb95c2930a87051f2aa30925d9727fd8 Mon Sep 17 00:00:00 2001 From: WS <20408400+WodansSon@users.noreply.github.com> Date: Mon, 13 Jan 2020 15:28:23 -0800 Subject: [PATCH 08/33] Update website/docs/r/front_door.html.markdown Co-Authored-By: Tom Harvey --- website/docs/r/front_door.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/front_door.html.markdown b/website/docs/r/front_door.html.markdown index db2d39a10187..c725a6254244 100644 --- a/website/docs/r/front_door.html.markdown +++ b/website/docs/r/front_door.html.markdown @@ -86,7 +86,7 @@ The following arguments are supported: * `load_balancer_enabled` - (Optional) Operational status of the `Front Door` load balancer. Permitted values are `true` or `false` Defaults to `true`. -* `friendly_name` - (Optional) A friendly name for the `Front Door` service. +* `friendly_name` - (Optional) A friendly name for the Front Door service. * `frontend_endpoint` - (Required) A `frontend_endpoint` block as defined below. From e46221e84994ecd7570617f3f0a0e75943f90d53 Mon Sep 17 00:00:00 2001 From: WS <20408400+WodansSon@users.noreply.github.com> Date: Mon, 13 Jan 2020 15:29:06 -0800 Subject: [PATCH 09/33] Update website/docs/r/front_door.html.markdown Co-Authored-By: Tom Harvey --- website/docs/r/front_door.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/front_door.html.markdown b/website/docs/r/front_door.html.markdown index c725a6254244..750d8e6b350c 100644 --- a/website/docs/r/front_door.html.markdown +++ b/website/docs/r/front_door.html.markdown @@ -84,7 +84,7 @@ The following arguments are supported: * `enforce_backend_pools_certificate_name_check` - (Required) Enforce certificate name check on `HTTPS` requests to all backend pools, this setting will have no effect on `HTTP` requests. Permitted values are `true` or `false`. -* `load_balancer_enabled` - (Optional) Operational status of the `Front Door` load balancer. Permitted values are `true` or `false` Defaults to `true`. +* `load_balancer_enabled` - (Optional) Should the Front Door Load Balancer be Enabled? Defaults to `true`. * `friendly_name` - (Optional) A friendly name for the Front Door service. From b88ef6b980e496cbe0d57cc0cd309900d64c0367 Mon Sep 17 00:00:00 2001 From: WS <20408400+WodansSon@users.noreply.github.com> Date: Mon, 13 Jan 2020 15:29:34 -0800 Subject: [PATCH 10/33] Update website/docs/r/front_door.html.markdown Co-Authored-By: Tom Harvey --- website/docs/r/front_door.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/front_door.html.markdown b/website/docs/r/front_door.html.markdown index 750d8e6b350c..79506c84fa44 100644 --- a/website/docs/r/front_door.html.markdown +++ b/website/docs/r/front_door.html.markdown @@ -102,7 +102,7 @@ The `backend_pool` block supports the following: * `backend` - (Required) A `backend` block as defined below. -* `load_balancing_name` - (Required) Specifies the name of the `backend_pool_load_balancing` block whithin this resource to use for this `Backend Pool`. +* `load_balancing_name` - (Required) Specifies the name of the `backend_pool_load_balancing` block within this resource to use for this `Backend Pool`. * `health_probe_name` - (Required) Specifies the name of the `backend_pool_health_probe` block whithin this resource to use for this `Backend Pool`. From 5e21698570a85a10032a318b730549eb17420f40 Mon Sep 17 00:00:00 2001 From: WS <20408400+WodansSon@users.noreply.github.com> Date: Mon, 13 Jan 2020 15:30:06 -0800 Subject: [PATCH 11/33] Update website/docs/r/front_door.html.markdown Co-Authored-By: Tom Harvey --- website/docs/r/front_door.html.markdown | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/website/docs/r/front_door.html.markdown b/website/docs/r/front_door.html.markdown index 79506c84fa44..917c386ac972 100644 --- a/website/docs/r/front_door.html.markdown +++ b/website/docs/r/front_door.html.markdown @@ -136,7 +136,9 @@ The `frontend_endpoint` block supports the following: * `custom_https_provisioning_enabled` - (Required) Whether to allow HTTPS protocol for a custom domain that's associated with Front Door to ensure sensitive data is delivered securely via TLS/SSL encryption when sent across the internet. Valid options are `true` or `false`. -* `custom_https_configuration` - (Optional) A `custom_https_configuration` block as defined below. This block is required if the `custom_https_provisioning_enabled` is set to `true`. +* `custom_https_configuration` - (Optional) A `custom_https_configuration` block as defined below. + +-> **NOTE:** This block is required when `custom_https_provisioning_enabled` is set to `true`. * `web_application_firewall_policy_link_id` - (Optional) Defines the Web Application Firewall policy `ID` for each host. From 5b17a5190e6cfacdc6cb8b7921cde90c6bb522a4 Mon Sep 17 00:00:00 2001 From: WS <20408400+WodansSon@users.noreply.github.com> Date: Mon, 13 Jan 2020 15:30:21 -0800 Subject: [PATCH 12/33] Update website/docs/r/front_door.html.markdown Co-Authored-By: Tom Harvey --- website/docs/r/front_door.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/front_door.html.markdown b/website/docs/r/front_door.html.markdown index 917c386ac972..6f23a2fd7bbd 100644 --- a/website/docs/r/front_door.html.markdown +++ b/website/docs/r/front_door.html.markdown @@ -98,7 +98,7 @@ The following arguments are supported: The `backend_pool` block supports the following: -* `name` - (Required) Specifies the name of the name of the `Backend Pool`. +* `name` - (Required) Specifies the name of the name of the Backend Pool. * `backend` - (Required) A `backend` block as defined below. From 644ac7149674e93fec6885713d3ca79708e863ed Mon Sep 17 00:00:00 2001 From: WS <20408400+WodansSon@users.noreply.github.com> Date: Mon, 13 Jan 2020 15:31:23 -0800 Subject: [PATCH 13/33] Update website/docs/r/front_door.html.markdown Co-Authored-By: Tom Harvey --- website/docs/r/front_door.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/front_door.html.markdown b/website/docs/r/front_door.html.markdown index 6f23a2fd7bbd..693b4525bc0e 100644 --- a/website/docs/r/front_door.html.markdown +++ b/website/docs/r/front_door.html.markdown @@ -134,7 +134,7 @@ The `frontend_endpoint` block supports the following: * `session_affinity_ttl_seconds` - (Optional) The TTL to use in seconds for session affinity, if applicable. Defaults to `0`. -* `custom_https_provisioning_enabled` - (Required) Whether to allow HTTPS protocol for a custom domain that's associated with Front Door to ensure sensitive data is delivered securely via TLS/SSL encryption when sent across the internet. Valid options are `true` or `false`. +* `custom_https_provisioning_enabled` - (Required) Should the HTTPS protocol be enabled for a custom domain associated with the Front Door? * `custom_https_configuration` - (Optional) A `custom_https_configuration` block as defined below. From 8ef9e23ffdb385bb428868fbd03712d8dcd2baca Mon Sep 17 00:00:00 2001 From: WS <20408400+WodansSon@users.noreply.github.com> Date: Mon, 13 Jan 2020 15:31:48 -0800 Subject: [PATCH 14/33] Update website/docs/r/front_door.html.markdown Co-Authored-By: Tom Harvey --- website/docs/r/front_door.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/front_door.html.markdown b/website/docs/r/front_door.html.markdown index 693b4525bc0e..a0723aaa1307 100644 --- a/website/docs/r/front_door.html.markdown +++ b/website/docs/r/front_door.html.markdown @@ -146,7 +146,7 @@ The `frontend_endpoint` block supports the following: The `backend_pool_health_probe` block supports the following: -* `name` - (Required) Specifies the name of the `backend_pool_health_probe`. +* `name` - (Required) Specifies the name of the Health Probe. * `path` - (Optional) The path to use for the `backend_pool_health_probe`. Default is `/`. From 9cf59c2955fb605513cd0945729f64faee742d63 Mon Sep 17 00:00:00 2001 From: WS <20408400+WodansSon@users.noreply.github.com> Date: Mon, 13 Jan 2020 15:32:14 -0800 Subject: [PATCH 15/33] Update website/docs/r/front_door.html.markdown Co-Authored-By: Tom Harvey --- website/docs/r/front_door.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/front_door.html.markdown b/website/docs/r/front_door.html.markdown index a0723aaa1307..3e6ec12a5ec8 100644 --- a/website/docs/r/front_door.html.markdown +++ b/website/docs/r/front_door.html.markdown @@ -152,7 +152,7 @@ The `backend_pool_health_probe` block supports the following: * `protocol` - (Optional) Protocol scheme to use for the `backend_pool_health_probe`. Defaults to `Http`. -* `interval_in_seconds` - (Optional) The number of seconds between the `backend_pool_health_probe` probes. Defaults to `120`. +* `interval_in_seconds` - (Optional) The number of seconds between each Health Probe. Defaults to `120`. --- From 2ca543735095f671088494127461a7af15a03a89 Mon Sep 17 00:00:00 2001 From: WS <20408400+WodansSon@users.noreply.github.com> Date: Mon, 13 Jan 2020 15:32:37 -0800 Subject: [PATCH 16/33] Update website/docs/r/front_door.html.markdown Co-Authored-By: Tom Harvey --- website/docs/r/front_door.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/front_door.html.markdown b/website/docs/r/front_door.html.markdown index 3e6ec12a5ec8..8bd96303cb4c 100644 --- a/website/docs/r/front_door.html.markdown +++ b/website/docs/r/front_door.html.markdown @@ -150,7 +150,7 @@ The `backend_pool_health_probe` block supports the following: * `path` - (Optional) The path to use for the `backend_pool_health_probe`. Default is `/`. -* `protocol` - (Optional) Protocol scheme to use for the `backend_pool_health_probe`. Defaults to `Http`. +* `protocol` - (Optional) Protocol scheme to use for the Health Probe. Defaults to `Http`. * `interval_in_seconds` - (Optional) The number of seconds between each Health Probe. Defaults to `120`. From e8978c5a7c2418bd127f6beef66b64decebf7a35 Mon Sep 17 00:00:00 2001 From: WS <20408400+WodansSon@users.noreply.github.com> Date: Mon, 13 Jan 2020 15:32:57 -0800 Subject: [PATCH 17/33] Update website/docs/r/front_door.html.markdown Co-Authored-By: Tom Harvey --- website/docs/r/front_door.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/front_door.html.markdown b/website/docs/r/front_door.html.markdown index 8bd96303cb4c..b451859ae550 100644 --- a/website/docs/r/front_door.html.markdown +++ b/website/docs/r/front_door.html.markdown @@ -148,7 +148,7 @@ The `backend_pool_health_probe` block supports the following: * `name` - (Required) Specifies the name of the Health Probe. -* `path` - (Optional) The path to use for the `backend_pool_health_probe`. Default is `/`. +* `path` - (Optional) The path to use for the Health Probe. Default is `/`. * `protocol` - (Optional) Protocol scheme to use for the Health Probe. Defaults to `Http`. From ba86c8289ea87b2b11b0772506bd9ba4041c9dfd Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Mon, 13 Jan 2020 18:32:47 -0800 Subject: [PATCH 18/33] Progress --- azurerm/internal/services/frontdoor/helper.go | 91 ------------------- .../frontdoor/resource_arm_front_door.go | 67 ++++++++++---- website/docs/r/front_door.html.markdown | 8 +- 3 files changed, 53 insertions(+), 113 deletions(-) diff --git a/azurerm/internal/services/frontdoor/helper.go b/azurerm/internal/services/frontdoor/helper.go index 6b2aad654dff..8dc1e23e2493 100644 --- a/azurerm/internal/services/frontdoor/helper.go +++ b/azurerm/internal/services/frontdoor/helper.go @@ -2,11 +2,9 @@ package frontdoor import ( "fmt" - "net/url" "strings" "github.com/Azure/azure-sdk-for-go/services/frontdoor/mgmt/2019-04-01/frontdoor" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" ) func VerifyBackendPoolExists(backendPoolName string, backendPools []interface{}) error { @@ -203,92 +201,3 @@ func FlattenFrontendEndpointLinkSlice(input *[]frontdoor.FrontendEndpointLink) [ } return result } - -// ParseAzureResourceIDLowerPath converts a long-form Azure Resource Manager ID -// into a ResourceID. We make assumptions about the structure of URLs, -// which is obviously not good, but the best thing available given the -// SDK. I had to normalize the key casing of Path because the Front Door API -// via Portal does not have consistent casing within the resource, for example: -// -// In the backendPools block the casing of the HealthProbeSettings is (notice the lowercase 'h'): -// portal-front-door/ -> healthProbeSettings/healthProbeSettings-1571100669337 -// -// but in the HealthProbeSettings block the casing of the HealthProbeSettings is (notice the uppercase 'H'):: -// portal-front-door/ -> HealthProbeSettings/healthProbeSettings-1571100669337 -// -// so if I need to parse the name of the resource from its ID string I would be -// unable to do so with the current implementation so I normalize the key into -// a known format so I can reliable parse the ID string. -// -// Link to issue: https://github.com/Azure/azure-sdk-for-go/issues/6762 -func ParseAzureResourceIDLowerPath(id string) (*azure.ResourceID, error) { - idURL, err := url.ParseRequestURI(id) - if err != nil { - return nil, fmt.Errorf("Cannot parse Azure ID: %s", err) - } - - path := idURL.Path - - path = strings.TrimPrefix(path, "/") - path = strings.TrimSuffix(path, "/") - - components := strings.Split(path, "/") - - // We should have an even number of key-value pairs. - if len(components)%2 != 0 { - return nil, fmt.Errorf("The number of path segments is not divisible by 2 in %q", path) - } - - var subscriptionID string - - // Put the constituent key-value pairs into a map - componentMap := make(map[string]string, len(components)/2) - for current := 0; current < len(components); current += 2 { - key := strings.ToLower(components[current]) - value := components[current+1] - - // Check key/value for empty strings. - if key == "" || value == "" { - return nil, fmt.Errorf("Key/Value cannot be empty strings. Key: '%s', Value: '%s'", key, value) - } - - // Catch the subscriptionID before it can be overwritten by another "subscriptions" - // value in the ID which is the case for the Service Bus subscription resource - if key == "subscriptions" && subscriptionID == "" { - subscriptionID = value - } else { - componentMap[key] = value - } - } - - // Build up a ResourceID from the map - idObj := &azure.ResourceID{} - idObj.Path = componentMap - - if subscriptionID != "" { - idObj.SubscriptionID = subscriptionID - } else { - return nil, fmt.Errorf("No subscription ID found in: %q", path) - } - - if resourceGroup, ok := componentMap["resourceGroups"]; ok { - idObj.ResourceGroup = resourceGroup - delete(componentMap, "resourceGroups") - } else { - // Some Azure APIs are weird and provide things in lower case... - // However it's not clear whether the casing of other elements in the URI - // matter, so we explicitly look for that case here. - if resourceGroup, ok := componentMap["resourcegroups"]; ok { - idObj.ResourceGroup = resourceGroup - delete(componentMap, "resourcegroups") - } - } - - // It is OK not to have a provider in the case of a resource group - if provider, ok := componentMap["providers"]; ok { - idObj.Provider = provider - delete(componentMap, "providers") - } - - return idObj, nil -} diff --git a/azurerm/internal/services/frontdoor/resource_arm_front_door.go b/azurerm/internal/services/frontdoor/resource_arm_front_door.go index a10d1b692931..5c60ab0909b6 100644 --- a/azurerm/internal/services/frontdoor/resource_arm_front_door.go +++ b/azurerm/internal/services/frontdoor/resource_arm_front_door.go @@ -3,7 +3,6 @@ package frontdoor import ( "fmt" "log" - "strings" "time" "github.com/Azure/azure-sdk-for-go/services/frontdoor/mgmt/2019-04-01/frontdoor" @@ -173,12 +172,16 @@ func resourceArmFrontDoor() *schema.Resource { Required: true, ValidateFunc: ValidateBackendPoolRoutingRuleName, }, - // Remove default value for #4461 + "cache_enabled": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, "cache_use_dynamic_compression": { Type: schema.TypeBool, Optional: true, + Default: false, }, - // Remove default value for #4461 "cache_query_parameter_strip_directive": { Type: schema.TypeString, Optional: true, @@ -186,6 +189,7 @@ func resourceArmFrontDoor() *schema.Resource { string(frontdoor.StripAll), string(frontdoor.StripNone), }, false), + Default: string(frontdoor.StripNone), }, "custom_forwarding_path": { Type: schema.TypeString, @@ -200,7 +204,7 @@ func resourceArmFrontDoor() *schema.Resource { string(frontdoor.HTTPSOnly), string(frontdoor.MatchRequest), }, false), - Default: string(frontdoor.HTTPSOnly), + Default: string(frontdoor.MatchRequest), }, }, }, @@ -598,12 +602,16 @@ func resourceArmFrontDoorRead(d *schema.ResourceData, meta interface{}) error { ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := ParseAzureResourceIDLowerPath(d.Id()) + id, err := azure.ParseAzureResourceID(d.Id()) if err != nil { return err } resourceGroup := id.ResourceGroup name := id.Path["frontdoors"] + // Link to issue: https://github.com/Azure/azure-sdk-for-go/issues/6762 + if name == "" { + name = id.Path["Frontdoors"] + } resp, err := client.Get(ctx, resourceGroup, name) if err != nil { @@ -670,12 +678,16 @@ func resourceArmFrontDoorDelete(d *schema.ResourceData, meta interface{}) error ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := ParseAzureResourceIDLowerPath(d.Id()) + id, err := azure.ParseAzureResourceID(d.Id()) if err != nil { return err } resourceGroup := id.ResourceGroup name := id.Path["frontdoors"] + // Link to issue: https://github.com/Azure/azure-sdk-for-go/issues/6762 + if name == "" { + name = id.Path["Frontdoors"] + } future, err := client.Delete(ctx, resourceGroup, name) if err != nil { @@ -1055,6 +1067,7 @@ func expandArmFrontDoorForwardingConfiguration(input []interface{}, frontDoorPat backendPoolName := v["backend_pool_name"].(string) cacheUseDynamicCompression := v["cache_use_dynamic_compression"].(bool) cacheQueryParameterStripDirective := v["cache_query_parameter_strip_directive"].(string) + cacheEnabled := v["cache_enabled"].(bool) backend := &frontdoor.SubResource{ ID: utils.String(frontDoorPath + "/BackendPools/" + backendPoolName), @@ -1068,9 +1081,14 @@ func expandArmFrontDoorForwardingConfiguration(input []interface{}, frontDoorPat // Per the portal, if you enable the cache the cache_query_parameter_strip_directive // is then a required attribute else the CacheConfiguration type is null - if cacheUseDynamicCompression { + if cacheEnabled { + dynamicCompression := frontdoor.DynamicCompressionEnabledEnabled + if !cacheUseDynamicCompression { + dynamicCompression = frontdoor.DynamicCompressionEnabledDisabled + } + forwardingConfiguration.CacheConfiguration = &frontdoor.CacheConfiguration{ - DynamicCompression: frontdoor.DynamicCompressionEnabledEnabled, + DynamicCompression: dynamicCompression, QueryParameterStripDirective: frontdoor.Query(cacheQueryParameterStripDirective), } } @@ -1103,7 +1121,16 @@ func flattenArmFrontDoorBackendPools(input *[]frontdoor.BackendPool) []map[strin if properties := v.BackendPoolProperties; properties != nil { result["backend"] = flattenArmFrontDoorBackend(properties.Backends) result["health_probe_name"] = flattenArmFrontDoorSubResource(properties.HealthProbeSettings, "HealthProbeSettings") + // Link to issue: https://github.com/Azure/azure-sdk-for-go/issues/6762 + if result["health_probe_name"] == "" { + result["health_probe_name"] = flattenArmFrontDoorSubResource(properties.HealthProbeSettings, "healthProbeSettings") + } + result["load_balancing_name"] = flattenArmFrontDoorSubResource(properties.LoadBalancingSettings, "LoadBalancingSettings") + // Link to issue: https://github.com/Azure/azure-sdk-for-go/issues/6762 + if result["load_balancing_name"] == "" { + result["load_balancing_name"] = flattenArmFrontDoorSubResource(properties.LoadBalancingSettings, "loadBalancingSettings") + } } output = append(output, result) } @@ -1345,22 +1372,20 @@ func flattenArmFrontDoorRoutingRule(input *[]frontdoor.RoutingRule) []interface{ v := brc.(frontdoor.ForwardingConfiguration) c["backend_pool_name"] = flattenArmFrontDoorSubResource(v.BackendPool, "BackendPools") + // Link to issue: https://github.com/Azure/azure-sdk-for-go/issues/6762 + if c["backend_pool_name"] == "" { + c["backend_pool_name"] = flattenArmFrontDoorSubResource(v.BackendPool, "backendPools") + } c["custom_forwarding_path"] = v.CustomForwardingPath c["forwarding_protocol"] = string(v.ForwardingProtocol) if cacheConfiguration := v.CacheConfiguration; cacheConfiguration != nil { - if queryParameter := cacheConfiguration.QueryParameterStripDirective; queryParameter != "" { - c["cache_query_parameter_strip_directive"] = string(queryParameter) - } else { - c["cache_query_parameter_strip_directive"] = string(frontdoor.StripNone) + if stripDirective := cacheConfiguration.QueryParameterStripDirective; stripDirective != "" { + c["cache_query_parameter_strip_directive"] = string(stripDirective) } - c["cache_use_dynamic_compression"] = false - if dynamicCompression := cacheConfiguration.DynamicCompression; dynamicCompression != "" { - if dynamicCompression == frontdoor.DynamicCompressionEnabledEnabled { - c["cache_use_dynamic_compression"] = true - } + c["cache_use_dynamic_compression"] = (dynamicCompression == frontdoor.DynamicCompressionEnabledEnabled) } } @@ -1408,11 +1433,11 @@ func flattenArmFrontDoorSubResource(input *frontdoor.SubResource, resourceType s name := "" if id := input.ID; id != nil { - aid, err := ParseAzureResourceIDLowerPath(*id) + aid, err := azure.ParseAzureResourceID(*id) if err != nil { return "" } - name = aid.Path[strings.ToLower(resourceType)] + name = aid.Path[resourceType] } return name @@ -1427,6 +1452,10 @@ func flattenArmFrontDoorFrontendEndpointsSubResources(input *[]frontdoor.SubReso for _, v := range *input { name := flattenArmFrontDoorSubResource(&v, "FrontendEndpoints") + // Link to issue: https://github.com/Azure/azure-sdk-for-go/issues/6762 + if name == "" { + name = flattenArmFrontDoorSubResource(&v, "frontendEndpoints") + } output = append(output, name) } diff --git a/website/docs/r/front_door.html.markdown b/website/docs/r/front_door.html.markdown index b451859ae550..569f78444c39 100644 --- a/website/docs/r/front_door.html.markdown +++ b/website/docs/r/front_door.html.markdown @@ -190,13 +190,15 @@ The `forwarding_configuration` block supports the following: * `backend_pool_name` - (Required) Specifies the name of the Backend Pool to forward the incoming traffic to. +* `cache_enabled` - (Optional) Specifies whether to Enable caching or not. Valid options are `true` or `false`. Defaults to `false`. + * `cache_use_dynamic_compression` - (Optional) Whether to use dynamic compression when caching. Valid options are `true` or `false`. Defaults to `false`. -* `cache_query_parameter_strip_directive` - (Optional) Defines cache behavior in releation to query string parameters. Valid options are `StripAll` or `StripNone`. +* `cache_query_parameter_strip_directive` - (Optional) Defines cache behavior in releation to query string parameters. Valid options are `StripAll` or `StripNone`. Defaults to `StripNone`. * `custom_forwarding_path` - (Optional) Path to use when constructing the request to forward to the backend. This functions as a URL Rewrite. Default behavior preserves the URL path. -* `forwarding_protocol` - (Optional) Protocol to use when redirecting. Valid options are `HTTPOnly`, `HTTPSOnly`, or `MatchRequest`. Defaults to `HTTPSOnly`. +* `forwarding_protocol` - (Optional) Protocol to use when redirecting. Valid options are `HttpOnly`, `HttpsOnly`, or `MatchRequest`. Defaults to `HttpsOnly`. --- @@ -204,7 +206,7 @@ The `redirect_configuration` block supports the following: * `custom_host` - (Optional) Set this to change the URL for the redirection. -* `redirect_protocol` - (Optional) Protocol to use when redirecting. Valid options are `HTTPOnly`, `HTTPSOnly`, `MatchRequest`. Defaults to `MatchRequest` +* `redirect_protocol` - (Optional) Protocol to use when redirecting. Valid options are `HttpOnly`, `HttpsOnly`, or `MatchRequest`. Defaults to `MatchRequest` * `redirect_type` - (Optional) Status code for the redirect. Valida options are `Moved`, `Found`, `TemporaryRedirect`, `PermanentRedirect`. Defaults to `Found` From 6c9af26723c17f302b2e53a740ecbc9e5f2b9852 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Tue, 14 Jan 2020 18:10:09 -0800 Subject: [PATCH 19/33] Saving progress --- .../services/frontdoor/resource_arm_front_door.go | 2 -- azurerm/internal/services/frontdoor/validate.go | 11 ++++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/azurerm/internal/services/frontdoor/resource_arm_front_door.go b/azurerm/internal/services/frontdoor/resource_arm_front_door.go index 5c60ab0909b6..f0c8fd24cfa7 100644 --- a/azurerm/internal/services/frontdoor/resource_arm_front_door.go +++ b/azurerm/internal/services/frontdoor/resource_arm_front_door.go @@ -180,7 +180,6 @@ func resourceArmFrontDoor() *schema.Resource { "cache_use_dynamic_compression": { Type: schema.TypeBool, Optional: true, - Default: false, }, "cache_query_parameter_strip_directive": { Type: schema.TypeString, @@ -189,7 +188,6 @@ func resourceArmFrontDoor() *schema.Resource { string(frontdoor.StripAll), string(frontdoor.StripNone), }, false), - Default: string(frontdoor.StripNone), }, "custom_forwarding_path": { Type: schema.TypeString, diff --git a/azurerm/internal/services/frontdoor/validate.go b/azurerm/internal/services/frontdoor/validate.go index 6a38df599011..74ab1dd9018e 100644 --- a/azurerm/internal/services/frontdoor/validate.go +++ b/azurerm/internal/services/frontdoor/validate.go @@ -62,15 +62,20 @@ func ValidateFrontdoorSettings(d *schema.ResourceDiff) error { // Check 2. routing rule is a forwarding_configuration type make sure the backend_pool_name exists in the configuration file if len(forwardConfig) > 0 { fc := forwardConfig[0].(map[string]interface{}) + cacheEnabled := fc["cache_enabled"].(bool) + if err := VerifyBackendPoolExists(fc["backend_pool_name"].(string), backendPools); err != nil { return fmt.Errorf(`"routing_rule":%q is invalid. %+v`, routingRuleName, err) } // Check 3. validate if the cache_query_parameter_strip_directive is defined // that the cache_use_dynamic_compression is set to true - if cacheQueryParameterStripDirective := fc["cache_query_parameter_strip_directive"].(string); cacheQueryParameterStripDirective != "" { - if !fc["cache_use_dynamic_compression"].(bool) { - return fmt.Errorf(`"routing_rule": %q is invalid. "cache_use_dynamic_compression" must be set to "true" if the "cache_query_parameter_strip_directive" attribute is defined`, routingRuleName) + // !!! DO NOT VALIDATE IF CACHE IS DISABLED AS THE VALUES WILL BE IGNORED !!! + if cacheEnabled { + if cacheQueryParameterStripDirective := fc["cache_query_parameter_strip_directive"].(string); cacheQueryParameterStripDirective != "" { + if !fc["cache_use_dynamic_compression"].(bool) { + return fmt.Errorf(`"routing_rule": %q is invalid. "cache_use_dynamic_compression" must be set to "true" if the "cache_query_parameter_strip_directive" attribute is defined`, routingRuleName) + } } } } From 9923e355c7c68f560f35a8e45ea3f49b8e449bd3 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Thu, 16 Jan 2020 19:32:05 -0800 Subject: [PATCH 20/33] Almost right --- .../frontdoor/resource_arm_front_door.go | 18 +++++++++++++-- .../internal/services/frontdoor/validate.go | 22 ++++++++++--------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/azurerm/internal/services/frontdoor/resource_arm_front_door.go b/azurerm/internal/services/frontdoor/resource_arm_front_door.go index f0c8fd24cfa7..b21b1a85fa5a 100644 --- a/azurerm/internal/services/frontdoor/resource_arm_front_door.go +++ b/azurerm/internal/services/frontdoor/resource_arm_front_door.go @@ -175,15 +175,17 @@ func resourceArmFrontDoor() *schema.Resource { "cache_enabled": { Type: schema.TypeBool, Optional: true, - Default: false, + Default: true, }, "cache_use_dynamic_compression": { Type: schema.TypeBool, Optional: true, + Computed: true, }, "cache_query_parameter_strip_directive": { Type: schema.TypeString, Optional: true, + Computed: true, ValidateFunc: validation.StringInSlice([]string{ string(frontdoor.StripAll), string(frontdoor.StripNone), @@ -1080,11 +1082,17 @@ func expandArmFrontDoorForwardingConfiguration(input []interface{}, frontDoorPat // Per the portal, if you enable the cache the cache_query_parameter_strip_directive // is then a required attribute else the CacheConfiguration type is null if cacheEnabled { + // Set the default value for dynamic compression or use the value defined in the config dynamicCompression := frontdoor.DynamicCompressionEnabledEnabled if !cacheUseDynamicCompression { dynamicCompression = frontdoor.DynamicCompressionEnabledDisabled } + if cacheQueryParameterStripDirective == "" { + // Set Default Value for strip directive is not in the key slice and cache is enabled + cacheQueryParameterStripDirective = string(frontdoor.StripNone) + } + forwardingConfiguration.CacheConfiguration = &frontdoor.CacheConfiguration{ DynamicCompression: dynamicCompression, QueryParameterStripDirective: frontdoor.Query(cacheQueryParameterStripDirective), @@ -1378,13 +1386,19 @@ func flattenArmFrontDoorRoutingRule(input *[]frontdoor.RoutingRule) []interface{ c["forwarding_protocol"] = string(v.ForwardingProtocol) if cacheConfiguration := v.CacheConfiguration; cacheConfiguration != nil { + c["cache_enabled"] = true if stripDirective := cacheConfiguration.QueryParameterStripDirective; stripDirective != "" { c["cache_query_parameter_strip_directive"] = string(stripDirective) + } else { + c["cache_query_parameter_strip_directive"] = string(frontdoor.StripNone) } if dynamicCompression := cacheConfiguration.DynamicCompression; dynamicCompression != "" { - c["cache_use_dynamic_compression"] = (dynamicCompression == frontdoor.DynamicCompressionEnabledEnabled) + c["cache_use_dynamic_compression"] = bool(string(dynamicCompression) == string(frontdoor.DynamicCompressionEnabledEnabled)) } + } else { + + c["cache_enabled"] = false } rc = append(rc, c) diff --git a/azurerm/internal/services/frontdoor/validate.go b/azurerm/internal/services/frontdoor/validate.go index 74ab1dd9018e..07257b603d9c 100644 --- a/azurerm/internal/services/frontdoor/validate.go +++ b/azurerm/internal/services/frontdoor/validate.go @@ -32,7 +32,7 @@ func ValidateCustomBlockResponseBody(i interface{}, k string) (_ []string, error } func ValidateFrontdoorSettings(d *schema.ResourceDiff) error { - routingRules := d.Get("routing_rule").([]interface{}) + _, routingRules := d.GetChange("routing_rule") //.([]interface{}) configFrontendEndpoints := d.Get("frontend_endpoint").([]interface{}) backendPools := d.Get("backend_pool").([]interface{}) loadBalancingSettings := d.Get("backend_pool_load_balancing").([]interface{}) @@ -43,7 +43,7 @@ func ValidateFrontdoorSettings(d *schema.ResourceDiff) error { } // Loop over all of the Routing Rules and validate that only one type of configuration is defined per Routing Rule - for _, rr := range routingRules { + for _, rr := range routingRules.([]interface{}) { routingRule := rr.(map[string]interface{}) routingRuleName := routingRule["name"] redirectConfig := routingRule["redirect_configuration"].([]interface{}) @@ -68,14 +68,16 @@ func ValidateFrontdoorSettings(d *schema.ResourceDiff) error { return fmt.Errorf(`"routing_rule":%q is invalid. %+v`, routingRuleName, err) } - // Check 3. validate if the cache_query_parameter_strip_directive is defined - // that the cache_use_dynamic_compression is set to true - // !!! DO NOT VALIDATE IF CACHE IS DISABLED AS THE VALUES WILL BE IGNORED !!! - if cacheEnabled { - if cacheQueryParameterStripDirective := fc["cache_query_parameter_strip_directive"].(string); cacheQueryParameterStripDirective != "" { - if !fc["cache_use_dynamic_compression"].(bool) { - return fmt.Errorf(`"routing_rule": %q is invalid. "cache_use_dynamic_compression" must be set to "true" if the "cache_query_parameter_strip_directive" attribute is defined`, routingRuleName) - } + // Check 3. Check cache enabled states + if !cacheEnabled { + // If the cache is not enabled make sure the cache values are not set in the config file + // Get new value instead of old value + if stripDirective := fc["cache_query_parameter_strip_directive"]; stripDirective != "" { + return fmt.Errorf(`"routing_rule": %q "forwarding_configuration" is invalid. Please make sure that the "cache_query_parameter_strip_directive" and "cache_use_dynamic_compression" do not exist in the configuration file`, routingRuleName) + } + + if v, ok := fc["cache_use_dynamic_compression"]; ok && v == true { + return fmt.Errorf(`"routing_rule": %q "forwarding_configuration" is invalid. Please make sure that the "cache_use_dynamic_compression" does not exist in the configuration file`, routingRuleName) } } } From ffafcb96cefa6d517917f143c48a7cdbd208b9f9 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Fri, 17 Jan 2020 13:44:21 -0800 Subject: [PATCH 21/33] Cache working --- .../frontdoor/resource_arm_front_door.go | 5 +- .../internal/services/frontdoor/validate.go | 49 ++++++++++++------- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/azurerm/internal/services/frontdoor/resource_arm_front_door.go b/azurerm/internal/services/frontdoor/resource_arm_front_door.go index b21b1a85fa5a..35239226885d 100644 --- a/azurerm/internal/services/frontdoor/resource_arm_front_door.go +++ b/azurerm/internal/services/frontdoor/resource_arm_front_door.go @@ -451,6 +451,10 @@ func resourceArmFrontDoor() *schema.Resource { } func resourceArmFrontDoorCreateUpdate(d *schema.ResourceData, meta interface{}) error { + if err := ValidateFrontdoorRoutingRuleSettings(d); err != nil { + return err + } + client := meta.(*clients.Client).Frontdoor.FrontDoorsClient ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() @@ -1397,7 +1401,6 @@ func flattenArmFrontDoorRoutingRule(input *[]frontdoor.RoutingRule) []interface{ c["cache_use_dynamic_compression"] = bool(string(dynamicCompression) == string(frontdoor.DynamicCompressionEnabledEnabled)) } } else { - c["cache_enabled"] = false } diff --git a/azurerm/internal/services/frontdoor/validate.go b/azurerm/internal/services/frontdoor/validate.go index 07257b603d9c..31fa2d8f27cc 100644 --- a/azurerm/internal/services/frontdoor/validate.go +++ b/azurerm/internal/services/frontdoor/validate.go @@ -32,7 +32,7 @@ func ValidateCustomBlockResponseBody(i interface{}, k string) (_ []string, error } func ValidateFrontdoorSettings(d *schema.ResourceDiff) error { - _, routingRules := d.GetChange("routing_rule") //.([]interface{}) + routingRules := d.Get("routing_rule").([]interface{}) configFrontendEndpoints := d.Get("frontend_endpoint").([]interface{}) backendPools := d.Get("backend_pool").([]interface{}) loadBalancingSettings := d.Get("backend_pool_load_balancing").([]interface{}) @@ -43,7 +43,7 @@ func ValidateFrontdoorSettings(d *schema.ResourceDiff) error { } // Loop over all of the Routing Rules and validate that only one type of configuration is defined per Routing Rule - for _, rr := range routingRules.([]interface{}) { + for _, rr := range routingRules { routingRule := rr.(map[string]interface{}) routingRuleName := routingRule["name"] redirectConfig := routingRule["redirect_configuration"].([]interface{}) @@ -62,27 +62,13 @@ func ValidateFrontdoorSettings(d *schema.ResourceDiff) error { // Check 2. routing rule is a forwarding_configuration type make sure the backend_pool_name exists in the configuration file if len(forwardConfig) > 0 { fc := forwardConfig[0].(map[string]interface{}) - cacheEnabled := fc["cache_enabled"].(bool) if err := VerifyBackendPoolExists(fc["backend_pool_name"].(string), backendPools); err != nil { return fmt.Errorf(`"routing_rule":%q is invalid. %+v`, routingRuleName, err) } - - // Check 3. Check cache enabled states - if !cacheEnabled { - // If the cache is not enabled make sure the cache values are not set in the config file - // Get new value instead of old value - if stripDirective := fc["cache_query_parameter_strip_directive"]; stripDirective != "" { - return fmt.Errorf(`"routing_rule": %q "forwarding_configuration" is invalid. Please make sure that the "cache_query_parameter_strip_directive" and "cache_use_dynamic_compression" do not exist in the configuration file`, routingRuleName) - } - - if v, ok := fc["cache_use_dynamic_compression"]; ok && v == true { - return fmt.Errorf(`"routing_rule": %q "forwarding_configuration" is invalid. Please make sure that the "cache_use_dynamic_compression" does not exist in the configuration file`, routingRuleName) - } - } } - // Check 4. validate that each routing rule frontend_endpoints are actually defined in the resource schema + // Check 3. validate that each routing rule frontend_endpoints are actually defined in the resource schema if routingRuleFrontends := routingRule["frontend_endpoints"].([]interface{}); len(routingRuleFrontends) > 0 { if err := VerifyRoutingRuleFrontendEndpoints(routingRuleFrontends, configFrontendEndpoints); err != nil { return fmt.Errorf(`"routing_rule":%q %+v`, routingRuleName, err) @@ -104,3 +90,32 @@ func ValidateFrontdoorSettings(d *schema.ResourceDiff) error { return nil } + +func ValidateFrontdoorRoutingRuleSettings(d *schema.ResourceData) error { + routingRules := d.Get("routing_rule").([]interface{}) + + // Loop over all of the Routing Rules and validate that only one type of configuration is defined per Routing Rule + for _, rr := range routingRules { + routingRule := rr.(map[string]interface{}) + forwardConfig := routingRule["forwarding_configuration"].([]interface{}) + + // If the routing rule is a forwarding_configuration type and the cache has been disabled + // make sure none of the other cache attributes have values + if len(forwardConfig) > 0 { + fc := forwardConfig[0].(map[string]interface{}) + cacheEnabled := fc["cache_enabled"].(bool) + + if !cacheEnabled { + if stripDirective := fc["cache_query_parameter_strip_directive"]; stripDirective != "" { + return fmt.Errorf(`"routing_rule:forwarding_configuration" is invalid. Please make sure that the "cache_query_parameter_strip_directive" does not exist in the configuration file`) + } + + if v, ok := fc["cache_use_dynamic_compression"]; ok && v == true { + return fmt.Errorf(`"routing_rule:forwarding_configuration" is invalid. Please make sure that the "cache_use_dynamic_compression" does not exist in the configuration file`) + } + } + } + } + + return nil +} From 20032ed2658ae6e37e420bed757c812ed3344f67 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Tue, 21 Jan 2020 19:11:30 -0800 Subject: [PATCH 22/33] Fully working without defaults --- .../frontdoor/resource_arm_front_door.go | 9 +--- .../internal/services/frontdoor/validate.go | 53 ++++++++----------- 2 files changed, 22 insertions(+), 40 deletions(-) diff --git a/azurerm/internal/services/frontdoor/resource_arm_front_door.go b/azurerm/internal/services/frontdoor/resource_arm_front_door.go index 35239226885d..3906acd5db49 100644 --- a/azurerm/internal/services/frontdoor/resource_arm_front_door.go +++ b/azurerm/internal/services/frontdoor/resource_arm_front_door.go @@ -175,17 +175,15 @@ func resourceArmFrontDoor() *schema.Resource { "cache_enabled": { Type: schema.TypeBool, Optional: true, - Default: true, + Default: false, }, "cache_use_dynamic_compression": { Type: schema.TypeBool, Optional: true, - Computed: true, }, "cache_query_parameter_strip_directive": { Type: schema.TypeString, Optional: true, - Computed: true, ValidateFunc: validation.StringInSlice([]string{ string(frontdoor.StripAll), string(frontdoor.StripNone), @@ -195,7 +193,6 @@ func resourceArmFrontDoor() *schema.Resource { Type: schema.TypeString, Optional: true, }, - // Added Portal Default value for #4627 "forwarding_protocol": { Type: schema.TypeString, Optional: true, @@ -451,10 +448,6 @@ func resourceArmFrontDoor() *schema.Resource { } func resourceArmFrontDoorCreateUpdate(d *schema.ResourceData, meta interface{}) error { - if err := ValidateFrontdoorRoutingRuleSettings(d); err != nil { - return err - } - client := meta.(*clients.Client).Frontdoor.FrontDoorsClient ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() diff --git a/azurerm/internal/services/frontdoor/validate.go b/azurerm/internal/services/frontdoor/validate.go index 31fa2d8f27cc..06f031053574 100644 --- a/azurerm/internal/services/frontdoor/validate.go +++ b/azurerm/internal/services/frontdoor/validate.go @@ -51,20 +51,38 @@ func ValidateFrontdoorSettings(d *schema.ResourceDiff) error { // Check 0. validate that at least one routing configuration exists per routing rule if len(redirectConfig) == 0 && len(forwardConfig) == 0 { - return fmt.Errorf(`"routing_rule":%q is invalid. you must have either a "redirect_configuration" or a "forwarding_configuration" defined for the "routing_rule":%q `, routingRuleName, routingRuleName) + return fmt.Errorf(`routing_rule %s block is invalid. you must have either a "redirect_configuration" or a "forwarding_configuration" defined for the routing_rule %s`, routingRuleName, routingRuleName) } // Check 1. validate that only one configuration type is defined per routing rule if len(redirectConfig) == 1 && len(forwardConfig) == 1 { - return fmt.Errorf(`"routing_rule":%q is invalid. "redirect_configuration" conflicts with "forwarding_configuration". You can only have one configuration type per each routing rule`, routingRuleName) + return fmt.Errorf(`routing_rule %s block is invalid. "redirect_configuration" conflicts with "forwarding_configuration". You can only have one configuration type per each routing rule`, routingRuleName) } // Check 2. routing rule is a forwarding_configuration type make sure the backend_pool_name exists in the configuration file if len(forwardConfig) > 0 { fc := forwardConfig[0].(map[string]interface{}) + cacheEnabled := fc["cache_enabled"].(bool) if err := VerifyBackendPoolExists(fc["backend_pool_name"].(string), backendPools); err != nil { - return fmt.Errorf(`"routing_rule":%q is invalid. %+v`, routingRuleName, err) + return fmt.Errorf(`routing_rule %s is invalid. %+v`, routingRuleName, err) + } + + // check existance of attributes in config based off cache enabled state + if !cacheEnabled { + if stripDirective := fc["cache_query_parameter_strip_directive"]; stripDirective != "" { + return fmt.Errorf(`routing_rule %s forwarding_configuration block is invalid. Please make sure that the "cache_query_parameter_strip_directive" attribute does not exist in the configuration file`, routingRuleName) + } + + // Since dynamic compression is type bool it will always be initialized as false and I will not know if it is really in the config or not, the only one I can validate here is in the true case + if dynamicCompression := fc["cache_use_dynamic_compression"]; dynamicCompression == true { + return fmt.Errorf(`routing_rule %s forwarding_configuration block is invalid. Please make sure that the "cache_use_dynamic_compression" attribute does not exist in the configuration file`, routingRuleName) + } + } else { + // Don't need to worry about dynamic compression in this case because it's data type is bool and will always initialize to false if not present in the config + if stripDirective := fc["cache_query_parameter_strip_directive"]; stripDirective == "" { + return fmt.Errorf(`routing_rule %s forwarding_configuration block is invalid. Please make sure that the "cache_query_parameter_strip_directive" attribute is defined in the configuration file`, routingRuleName) + } } } @@ -90,32 +108,3 @@ func ValidateFrontdoorSettings(d *schema.ResourceDiff) error { return nil } - -func ValidateFrontdoorRoutingRuleSettings(d *schema.ResourceData) error { - routingRules := d.Get("routing_rule").([]interface{}) - - // Loop over all of the Routing Rules and validate that only one type of configuration is defined per Routing Rule - for _, rr := range routingRules { - routingRule := rr.(map[string]interface{}) - forwardConfig := routingRule["forwarding_configuration"].([]interface{}) - - // If the routing rule is a forwarding_configuration type and the cache has been disabled - // make sure none of the other cache attributes have values - if len(forwardConfig) > 0 { - fc := forwardConfig[0].(map[string]interface{}) - cacheEnabled := fc["cache_enabled"].(bool) - - if !cacheEnabled { - if stripDirective := fc["cache_query_parameter_strip_directive"]; stripDirective != "" { - return fmt.Errorf(`"routing_rule:forwarding_configuration" is invalid. Please make sure that the "cache_query_parameter_strip_directive" does not exist in the configuration file`) - } - - if v, ok := fc["cache_use_dynamic_compression"]; ok && v == true { - return fmt.Errorf(`"routing_rule:forwarding_configuration" is invalid. Please make sure that the "cache_use_dynamic_compression" does not exist in the configuration file`) - } - } - } - } - - return nil -} From dadf851587233a463e9f586a643137e4db398c66 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Wed, 22 Jan 2020 12:58:16 -0800 Subject: [PATCH 23/33] Update docs to document new behavior --- azurerm/internal/services/frontdoor/validate.go | 2 +- website/docs/r/front_door.html.markdown | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/azurerm/internal/services/frontdoor/validate.go b/azurerm/internal/services/frontdoor/validate.go index 06f031053574..dd91cafaa304 100644 --- a/azurerm/internal/services/frontdoor/validate.go +++ b/azurerm/internal/services/frontdoor/validate.go @@ -76,7 +76,7 @@ func ValidateFrontdoorSettings(d *schema.ResourceDiff) error { // Since dynamic compression is type bool it will always be initialized as false and I will not know if it is really in the config or not, the only one I can validate here is in the true case if dynamicCompression := fc["cache_use_dynamic_compression"]; dynamicCompression == true { - return fmt.Errorf(`routing_rule %s forwarding_configuration block is invalid. Please make sure that the "cache_use_dynamic_compression" attribute does not exist in the configuration file`, routingRuleName) + return fmt.Errorf(`routing_rule %s forwarding_configuration block is invalid. Please make sure that the "cache_use_dynamic_compression" attribute does not exist in the configuration file or is set its value to false`, routingRuleName) } } else { // Don't need to worry about dynamic compression in this case because it's data type is bool and will always initialize to false if not present in the config diff --git a/website/docs/r/front_door.html.markdown b/website/docs/r/front_door.html.markdown index 569f78444c39..5cb1e908fcde 100644 --- a/website/docs/r/front_door.html.markdown +++ b/website/docs/r/front_door.html.markdown @@ -192,9 +192,11 @@ The `forwarding_configuration` block supports the following: * `cache_enabled` - (Optional) Specifies whether to Enable caching or not. Valid options are `true` or `false`. Defaults to `false`. +-> **NOTE:** If `cache_enabled` is set to **false** the `cache_query_parameter_strip_directive` attribute must be removed from the configuration file and the `cache_use_dynamic_compression` should be removed or set to `false`, conversely if `cache_enabled` is set to **true** the `cache_query_parameter_strip_directive` must be defined in the configuration. + * `cache_use_dynamic_compression` - (Optional) Whether to use dynamic compression when caching. Valid options are `true` or `false`. Defaults to `false`. -* `cache_query_parameter_strip_directive` - (Optional) Defines cache behavior in releation to query string parameters. Valid options are `StripAll` or `StripNone`. Defaults to `StripNone`. +* `cache_query_parameter_strip_directive` - (Optional/Required) Defines cache behavior in releation to query string parameters. Valid options are `StripAll` or `StripNone`. * `custom_forwarding_path` - (Optional) Path to use when constructing the request to forward to the backend. This functions as a URL Rewrite. Default behavior preserves the URL path. From 3eb71d93f853e03593bc7528ea69aebeb074a014 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Wed, 22 Jan 2020 17:13:20 -0800 Subject: [PATCH 24/33] Fix tests and documentation --- ...rce_arm_front_door_firewall_policy_test.go | 108 +++++++++++++----- website/docs/r/front_door.html.markdown | 7 ++ 2 files changed, 87 insertions(+), 28 deletions(-) diff --git a/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_firewall_policy_test.go b/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_firewall_policy_test.go index 06aa6d9c9442..be180c3f8665 100644 --- a/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_firewall_policy_test.go +++ b/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_firewall_policy_test.go @@ -209,37 +209,65 @@ resource "azurerm_frontdoor_firewall_policy" "import" { } func testAccAzureRMFrontDoorFirewallPolicy_update(data acceptance.TestData, update bool) string { - inner := "" if update { - inner = fmt.Sprintf(` -custom_rule { - name = "Rule2" - enabled = true - priority = 2 - rate_limit_duration_in_minutes = 1 - rate_limit_threshold = 10 - type = "MatchRule" - action = "Block" - - match_condition { - match_variable = "RemoteAddr" - operator = "IPMatch" - negation_condition = false - match_values = ["192.168.1.0/24"] + return testAccAzureRMFrontDoorFirewallPolicy_updated(data) + } + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "testAccRG-%d" + location = "%s" +} + +resource "azurerm_frontdoor_firewall_policy" "test" { + name = "testAccFrontDoorWAF%[1]d" + resource_group_name = azurerm_resource_group.test.name + enabled = true + mode = "Prevention" + redirect_url = "https://www.contoso.com" + custom_block_response_status_code = 403 + custom_block_response_body = "PGh0bWw+CjxoZWFkZXI+PHRpdGxlPkhlbGxvPC90aXRsZT48L2hlYWRlcj4KPGJvZHk+CkhlbGxvIHdvcmxkCjwvYm9keT4KPC9odG1sPg==" + + custom_rule { + name = "Rule1" + enabled = true + priority = 1 + rate_limit_duration_in_minutes = 1 + rate_limit_threshold = 10 + type = "MatchRule" + action = "Block" + + match_condition { + match_variable = "RemoteAddr" + operator = "IPMatch" + negation_condition = false + match_values = ["192.168.1.0/24", "10.0.0.0/24"] + } + } + + managed_rule { + type = "DefaultRuleSet" + version = "preview-0.1" + + override { + rule_group_name = "PHP" + + rule { + rule_id = "933111" + enabled = false + action = "Block" + } + } } - match_condition { - match_variable = "RequestHeader" - selector = "UserAgent" - operator = "Contains" - negation_condition = false - match_values = ["windows"] - transforms = ["Lowercase", "Trim"] + managed_rule { + type = "BotProtection" + version = "preview-0.1" } } -`) - } +`, data.RandomInteger, data.Locations.Primary) +} +func testAccAzureRMFrontDoorFirewallPolicy_updated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "testAccRG-%d" @@ -248,7 +276,7 @@ resource "azurerm_resource_group" "test" { resource "azurerm_frontdoor_firewall_policy" "test" { name = "testAccFrontDoorWAF%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name enabled = true mode = "Prevention" redirect_url = "https://www.contoso.com" @@ -272,7 +300,31 @@ resource "azurerm_frontdoor_firewall_policy" "test" { } } - %s + custom_rule { + name = "Rule2" + enabled = true + priority = 2 + rate_limit_duration_in_minutes = 1 + rate_limit_threshold = 10 + type = "MatchRule" + action = "Block" + + match_condition { + match_variable = "RemoteAddr" + operator = "IPMatch" + negation_condition = false + match_values = ["192.168.1.0/24"] + } + + match_condition { + match_variable = "RequestHeader" + selector = "UserAgent" + operator = "Contains" + negation_condition = false + match_values = ["windows"] + transforms = ["Lowercase", "Trim"] + } + } managed_rule { type = "DefaultRuleSet" @@ -294,5 +346,5 @@ resource "azurerm_frontdoor_firewall_policy" "test" { version = "preview-0.1" } } -`, data.RandomInteger, data.Locations.Primary, inner) +`, data.RandomInteger, data.Locations.Primary) } diff --git a/website/docs/r/front_door.html.markdown b/website/docs/r/front_door.html.markdown index 5cb1e908fcde..f9677c702b7a 100644 --- a/website/docs/r/front_door.html.markdown +++ b/website/docs/r/front_door.html.markdown @@ -20,6 +20,11 @@ Below are some of the key scenarios that Azure Front Door Service addresses: ## Example Usage ```hcl +resource "azurerm_resource_group" "example" { + name = "FrontDoorExampleResourceGroup" + location = "EastUS2" +} + resource "azurerm_frontdoor" "example" { name = "example-FrontDoor" location = "${azurerm_resource_group.example.location}" @@ -110,6 +115,8 @@ The `backend_pool` block supports the following: The `backend` block supports the following: +* `enabled` - (Optional) Specifies if the backend is enabled or not. Valid options are `true` or `false`. Defaults to `true`. + * `address` - (Required) Location of the backend (IP address or FQDN) * `host_header` - (Required) The value to use as the host header sent to the backend. From 9c358bdadcb5dede21f66592fe93e06391ebff9f Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Wed, 22 Jan 2020 18:28:04 -0800 Subject: [PATCH 25/33] Add test case for cache regression --- .../frontdoor/resource_arm_front_door.go | 1 + .../tests/resource_arm_front_door_test.go | 165 ++++++++++++++++++ 2 files changed, 166 insertions(+) diff --git a/azurerm/internal/services/frontdoor/resource_arm_front_door.go b/azurerm/internal/services/frontdoor/resource_arm_front_door.go index 67478037b6c6..115c674943b8 100644 --- a/azurerm/internal/services/frontdoor/resource_arm_front_door.go +++ b/azurerm/internal/services/frontdoor/resource_arm_front_door.go @@ -193,6 +193,7 @@ func resourceArmFrontDoor() *schema.Resource { Type: schema.TypeString, Optional: true, }, + // TODO: In 2.0 Switch default value from MatchRequest to HTTPSOnly #4627 "forwarding_protocol": { Type: schema.TypeString, Optional: true, diff --git a/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_test.go b/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_test.go index ede210cac5ab..528b15782675 100644 --- a/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_test.go +++ b/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_test.go @@ -121,6 +121,45 @@ func TestAccAzureRMFrontDoor_waf(t *testing.T) { }) } +func TestAccAzureRMFrontDoor_EnableDisableCache(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_frontdoor", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMFrontDoorDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMFrontDoor_DisableCache(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMFrontDoorExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_enabled", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_use_dynamic_compression", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_query_parameter_strip_directive", ""), + ), + }, + { + Config: testAccAzureRMFrontDoor_EnableCache(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMFrontDoorExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_use_dynamic_compression", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_query_parameter_strip_directive", "StripAll"), + ), + }, + { + Config: testAccAzureRMFrontDoor_DisableCache(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMFrontDoorExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_enabled", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_use_dynamic_compression", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_query_parameter_strip_directive", ""), + ), + }, + data.ImportStep(), + }, + }) +} + func testCheckAzureRMFrontDoorExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { client := acceptance.AzureProvider.Meta().(*clients.Client).Frontdoor.FrontDoorsClient @@ -410,3 +449,129 @@ resource "azurerm_frontdoor" "test" { } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } + +func testAccAzureRMFrontDoor_DisableCache(data acceptance.TestData) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +locals { + backend_name = "backend-bing" + endpoint_name = "frontend-endpoint" + health_probe_name = "health-probe" + load_balancing_name = "load-balancing-setting" +} + +resource "azurerm_frontdoor" "test" { + name = "acctestfd-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + enforce_backend_pools_certificate_name_check = false + + routing_rule { + name = "routing-rule" + accepted_protocols = ["Http", "Https"] + patterns_to_match = ["/*"] + frontend_endpoints = [local.endpoint_name] + forwarding_configuration { + forwarding_protocol = "MatchRequest" + backend_pool_name = local.backend_name + } + } + + backend_pool_load_balancing { + name = local.load_balancing_name + } + + backend_pool_health_probe { + name = local.health_probe_name + } + + backend_pool { + name = local.backend_name + backend { + host_header = "www.bing.com" + address = "www.bing.com" + http_port = 80 + https_port = 443 + } + + load_balancing_name = local.load_balancing_name + health_probe_name = local.health_probe_name + } + + frontend_endpoint { + name = local.endpoint_name + host_name = "acctestfd-%d.azurefd.net" + custom_https_provisioning_enabled = false + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} + +func testAccAzureRMFrontDoor_EnableCache(data acceptance.TestData) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +locals { + backend_name = "backend-bing" + endpoint_name = "frontend-endpoint" + health_probe_name = "health-probe" + load_balancing_name = "load-balancing-setting" +} + +resource "azurerm_frontdoor" "test" { + name = "acctestfd-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + enforce_backend_pools_certificate_name_check = false + + routing_rule { + name = "routing-rule" + accepted_protocols = ["Http", "Https"] + patterns_to_match = ["/*"] + frontend_endpoints = [local.endpoint_name] + + forwarding_configuration { + forwarding_protocol = "MatchRequest" + backend_pool_name = local.backend_name + cache_enabled = true + cache_query_parameter_strip_directive = "StripAll" + cache_use_dynamic_compression = true + } + } + + backend_pool_load_balancing { + name = local.load_balancing_name + } + + backend_pool_health_probe { + name = local.health_probe_name + } + + backend_pool { + name = local.backend_name + backend { + host_header = "www.bing.com" + address = "www.bing.com" + http_port = 80 + https_port = 443 + } + + load_balancing_name = local.load_balancing_name + health_probe_name = local.health_probe_name + } + + frontend_endpoint { + name = local.endpoint_name + host_name = "acctestfd-%d.azurefd.net" + custom_https_provisioning_enabled = false + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} From 6adb4375b456c77c938c49c21420672255a8523c Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Wed, 22 Jan 2020 18:47:52 -0800 Subject: [PATCH 26/33] Fix test code terrafmt --- .../tests/resource_arm_front_door_firewall_policy_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_firewall_policy_test.go b/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_firewall_policy_test.go index aa3b443312c2..528df275cdfe 100644 --- a/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_firewall_policy_test.go +++ b/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_firewall_policy_test.go @@ -243,7 +243,7 @@ resource "azurerm_frontdoor_firewall_policy" "test" { match_values = ["192.168.1.0/24", "10.0.0.0/24"] } } - + managed_rule { type = "DefaultRuleSet" version = "preview-0.1" From 8efc0ac5c70f40855cee968fad3ef2df14f16cd4 Mon Sep 17 00:00:00 2001 From: WS <20408400+WodansSon@users.noreply.github.com> Date: Wed, 22 Jan 2020 21:52:04 -0800 Subject: [PATCH 27/33] Fixed linting error in comment --- azurerm/internal/services/frontdoor/validate.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/frontdoor/validate.go b/azurerm/internal/services/frontdoor/validate.go index dd91cafaa304..ce023a187506 100644 --- a/azurerm/internal/services/frontdoor/validate.go +++ b/azurerm/internal/services/frontdoor/validate.go @@ -68,7 +68,7 @@ func ValidateFrontdoorSettings(d *schema.ResourceDiff) error { return fmt.Errorf(`routing_rule %s is invalid. %+v`, routingRuleName, err) } - // check existance of attributes in config based off cache enabled state + // check existence of attributes in config based off cache enabled state if !cacheEnabled { if stripDirective := fc["cache_query_parameter_strip_directive"]; stripDirective != "" { return fmt.Errorf(`routing_rule %s forwarding_configuration block is invalid. Please make sure that the "cache_query_parameter_strip_directive" attribute does not exist in the configuration file`, routingRuleName) From 613bc0ebbe8a914db164a55665d3dd7fb5e38301 Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 23 Jan 2020 15:46:06 -0800 Subject: [PATCH 28/33] pull value through test --- .../frontdoor/resource_arm_front_door.go | 32 ++++++++++++++++--- .../internal/services/frontdoor/validate.go | 6 ++-- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/azurerm/internal/services/frontdoor/resource_arm_front_door.go b/azurerm/internal/services/frontdoor/resource_arm_front_door.go index 115c674943b8..6913c97b1154 100644 --- a/azurerm/internal/services/frontdoor/resource_arm_front_door.go +++ b/azurerm/internal/services/frontdoor/resource_arm_front_door.go @@ -175,11 +175,12 @@ func resourceArmFrontDoor() *schema.Resource { "cache_enabled": { Type: schema.TypeBool, Optional: true, - Default: false, + Default: true, }, "cache_use_dynamic_compression": { Type: schema.TypeBool, Optional: true, + Default: false, }, "cache_query_parameter_strip_directive": { Type: schema.TypeString, @@ -188,6 +189,7 @@ func resourceArmFrontDoor() *schema.Resource { string(frontdoor.StripAll), string(frontdoor.StripNone), }, false), + Default: string(frontdoor.StripNone), }, "custom_forwarding_path": { Type: schema.TypeString, @@ -663,7 +665,7 @@ func resourceArmFrontDoorRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("Error setting `backend_pool_load_balancing`: %+v", err) } - if err := d.Set("routing_rule", flattenArmFrontDoorRoutingRule(properties.RoutingRules)); err != nil { + if err := d.Set("routing_rule", flattenArmFrontDoorRoutingRule(properties.RoutingRules, d.Get("routing_rule"))); err != nil { return fmt.Errorf("Error setting `routing_rules`: %+v", err) } } @@ -1344,20 +1346,29 @@ func flattenArmFrontDoorLoadBalancingSettingsModel(input *[]frontdoor.LoadBalanc return []interface{}{result} } -func flattenArmFrontDoorRoutingRule(input *[]frontdoor.RoutingRule) []interface{} { +func flattenArmFrontDoorRoutingRule(input *[]frontdoor.RoutingRule, oldBlocks interface{}) []interface{} { if input == nil { return make([]interface{}, 0) } - output := make([]interface{}, 0) + oldByName := map[string]map[string]interface{}{} + + for _, i := range oldBlocks.([]interface{}) { + v := i.(map[string]interface{}) + + oldByName[v["name"].(string)] = v + } + output := make([]interface{}, 0) for _, v := range *input { result := make(map[string]interface{}) if id := v.ID; id != nil { result["id"] = *id } - if name := v.Name; name != nil { + + name := v.Name + if name != nil { result["name"] = *name } @@ -1399,6 +1410,17 @@ func flattenArmFrontDoorRoutingRule(input *[]frontdoor.RoutingRule) []interface{ } } else { c["cache_enabled"] = false + + //get `forwarding_configuration` + if o, ok := oldByName[*name]; ok { + ofcs := o["forwarding_configuration"].([]interface{}) + if len(ofcs) > 0 { + ofc := ofcs[0].(map[string]interface{}) + + c["cache_query_parameter_strip_directive"] = ofc["cache_query_parameter_strip_directive"] + c["cache_use_dynamic_compression"] = ofc["cache_use_dynamic_compression"] + } + } } rc = append(rc, c) diff --git a/azurerm/internal/services/frontdoor/validate.go b/azurerm/internal/services/frontdoor/validate.go index ce023a187506..cba3b72265a9 100644 --- a/azurerm/internal/services/frontdoor/validate.go +++ b/azurerm/internal/services/frontdoor/validate.go @@ -62,14 +62,14 @@ func ValidateFrontdoorSettings(d *schema.ResourceDiff) error { // Check 2. routing rule is a forwarding_configuration type make sure the backend_pool_name exists in the configuration file if len(forwardConfig) > 0 { fc := forwardConfig[0].(map[string]interface{}) - cacheEnabled := fc["cache_enabled"].(bool) + //cacheEnabled := fc["cache_enabled"].(bool) if err := VerifyBackendPoolExists(fc["backend_pool_name"].(string), backendPools); err != nil { return fmt.Errorf(`routing_rule %s is invalid. %+v`, routingRuleName, err) } // check existence of attributes in config based off cache enabled state - if !cacheEnabled { + /*if !cacheEnabled { if stripDirective := fc["cache_query_parameter_strip_directive"]; stripDirective != "" { return fmt.Errorf(`routing_rule %s forwarding_configuration block is invalid. Please make sure that the "cache_query_parameter_strip_directive" attribute does not exist in the configuration file`, routingRuleName) } @@ -83,7 +83,7 @@ func ValidateFrontdoorSettings(d *schema.ResourceDiff) error { if stripDirective := fc["cache_query_parameter_strip_directive"]; stripDirective == "" { return fmt.Errorf(`routing_rule %s forwarding_configuration block is invalid. Please make sure that the "cache_query_parameter_strip_directive" attribute is defined in the configuration file`, routingRuleName) } - } + }*/ } // Check 3. validate that each routing rule frontend_endpoints are actually defined in the resource schema From 3412cf1db4d541bdf214650a0bcdec4f84f1384d Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Thu, 23 Jan 2020 17:04:20 -0800 Subject: [PATCH 29/33] Update docs and remove commented code --- .../internal/services/frontdoor/validate.go | 18 ------------------ website/docs/r/front_door.html.markdown | 6 ++---- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/azurerm/internal/services/frontdoor/validate.go b/azurerm/internal/services/frontdoor/validate.go index cba3b72265a9..0a78075a9d85 100644 --- a/azurerm/internal/services/frontdoor/validate.go +++ b/azurerm/internal/services/frontdoor/validate.go @@ -62,28 +62,10 @@ func ValidateFrontdoorSettings(d *schema.ResourceDiff) error { // Check 2. routing rule is a forwarding_configuration type make sure the backend_pool_name exists in the configuration file if len(forwardConfig) > 0 { fc := forwardConfig[0].(map[string]interface{}) - //cacheEnabled := fc["cache_enabled"].(bool) if err := VerifyBackendPoolExists(fc["backend_pool_name"].(string), backendPools); err != nil { return fmt.Errorf(`routing_rule %s is invalid. %+v`, routingRuleName, err) } - - // check existence of attributes in config based off cache enabled state - /*if !cacheEnabled { - if stripDirective := fc["cache_query_parameter_strip_directive"]; stripDirective != "" { - return fmt.Errorf(`routing_rule %s forwarding_configuration block is invalid. Please make sure that the "cache_query_parameter_strip_directive" attribute does not exist in the configuration file`, routingRuleName) - } - - // Since dynamic compression is type bool it will always be initialized as false and I will not know if it is really in the config or not, the only one I can validate here is in the true case - if dynamicCompression := fc["cache_use_dynamic_compression"]; dynamicCompression == true { - return fmt.Errorf(`routing_rule %s forwarding_configuration block is invalid. Please make sure that the "cache_use_dynamic_compression" attribute does not exist in the configuration file or is set its value to false`, routingRuleName) - } - } else { - // Don't need to worry about dynamic compression in this case because it's data type is bool and will always initialize to false if not present in the config - if stripDirective := fc["cache_query_parameter_strip_directive"]; stripDirective == "" { - return fmt.Errorf(`routing_rule %s forwarding_configuration block is invalid. Please make sure that the "cache_query_parameter_strip_directive" attribute is defined in the configuration file`, routingRuleName) - } - }*/ } // Check 3. validate that each routing rule frontend_endpoints are actually defined in the resource schema diff --git a/website/docs/r/front_door.html.markdown b/website/docs/r/front_door.html.markdown index f9677c702b7a..8b11b9c0b7e6 100644 --- a/website/docs/r/front_door.html.markdown +++ b/website/docs/r/front_door.html.markdown @@ -197,13 +197,11 @@ The `forwarding_configuration` block supports the following: * `backend_pool_name` - (Required) Specifies the name of the Backend Pool to forward the incoming traffic to. -* `cache_enabled` - (Optional) Specifies whether to Enable caching or not. Valid options are `true` or `false`. Defaults to `false`. - --> **NOTE:** If `cache_enabled` is set to **false** the `cache_query_parameter_strip_directive` attribute must be removed from the configuration file and the `cache_use_dynamic_compression` should be removed or set to `false`, conversely if `cache_enabled` is set to **true** the `cache_query_parameter_strip_directive` must be defined in the configuration. +* `cache_enabled` - (Optional) Specifies whether to Enable caching or not. Valid options are `true` or `false`. Defaults to `true`. * `cache_use_dynamic_compression` - (Optional) Whether to use dynamic compression when caching. Valid options are `true` or `false`. Defaults to `false`. -* `cache_query_parameter_strip_directive` - (Optional/Required) Defines cache behavior in releation to query string parameters. Valid options are `StripAll` or `StripNone`. +* `cache_query_parameter_strip_directive` - (Optional/Required) Defines cache behavior in releation to query string parameters. Valid options are `StripAll` or `StripNone`. Defaults to `StripNone`. * `custom_forwarding_path` - (Optional) Path to use when constructing the request to forward to the backend. This functions as a URL Rewrite. Default behavior preserves the URL path. From b2eda4f3cc70af2ae80355e0f877a720ef9bfc87 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Thu, 23 Jan 2020 19:02:22 -0800 Subject: [PATCH 30/33] Update test case --- .../tests/resource_arm_front_door_test.go | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_test.go b/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_test.go index 528b15782675..ac459b550c84 100644 --- a/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_test.go +++ b/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_test.go @@ -129,30 +129,30 @@ func TestAccAzureRMFrontDoor_EnableDisableCache(t *testing.T) { CheckDestroy: testCheckAzureRMFrontDoorDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFrontDoor_DisableCache(data), + Config: testAccAzureRMFrontDoor_EnableCache(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMFrontDoorExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_enabled", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_enabled", "true"), resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_use_dynamic_compression", "false"), - resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_query_parameter_strip_directive", ""), + resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_query_parameter_strip_directive", "StripNone"), ), }, { - Config: testAccAzureRMFrontDoor_EnableCache(data), + Config: testAccAzureRMFrontDoor_DisableCache(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMFrontDoorExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_enabled", "true"), - resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_use_dynamic_compression", "true"), - resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_query_parameter_strip_directive", "StripAll"), + resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_enabled", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_use_dynamic_compression", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_query_parameter_strip_directive", "StripNone"), ), }, { - Config: testAccAzureRMFrontDoor_DisableCache(data), + Config: testAccAzureRMFrontDoor_EnableCache(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMFrontDoorExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_enabled", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_enabled", "true"), resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_use_dynamic_compression", "false"), - resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_query_parameter_strip_directive", ""), + resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_query_parameter_strip_directive", "StripNone"), ), }, data.ImportStep(), @@ -478,6 +478,7 @@ resource "azurerm_frontdoor" "test" { forwarding_configuration { forwarding_protocol = "MatchRequest" backend_pool_name = local.backend_name + cache_enabled = false } } @@ -540,9 +541,6 @@ resource "azurerm_frontdoor" "test" { forwarding_configuration { forwarding_protocol = "MatchRequest" backend_pool_name = local.backend_name - cache_enabled = true - cache_query_parameter_strip_directive = "StripAll" - cache_use_dynamic_compression = true } } From a2e78b083ccd312124d701e726f3765b8b5253b9 Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 24 Jan 2020 12:34:34 -0800 Subject: [PATCH 31/33] terrafmt --- .../services/frontdoor/tests/resource_arm_front_door_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_test.go b/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_test.go index ac459b550c84..693b739a83dc 100644 --- a/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_test.go +++ b/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_test.go @@ -539,8 +539,8 @@ resource "azurerm_frontdoor" "test" { frontend_endpoints = [local.endpoint_name] forwarding_configuration { - forwarding_protocol = "MatchRequest" - backend_pool_name = local.backend_name + forwarding_protocol = "MatchRequest" + backend_pool_name = local.backend_name } } From 2c4f4f4aeb581aa5fd532a48d9de4eb6f06a6a24 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Fri, 24 Jan 2020 14:15:52 -0800 Subject: [PATCH 32/33] Minor doc update --- website/docs/r/front_door.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/website/docs/r/front_door.html.markdown b/website/docs/r/front_door.html.markdown index 8b11b9c0b7e6..87136435d8bc 100644 --- a/website/docs/r/front_door.html.markdown +++ b/website/docs/r/front_door.html.markdown @@ -103,7 +103,7 @@ The following arguments are supported: The `backend_pool` block supports the following: -* `name` - (Required) Specifies the name of the name of the Backend Pool. +* `name` - (Required) Specifies the name of the Backend Pool. * `backend` - (Required) A `backend` block as defined below. @@ -201,11 +201,11 @@ The `forwarding_configuration` block supports the following: * `cache_use_dynamic_compression` - (Optional) Whether to use dynamic compression when caching. Valid options are `true` or `false`. Defaults to `false`. -* `cache_query_parameter_strip_directive` - (Optional/Required) Defines cache behavior in releation to query string parameters. Valid options are `StripAll` or `StripNone`. Defaults to `StripNone`. +* `cache_query_parameter_strip_directive` - (Optional) Defines cache behavior in releation to query string parameters. Valid options are `StripAll` or `StripNone`. Defaults to `StripNone`. * `custom_forwarding_path` - (Optional) Path to use when constructing the request to forward to the backend. This functions as a URL Rewrite. Default behavior preserves the URL path. -* `forwarding_protocol` - (Optional) Protocol to use when redirecting. Valid options are `HttpOnly`, `HttpsOnly`, or `MatchRequest`. Defaults to `HttpsOnly`. +* `forwarding_protocol` - (Optional) Protocol to use when redirecting. Valid options are `HttpOnly`, `HttpsOnly`, or `MatchRequest`. Defaults to `MatchRequest`. --- From efdfb5809e0145ddbce476195806c37e5c393000 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Fri, 24 Jan 2020 16:44:51 -0800 Subject: [PATCH 33/33] Added nil check per PR review --- .../frontdoor/resource_arm_front_door.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/azurerm/internal/services/frontdoor/resource_arm_front_door.go b/azurerm/internal/services/frontdoor/resource_arm_front_door.go index 6913c97b1154..899127785c60 100644 --- a/azurerm/internal/services/frontdoor/resource_arm_front_door.go +++ b/azurerm/internal/services/frontdoor/resource_arm_front_door.go @@ -1411,14 +1411,16 @@ func flattenArmFrontDoorRoutingRule(input *[]frontdoor.RoutingRule, oldBlocks in } else { c["cache_enabled"] = false - //get `forwarding_configuration` - if o, ok := oldByName[*name]; ok { - ofcs := o["forwarding_configuration"].([]interface{}) - if len(ofcs) > 0 { - ofc := ofcs[0].(map[string]interface{}) - - c["cache_query_parameter_strip_directive"] = ofc["cache_query_parameter_strip_directive"] - c["cache_use_dynamic_compression"] = ofc["cache_use_dynamic_compression"] + if name != nil { + //get `forwarding_configuration` + if o, ok := oldByName[*name]; ok { + ofcs := o["forwarding_configuration"].([]interface{}) + if len(ofcs) > 0 { + ofc := ofcs[0].(map[string]interface{}) + + c["cache_query_parameter_strip_directive"] = ofc["cache_query_parameter_strip_directive"] + c["cache_use_dynamic_compression"] = ofc["cache_use_dynamic_compression"] + } } } }