Skip to content

Commit b8778b8

Browse files
committed
provider/cloudflare: Change cloudflare_record type to ForceNew. The
CloudFlare API does not allow types to be changed (i.e. A to CNAME) after creation
1 parent cbc4dda commit b8778b8

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

builtin/providers/cloudflare/resource_cloudflare_record.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func resourceCloudFlareRecord() *schema.Resource {
3535
"type": &schema.Schema{
3636
Type: schema.TypeString,
3737
Required: true,
38+
ForceNew: true,
3839
},
3940

4041
"value": &schema.Schema{

builtin/providers/cloudflare/resource_cloudflare_record_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
78114
func 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

Comments
 (0)