diff --git a/azurerm/internal/services/trafficmanager/traffic_manager_profile_resource.go b/azurerm/internal/services/trafficmanager/traffic_manager_profile_resource.go index 892dc3820bba..fbfb0d632ceb 100644 --- a/azurerm/internal/services/trafficmanager/traffic_manager_profile_resource.go +++ b/azurerm/internal/services/trafficmanager/traffic_manager_profile_resource.go @@ -174,6 +174,12 @@ func resourceArmTrafficManagerProfile() *schema.Resource { Computed: true, }, + "max_return": { + Type: schema.TypeInt, + Optional: true, + ValidateFunc: validation.IntBetween(1, 8), + }, + "tags": tags.Schema(), }, } @@ -212,10 +218,19 @@ func resourceArmTrafficManagerProfileCreate(d *schema.ResourceData, meta interfa Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } + if maxReturn, ok := d.GetOk("max_return"); ok { + profile.MaxReturn = utils.Int64(int64(maxReturn.(int))) + } + if status, ok := d.GetOk("profile_status"); ok { profile.ProfileStatus = trafficmanager.ProfileStatus(status.(string)) } + if profile.ProfileProperties.TrafficRoutingMethod == trafficmanager.MultiValue && + profile.ProfileProperties.MaxReturn == nil { + return fmt.Errorf("`max_return` must be specified when `traffic_routing_method` is set to `MultiValue`") + } + if *profile.ProfileProperties.MonitorConfig.IntervalInSeconds == int64(10) && *profile.ProfileProperties.MonitorConfig.TimeoutInSeconds == int64(10) { return fmt.Errorf("`timeout_in_seconds` must be between `5` and `9` when `interval_in_seconds` is set to `10`") @@ -265,6 +280,7 @@ func resourceArmTrafficManagerProfileRead(d *schema.ResourceData, meta interface if profile := resp.ProfileProperties; profile != nil { d.Set("profile_status", profile.ProfileStatus) d.Set("traffic_routing_method", profile.TrafficRoutingMethod) + d.Set("max_return", profile.MaxReturn) d.Set("dns_config", flattenAzureRMTrafficManagerProfileDNSConfig(profile.DNSConfig)) d.Set("monitor_config", flattenAzureRMTrafficManagerProfileMonitorConfig(profile.MonitorConfig)) @@ -304,6 +320,12 @@ func resourceArmTrafficManagerProfileUpdate(d *schema.ResourceData, meta interfa update.ProfileProperties.TrafficRoutingMethod = trafficmanager.TrafficRoutingMethod(d.Get("traffic_routing_method").(string)) } + if d.HasChange("max_return") { + if maxReturn, ok := d.GetOk("max_return"); ok { + update.MaxReturn = utils.Int64(int64(maxReturn.(int))) + } + } + if d.HasChange("dns_config") { update.ProfileProperties.DNSConfig = expandArmTrafficManagerDNSConfig(d) } diff --git a/azurerm/internal/services/trafficmanager/traffic_manager_profile_resource_test.go b/azurerm/internal/services/trafficmanager/traffic_manager_profile_resource_test.go index 1961e4806f19..56c0a6704216 100644 --- a/azurerm/internal/services/trafficmanager/traffic_manager_profile_resource_test.go +++ b/azurerm/internal/services/trafficmanager/traffic_manager_profile_resource_test.go @@ -158,6 +158,15 @@ func TestAccAzureRMTrafficManagerProfile_cycleMethod(t *testing.T) { ), }, data.ImportStep(), + { + Config: r.multiValue(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("traffic_routing_method").HasValue("MultiValue"), + check.That(data.ResourceName).Key("fqdn").HasValue(fmt.Sprintf("acctest-tmp-%d.trafficmanager.net", data.RandomInteger)), + ), + }, + data.ImportStep(), }) } @@ -173,6 +182,18 @@ func TestAccAzureRMTrafficManagerProfile_fastEndpointFailoverSettingsError(t *te }) } +func TestAccAzureRMTrafficManagerProfile_fastMaxReturnSettingError(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_traffic_manager_profile", "test") + r := TrafficManagerProfileResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.maxReturnError(data), + ExpectError: regexp.MustCompile("`max_return` must be specified when `traffic_routing_method` is set to `MultiValue`"), + }, + }) +} + func TestAccAzureRMTrafficManagerProfile_updateTTL(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_traffic_manager_profile", "test") r := TrafficManagerProfileResource{} @@ -247,6 +268,31 @@ resource "azurerm_traffic_manager_profile" "test" { `, template, data.RandomInteger, method, data.RandomInteger) } +func (r TrafficManagerProfileResource) multiValue(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_traffic_manager_profile" "test" { + name = "acctest-TMP-%d" + resource_group_name = azurerm_resource_group.test.name + traffic_routing_method = "MultiValue" + max_return = 8 + + dns_config { + relative_name = "acctest-tmp-%d" + ttl = 30 + } + + monitor_config { + protocol = "https" + port = 443 + path = "/" + } +} +`, template, data.RandomInteger, data.RandomInteger) +} + func (r TrafficManagerProfileResource) requiresImport(data acceptance.TestData) string { template := r.basic(data, "Geographic") return fmt.Sprintf(` @@ -483,6 +529,33 @@ resource "azurerm_traffic_manager_profile" "test" { `, template, data.RandomInteger, data.RandomInteger) } +func (r TrafficManagerProfileResource) maxReturnError(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_traffic_manager_profile" "test" { + name = "acctest-TMP-%d" + resource_group_name = azurerm_resource_group.test.name + traffic_routing_method = "MultiValue" + + dns_config { + relative_name = "acctest-tmp-%d" + ttl = 30 + } + + monitor_config { + protocol = "https" + port = 443 + path = "/" + interval_in_seconds = 10 + timeout_in_seconds = 8 + tolerated_number_of_failures = 3 + } +} +`, template, data.RandomInteger, data.RandomInteger) +} + func (r TrafficManagerProfileResource) withTTL(data acceptance.TestData, method string, ttl int) string { template := r.template(data) return fmt.Sprintf(` diff --git a/website/docs/r/traffic_manager_profile.html.markdown b/website/docs/r/traffic_manager_profile.html.markdown index 6e8e23d3fa3d..38e54e099cee 100644 --- a/website/docs/r/traffic_manager_profile.html.markdown +++ b/website/docs/r/traffic_manager_profile.html.markdown @@ -74,6 +74,10 @@ The following arguments are supported: * `monitor_config` - (Required) This block specifies the Endpoint monitoring configuration for the Profile, it supports the fields documented below. +* `max_return` - (Optional) The amount of endpoints to return for DNS queries to this Profile. Possible values range from `1` to `8`. + +~> **NOTE**: `max_return` must be set when the `traffic_routing_method` is `MultiValue`. + * `tags` - (Optional) A mapping of tags to assign to the resource. The `dns_config` block supports: