From f9ee18168bc21529fdd40db277681b55a57a8fbb Mon Sep 17 00:00:00 2001 From: SAY-5 Date: Wed, 22 Apr 2026 21:49:42 -0700 Subject: [PATCH] fix(custom-property): return error for empty property_value instead of panicking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit resource_github_repository_custom_property.go:72 unconditionally dereferenced propertyValue[0] for scalar property_type values (string, single_select, url, true_false). Terraform configurations that supplied property_value as an empty list — or where a computed value resolved to empty at apply time — crashed the provider with: panic: runtime error: index out of range [0] with length 0 resourceGithubRepositoryCustomPropertyCreate ... +0x698 OpenTofu / Terraform recovers from this as a plugin crash, leaves dangling resource state, and reports it as an internal provider error rather than a user-facing configuration error. Guard the index with an explicit length check that returns a clear Terraform error naming the offending property_type. Multi_select is unaffected — an empty slice there is intentionally allowed. Refs integrations/terraform-provider-github issue 3358. --- github/resource_github_repository_custom_property.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/github/resource_github_repository_custom_property.go b/github/resource_github_repository_custom_property.go index 9da207a1be..8c6d3ce8c6 100644 --- a/github/resource_github_repository_custom_property.go +++ b/github/resource_github_repository_custom_property.go @@ -69,6 +69,9 @@ func resourceGithubRepositoryCustomPropertyCreate(d *schema.ResourceData, meta a // The propertyValue can either be a list of strings or a string switch propertyType { case github.PropertyValueTypeString, github.PropertyValueTypeSingleSelect, github.PropertyValueTypeURL, github.PropertyValueTypeTrueFalse: + if len(propertyValue) == 0 { + return fmt.Errorf("property_value must contain at least one element for property_type %q", propertyType) + } customProperty.Value = propertyValue[0] case github.PropertyValueTypeMultiSelect: customProperty.Value = propertyValue