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_profile - support for the interval_in_seconds, timeout_in_seconds, and tolerated_number_of_failures properties #3473

Merged
merged 5 commits into from
Aug 3, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
45 changes: 41 additions & 4 deletions azurerm/resource_arm_traffic_manager_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,21 @@ func resourceArmTrafficManagerProfile() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"interval_in_seconds": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntInSlice([]int{10, 30}),
},
"timeout_in_seconds": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(5, 10),
},
"tolerated_number_of_failures": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(0, 9),
},
},
},
Set: resourceAzureRMTrafficManagerMonitorConfigHash,
Expand All @@ -121,7 +136,7 @@ func resourceArmTrafficManagerProfileCreateUpdate(d *schema.ResourceData, meta i
client := meta.(*ArmClient).trafficManagerProfilesClient
ctx := meta.(*ArmClient).StopContext

log.Printf("[INFO] preparing arguments for Azure ARM virtual network creation.")
log.Printf("[INFO] preparing arguments for TrafficManager Profile creation.")

name := d.Get("name").(string)
// must be provided in request
Expand Down Expand Up @@ -252,11 +267,17 @@ func expandArmTrafficManagerMonitorConfig(d *schema.ResourceData) *trafficmanage
proto := monitor["protocol"].(string)
port := int64(monitor["port"].(int))
path := monitor["path"].(string)
interval := int64(monitor["interval_in_seconds"].(int))
timeout := int64(monitor["timeout_in_seconds"].(int))
tolerated := int64(monitor["tolerated_number_of_failures"].(int))

return &trafficmanager.MonitorConfig{
Protocol: trafficmanager.MonitorProtocol(proto),
Port: &port,
Path: &path,
Protocol: trafficmanager.MonitorProtocol(proto),
Port: &port,
Path: &path,
IntervalInSeconds: &interval,
TimeoutInSeconds: &timeout,
ToleratedNumberOfFailures: &tolerated,
}
}

Expand Down Expand Up @@ -292,6 +313,10 @@ func flattenAzureRMTrafficManagerProfileMonitorConfig(cfg *trafficmanager.Monito
result["path"] = *cfg.Path
}

result["interval_in_seconds"] = int(*cfg.IntervalInSeconds)
result["timeout_in_seconds"] = int(*cfg.TimeoutInSeconds)
result["tolerated_number_of_failures"] = int(*cfg.ToleratedNumberOfFailures)

return []interface{}{result}
}

Expand All @@ -316,6 +341,18 @@ func resourceAzureRMTrafficManagerMonitorConfigHash(v interface{}) int {
if v, ok := m["path"]; ok && v != "" {
buf.WriteString(fmt.Sprintf("%s-", m["path"].(string)))
}

if v, ok := m["interval_in_seconds"]; ok && v != "" {
katbyte marked this conversation as resolved.
Show resolved Hide resolved
buf.WriteString(fmt.Sprintf("%d-", m["interval_in_seconds"].(int)))
}

if v, ok := m["timeout_in_seconds"]; ok && v != "" {
buf.WriteString(fmt.Sprintf("%d-", m["timeout_in_seconds"].(int)))
}

if v, ok := m["tolerated_number_of_failures"]; ok && v != "" {
buf.WriteString(fmt.Sprintf("%d-", m["tolerated_number_of_failures"].(int)))
}
}

return hashcode.String(buf.String())
Expand Down
58 changes: 58 additions & 0 deletions azurerm/resource_arm_traffic_manager_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,35 @@ func TestAccAzureRMTrafficManagerProfile_priorityToWeighted(t *testing.T) {
})
}

func TestAccAzureRMTrafficManagerProfile_fastEndpointFailoverSettings(t *testing.T) {
resourceName := "azurerm_traffic_manager_profile.test"
rInt := tf.AccRandTimeInt()
location := testLocation()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMTrafficManagerProfileDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMTrafficManagerProfile_failover(rInt, location),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMTrafficManagerProfileExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "monitor_config.#", "1"),
resource.TestCheckResourceAttr(resourceName, "monitor_config.3418284669.interval_in_seconds", "30"),
resource.TestCheckResourceAttr(resourceName, "monitor_config.3418284669.timeout_in_seconds", "6"),
resource.TestCheckResourceAttr(resourceName, "monitor_config.3418284669.tolerated_number_of_failures", "3"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testCheckAzureRMTrafficManagerProfileExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
// Ensure we have enough information in state to look up in API
Expand Down Expand Up @@ -577,3 +606,32 @@ resource "azurerm_traffic_manager_profile" "test" {
}
`, rInt, location, rInt, rInt)
}

func testAccAzureRMTrafficManagerProfile_failover(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_traffic_manager_profile" "test" {
name = "acctesttmp%d"
resource_group_name = "${azurerm_resource_group.test.name}"
traffic_routing_method = "Performance"

dns_config {
relative_name = "acctesttmp%d"
ttl = 30
}

monitor_config {
protocol = "https"
port = 443
path = "/"
interval_in_seconds = 30
timeout_in_seconds = 6
tolerated_number_of_failures = 3
}
}
`, rInt, location, rInt, rInt)
}
9 changes: 6 additions & 3 deletions examples/traffic-manager/basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ resource "azurerm_traffic_manager_profile" "example" {
}

