Skip to content

fix: add plan-time validation to key_prefix in autolink reference resource (#3176)#3277

Open
LeC-D wants to merge 1 commit intointegrations:mainfrom
LeC-D:fix/autolink-key-prefix-validation
Open

fix: add plan-time validation to key_prefix in autolink reference resource (#3176)#3277
LeC-D wants to merge 1 commit intointegrations:mainfrom
LeC-D:fix/autolink-key-prefix-validation

Conversation

@LeC-D
Copy link

@LeC-D LeC-D commented Mar 15, 2026

Summary

Fixes #3176

Problem

terraform plan accepts any value for key_prefix in github_repository_autolink_reference, but terraform apply can fail with a 422 from the GitHub API if the value is invalid:

key_prefix must not end with a number
key_prefix must only contain letters, numbers, or .-_+=:/#

This creates a confusing plan/apply inconsistency where the plan shows a clean diff but apply fails.

Fix

Added ValidateDiagFunc to the key_prefix schema field using a regexp that mirrors GitHub's API constraints:

  • Allowed characters: letters, digits, and .-_+=:/#
  • Must not end with a digit
ValidateDiagFunc: validation.ToDiagFunc(validation.StringMatch(
    regexp.MustCompile(`^[a-zA-Z0-9.=+:/#_-]*[a-zA-Z.=+:/#_-]$`),
    "must only contain letters, numbers, or .-_+=:/# and must not end with a number",
)),

Both regexp and validation were already imported in this file (used by target_url_template). No new dependencies needed.

Testing

Existing acceptance tests use key_prefix values like TEST1-, TEST2-, etc. which all pass the new validation. Invalid values like PTFY25 (ends with digit) will now be caught at plan time.

…egrations#3176)

GitHub's API enforces that key_prefix:
- must only contain letters, numbers, or .-_+=:/#
- must not end with a number

Without client-side validation, terraform plan succeeds with an invalid
key_prefix (e.g. 'PTFY25') but terraform apply fails with a 422 from
the GitHub API, giving a confusing plan/apply inconsistency.

Added ValidateDiagFunc using a regexp that mirrors the API constraints,
so invalid key_prefix values are caught at plan time.
@github-actions
Copy link

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@github-actions github-actions bot added the Type: Bug Something isn't working as documented label Mar 15, 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.

[BUG]: autolink allows numbers during plan, but fails during apply

1 participant