@@ -502,6 +502,79 @@ func TestAccRecord_updatedWithTags(t *testing.T) {
502502 })
503503}
504504
505+ func TestAccRecord_updatedWithRegions (t * testing.T ) {
506+ var record dns.Record
507+ rString := acctest .RandStringFromCharSet (15 , acctest .CharSetAlphaNum )
508+ zoneName := fmt .Sprintf ("terraform-test-%s.io" , rString )
509+ domainName := fmt .Sprintf ("test.%s" , zoneName )
510+
511+ resource .Test (t , resource.TestCase {
512+ PreCheck : func () { testAccPreCheck (t ) },
513+ Providers : testAccProviders ,
514+ CheckDestroy : testAccCheckRecordDestroy ,
515+ Steps : []resource.TestStep {
516+ {
517+ Config : testAccRecordBasic (rString ),
518+ Check : resource .ComposeTestCheckFunc (
519+ testAccCheckRecordExists ("ns1_record.it" , & record ),
520+ testAccCheckRecordDomain (& record , domainName ),
521+ testAccCheckRecordTTL (& record , 60 ),
522+ testAccCheckRecordUseClientSubnet (& record , true ),
523+ testAccCheckRecordRegionName (& record , []string {"cal" }),
524+ testAccCheckRecordAnswerRdata (
525+ t , & record , 0 , []string {fmt .Sprintf ("test1.%s" , zoneName )},
526+ ),
527+ ),
528+ },
529+ {
530+ Config : testAccRecordUpdatedWithRegionWeight (rString ),
531+ Check : resource .ComposeTestCheckFunc (
532+ testAccCheckRecordExists ("ns1_record.it" , & record ),
533+ testAccCheckRecordDomain (& record , domainName ),
534+ testAccCheckRecordTTL (& record , 60 ),
535+ testAccCheckRecordUseClientSubnet (& record , true ),
536+ testAccCheckRecordRegionName (& record , []string {"cal" }),
537+ testAccCheckRecordAnswerRdata (
538+ t , & record , 0 , []string {fmt .Sprintf ("test1.%s" , zoneName )},
539+ ),
540+ ),
541+ },
542+ {
543+ Config : testAccRecordUpdatedWithRegions (rString ),
544+ Check : resource .ComposeTestCheckFunc (
545+ testAccCheckRecordExists ("ns1_record.it" , & record ),
546+ testAccCheckRecordDomain (& record , domainName ),
547+ testAccCheckRecordTTL (& record , 60 ),
548+ testAccCheckRecordUseClientSubnet (& record , true ),
549+ testAccCheckRecordRegionName (& record , []string {"ny" , "cal" }),
550+ testAccCheckRecordAnswerRdata (
551+ t , & record , 0 , []string {fmt .Sprintf ("test1.%s" , zoneName )},
552+ ),
553+ ),
554+ },
555+ {
556+ Config : testAccRecordUpdatedWithRegionWeight (rString ),
557+ Check : resource .ComposeTestCheckFunc (
558+ testAccCheckRecordExists ("ns1_record.it" , & record ),
559+ testAccCheckRecordDomain (& record , domainName ),
560+ testAccCheckRecordTTL (& record , 60 ),
561+ testAccCheckRecordUseClientSubnet (& record , true ),
562+ testAccCheckRecordRegionName (& record , []string {"cal" }),
563+ testAccCheckRecordAnswerRdata (
564+ t , & record , 0 , []string {fmt .Sprintf ("test1.%s" , zoneName )},
565+ ),
566+ ),
567+ },
568+ {
569+ ResourceName : "ns1_record.it" ,
570+ ImportState : true ,
571+ ImportStateId : fmt .Sprintf ("%s/%s/CNAME" , zoneName , domainName ),
572+ ImportStateVerify : true ,
573+ },
574+ },
575+ })
576+ }
577+
505578func TestAccRecord_validationError (t * testing.T ) {
506579 rString := acctest .RandStringFromCharSet (15 , acctest .CharSetAlphaNum )
507580
@@ -1038,18 +1111,6 @@ func mapToSlice(m map[string]interface{}) []string {
10381111 return sliceString
10391112}
10401113
1041- func testAccCheckRecordAnswerMetaWeight (r * dns.Record , expected float64 ) resource.TestCheckFunc {
1042- return func (s * terraform.State ) error {
1043- recordAnswer := r .Answers [0 ]
1044- recordMetas := recordAnswer .Meta
1045- weight := recordMetas .Weight .(float64 )
1046- if weight != expected {
1047- return fmt .Errorf ("r.Answers[0].Meta.Weight: got: %#v want: %#v" , weight , expected )
1048- }
1049- return nil
1050- }
1051- }
1052-
10531114func testAccCheckRecordAnswerMetaIPPrefixes (r * dns.Record , expected []string ) resource.TestCheckFunc {
10541115 return func (s * terraform.State ) error {
10551116 recordAnswer := r .Answers [0 ]
@@ -1637,6 +1698,93 @@ resource "ns1_zone" "test" {
16371698` , rString )
16381699}
16391700
1701+ func testAccRecordUpdatedWithRegionWeight (rString string ) string {
1702+ return fmt .Sprintf (`
1703+ resource "ns1_record" "it" {
1704+ zone = "${ns1_zone.test.zone}"
1705+ domain = "test.${ns1_zone.test.zone}"
1706+ type = "CNAME"
1707+ ttl = 60
1708+
1709+ answers {
1710+ answer = "test1.${ns1_zone.test.zone}"
1711+ region = "cal"
1712+ }
1713+
1714+ regions {
1715+ name = "cal"
1716+ meta = {
1717+ weight = 100
1718+ }
1719+ }
1720+
1721+ filters {
1722+ filter = "geotarget_country"
1723+ }
1724+
1725+ filters {
1726+ filter = "select_first_n"
1727+ config = {N=1}
1728+ }
1729+
1730+ filters {
1731+ filter = "up"
1732+ }
1733+ }
1734+
1735+ resource "ns1_zone" "test" {
1736+ zone = "terraform-test-%s.io"
1737+ }
1738+ ` , rString )
1739+ }
1740+
1741+ func testAccRecordUpdatedWithRegions (rString string ) string {
1742+ return fmt .Sprintf (`
1743+ resource "ns1_record" "it" {
1744+ zone = "${ns1_zone.test.zone}"
1745+ domain = "test.${ns1_zone.test.zone}"
1746+ type = "CNAME"
1747+ ttl = 60
1748+
1749+ answers {
1750+ answer = "test1.${ns1_zone.test.zone}"
1751+ region = "cal"
1752+ }
1753+
1754+ regions {
1755+ name = "cal"
1756+ meta = {
1757+ weight = 90
1758+ }
1759+ }
1760+
1761+ regions {
1762+ name = "ny"
1763+ meta = {
1764+ weight = 10
1765+ }
1766+ }
1767+
1768+ filters {
1769+ filter = "geotarget_country"
1770+ }
1771+
1772+ filters {
1773+ filter = "select_first_n"
1774+ config = {N=1}
1775+ }
1776+
1777+ filters {
1778+ filter = "up"
1779+ }
1780+ }
1781+
1782+ resource "ns1_zone" "test" {
1783+ zone = "terraform-test-%s.io"
1784+ }
1785+ ` , rString )
1786+ }
1787+
16401788// zone and domain have leading and trailing dots and should fail validation.
16411789func testAccRecordInvalid (rString string ) string {
16421790 return fmt .Sprintf (`
0 commit comments