Skip to content

Commit 9ed4f1a

Browse files
authored
azurerm_traffic_manager_profile - support for new field max_return and support for traffic_routing_method to be MultiValue (#9487)
This PR adds a new optional field to the `azurerm_traffic_manager_profile` resource, which is `max_return`, which allows profiles with the routing methods `MultiValue` to be set. Without this field, resources like this that attempt to be created are always rejected by the Azure API because the `MaxReturn` value isn't set, so it's impossible to create them with Terraform. Not coincidentally, this type of routing method was also omitted from the acceptance tests (probably because they wouldn't have passed if `MultiValue` was included). Thus I've done my best to add the missing tests there too, but did run into some trouble running the acceptance tests, so please let me know if there's anything I need to improve there!
1 parent 32b9dfd commit 9ed4f1a

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

azurerm/internal/services/trafficmanager/traffic_manager_profile_resource.go

+22
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ func resourceArmTrafficManagerProfile() *schema.Resource {
175175
Computed: true,
176176
},
177177

178+
"max_return": {
179+
Type: schema.TypeInt,
180+
Optional: true,
181+
ValidateFunc: validation.IntBetween(1, 8),
182+
},
183+
178184
"tags": tags.Schema(),
179185
},
180186
}
@@ -212,10 +218,19 @@ func resourceArmTrafficManagerProfileCreate(d *schema.ResourceData, meta interfa
212218
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
213219
}
214220

221+
if maxReturn, ok := d.GetOk("max_return"); ok {
222+
profile.MaxReturn = utils.Int64(int64(maxReturn.(int)))
223+
}
224+
215225
if status, ok := d.GetOk("profile_status"); ok {
216226
profile.ProfileStatus = trafficmanager.ProfileStatus(status.(string))
217227
}
218228

229+
if profile.ProfileProperties.TrafficRoutingMethod == trafficmanager.MultiValue &&
230+
profile.ProfileProperties.MaxReturn == nil {
231+
return fmt.Errorf("`max_return` must be specified when `traffic_routing_method` is set to `MultiValue`")
232+
}
233+
219234
if *profile.ProfileProperties.MonitorConfig.IntervalInSeconds == int64(10) &&
220235
*profile.ProfileProperties.MonitorConfig.TimeoutInSeconds == int64(10) {
221236
return fmt.Errorf("`timeout_in_seconds` must be between `5` and `9` when `interval_in_seconds` is set to `10`")
@@ -254,6 +269,7 @@ func resourceArmTrafficManagerProfileRead(d *schema.ResourceData, meta interface
254269
if profile := resp.ProfileProperties; profile != nil {
255270
d.Set("profile_status", profile.ProfileStatus)
256271
d.Set("traffic_routing_method", profile.TrafficRoutingMethod)
272+
d.Set("max_return", profile.MaxReturn)
257273

258274
d.Set("dns_config", flattenAzureRMTrafficManagerProfileDNSConfig(profile.DNSConfig))
259275
d.Set("monitor_config", flattenAzureRMTrafficManagerProfileMonitorConfig(profile.MonitorConfig))
@@ -291,6 +307,12 @@ func resourceArmTrafficManagerProfileUpdate(d *schema.ResourceData, meta interfa
291307
update.ProfileProperties.TrafficRoutingMethod = trafficmanager.TrafficRoutingMethod(d.Get("traffic_routing_method").(string))
292308
}
293309

310+
if d.HasChange("max_return") {
311+
if maxReturn, ok := d.GetOk("max_return"); ok {
312+
update.MaxReturn = utils.Int64(int64(maxReturn.(int)))
313+
}
314+
}
315+
294316
if d.HasChange("dns_config") {
295317
update.ProfileProperties.DNSConfig = expandArmTrafficManagerDNSConfig(d)
296318
}

azurerm/internal/services/trafficmanager/traffic_manager_profile_resource_test.go

+73
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,15 @@ func TestAccAzureRMTrafficManagerProfile_cycleMethod(t *testing.T) {
158158
),
159159
},
160160
data.ImportStep(),
161+
{
162+
Config: r.multiValue(data),
163+
Check: resource.ComposeTestCheckFunc(
164+
check.That(data.ResourceName).ExistsInAzure(r),
165+
check.That(data.ResourceName).Key("traffic_routing_method").HasValue("MultiValue"),
166+
check.That(data.ResourceName).Key("fqdn").HasValue(fmt.Sprintf("acctest-tmp-%d.trafficmanager.net", data.RandomInteger)),
167+
),
168+
},
169+
data.ImportStep(),
161170
})
162171
}
163172

