Skip to content

Commit

Permalink
providers/heroku: import heroku_pipeline_coupling resource (#14495)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmorent authored and catsby committed May 17, 2017
1 parent f8b1d81 commit 0c260d1
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
43 changes: 43 additions & 0 deletions builtin/providers/heroku/import_heroku_pipeline_coupling_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package heroku

import (
"fmt"
"testing"

heroku "github.com/cyberdelia/heroku-go/v3"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccHerokuPipelineCoupling_importBasic(t *testing.T) {
var coupling heroku.PipelineCouplingInfoResult

appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
pipelineName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
stageName := "development"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckHerokuPipelineCouplingDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckHerokuPipelineCouplingConfig_basic(appName, pipelineName, stageName),
Check: resource.ComposeTestCheckFunc(
testAccCheckHerokuPipelineCouplingExists("heroku_pipeline_coupling.default", &coupling),
testAccCheckHerokuPipelineCouplingAttributes(
&coupling,
"heroku_pipeline.default",
stageName,
),
),
},
{
ResourceName: "heroku_pipeline_coupling.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"config_vars"},
},
},
})
}
20 changes: 18 additions & 2 deletions builtin/providers/heroku/resource_heroku_pipeline_coupling.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ func resourceHerokuPipelineCoupling() *schema.Resource {
Read: resourceHerokuPipelineCouplingRead,
Delete: resourceHerokuPipelineCouplingDelete,

Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"app_id": {
Type: schema.TypeString,
Computed: true,
},
"app": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -81,9 +89,17 @@ func resourceHerokuPipelineCouplingRead(d *schema.ResourceData, meta interface{}
return fmt.Errorf("Error retrieving pipeline: %s", err)
}

d.Set("app", p.App)
d.Set("pipeline", p.Pipeline)
// grab App info
app, err := client.AppInfo(context.TODO(), p.App.ID)
if err != nil {
log.Printf("[WARN] Error looking up addional App info for pipeline coupling (%s): %s", d.Id(), err)
} else {
d.Set("app", app.Name)
}

d.Set("app_id", p.App.ID)
d.Set("stage", p.Stage)
d.Set("pipeline", p.Pipeline.ID)

return nil
}

0 comments on commit 0c260d1

Please sign in to comment.