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
This commit is contained in:
stack72 2016-02-27 00:43:06 +00:00
parent cbc4ddad03
commit b8778b8a3a
2 changed files with 47 additions and 0 deletions

View File

@ -35,6 +35,7 @@ func resourceCloudFlareRecord() *schema.Resource {
"type": &schema.Schema{ "type": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
ForceNew: true,
}, },
"value": &schema.Schema{ "value": &schema.Schema{

View File

@ -75,6 +75,42 @@ func TestAccCLOudflareRecord_Updated(t *testing.T) {
}) })
} }
func TestAccCLOudflareRecord_forceNewRecord(t *testing.T) {
var afterCreate, afterUpdate cloudflare.Record
domain := os.Getenv("CLOUDFLARE_DOMAIN")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckCLOudflareRecordDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: fmt.Sprintf(testAccCheckCLoudFlareRecordConfig_basic, domain),
Check: resource.ComposeTestCheckFunc(
testAccCheckCLOudflareRecordExists("cloudflare_record.foobar", &afterCreate),
),
},
resource.TestStep{
Config: fmt.Sprintf(testAccCheckCloudFlareRecordConfig_forceNew, domain, domain),
Check: resource.ComposeTestCheckFunc(
testAccCheckCLOudflareRecordExists("cloudflare_record.foobar", &afterUpdate),
testAccCheckCloudFlareRecordRecreated(t, &afterCreate, &afterUpdate),
),
},
},
})
}
func testAccCheckCloudFlareRecordRecreated(t *testing.T,
before, after *cloudflare.Record) resource.TestCheckFunc {
return func(s *terraform.State) error {
if before.Id == after.Id {
t.Fatalf("Expected change of Record Ids, but both were %v", before.Id)
}
return nil
}
}
func testAccCheckCLOudflareRecordDestroy(s *terraform.State) error { func testAccCheckCLOudflareRecordDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*cloudflare.Client) client := testAccProvider.Meta().(*cloudflare.Client)
@ -164,3 +200,13 @@ resource "cloudflare_record" "foobar" {
type = "A" type = "A"
ttl = 3600 ttl = 3600
}` }`
const testAccCheckCloudFlareRecordConfig_forceNew = `
resource "cloudflare_record" "foobar" {
domain = "%s"
name = "terraform"
value = "%s"
type = "CNAME"
ttl = 3600
}`