Skip to content

Commit

Permalink
Adding always_serve
Browse files Browse the repository at this point in the history
  • Loading branch information
smythluke committed Jan 19, 2024
1 parent b117779 commit 01e41df
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 4 deletions.
16 changes: 16 additions & 0 deletions internal/services/trafficmanager/azure_endpoint_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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{}))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
16 changes: 16 additions & 0 deletions internal/services/trafficmanager/external_endpoint_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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{}))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/traffic_manager_azure_endpoint.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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`.
Expand Down
11 changes: 7 additions & 4 deletions website/docs/r/traffic_manager_external_endpoint.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
```

Expand All @@ -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`.
Expand Down

0 comments on commit 01e41df

Please sign in to comment.