Repository navigation
fix: add plan-time validation to key_prefix in autolink reference resource (#3176) - #3277
Conversation
|
👋 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 |
austenstone
left a comment
There was a problem hiding this comment.
Left a concrete regression-test suggestion so the fix is covered at plan time as well as in the schema.
|
Good call! Added a |
d721ddc to
49a967c
Compare
|
Rebased on upstream |
|
Applied @deiga's review feedback: split the |
3e5df52 to
b1015f6
Compare
|
Rebased on upstream |
|
Rebased on upstream |
|
Rebased on upstream |
|
Rebased on upstream |
|
@LeC-D Sorry that this has taken long to get to. Would you be available to rebase this (possibly multiple times) during the next week? We're trying to get 6.13.0 out and will try to merge as many ~ready PRs as is reasonable |
stevehipwell
left a comment
There was a problem hiding this comment.
@LeC-D please could you rebase this PR?
|
@LeC-D are you in a position to continue working on this? |
b1015f6 to
83fc917
Compare
|
Rebased on upstream |
…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.
Adds a plan-time validation test asserting that a key_prefix ending in a digit (e.g. PTFY25) is rejected before any API call is made. Addresses review comment from @austenstone.
83fc917 to
7ba7d52
Compare
There was a problem hiding this comment.
Pull request overview
These provider review instructions are being used.
This PR fixes #3176 by adding plan-time validation to the key_prefix attribute of the github_repository_autolink_reference resource. Previously, terraform plan accepted any value while terraform apply could fail with a 422 from the GitHub API for invalid prefixes (e.g. ending in a digit or using disallowed characters), creating a confusing plan/apply inconsistency. The change surfaces the error at plan time instead.
Changes:
- Added a
ValidateDiagFuncusingvalidation.StringMatchwith a regexp mirroring GitHub'skey_prefixconstraints (allowed characters and "must not end with a number"). - Added a unit test asserting a
key_prefixending in a digit (PTFY25) is rejected at plan time.
I verified the regexp's allowed character set (. = + : / # _ -) matches GitHub's documented set (.-_+=:/#) exactly and that the trailing character class excludes digits, so it neither over- nor under-restricts relative to the API's stated rules. Because GitHub already enforces these constraints at apply, existing valid resources cannot be newly rejected. The regexp and validation imports are already present, the ValidateDiagFunc/StringMatch usage is consistent with existing schema fields (e.g. resource_github_repository.go:42), and the test's ExpectError substring matches the StringMatch error message. The schema Description is unchanged, so no docs regeneration is required.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| github/resource_github_repository_autolink_reference.go | Adds ValidateDiagFunc regexp validation to the key_prefix schema attribute to catch invalid values at plan time. |
| github/resource_github_repository_autolink_reference_test.go | Adds a plan-time validation unit test rejecting a key_prefix that ends with a digit. |
robert-crandall
left a comment
There was a problem hiding this comment.
Thanks for tackling this - moving the failure from apply-time 422 to plan-time is a really nice UX win. The regex matches GitHub's documented constraints exactly, and I like that you covered it with a fast unit test using ExpectError. Looks good to me!
Summary
Fixes #3176
Problem
terraform planaccepts any value forkey_prefixingithub_repository_autolink_reference, butterraform applycan fail with a 422 from the GitHub API if the value is invalid:This creates a confusing plan/apply inconsistency where the plan shows a clean diff but apply fails.
Fix
Added
ValidateDiagFuncto thekey_prefixschema field using a regexp that mirrors GitHub's API constraints:.-_+=:/#Both
regexpandvalidationwere already imported in this file (used bytarget_url_template). No new dependencies needed.Testing
Existing acceptance tests use
key_prefixvalues likeTEST1-,TEST2-, etc. which all pass the new validation. Invalid values likePTFY25(ends with digit) will now be caught at plan time.