Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_traffic_manager_external_endpoint & azurerm_traffic_manager_azure_endpoint - support for always_serve_enabled #24573

Merged
merged 6 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/services/dns/dns_cname_record_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/dns/2018-05-01/recordsets"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2018-08-01/endpoints"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2022-04-01/endpoints"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down
29 changes: 27 additions & 2 deletions internal/services/trafficmanager/azure_endpoint_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2018-08-01/endpoints"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2018-08-01/profiles"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2022-04-01/endpoints"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2022-04-01/profiles"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
azValidate "github.com/hashicorp/terraform-provider-azurerm/helpers/validate"
Expand Down Expand Up @@ -82,6 +82,12 @@ func resourceAzureEndpoint() *pluginsdk.Resource {
Default: true,
},

"always_serve_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},

"custom_header": {
Type: pluginsdk.TypeList,
Optional: true,
Expand Down Expand Up @@ -175,12 +181,17 @@ func resourceAzureEndpointCreate(d *pluginsdk.ResourceData, meta interface{}) er
Type: utils.String(fmt.Sprintf("Microsoft.Network/trafficManagerProfiles/%s", endpoints.EndpointTypeAzureEndpoints)),
Properties: &endpoints.EndpointProperties{
CustomHeaders: expandEndpointCustomHeaderConfig(d.Get("custom_header").([]interface{})),
AlwaysServe: pointer.To(endpoints.AlwaysServeDisabled),
EndpointStatus: &status,
TargetResourceId: utils.String(d.Get("target_resource_id").(string)),
Subnets: expandEndpointSubnetConfig(d.Get("subnet").([]interface{})),
},
}

if alwaysServe := d.Get("always_serve_enabled").(bool); alwaysServe {
params.Properties.AlwaysServe = pointer.To(endpoints.AlwaysServeEnabled)
}

if priority := d.Get("priority").(int); priority != 0 {
params.Properties.Priority = utils.Int64(int64(priority))
}
Expand Down Expand Up @@ -240,6 +251,12 @@ func resourceAzureEndpointRead(d *pluginsdk.ResourceData, meta interface{}) erro
d.Set("priority", props.Priority)
d.Set("geo_mappings", props.GeoMapping)

if props.AlwaysServe != nil && *props.AlwaysServe == endpoints.AlwaysServeEnabled {
d.Set("always_serve_enabled", true)
} else {
d.Set("always_serve_enabled", false)
}

if err := d.Set("custom_header", flattenEndpointCustomHeaderConfig(props.CustomHeaders)); err != nil {
return fmt.Errorf("setting `custom_header`: %s", err)
}
Expand Down Expand Up @@ -283,6 +300,14 @@ func resourceAzureEndpointUpdate(d *pluginsdk.ResourceData, meta interface{}) er
params.Properties.EndpointStatus = pointer.To(status)
}

if d.HasChange("always_serve_enabled") {
alwaysServe := endpoints.AlwaysServeDisabled
if d.Get("always_serve_enabled").(bool) {
alwaysServe = endpoints.AlwaysServeEnabled
}
params.Properties.AlwaysServe = pointer.To(alwaysServe)
}

