Skip to content

fix: restore adopt-existing behavior in github_issue_label create (regression in v6.13.0)#3560

Open
aklinkert wants to merge 1 commit into
integrations:mainfrom
aklinkert:fix/issue-label-adopt-existing
Open

fix: restore adopt-existing behavior in github_issue_label create (regression in v6.13.0)#3560
aklinkert wants to merge 1 commit into
integrations:mainfrom
aklinkert:fix/issue-label-adopt-existing

Conversation

@aklinkert

Copy link
Copy Markdown

Resolves #3559


Before the change?

resource "github_issue_label" used to be idempotent on create: a single
resourceGithubIssueLabelCreateOrUpdate did a GET first and adopted (updated)
a label that already existed instead of creating it. PR #3342 (released in
v6.13.0) split that into context-aware Create and Update functions, and the
new Create calls client.Issues.CreateLabel(...) directly with no GET-first
existence check.

As a result, creating a label whose name already exists on the repository fails
the very first apply with 422 Validation Failed [already_exists]. This is a
common case, not an edge case: GitHub (and GHES) seed every new repository with
default labels (bug, documentation, duplicate, enhancement,
good first issue, help wanted, invalid, question, wontfix), so any
config that manages one of those names now breaks on first apply. The resource's
own docs still promise the "check if the label exists, then update, otherwise
create" behavior.

After the change?

resourceGithubIssueLabelCreate now restores the pre-6.13.0 adopt-existing
behavior, in the current context-aware CRUD style: it calls
client.Issues.GetLabel(ctx, owner, repo, name) first; if the label already
exists it issues an EditLabel (adopting/updating it), and if the GET returns
404 it falls through to CreateLabel exactly as today. Any non-404 error from
the GET is returned. diag.Diagnostics/context signatures and tflog logging
are kept consistent with the rest of the file.

An acceptance test (adopts a pre-existing label on create without error) is
added: it manages the default bug label on an auto_init repository and
asserts the apply succeeds and the label's color/description are updated.

Note: I was not able to exercise the acceptance-test suite here as it requires
live GitHub org credentials. Maintainers should run
TF_ACC=1 go test ./github -run TestAccGithubIssueLabel to confirm. gofmt,
go vet ./github, and go build ./... all pass.

Pull request checklist

  • Schema migrations have been created if needed (example)
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

Does this introduce a breaking change?

Please see our docs on breaking changes to help!

  • Yes
  • No

Since PR integrations#3342 (v6.13.0) split the idempotent create-or-update into
separate Create and Update funcs, resourceGithubIssueLabelCreate calls
Issues.CreateLabel directly with no GET-first existence check. Creating a
label whose name already exists on the repository now fails with
"422 Validation Failed [already_exists]". This regressed a documented
behavior and breaks the common case of managing GitHub's default seeded
labels (bug, documentation, enhancement, ...) on a new repository.

Restore the pre-6.13.0 behavior in the context-aware Create path: GET the
label first and, if it already exists, EditLabel (adopt) it instead of
CreateLabel; a 404 falls through to CreateLabel as before.

Fixes integrations#3559

Signed-off-by: Alex Klinkert <alex.klinkert@cloudpilots.com>
@github-actions

Copy link
Copy Markdown

👋 Hi, and thank you for this contribution!

This repo is maintained by GitHub and community members on a best-effort basis. We'll get to this as soon as we can.

You can help us prioritize by joining the discussion on open issues and PRs, sharing details on the changes you need, and reviewing other contributions.


🤖 This is an automated message.

@github-actions github-actions Bot added the Type: Bug Something isn't working as documented label Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Bug Something isn't working as documented

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression in v6.13.0: github_issue_label create no longer adopts pre-existing labels (422 already_exists)

1 participant