From 01e41df947b608bbfbd5fa7912030a267e49ec3e Mon Sep 17 00:00:00 2001 From: Luke Smyth Date: Fri, 19 Jan 2024 23:45:13 +0000 Subject: [PATCH] Adding always_serve --- .../trafficmanager/azure_endpoint_resource.go | 16 ++++++++++++++++ .../azure_endpoint_resource_test.go | 1 + .../trafficmanager/external_endpoint_resource.go | 16 ++++++++++++++++ .../external_endpoint_resource_test.go | 1 + .../traffic_manager_azure_endpoint.html.markdown | 3 +++ ...affic_manager_external_endpoint.html.markdown | 11 +++++++---- 6 files changed, 44 insertions(+), 4 deletions(-) diff --git a/internal/services/trafficmanager/azure_endpoint_resource.go b/internal/services/trafficmanager/azure_endpoint_resource.go index 2f2b88a593aa5..ddad715d73eff 100644 --- a/internal/services/trafficmanager/azure_endpoint_resource.go +++ b/internal/services/trafficmanager/azure_endpoint_resource.go @@ -82,6 +82,13 @@ func resourceAzureEndpoint() *pluginsdk.Resource { Default: true, }, + "always_serve": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice(endpoints.PossibleValuesForAlwaysServe(), false), + Default: endpoints.AlwaysServeDisabled, + }, + "custom_header": { Type: pluginsdk.TypeList, Optional: true, @@ -170,10 +177,13 @@ func resourceAzureEndpointCreate(d *pluginsdk.ResourceData, meta interface{}) er status = endpoints.EndpointStatusDisabled } + alwaysServe := endpoints.AlwaysServe(d.Get("always_serve").(string)) + params := endpoints.Endpoint{ Name: utils.String(id.EndpointName), Type: utils.String(fmt.Sprintf("Microsoft.Network/trafficManagerProfiles/%s", endpoints.EndpointTypeAzureEndpoints)), Properties: &endpoints.EndpointProperties{ + AlwaysServe: &alwaysServe, CustomHeaders: expandEndpointCustomHeaderConfig(d.Get("custom_header").([]interface{})), EndpointStatus: &status, TargetResourceId: utils.String(d.Get("target_resource_id").(string)), @@ -235,6 +245,7 @@ func resourceAzureEndpointRead(d *pluginsdk.ResourceData, meta interface{}) erro enabled = false } d.Set("enabled", enabled) + d.Set("always_serve", props.AlwaysServe) d.Set("target_resource_id", props.TargetResourceId) d.Set("weight", props.Weight) d.Set("priority", props.Priority) @@ -283,6 +294,11 @@ func resourceAzureEndpointUpdate(d *pluginsdk.ResourceData, meta interface{}) er params.Properties.EndpointStatus = pointer.To(status) } + if d.HasChange("always_serve") { + alwaysServe := endpoints.AlwaysServe(d.Get("always_serve").(string)) + params.Properties.AlwaysServe = &alwaysServe + } + if d.HasChange("custom_header") { params.Properties.CustomHeaders = expandEndpointCustomHeaderConfig(d.Get("custom_header").([]interface{})) } diff --git a/internal/services/trafficmanager/azure_endpoint_resource_test.go b/internal/services/trafficmanager/azure_endpoint_resource_test.go index 472c1d6810f2a..1b8adb572bcf7 100644 --- a/internal/services/trafficmanager/azure_endpoint_resource_test.go +++ b/internal/services/trafficmanager/azure_endpoint_resource_test.go @@ -232,6 +232,7 @@ resource "azurerm_traffic_manager_azure_endpoint" "test" { weight = 5 profile_id = azurerm_traffic_manager_profile.test.id enabled = false + always_serve = "Enabled" priority = 4 geo_mappings = ["WORLD"] diff --git a/internal/services/trafficmanager/external_endpoint_resource.go b/internal/services/trafficmanager/external_endpoint_resource.go index f0bfae62bdc06..30cd6b5882143 100644 --- a/internal/services/trafficmanager/external_endpoint_resource.go +++ b/internal/services/trafficmanager/external_endpoint_resource.go @@ -82,6 +82,13 @@ func resourceExternalEndpoint() *pluginsdk.Resource { Default: true, }, + "always_serve": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice(endpoints.PossibleValuesForAlwaysServe(), false), + Default: endpoints.AlwaysServeDisabled, + }, + "custom_header": { Type: pluginsdk.TypeList, Optional: true, @@ -178,10 +185,13 @@ func resourceExternalEndpointCreate(d *pluginsdk.ResourceData, meta interface{}) status = endpoints.EndpointStatusDisabled } + alwaysServe := endpoints.AlwaysServe(d.Get("always_serve").(string)) + params := endpoints.Endpoint{ Name: utils.String(id.EndpointName), Type: utils.String(fmt.Sprintf("Microsoft.Network/trafficManagerProfiles/%s", endpoints.EndpointTypeExternalEndpoints)), Properties: &endpoints.EndpointProperties{ + AlwaysServe: &alwaysServe, CustomHeaders: expandEndpointCustomHeaderConfig(d.Get("custom_header").([]interface{})), EndpointStatus: &status, Target: utils.String(d.Get("target").(string)), @@ -247,6 +257,7 @@ func resourceExternalEndpointRead(d *pluginsdk.ResourceData, meta interface{}) e enabled = false } d.Set("enabled", enabled) + d.Set("always_serve", props.AlwaysServe) d.Set("target", props.Target) d.Set("weight", props.Weight) d.Set("priority", props.Priority) @@ -296,6 +307,11 @@ func resourceExternalEndpointUpdate(d *pluginsdk.ResourceData, meta interface{}) params.Properties.EndpointStatus = pointer.To(status) } + if d.HasChange("always_serve") { + alwaysServe := endpoints.AlwaysServe(d.Get("always_serve").(string)) + params.Properties.AlwaysServe = &alwaysServe + } + if d.HasChange("custom_header") { params.Properties.CustomHeaders = expandEndpointCustomHeaderConfig(d.Get("custom_header").([]interface{})) } diff --git a/internal/services/trafficmanager/external_endpoint_resource_test.go b/internal/services/trafficmanager/external_endpoint_resource_test.go index 3cb81b466bdb4..df2fd8522b589 100644 --- a/internal/services/trafficmanager/external_endpoint_resource_test.go +++ b/internal/services/trafficmanager/external_endpoint_resource_test.go @@ -219,6 +219,7 @@ resource "azurerm_traffic_manager_external_endpoint" "test" { weight = 5 profile_id = azurerm_traffic_manager_profile.test.id enabled = false + always_serve = "Enabled" priority = 4 endpoint_location = azurerm_resource_group.test.location diff --git a/website/docs/r/traffic_manager_azure_endpoint.html.markdown b/website/docs/r/traffic_manager_azure_endpoint.html.markdown index 94dedf06b08ff..83fb112bf69bd 100644 --- a/website/docs/r/traffic_manager_azure_endpoint.html.markdown +++ b/website/docs/r/traffic_manager_azure_endpoint.html.markdown @@ -54,6 +54,7 @@ resource "azurerm_traffic_manager_profile" "example" { resource "azurerm_traffic_manager_azure_endpoint" "example" { name = "example-endpoint" profile_id = azurerm_traffic_manager_profile.example.id + always_serve = "Enabled" weight = 100 target_resource_id = azurerm_public_ip.example.id } @@ -73,6 +74,8 @@ The following arguments are supported: --- +* `always_serve` - (Optional) If Always Serve is enabled, probing for endpoint health will be disabled and endpoints will be included in the traffic routing method. + * `custom_header` - (Optional) One or more `custom_header` blocks as defined below. * `enabled` - (Optional) Is the endpoint enabled? Defaults to `true`. diff --git a/website/docs/r/traffic_manager_external_endpoint.html.markdown b/website/docs/r/traffic_manager_external_endpoint.html.markdown index 3b153cfde56e0..670b02de136d1 100644 --- a/website/docs/r/traffic_manager_external_endpoint.html.markdown +++ b/website/docs/r/traffic_manager_external_endpoint.html.markdown @@ -43,10 +43,11 @@ resource "azurerm_traffic_manager_profile" "example" { } resource "azurerm_traffic_manager_external_endpoint" "example" { - name = "example-endpoint" - profile_id = azurerm_traffic_manager_profile.example.id - weight = 100 - target = "www.example.com" + name = "example-endpoint" + profile_id = azurerm_traffic_manager_profile.example.id + always_serve = "Enabled" + weight = 100 + target = "www.example.com" } ``` @@ -66,6 +67,8 @@ The following arguments are supported: --- +* `always_serve` - (Optional) If Always Serve is enabled, probing for endpoint health will be disabled and endpoints will be included in the traffic routing method. + * `custom_header` - (Optional) One or more `custom_header` blocks as defined below. * `enabled` - (Optional) Is the endpoint enabled? Defaults to `true`.