@@ -173,6 +182,18 @@ func TestAccAzureRMTrafficManagerProfile_fastEndpointFailoverSettingsError(t *te
173182
})
174183
}
175184

185+
func TestAccAzureRMTrafficManagerProfile_fastMaxReturnSettingError(t *testing.T) {
186+
data := acceptance.BuildTestData(t, "azurerm_traffic_manager_profile", "test")
187+
r := TrafficManagerProfileResource{}
188+
189+
data.ResourceTest(t, r, []resource.TestStep{
190+
{
191+
Config: r.maxReturnError(data),
192+
ExpectError: regexp.MustCompile("`max_return` must be specified when `traffic_routing_method` is set to `MultiValue`"),
193+
},
194+
})
195+
}
196+
176197
func TestAccAzureRMTrafficManagerProfile_updateTTL(t *testing.T) {
177198
data := acceptance.BuildTestData(t, "azurerm_traffic_manager_profile", "test")
178199
r := TrafficManagerProfileResource{}
@@ -247,6 +268,31 @@ resource "azurerm_traffic_manager_profile" "test" {
247268
`, template, data.RandomInteger, method, data.RandomInteger)
248269
}
249270

271+
func (r TrafficManagerProfileResource) multiValue(data acceptance.TestData) string {
272+
template := r.template(data)
273+
return fmt.Sprintf(`
274+
%s
275+
276+
resource "azurerm_traffic_manager_profile" "test" {
277+
name = "acctest-TMP-%d"
278+
resource_group_name = azurerm_resource_group.test.name
279+
traffic_routing_method = "MultiValue"
280+
max_return = 8
281+
282+
dns_config {
283+
relative_name = "acctest-tmp-%d"
284+
ttl = 30
285+
}
286+
287+
monitor_config {
288+
protocol = "https"
289+
port = 443
290+
path = "/"
291+
}
292+
}
293+
`, template, data.RandomInteger, data.RandomInteger)
294+
}
295+
250296
func (r TrafficManagerProfileResource) requiresImport(data acceptance.TestData) string {
251297
template := r.basic(data, "Geographic")
252298
return fmt.Sprintf(`
@@ -483,6 +529,33 @@ resource "azurerm_traffic_manager_profile" "test" {
483529
`, template, data.RandomInteger, data.RandomInteger)
484530
}
485531

532+
func (r TrafficManagerProfileResource) maxReturnError(data acceptance.TestData) string {
533+
template := r.template(data)
534+
return fmt.Sprintf(`
535+
%s
536+
537+
resource "azurerm_traffic_manager_profile" "test" {
538+
name = "acctest-TMP-%d"
539+
resource_group_name = azurerm_resource_group.test.name
540+
traffic_routing_method = "MultiValue"
541+
542+
dns_config {
543+
relative_name = "acctest-tmp-%d"
544+
ttl = 30
545+
}
546+
547+
monitor_config {
548+
protocol = "https"
549+
port = 443
550+
path = "/"
551+
interval_in_seconds = 10
552+
timeout_in_seconds = 8
553+
tolerated_number_of_failures = 3
554+
}
555+
}
556+
`, template, data.RandomInteger, data.RandomInteger)
557+
}
558+
486559
func (r TrafficManagerProfileResource) withTTL(data acceptance.TestData, method string, ttl int) string {
487560
template := r.template(data)
488561
return fmt.Sprintf(`

website/docs/r/traffic_manager_profile.html.markdown

+4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ The following arguments are supported:
7474

7575
* `monitor_config` - (Required) This block specifies the Endpoint monitoring configuration for the Profile, it supports the fields documented below.
7676

77+
* `max_return` - (Optional) The amount of endpoints to return for DNS queries to this Profile. Possible values range from `1` to `8`.
78+
79+
~> **NOTE**: `max_return` must be set when the `traffic_routing_method` is `MultiValue`.
80+
7781
* `tags` - (Optional) A mapping of tags to assign to the resource.
7882

7983
The `dns_config` block supports:

0 commit comments

Comments
 (0)