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

[MAINT]: Tag protection deprecated

Open fatbasstard opened this issue 1 year ago • 4 comments

Describe the need

Just received an email that tag protection is deprecated and will be removed August 30, 2024

See also: https://github.blog/changelog/2024-05-29-sunset-notice-tag-protections/?elqTrackId=f621f1b322814b558e4a0277a4566191&elq=342e4d04c598490ea3023e0874169979&elqaid=4165&elqat=1&elqCampaignId=4374

Can't find any changed related to this (e.g. marking tag protection as deprecated). It's replaced with Repository rulesets

SDK Version

No response

API Version

No response

Relevant log output

No response

Code of Conduct

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

fatbasstard avatar Aug 12 '24 09:08 fatbasstard

FYI: Tag protection is now completely deprecated and broken::

Error: POST https://api.github.com/repos/xxx/yyy/tags/protection: 410 This is a scheduled brownout of the tag 
protections API. Tag protections will be fully deprecated on 2024-08-30. At that point, this API endpoint will be removed.
 Please use tag rulesets instead. []```

fatbasstard avatar Sep 02 '24 09:09 fatbasstard

Jump into the same issue. Could not delete the resources since the deletion API was also deprecated. What is the migration step for Terromform? manually clean the state file?

NoSugarCoffee avatar Sep 04 '24 03:09 NoSugarCoffee

I've solved the headache problem by removing the github_repository_tag_protection resource in the state file and instead, you should use github_repository_ruleset.

For the state removal, You can use cli state rm or use removed block, I'd prefer to use the latter one.

Please make sure your Terraform version is the latest because I faced some issues with the removed block(at least in v1.7.0, the first version of the Terraform supports removed)

The following code is FYI

# resource "github_repository_tag_protection" "v_tags" {
#   count = var.settings.v_prefix_tags_protection ? 1 : 0
#
#   repository = github_repository.repo.name
#   pattern    = "v*"
#   lifecycle {
#     replace_triggered_by = [
#       github_repository.repo.repo_id,
#     ]
#   }
# }

removed {
  from = github_repository_tag_protection.v_tags
  lifecycle {
    destroy = false
  }
}

resource "github_repository_ruleset" "v_tags" {
  count       = var.settings.v_prefix_tags_protection ? 1 : 0
  name        = "v_tags"
  repository  = github_repository.repo.name
  target      = "tag"
  enforcement = "active"

  conditions {
    ref_name {
      include = ["refs/tags/v*"]
      exclude = []
    }
  }

  rules {}
}

NoSugarCoffee avatar Sep 04 '24 12:09 NoSugarCoffee

I've solved the headache problem by removing the github_repository_tag_protection resource in the state file and instead, you should use github_repository_ruleset.

For the state removal, You can use cli state rm or use removed block, I'd prefer to use the latter one.

Please make sure your Terraform version is the latest because I faced some issues with the removed block(at least in v1.7.0, the first version of the Terraform supports removed)

The following code is FYI

# resource "github_repository_tag_protection" "v_tags" {
#   count = var.settings.v_prefix_tags_protection ? 1 : 0
#
#   repository = github_repository.repo.name
#   pattern    = "v*"
#   lifecycle {
#     replace_triggered_by = [
#       github_repository.repo.repo_id,
#     ]
#   }
# }

removed {
  from = github_repository_tag_protection.v_tags
  lifecycle {
    destroy = false
  }
}

resource "github_repository_ruleset" "v_tags" {
  count       = var.settings.v_prefix_tags_protection ? 1 : 0
  name        = "v_tags"
  repository  = github_repository.repo.name
  target      = "tag"
  enforcement = "active"

  conditions {
    ref_name {
      include = ["refs/tags/v*"]
      exclude = []
    }
  }

  rules {}
}

Thank you for resolution details., removed block option with latest terraform version is the best approach here !

kkhancst avatar Oct 07 '24 21:10 kkhancst

👋 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 Jul 05 '25 02:07 github-actions[bot]