From 73c3610897d50ecc50f8ede69a9ccc3361ba1f4a Mon Sep 17 00:00:00 2001 From: Brandon Willett Date: Wed, 25 Nov 2020 14:24:56 -0500 Subject: [PATCH 1/6] Adds max_return parameter for creating MultiValue traffic manager resources --- GNUmakefile | 1 - .../resource_arm_traffic_manager_profile.go | 17 ++++ ...source_arm_traffic_manager_profile_test.go | 77 +++++++++++++++++++ 3 files changed, 94 insertions(+), 1 deletion(-) diff --git a/GNUmakefile b/GNUmakefile index 8b3aeb501054..b27edddcd909 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -15,7 +15,6 @@ tools: @sh "$(CURDIR)/scripts/gogetcookie.sh" GO111MODULE=off go get -u github.com/client9/misspell/cmd/misspell GO111MODULE=off go get -u github.com/bflad/tfproviderlint/cmd/tfproviderlint - GO111MODULE=off go get -u github.com/bflad/tfproviderdocs GO111MODULE=off go get -u github.com/katbyte/terrafmt curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH || $$GOPATH)/bin v1.32.0 diff --git a/azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_profile.go b/azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_profile.go index 43adfc14fb05..8695405c918c 100644 --- a/azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_profile.go +++ b/azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_profile.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,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 := maxReturn.(int64) + 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`") @@ -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)) diff --git a/azurerm/internal/services/trafficmanager/tests/resource_arm_traffic_manager_profile_test.go b/azurerm/internal/services/trafficmanager/tests/resource_arm_traffic_manager_profile_test.go index 2276a56e2a35..2461fa514b2c 100644 --- a/azurerm/internal/services/trafficmanager/tests/resource_arm_traffic_manager_profile_test.go +++ b/azurerm/internal/services/trafficmanager/tests/resource_arm_traffic_manager_profile_test.go @@ -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(), }, }) } @@ -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 @@ -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(` @@ -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) +} From ccdfd283cf57185dabb1db23962ccd4fffbb2267 Mon Sep 17 00:00:00 2001 From: Brandon Willett Date: Wed, 25 Nov 2020 16:20:19 -0500 Subject: [PATCH 2/6] bugfixes --- .../resource_arm_traffic_manager_profile.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_profile.go b/azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_profile.go index 8695405c918c..711fad2410db 100644 --- a/azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_profile.go +++ b/azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_profile.go @@ -219,7 +219,7 @@ func resourceArmTrafficManagerProfileCreate(d *schema.ResourceData, meta interfa } if maxReturn, ok := d.GetOk("max_return"); ok { - maxReturnInt := maxReturn.(int64) + maxReturnInt := int64(maxReturn.(int)) profile.ProfileProperties.MaxReturn = &maxReturnInt } @@ -228,7 +228,7 @@ func resourceArmTrafficManagerProfileCreate(d *schema.ResourceData, meta interfa } if profile.ProfileProperties.TrafficRoutingMethod == trafficmanager.MultiValue && - profile.ProfileProperties.MaxReturn != nil { + profile.ProfileProperties.MaxReturn == nil { return fmt.Errorf("`max_return` must be specified when `traffic_routing_method` is set to `MultiValue`") } @@ -321,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) } From 65c594dd5d641daf19eed9391566aa007a09768a Mon Sep 17 00:00:00 2001 From: Brandon Willett Date: Wed, 25 Nov 2020 16:22:59 -0500 Subject: [PATCH 3/6] undo makefile change --- GNUmakefile | 1 + 1 file changed, 1 insertion(+) diff --git a/GNUmakefile b/GNUmakefile index b27edddcd909..8b3aeb501054 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -15,6 +15,7 @@ tools: @sh "$(CURDIR)/scripts/gogetcookie.sh" GO111MODULE=off go get -u github.com/client9/misspell/cmd/misspell GO111MODULE=off go get -u github.com/bflad/tfproviderlint/cmd/tfproviderlint + GO111MODULE=off go get -u github.com/bflad/tfproviderdocs GO111MODULE=off go get -u github.com/katbyte/terrafmt curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH || $$GOPATH)/bin v1.32.0 From 85d47f7d69ee16c6bb8d6fccfa3b5be8dbdb4010 Mon Sep 17 00:00:00 2001 From: Brandon Willett Date: Mon, 30 Nov 2020 12:37:42 -0500 Subject: [PATCH 4/6] Add doc entry for max_return --- website/docs/r/traffic_manager_profile.html.markdown | 2 ++ 1 file changed, 2 insertions(+) diff --git a/website/docs/r/traffic_manager_profile.html.markdown b/website/docs/r/traffic_manager_profile.html.markdown index 6e8e23d3fa3d..6d9e5771415e 100644 --- a/website/docs/r/traffic_manager_profile.html.markdown +++ b/website/docs/r/traffic_manager_profile.html.markdown @@ -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. + * `tags` - (Optional) A mapping of tags to assign to the resource. The `dns_config` block supports: From 2287f97755e34f92af8d015b1767a1f0a1c3a3e9 Mon Sep 17 00:00:00 2001 From: Brandon Willett Date: Mon, 30 Nov 2020 12:56:56 -0500 Subject: [PATCH 5/6] merge conflicts --- ...source_arm_traffic_manager_profile_test.go | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/azurerm/internal/services/trafficmanager/tests/resource_arm_traffic_manager_profile_test.go b/azurerm/internal/services/trafficmanager/tests/resource_arm_traffic_manager_profile_test.go index 21c1a715f4a0..1f48b75601b8 100644 --- a/azurerm/internal/services/trafficmanager/tests/resource_arm_traffic_manager_profile_test.go +++ b/azurerm/internal/services/trafficmanager/tests/resource_arm_traffic_manager_profile_test.go @@ -206,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 TestAccAzureRMTrafficManagerProfile_updateTTL(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_traffic_manager_profile", "test") @@ -587,6 +603,33 @@ 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) +} + func testAccAzureRMTrafficManagerProfile_withTTL(data acceptance.TestData, method string, ttl int) string { template := testAccAzureRMTrafficManagerProfile_template(data) return fmt.Sprintf(` From 0c80b22f7bc64bf7eddd1788da08f8f6c5e7d49a Mon Sep 17 00:00:00 2001 From: Brandon Willett Date: Fri, 11 Dec 2020 17:20:22 -0500 Subject: [PATCH 6/6] Review comments --- .../trafficmanager/traffic_manager_profile_resource.go | 8 ++------ website/docs/r/traffic_manager_profile.html.markdown | 4 +++- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/azurerm/internal/services/trafficmanager/traffic_manager_profile_resource.go b/azurerm/internal/services/trafficmanager/traffic_manager_profile_resource.go index c97511583829..fbfb0d632ceb 100644 --- a/azurerm/internal/services/trafficmanager/traffic_manager_profile_resource.go +++ b/azurerm/internal/services/trafficmanager/traffic_manager_profile_resource.go @@ -219,8 +219,7 @@ func resourceArmTrafficManagerProfileCreate(d *schema.ResourceData, meta interfa } if maxReturn, ok := d.GetOk("max_return"); ok { - maxReturnInt := int64(maxReturn.(int)) - profile.ProfileProperties.MaxReturn = &maxReturnInt + profile.MaxReturn = utils.Int64(int64(maxReturn.(int))) } if status, ok := d.GetOk("profile_status"); ok { @@ -323,10 +322,7 @@ func resourceArmTrafficManagerProfileUpdate(d *schema.ResourceData, meta interfa 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 + update.MaxReturn = utils.Int64(int64(maxReturn.(int))) } } diff --git a/website/docs/r/traffic_manager_profile.html.markdown b/website/docs/r/traffic_manager_profile.html.markdown index 6d9e5771415e..38e54e099cee 100644 --- a/website/docs/r/traffic_manager_profile.html.markdown +++ b/website/docs/r/traffic_manager_profile.html.markdown @@ -74,7 +74,9 @@ 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. +* `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.