Skip to content

Commit

Permalink
providers/heroku: import heroku_pipeline_coupling resource
Browse files Browse the repository at this point in the history
  • Loading branch information
cmorent authored and cmorent committed May 15, 2017
1 parent 551e284 commit 1b2c2d1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
37 changes: 37 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,37 @@
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,
),
),
},
},
})
}
15 changes: 15 additions & 0 deletions builtin/providers/heroku/resource_heroku_pipeline_coupling.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ func resourceHerokuPipelineCoupling() *schema.Resource {
Read: resourceHerokuPipelineCouplingRead,
Delete: resourceHerokuPipelineCouplingDelete,

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

Schema: map[string]*schema.Schema{
"app": {
Type: schema.TypeString,
Expand All @@ -37,6 +41,17 @@ func resourceHerokuPipelineCoupling() *schema.Resource {
}
}

func resourceHerokuPipelineCouplingImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
client := meta.(*heroku.Service)

_, err := client.PipelineCouplingInfo(context.TODO(), d.Id())
if err != nil {
return nil, err
}

return []*schema.ResourceData{d}, nil
}

func resourceHerokuPipelineCouplingCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*heroku.Service)

Expand Down

0 comments on commit 1b2c2d1

Please sign in to comment.