terraform-provider-github icon indicating copy to clipboard operation
terraform-provider-github copied to clipboard

[BUG]: `github_issue_labels` can't clobber existing labels

Open ezzatron opened this issue 1 year ago • 10 comments

Expected Behavior

I expected the github_issue_labels resource to allow me to specify the full list of issue labels I want, even if those issue labels overlap some of the default ones created in a new GitHub repo, or include other existing labels in the repo.

Actual Behavior

When using github_issue_labels with a set of labels that includes an existing label, the apply fails with an error like:

{"@level":"error","@message":"Error: POST https://api.github.com/repos/org/repo/labels: 422 Validation Failed [{Resource:Label Field:name Code:already_exists Message:}]","@module":"terraform.ui","@timestamp":"2024-01-10T04:48:36.512181Z","diagnostic":{"severity":"error","summary":"POST https://api.github.com/repos/org/repo/labels: 422 Validation Failed [{Resource:Label Field:name Code:already_exists Message:}]","detail":"","address":"module.name.github_issue_labels.this","range":{"filename":"modules/repo/issue-labels.tf","start":{"line":8,"column":39,"byte":246},"end":{"line":8,"column":40,"byte":247}},"snippet":{"context":"resource \"github_issue_labels\" \"this\"","code":"resource \"github_issue_labels\" \"this\" {","start_line":8,"highlight_start_offset":38,"highlight_end_offset":39,"values":[]}},"type":"diagnostic"}

This makes it impossible to use this resource with a set of labels that includes any of the default labels for new repos. This would be fine if you could simply omit those labels, but if you do, the default labels will be removed on subsequent runs.

Terraform Version

Terraform v1.6.6
on darwin_arm64
+ provider registry.terraform.io/integrations/github v5.43.0

Affected Resource(s)

  • github_issue_labels

Terraform Configuration Files

No response

Steps to Reproduce

No response

Debug Output

No response

Panic Output

No response

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

ezzatron avatar Jan 10 '24 05:01 ezzatron

👋 Hey Friends, this issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please add the Status: Pinned label if you feel that this issue needs to remain open/active. Thank you for your contributions and help in keeping things tidy!

github-actions[bot] avatar Oct 15 '24 02:10 github-actions[bot]

As far as I'm aware this is still an issue.

ezzatron avatar Oct 15 '24 02:10 ezzatron

I just ran into this myself; it makes the provider just about useless. We've had to switch to using github_issue_label instead, which while it works means we're now managing individual labels rather than an exclusive set.

I see there's been a pull request in place since October that looks like it addresses the problem; it would be awesome if that could get merged.

Thanks @stevehipwell for tackling this.

larsks avatar Feb 06 '25 12:02 larsks

Let me chip in. I want to start controlling the labels as well which is pretty much impossible due to the default tags.

Workaround is to either use import or change the organisational labels configuration to manupilate the tags of new repositories so they don't collide.

For a "maintain all labels of a repositories" resource a solution could be to automatically adopt all existing labels automatically and just take full control.

There are other resources that behave like this, e.g. aws_securityhub_standards_control_association

fatbasstard avatar Mar 25 '25 08:03 fatbasstard

@fatbasstard #2430 fixes this and adds tests (5+ months ago) but hasn't even been acknowledged by the maintainers.

stevehipwell avatar Mar 25 '25 10:03 stevehipwell

@kfcampbell @nickfloyd Do you have any time to take a look at this issue and related PR https://github.com/integrations/terraform-provider-github/pull/2430

fatbasstard avatar Mar 25 '25 10:03 fatbasstard

Came here looking for this. If you create a repository, a default set of labels exist. I wish github_repository had a parameter to not create labels, because I also use github_issue_labels to define labels, but this fails every single time I create a new repository and I'm either stuck importing the default labels to only destroy or deleting the default labels so I can then apply cleanly. Tangentially, if I use a template repository, why am I not getting that template's labels? This would still be less than ideal than a repository coming up with no labels by default, but at least with taking the labels from the template repository, I'm more aligned with my default set of labels.

esacteksab avatar Apr 23 '25 14:04 esacteksab

The workaround I'm currently using is to remove the default labels at the organization level, so that new repos created by Terraform get no labels at all. Then I'm free to set whatever labels I want with github_issue_labels.

Unfortunately this only works for organizations, as far as I know: https://docs.github.com/en/organizations/managing-organization-settings/managing-default-labels-for-repositories-in-your-organization#deleting-a-default-label

ezzatron avatar Apr 23 '25 23:04 ezzatron

Is this fixed? I ran terraform plan and saw that my existing labels were being removed, like the resource should do.

JvdsReform avatar May 19 '25 13:05 JvdsReform

Yeah, I'm seeing similar behavior. More aligned with expectations. No change in the provider (v6.6.0).

esacteksab avatar May 20 '25 02:05 esacteksab

I've imported the labels for a repository, but the apply wants to first delete them, and then create them (exactly the same as they are).

Slightly different to the original issue description but could it be related or should I open a new issue?

NickLarsenNZ avatar Nov 11 '25 14:11 NickLarsenNZ

@NickLarsenNZ which provider version and could you please share the output?

stevehipwell avatar Nov 11 '25 15:11 stevehipwell