Skip to content

Commit cfee7c5

Browse files
committed
fix: add validation to key_prefix in autolink reference resource (#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.
1 parent e57f353 commit cfee7c5

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

github/resource_github_repository_autolink_reference.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ func resourceGithubRepositoryAutolinkReference() *schema.Resource {
6969
Required: true,
7070
ForceNew: true,
7171
Description: "This prefix appended by a number will generate a link any time it is found in an issue, pull request, or commit",
72+
ValidateDiagFunc: validation.ToDiagFunc(validation.StringMatch(
73+
regexp.MustCompile(`^[a-zA-Z0-9.=+:/#_-]*[a-zA-Z.=+:/#_-]$`),
74+
"must only contain letters, numbers, or .-_+=:/# and must not end with a number",
75+
)),
7276
},
7377
"target_url_template": {
7478
Type: schema.TypeString,

0 commit comments

Comments
 (0)