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 new field max_return and support for traffic_routing_method to be MultiValue #9487

Merged
merged 8 commits into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from 7 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
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
}
Expand Down Expand Up @@ -212,10 +218,20 @@ func resourceArmTrafficManagerProfileCreate(d *schema.ResourceData, meta interfa
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
}

if maxReturn, ok := d.GetOk("max_return"); ok {
maxReturnInt := int64(maxReturn.(int))
profile.ProfileProperties.MaxReturn = &maxReturnInt
}
brandon-dd marked this conversation as resolved.
Show resolved Hide resolved

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`")
Expand Down Expand Up @@ -265,6 +281,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))
Expand Down Expand Up @@ -304,6 +321,15 @@ 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 {
maxReturnInt := int64(maxReturn.(int))
update.ProfileProperties.MaxReturn = &maxReturnInt
} else {
update.ProfileProperties.MaxReturn = nil
}
brandon-dd marked this conversation as resolved.
Show resolved Hide resolved
}

if d.HasChange("dns_config") {
update.ProfileProperties.DNSConfig = expandArmTrafficManagerDNSConfig(d)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
})
}

Expand All @@ -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{}
Expand Down Expand Up @@ -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(`
Expand Down Expand Up @@ -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(`
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/traffic_manager_profile.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ 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) How many endpoints to return for DNS queries to this profile. Necessary when the `traffic_routing_method` is `MultiValue`, and ignored otherwise. Must be an integer between 1 and 8, with the default being 8.
brandon-dd marked this conversation as resolved.
Show resolved Hide resolved

* `tags` - (Optional) A mapping of tags to assign to the resource.

The `dns_config` block supports:
Expand Down