From 97bae0ea3071830f4d1fdccb708f683303e3b48f Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Thu, 4 Feb 2016 09:57:44 -0600 Subject: [PATCH] provider/heroku: address cert test failure * Randomize app name in test * Return error and don't panic when there is a problem It's possible there may still be an underlying problem that caused the error that made the cert leak in the first place - this should help us diagnose it. --- builtin/providers/heroku/resource_heroku_cert.go | 2 +- builtin/providers/heroku/resource_heroku_cert_test.go | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/builtin/providers/heroku/resource_heroku_cert.go b/builtin/providers/heroku/resource_heroku_cert.go index 90a49c2b4..d6c7a9490 100644 --- a/builtin/providers/heroku/resource_heroku_cert.go +++ b/builtin/providers/heroku/resource_heroku_cert.go @@ -58,7 +58,7 @@ func resourceHerokuCertCreate(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] SSL Certificate create configuration: %#v, %#v", app, opts) a, err := client.SSLEndpointCreate(app, opts) if err != nil { - panic(err) + return fmt.Errorf("Error creating SSL endpoint: %s", err) } d.SetId(a.ID) diff --git a/builtin/providers/heroku/resource_heroku_cert_test.go b/builtin/providers/heroku/resource_heroku_cert_test.go index 1a2c7879b..1228c3d2e 100644 --- a/builtin/providers/heroku/resource_heroku_cert_test.go +++ b/builtin/providers/heroku/resource_heroku_cert_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/cyberdelia/heroku-go/v3" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) @@ -17,9 +18,10 @@ func TestAccHerokuCert_Basic(t *testing.T) { certificateChainFile := wd + "/test-fixtures/terraform.cert" certificateChainBytes, _ := ioutil.ReadFile(certificateChainFile) certificateChain := string(certificateChainBytes) + appName := fmt.Sprintf("tftest-%s", acctest.RandString(10)) testAccCheckHerokuCertConfig_basic := ` resource "heroku_app" "foobar" { - name = "terraform-test-cert-app" + name = "` + appName + `" region = "eu" } @@ -47,7 +49,8 @@ func TestAccHerokuCert_Basic(t *testing.T) { testAccCheckHerokuCertExists("heroku_cert.ssl_certificate", &endpoint), testAccCheckHerokuCertificateChain(&endpoint, certificateChain), resource.TestCheckResourceAttr( - "heroku_cert.ssl_certificate", "cname", "terraform-test-cert-app.herokuapp.com"), + "heroku_cert.ssl_certificate", + "cname", fmt.Sprintf("%s.herokuapp.com", appName)), ), }, },