if d.HasChange("custom_header") {
params.Properties.CustomHeaders = expandEndpointCustomHeaderConfig(d.Get("custom_header").([]interface{}))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2018-08-01/endpoints"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2022-04-01/endpoints"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down Expand Up @@ -227,12 +227,13 @@ resource "azurerm_public_ip" "test" {
}

resource "azurerm_traffic_manager_azure_endpoint" "test" {
name = "acctestend-azure%[2]d"
target_resource_id = azurerm_public_ip.test.id
weight = 5
profile_id = azurerm_traffic_manager_profile.test.id
enabled = false
priority = 4
name = "acctestend-azure%[2]d"
target_resource_id = azurerm_public_ip.test.id
weight = 5
profile_id = azurerm_traffic_manager_profile.test.id
enabled = false
always_serve_enabled = true
priority = 4

geo_mappings = ["WORLD"]

Expand Down
6 changes: 3 additions & 3 deletions internal/services/trafficmanager/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ package client
import (
"fmt"

"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2018-08-01/endpoints"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2018-08-01/geographichierarchies"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2018-08-01/profiles"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2022-04-01/endpoints"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2022-04-01/geographichierarchies"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2022-04-01/profiles"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/services/trafficmanager/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package trafficmanager

import (
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2018-08-01/endpoints"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2022-04-01/endpoints"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)

Expand Down
29 changes: 27 additions & 2 deletions internal/services/trafficmanager/external_endpoint_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2018-08-01/endpoints"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2018-08-01/profiles"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2022-04-01/endpoints"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2022-04-01/profiles"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
azValidate "github.com/hashicorp/terraform-provider-azurerm/helpers/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down Expand Up @@ -82,6 +82,12 @@ func resourceExternalEndpoint() *pluginsdk.Resource {
Default: true,
},

"always_serve_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},

"custom_header": {
Type: pluginsdk.TypeList,
Optional: true,
Expand Down Expand Up @@ -182,13 +188,18 @@ func resourceExternalEndpointCreate(d *pluginsdk.ResourceData, meta interface{})
Name: utils.String(id.EndpointName),
Type: utils.String(fmt.Sprintf("Microsoft.Network/trafficManagerProfiles/%s", endpoints.EndpointTypeExternalEndpoints)),
Properties: &endpoints.EndpointProperties{
AlwaysServe: pointer.To(endpoints.AlwaysServeDisabled),
CustomHeaders: expandEndpointCustomHeaderConfig(d.Get("custom_header").([]interface{})),
EndpointStatus: &status,
Target: utils.String(d.Get("target").(string)),
Subnets: expandEndpointSubnetConfig(d.Get("subnet").([]interface{})),
},
}

if alwaysServe := d.Get("always_serve_enabled").(bool); alwaysServe {
params.Properties.AlwaysServe = pointer.To(endpoints.AlwaysServeEnabled)
}

if priority := d.Get("priority").(int); priority != 0 {
params.Properties.Priority = utils.Int64(int64(priority))
}
Expand Down Expand Up @@ -253,6 +264,12 @@ func resourceExternalEndpointRead(d *pluginsdk.ResourceData, meta interface{}) e
d.Set("endpoint_location", props.EndpointLocation)
d.Set("geo_mappings", props.GeoMapping)

if props.AlwaysServe != nil && *props.AlwaysServe == endpoints.AlwaysServeEnabled {
d.Set("always_serve_enabled", true)
} else {
d.Set("always_serve_enabled", false)
}

if err := d.Set("custom_header", flattenEndpointCustomHeaderConfig(props.CustomHeaders)); err != nil {
return fmt.Errorf("setting `custom_header`: %s", err)
}
Expand Down Expand Up @@ -296,6 +313,14 @@ func resourceExternalEndpointUpdate(d *pluginsdk.ResourceData, meta interface{})
params.Properties.EndpointStatus = pointer.To(status)
}

if d.HasChange("always_serve_enabled") {
alwaysServe := endpoints.AlwaysServeDisabled
if d.Get("always_serve_enabled").(bool) {
alwaysServe = endpoints.AlwaysServeEnabled
}
params.Properties.AlwaysServe = pointer.To(alwaysServe)
}

if d.HasChange("custom_header") {
params.Properties.CustomHeaders = expandEndpointCustomHeaderConfig(d.Get("custom_header").([]interface{}))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2018-08-01/endpoints"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2022-04-01/endpoints"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down Expand Up @@ -214,13 +214,14 @@ provider "azurerm" {
%s

resource "azurerm_traffic_manager_external_endpoint" "test" {
name = "acctestend-azure%d"
target = "www.example.com"
weight = 5
profile_id = azurerm_traffic_manager_profile.test.id
enabled = false
priority = 4
endpoint_location = azurerm_resource_group.test.location
name = "acctestend-azure%d"
target = "www.example.com"
weight = 5
profile_id = azurerm_traffic_manager_profile.test.id
enabled = false
always_serve_enabled = true
priority = 4
endpoint_location = azurerm_resource_group.test.location

geo_mappings = ["WORLD"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2018-08-01/endpoints"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2018-08-01/profiles"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2022-04-01/endpoints"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2022-04-01/profiles"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
azValidate "github.com/hashicorp/terraform-provider-azurerm/helpers/validate"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2018-08-01/endpoints"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2022-04-01/endpoints"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"time"

"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2018-08-01/geographichierarchies"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2022-04-01/geographichierarchies"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2018-08-01/profiles"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2022-04-01/profiles"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2018-08-01/profiles"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2022-04-01/profiles"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"testing"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2018-08-01/profiles"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2022-04-01/profiles"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading