Skip to content

Commit

Permalink
Merge pull request #5353 from stack72/f-cloudflare-type-forcenew
Browse files Browse the repository at this point in the history
provider/cloudflare: Change `cloudflare_record` type to ForceNew
  • Loading branch information
stack72 committed Feb 27, 2016
2 parents cbc4dda + b8778b8 commit c59303a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions builtin/providers/cloudflare/resource_cloudflare_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func resourceCloudFlareRecord() *schema.Resource {
"type": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
},

"value": &schema.Schema{
Expand Down
46 changes: 46 additions & 0 deletions builtin/providers/cloudflare/resource_cloudflare_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
client := testAccProvider.Meta().(*cloudflare.Client)

Expand Down Expand Up @@ -164,3 +200,13 @@ resource "cloudflare_record" "foobar" {
type = "A"
ttl = 3600
}`

const testAccCheckCloudFlareRecordConfig_forceNew = `
resource "cloudflare_record" "foobar" {
domain = "%s"
name = "terraform"
value = "%s"
type = "CNAME"
ttl = 3600
}`

0 comments on commit c59303a

Please sign in to comment.