monitor_config {
protocol = "http"
port = 80
path = "/"
protocol = "http"
port = 80
path = "/"
interval_in_seconds = 30
timeout_in_seconds = 9
tolerated_number_of_failures = 3
}
}
9 changes: 6 additions & 3 deletions website/docs/r/traffic_manager_endpoint.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ resource "azurerm_traffic_manager_profile" "test" {
}

monitor_config {
protocol = "http"
port = 80
path = "/"
protocol = "http"
port = 80
path = "/"
interval_in_seconds = 30
timeout_in_seconds = 9
tolerated_number_of_failures = 3
}

tags = {
Expand Down
15 changes: 12 additions & 3 deletions website/docs/r/traffic_manager_profile.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ resource "azurerm_traffic_manager_profile" "test" {
}

monitor_config {
protocol = "http"
port = 80
path = "/"
protocol = "http"
port = 80
path = "/"
interval_in_seconds = 30
timeout_in_seconds = 9
tolerated_number_of_failures = 3
}

tags = {
Expand Down Expand Up @@ -97,6 +100,12 @@ The `monitor_config` block supports:

* `path` - (Optional) The path used by the monitoring checks. Required when `protocol` is set to `HTTP` or `HTTPS` - cannot be set when `protocol` is set to `TCP`.

* `interval_in_seconds` - (Optional) The interval used to check the endpoint health from a Traffic Manager probing agent. You can specify two values here: 30 seconds (normal probing) and 10 seconds (fast probing). If no values are provided, the profile sets to a default value of 30 seconds.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we quote the values and for consistency work it like:

Suggested change
* `interval_in_seconds` - (Optional) The interval used to check the endpoint health from a Traffic Manager probing agent. You can specify two values here: 30 seconds (normal probing) and 10 seconds (fast probing). If no values are provided, the profile sets to a default value of 30 seconds.
* `interval_in_seconds` - (Optional) The interval used to check the endpoint health from a Traffic Manager probing agent in seconds. Possible values are `30` (normal probing) and `10` (fast probing). Defaults to `30` seconds.


* `timeout_in_seconds` - (Optional) The amount of time the Traffic Manager probing agent should wait before considering that check a failure when a health check probe is sent to the endpoint. If the Probing Interval is set to 30 seconds, then you can set the Timeout value between 5 and 10 seconds. If no value is specified, it uses a default value of 10 seconds. If the Probing Interval is set to 10 seconds, then you can set the Timeout value between 5 and 9 seconds. If no Timeout value is specified, it uses a default value of 9 seconds.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* `timeout_in_seconds` - (Optional) The amount of time the Traffic Manager probing agent should wait before considering that check a failure when a health check probe is sent to the endpoint. If the Probing Interval is set to 30 seconds, then you can set the Timeout value between 5 and 10 seconds. If no value is specified, it uses a default value of 10 seconds. If the Probing Interval is set to 10 seconds, then you can set the Timeout value between 5 and 9 seconds. If no Timeout value is specified, it uses a default value of 9 seconds.
* `timeout_in_seconds` - (Optional) The amount of time the Traffic Manager probing agent should wait before considering that check a failure when a health check probe is sent to the endpoint. If the Probing Interval is set to `30` seconds, then you can set the Timeout value between `5` and `10` seconds. If no value is specified, it uses a default value of `10` seconds. If the Probing Interval is set to `10` seconds, then you can set the Timeout value between `5` and `9` seconds. If no Timeout value is specified, it uses a default value of `9` seconds.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also adding some validation to enforce this would be nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any example available to validate a property of scheme based on the value of another property? I couldn't find such example, and not sure if it would be feasible here, as for the optional parameters I am relying on the default defined by Azure rather then replicate them here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately that's not possible at this time (whilst it's possible via customizeDiff, that won't work if the fields interpolated) - as such the best place to do that is within the Create/Update function at this point in time


* `tolerated_number_of_failures` - (Optional) The number of failures a Traffic Manager probing agent tolerates before marking that endpoint as unhealthy. Its value can range between 0 and 9. A value of 0 means a single monitoring failure can cause that endpoint to be marked as unhealthy. If no value is specified, it uses the default value of 3.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* `tolerated_number_of_failures` - (Optional) The number of failures a Traffic Manager probing agent tolerates before marking that endpoint as unhealthy. Its value can range between 0 and 9. A value of 0 means a single monitoring failure can cause that endpoint to be marked as unhealthy. If no value is specified, it uses the default value of 3.
* `tolerated_number_of_failures` - (Optional) The number of failures a Traffic Manager probing agent tolerates before marking that endpoint as unhealthy. Its value can range between `0` and 9. A value of `0` means a single monitoring failure can cause that endpoint to be marked as unhealthy. Defaults to `3`.


## Attributes Reference

The following attributes are exported:
Expand Down