provider/heroku: Allow renaming a pipeline

This commit is contained in:
Justin Campbell 2017-04-28 15:46:06 -04:00
parent dd48b5b7e7
commit e2b361f603
2 changed files with 29 additions and 12 deletions

View File

@ -12,6 +12,7 @@ import (
func resourceHerokuPipeline() *schema.Resource {
return &schema.Resource{
Create: resourceHerokuPipelineCreate,
Update: resourceHerokuPipelineUpdate,
Read: resourceHerokuPipelineRead,
Delete: resourceHerokuPipelineDelete,
@ -19,7 +20,6 @@ func resourceHerokuPipeline() *schema.Resource {
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true, // TODO does it?
},
},
}
@ -43,6 +43,24 @@ func resourceHerokuPipelineCreate(d *schema.ResourceData, meta interface{}) erro
log.Printf("[INFO] Pipeline ID: %s", d.Id())
return resourceHerokuPipelineUpdate(d, meta)
}
func resourceHerokuPipelineUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*heroku.Service)
if d.HasChange("name") {
name := d.Get("name").(string)
opts := heroku.PipelineUpdateOpts{
Name: &name,
}
_, err := client.PipelineUpdate(context.TODO(), d.Id(), opts)
if err != nil {
return err
}
}
return resourceHerokuPipelineRead(d, meta)
}

View File

@ -14,6 +14,7 @@ import (
func TestAccHerokuPipeline_Basic(t *testing.T) {
var pipeline heroku.PipelineInfoResult
pipelineName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
pipelineName2 := fmt.Sprintf("%s-2", pipelineName)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
@ -24,7 +25,15 @@ func TestAccHerokuPipeline_Basic(t *testing.T) {
Config: testAccCheckHerokuPipelineConfig_basic(pipelineName),
Check: resource.ComposeTestCheckFunc(
testAccCheckHerokuPipelineExists("heroku_pipeline.foobar", &pipeline),
testAccCheckHerokuPipelineAttributes(&pipeline, pipelineName),
resource.TestCheckResourceAttr(
"heroku_pipeline.foobar", "name", pipelineName),
),
},
{
Config: testAccCheckHerokuPipelineConfig_basic(pipelineName2),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"heroku_pipeline.foobar", "name", pipelineName2),
),
},
},
@ -68,16 +77,6 @@ func testAccCheckHerokuPipelineExists(n string, pipeline *heroku.PipelineInfoRes
}
}
func testAccCheckHerokuPipelineAttributes(pipeline *heroku.PipelineInfoResult, pipelineName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
if pipeline.Name != pipelineName {
return fmt.Errorf("Bad name: %s", pipeline.Name)
}
return nil
}
}
func testAccCheckHerokuPipelineDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*heroku.Service)