@@ -506,7 +506,7 @@ func TestAccRecord_CAA(t *testing.T) {
506506 Config : testAccRecordCAA (rString ),
507507 Check : resource .ComposeTestCheckFunc (
508508 testAccCheckRecordExists ("ns1_record.caa" , & record ),
509- testAccCheckRecordDomain (& record , zoneName ),
509+ testAccCheckRecordDomain (& record , "caa." + zoneName ),
510510 testAccCheckRecordTTL (& record , 3600 ),
511511 testAccCheckRecordUseClientSubnet (& record , true ),
512512 testAccCheckRecordAnswerRdata (
@@ -520,7 +520,7 @@ func TestAccRecord_CAA(t *testing.T) {
520520 {
521521 ResourceName : "ns1_record.caa" ,
522522 ImportState : true ,
523- ImportStateId : fmt .Sprintf ("%[1] s/%[1] s/CAA" , zoneName ),
523+ ImportStateId : fmt .Sprintf ("%s/%s/CAA" , zoneName , "caa." + zoneName ),
524524 ImportStateVerify : true ,
525525 },
526526 {
@@ -642,8 +642,9 @@ func TestAccRecord_validationError(t *testing.T) {
642642 ExpectError : regexp .MustCompile (`(?s)(Error: (zone|domain) has an invalid (leading|trailing) "\.", got: .*){4}` ),
643643 },
644644 {
645- Config : testAccRecordNoAnswers (rString ),
646- ExpectError : regexp .MustCompile (`Invalid body` ),
645+ Config : testAccRecordNoAnswers (rString ),
646+ // seems to have changed, was: ExpectError: regexp.MustCompile(`Invalid body`),
647+ ExpectError : regexp .MustCompile (`404 zone not found` ),
647648 },
648649 },
649650 })
@@ -1113,6 +1114,70 @@ func TestAccRecord_Link(t *testing.T) {
11131114 })
11141115}
11151116
1117+ func TestAccRecord_TXT (t * testing.T ) {
1118+ var record dns.Record
1119+ rString := acctest .RandStringFromCharSet (15 , acctest .CharSetAlphaNum )
1120+ zoneName := fmt .Sprintf ("terraform-test-%s.io" , rString )
1121+ domainName := fmt .Sprintf ("txt-test.%s" , zoneName )
1122+
1123+ resource .Test (t , resource.TestCase {
1124+ PreCheck : func () { testAccPreCheck (t ) },
1125+ Providers : testAccProviders ,
1126+ CheckDestroy : testAccCheckRecordDestroy ,
1127+ Steps : []resource.TestStep {
1128+ {
1129+ Config : testAccRecordTXTWithBothFields (rString ),
1130+ ExpectError : regexp .MustCompile ("cannot specify both 'answer' and 'answer_parts'" ),
1131+ },
1132+ {
1133+ Config : testAccRecordTXTWithAnswerParts (rString ),
1134+ Check : resource .ComposeTestCheckFunc (
1135+ testAccCheckRecordExists ("ns1_record.txt_test" , & record ),
1136+ testAccCheckRecordDomain (& record , domainName ),
1137+ testAccCheckRecordTTL (& record , 300 ),
1138+ testAccCheckRecordAnswerRdata (
1139+ t , & record , 0 , []string {"foo" , "bar" , "qux" },
1140+ ),
1141+ ),
1142+ },
1143+ {
1144+ Config : testAccRecordTXTWithAnswer (rString ),
1145+ Check : resource .ComposeTestCheckFunc (
1146+ testAccCheckRecordExists ("ns1_record.txt_test" , & record ),
1147+ testAccCheckRecordDomain (& record , domainName ),
1148+ testAccCheckRecordTTL (& record , 300 ),
1149+ testAccCheckRecordAnswerRdata (
1150+ t , & record , 0 , []string {"foo bar qux" },
1151+ ),
1152+ ),
1153+ },
1154+ {
1155+ ResourceName : "ns1_record.txt_test" ,
1156+ ImportState : true ,
1157+ ImportStateId : fmt .Sprintf ("%s/%s/TXT" , zoneName , domainName ),
1158+ ImportStateVerify : true ,
1159+ },
1160+ {
1161+ Config : testAccRecordTXTWithAnswerPartsUpdated (rString ),
1162+ Check : resource .ComposeTestCheckFunc (
1163+ testAccCheckRecordExists ("ns1_record.txt_test" , & record ),
1164+ testAccCheckRecordDomain (& record , domainName ),
1165+ testAccCheckRecordTTL (& record , 300 ),
1166+ testAccCheckRecordAnswerRdata (
1167+ t , & record , 0 , []string {"foo" , "bar" , "baz" , "qux" },
1168+ ),
1169+ ),
1170+ },
1171+ {
1172+ ResourceName : "ns1_record.txt_test" ,
1173+ ImportState : true ,
1174+ ImportStateId : fmt .Sprintf ("%s/%s/TXT" , zoneName , domainName ),
1175+ ImportStateVerify : true ,
1176+ },
1177+ },
1178+ })
1179+ }
1180+
11161181func testAccCheckRecordExists (n string , record * dns.Record ) resource.TestCheckFunc {
11171182 return func (s * terraform.State ) error {
11181183 rs , ok := s .RootModule ().Resources [n ]
@@ -1717,11 +1782,11 @@ resource "ns1_record" "caa" {
17171782 domain = "caa.${ns1_zone.test.zone}"
17181783 type = "CAA"
17191784 ttl = 3600
1720-
1785+
17211786 answers {
17221787 answer = "0 issue \"letsencrypt.org\""
17231788 }
1724-
1789+
17251790 answers {
17261791 answer = "0 issuewild \";\""
17271792 }
@@ -1745,7 +1810,7 @@ resource "ns1_record" "apl" {
17451810 answers {
17461811 answer = "1:127.0.0.0/16"
17471812 }
1748-
1813+
17491814}
17501815` , zone , zone )
17511816}
@@ -2062,13 +2127,13 @@ func testAccRecordOPENPGPKEY(rString string) string {
20622127 resource "ns1_zone" "test" {
20632128 zone = "terraform-test-%s.io"
20642129 }
2065-
2130+
20662131 resource "ns1_record" "openpgpkey" {
20672132 zone = ns1_zone.test.zone
20682133 domain = "openpgpkey.${ns1_zone.test.zone}"
20692134 type = "OPENPGPKEY"
20702135 ttl = 3600
2071-
2136+
20722137 answers {
20732138 answer = "abba"
20742139 }
@@ -2208,6 +2273,83 @@ resource "ns1_zone" "test" {
22082273` , rString )
22092274}
22102275
2276+ func testAccRecordTXTWithAnswerParts (rString string ) string {
2277+ return fmt .Sprintf (`
2278+ resource "ns1_record" "txt_test" {
2279+ zone = "${ns1_zone.test.zone}"
2280+ domain = "txt-test.${ns1_zone.test.zone}"
2281+ type = "TXT"
2282+ ttl = 300
2283+ use_client_subnet = "true"
2284+ answers {
2285+ answer_parts = ["foo", "bar", "qux"]
2286+ }
2287+ }
2288+
2289+ resource "ns1_zone" "test" {
2290+ zone = "terraform-test-%s.io"
2291+ }
2292+ ` , rString )
2293+ }
2294+
2295+ func testAccRecordTXTWithAnswer (rString string ) string {
2296+ return fmt .Sprintf (`
2297+ resource "ns1_record" "txt_test" {
2298+ zone = "${ns1_zone.test.zone}"
2299+ domain = "txt-test.${ns1_zone.test.zone}"
2300+ type = "TXT"
2301+ ttl = 300
2302+ use_client_subnet = "true"
2303+ answers {
2304+ answer = "foo bar qux"
2305+ }
2306+ }
2307+
2308+ resource "ns1_zone" "test" {
2309+ zone = "terraform-test-%s.io"
2310+ }
2311+ ` , rString )
2312+ }
2313+
2314+ func testAccRecordTXTWithAnswerPartsUpdated (rString string ) string {
2315+ return fmt .Sprintf (`
2316+ resource "ns1_record" "txt_test" {
2317+ zone = "${ns1_zone.test.zone}"
2318+ domain = "txt-test.${ns1_zone.test.zone}"
2319+ type = "TXT"
2320+ ttl = 300
2321+ use_client_subnet = "true"
2322+ answers {
2323+ answer_parts = ["foo", "bar", "baz", "qux"]
2324+ }
2325+ }
2326+
2327+ resource "ns1_zone" "test" {
2328+ zone = "terraform-test-%s.io"
2329+ }
2330+ ` , rString )
2331+ }
2332+
2333+ func testAccRecordTXTWithBothFields (rString string ) string {
2334+ return fmt .Sprintf (`
2335+ resource "ns1_record" "txt_test" {
2336+ zone = "${ns1_zone.test.zone}"
2337+ domain = "txt-test.${ns1_zone.test.zone}"
2338+ type = "TXT"
2339+ ttl = 300
2340+ use_client_subnet = "true"
2341+ answers {
2342+ answer = "foo bar qux"
2343+ answer_parts = ["foo", "bar", "qux"]
2344+ }
2345+ }
2346+
2347+ resource "ns1_zone" "test" {
2348+ zone = "terraform-test-%s.io"
2349+ }
2350+ ` , rString )
2351+ }
2352+
22112353func TestRegionsMetaDiffSuppress (t * testing.T ) {
22122354 metaKeys := []string {"georegion" , "country" , "us_state" , "ca_province" }
22132355
0 commit comments