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
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
}

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
}
}

if d.HasChange("dns_config") {
update.ProfileProperties.DNSConfig = expandArmTrafficManagerDNSConfig(d)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ func TestAccAzureRMTrafficManagerProfile_cycleMethod(t *testing.T) {
),
},
data.ImportStep(),
{
Config: testAccAzureRMTrafficManagerProfile_multivalue(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMTrafficManagerProfileExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "traffic_routing_method", "MultiValue"),
resource.TestCheckResourceAttr(data.ResourceName, "fqdn", fmt.Sprintf("acctest-tmp-%d.trafficmanager.net", data.RandomInteger)),
),
},
data.ImportStep(),
},
})
}
Expand All @@ -197,6 +206,22 @@ func TestAccAzureRMTrafficManagerProfile_fastEndpointFailoverSettingsError(t *te
})
}

func TestAccAzureRMTrafficManagerProfile_fastMaxReturnSettingError(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_traffic_manager_profile", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMTrafficManagerProfileDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMTrafficManagerProfile_maxReturnError(data),
ExpectError: regexp.MustCompile("`max_return` must be specified when `traffic_routing_method` is set to `MultiValue`"),
},
},
})
}

func testCheckAzureRMTrafficManagerProfileExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := acceptance.AzureProvider.Meta().(*clients.Client).TrafficManager.ProfilesClient
Expand Down Expand Up @@ -291,6 +316,31 @@ resource "azurerm_traffic_manager_profile" "test" {
`, template, data.RandomInteger, method, data.RandomInteger)
}

func testAccAzureRMTrafficManagerProfile_multivalue(data acceptance.TestData) string {
template := testAccAzureRMTrafficManagerProfile_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 testAccAzureRMTrafficManagerProfile_requiresImport(data acceptance.TestData) string {
template := testAccAzureRMTrafficManagerProfile_basic(data, "Geographic")
return fmt.Sprintf(`
Expand Down Expand Up @@ -526,3 +576,30 @@ resource "azurerm_traffic_manager_profile" "test" {
}
`, template, data.RandomInteger, data.RandomInteger)
}

func testAccAzureRMTrafficManagerProfile_maxReturnError(data acceptance.TestData) string {
template := testAccAzureRMTrafficManagerProfile_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)
}