@@ -75,6 +75,42 @@ func TestAccCLOudflareRecord_Updated(t *testing.T) {
7575 })
7676}
7777
78+ func TestAccCLOudflareRecord_forceNewRecord (t * testing.T ) {
79+ var afterCreate , afterUpdate cloudflare.Record
80+ domain := os .Getenv ("CLOUDFLARE_DOMAIN" )
81+
82+ resource .Test (t , resource.TestCase {
83+ PreCheck : func () { testAccPreCheck (t ) },
84+ Providers : testAccProviders ,
85+ CheckDestroy : testAccCheckCLOudflareRecordDestroy ,
86+ Steps : []resource.TestStep {
87+ resource.TestStep {
88+ Config : fmt .Sprintf (testAccCheckCLoudFlareRecordConfig_basic , domain ),
89+ Check : resource .ComposeTestCheckFunc (
90+ testAccCheckCLOudflareRecordExists ("cloudflare_record.foobar" , & afterCreate ),
91+ ),
92+ },
93+ resource.TestStep {
94+ Config : fmt .Sprintf (testAccCheckCloudFlareRecordConfig_forceNew , domain , domain ),
95+ Check : resource .ComposeTestCheckFunc (
96+ testAccCheckCLOudflareRecordExists ("cloudflare_record.foobar" , & afterUpdate ),
97+ testAccCheckCloudFlareRecordRecreated (t , & afterCreate , & afterUpdate ),
98+ ),
99+ },
100+ },
101+ })
102+ }
103+
104+ func testAccCheckCloudFlareRecordRecreated (t * testing.T ,
105+ before , after * cloudflare.Record ) resource.TestCheckFunc {
106+ return func (s * terraform.State ) error {
107+ if before .Id == after .Id {
108+ t .Fatalf ("Expected change of Record Ids, but both were %v" , before .Id )
109+ }
110+ return nil
111+ }
112+ }
113+
78114func testAccCheckCLOudflareRecordDestroy (s * terraform.State ) error {
79115 client := testAccProvider .Meta ().(* cloudflare.Client )
80116
@@ -164,3 +200,13 @@ resource "cloudflare_record" "foobar" {
164200 type = "A"
165201 ttl = 3600
166202}`
203+
204+ const testAccCheckCloudFlareRecordConfig_forceNew = `
205+ resource "cloudflare_record" "foobar" {
206+ domain = "%s"
207+
208+ name = "terraform"
209+ value = "%s"
210+ type = "CNAME"
211+ ttl = 3600
212+ }`
0 commit comments