diff --git a/builtin/providers/heroku/resource_heroku_pipeline.go b/builtin/providers/heroku/resource_heroku_pipeline.go index 8b23dd7d3..1293aef46 100644 --- a/builtin/providers/heroku/resource_heroku_pipeline.go +++ b/builtin/providers/heroku/resource_heroku_pipeline.go @@ -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) } diff --git a/builtin/providers/heroku/resource_heroku_pipeline_test.go b/builtin/providers/heroku/resource_heroku_pipeline_test.go index 7ce7f0707..1c40e1403 100644 --- a/builtin/providers/heroku/resource_heroku_pipeline_test.go +++ b/builtin/providers/heroku/resource_heroku_pipeline_test.go @@ -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)