From 21efbcc37a5f8649686842935813c0724ed16389 Mon Sep 17 00:00:00 2001 From: Philipp Resch Date: Wed, 18 Dec 2019 10:35:04 +0100 Subject: [PATCH 1/2] Made name on dns_mx_record optional + test --- azurerm/resource_arm_dns_mx_record.go | 7 ++- azurerm/resource_arm_dns_mx_record_test.go | 56 ++++++++++++++++++++++ 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/azurerm/resource_arm_dns_mx_record.go b/azurerm/resource_arm_dns_mx_record.go index e170bca72aee..13edef07daab 100644 --- a/azurerm/resource_arm_dns_mx_record.go +++ b/azurerm/resource_arm_dns_mx_record.go @@ -38,8 +38,9 @@ func resourceArmDnsMxRecord() *schema.Resource { Schema: map[string]*schema.Schema{ "name": { Type: schema.TypeString, - Required: true, + Optional: true, ForceNew: true, + Default: "@", }, "resource_group_name": azure.SchemaResourceGroupName(), @@ -118,9 +119,7 @@ func resourceArmDnsMxRecordCreateUpdate(d *schema.ResourceData, meta interface{} }, } - eTag := "" - ifNoneMatch := "" // set to empty to allow updates to records after creation - if _, err := client.CreateOrUpdate(ctx, resGroup, zoneName, name, dns.MX, parameters, eTag, ifNoneMatch); err != nil { + if _, err := client.CreateOrUpdate(ctx, resGroup, zoneName, name, dns.MX, parameters, "", ""); err != nil { return fmt.Errorf("Error creating/updating DNS MX Record %q (Zone %q / Resource Group %q): %s", name, zoneName, resGroup, err) } diff --git a/azurerm/resource_arm_dns_mx_record_test.go b/azurerm/resource_arm_dns_mx_record_test.go index 2339b2b33415..956bd4ebab7e 100644 --- a/azurerm/resource_arm_dns_mx_record_test.go +++ b/azurerm/resource_arm_dns_mx_record_test.go @@ -38,6 +38,32 @@ func TestAccAzureRMDnsMxRecord_basic(t *testing.T) { }) } +func TestAccAzureRMDnsMxRecord_rootrecord(t *testing.T) { + resourceName := "azurerm_dns_mx_record.test" + ri := tf.AccRandTimeInt() + config := testAccAzureRMDnsMxRecord_rootrecord(ri, testLocation()) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMDnsMxRecordDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDnsMxRecordExists(resourceName), + resource.TestCheckResourceAttrSet(resourceName, "fqdn"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccAzureRMDnsMxRecord_requiresImport(t *testing.T) { if !features.ShouldResourcesBeImported() { t.Skip("Skipping since resources aren't required to be imported") @@ -222,6 +248,36 @@ resource "azurerm_dns_mx_record" "test" { `, rInt, location, rInt, rInt) } +func testAccAzureRMDnsMxRecord_rootrecord(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_dns_zone" "test" { + name = "acctestzone%d.com" + resource_group_name = "${azurerm_resource_group.test.name}" +} + +resource "azurerm_dns_mx_record" "test" { + resource_group_name = "${azurerm_resource_group.test.name}" + zone_name = "${azurerm_dns_zone.test.name}" + ttl = 300 + + record { + preference = "10" + exchange = "mail1.contoso.com" + } + + record { + preference = "20" + exchange = "mail2.contoso.com" + } +} +`, rInt, location, rInt) +} + func testAccAzureRMDnsMxRecord_requiresImport(rInt int, location string) string { template := testAccAzureRMDnsMxRecord_basic(rInt, location) return fmt.Sprintf(` From 584e965b335e2f1154c458502d447bfab6cc5191 Mon Sep 17 00:00:00 2001 From: Philipp Resch Date: Wed, 18 Dec 2019 10:36:55 +0100 Subject: [PATCH 2/2] documentation --- website/docs/r/dns_mx_record.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/dns_mx_record.html.markdown b/website/docs/r/dns_mx_record.html.markdown index b03d498e74fd..d137969508fc 100644 --- a/website/docs/r/dns_mx_record.html.markdown +++ b/website/docs/r/dns_mx_record.html.markdown @@ -49,7 +49,7 @@ resource "azurerm_dns_mx_record" "example" { The following arguments are supported: -* `name` - (Required) The name of the DNS MX Record. +* `name` - (Optional) The name of the DNS MX Record. Defaults to `@` (root). Changing this forces a new resource to be created. * `resource_group_name` - (Required) Specifies the resource group where the resource exists. Changing this forces a new resource to be created.