From 943583925d70cc5c477eef14728dca12fc74d5e8 Mon Sep 17 00:00:00 2001 From: clint shryock Date: Mon, 6 Jun 2016 14:57:26 -0500 Subject: [PATCH] provider/cloudfront: Minor adjustments for new cloudflare-go lib --- builtin/providers/cloudflare/config.go | 6 +++++- .../providers/cloudflare/resource_cloudflare_record.go | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/builtin/providers/cloudflare/config.go b/builtin/providers/cloudflare/config.go index c6ff82110..8fabbed77 100644 --- a/builtin/providers/cloudflare/config.go +++ b/builtin/providers/cloudflare/config.go @@ -1,6 +1,7 @@ package cloudflare import ( + "fmt" "log" "github.com/cloudflare/cloudflare-go" @@ -13,7 +14,10 @@ type Config struct { // Client() returns a new client for accessing cloudflare. func (c *Config) Client() (*cloudflare.API, error) { - client := cloudflare.New(c.Token, c.Email) + client, err := cloudflare.New(c.Token, c.Email) + if err != nil { + return nil, fmt.Errorf("Error creating new CloudFlare client: %s", err) + } log.Printf("[INFO] CloudFlare Client configured for user: %s", c.Email) return client, nil } diff --git a/builtin/providers/cloudflare/resource_cloudflare_record.go b/builtin/providers/cloudflare/resource_cloudflare_record.go index 1823d7d99..a738aa726 100644 --- a/builtin/providers/cloudflare/resource_cloudflare_record.go +++ b/builtin/providers/cloudflare/resource_cloudflare_record.go @@ -101,7 +101,13 @@ func resourceCloudFlareRecordCreate(d *schema.ResourceData, meta interface{}) er return fmt.Errorf("Failed to create record: %s", err) } - d.SetId(r.ID) + // In the Event that the API returns an empty DNS Record, we verify that the + // ID returned is not the default "" + if r.Result.ID == "" { + return fmt.Errorf("Failed to find record in Creat response; Record was empty") + } + + d.SetId(r.Result.ID) log.Printf("[INFO] CloudFlare Record ID: %s", d.Id())