diff --git a/github/resource_github_issue_label.go b/github/resource_github_issue_label.go index 42dfcaa8af..8612668ef0 100644 --- a/github/resource_github_issue_label.go +++ b/github/resource_github_issue_label.go @@ -80,10 +80,23 @@ func resourceGithubIssueLabelCreateOrUpdate(d *schema.ResourceData, meta interfa ctx = context.WithValue(ctx, ctxId, d.Id()) } + // Pull out the original name. If we already have a resource, this is the + // parsed ID. If not, it's the value given to the resource. + var originalName string + if d.Id() == "" { + originalName = name + } else { + var err error + _, originalName, err = parseTwoPartID(d.Id(), "repository", "name") + if err != nil { + return err + } + } + log.Printf("[DEBUG] Querying label existence: %s (%s/%s)", name, orgName, repoName) existing, resp, err := client.Issues.GetLabel(ctx, - orgName, repoName, name) + orgName, repoName, originalName) if err != nil && resp.StatusCode != http.StatusNotFound { return err } diff --git a/github/resource_github_issue_label_test.go b/github/resource_github_issue_label_test.go index 89d5bb0f7c..5ca77e60eb 100644 --- a/github/resource_github_issue_label_test.go +++ b/github/resource_github_issue_label_test.go @@ -12,7 +12,7 @@ import ( ) func TestAccGithubIssueLabel_basic(t *testing.T) { - var label github.Label + var label, updatedLabel github.Label rn := "github_issue_label.test" rString := acctest.RandString(5) @@ -33,8 +33,9 @@ func TestAccGithubIssueLabel_basic(t *testing.T) { { Config: testAccGithubIssueLabelUpdateConfig(repoName), Check: resource.ComposeTestCheckFunc( - testAccCheckGithubIssueLabelExists(rn, &label), - testAccCheckGithubIssueLabelAttributes(&label, "bar", "FFFFFF"), + testAccCheckGithubIssueLabelExists(rn, &updatedLabel), + testAccCheckGithubIssueLabelAttributes(&updatedLabel, "bar", "FFFFFF"), + testAccCheckGithubIssueLabelIDUnchanged(&label, &updatedLabel), ), }, { @@ -168,6 +169,15 @@ func testAccCheckGithubIssueLabelAttributes(label *github.Label, name, color str } } +func testAccCheckGithubIssueLabelIDUnchanged(label, updatedLabel *github.Label) resource.TestCheckFunc { + return func(_ *terraform.State) error { + if *label.ID != *updatedLabel.ID { + return fmt.Errorf("label was recreated") + } + return nil + } +} + func testAccGithubIssueLabelDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*Organization).client