Skip to content

Commit f9ee181

Browse files
committed
fix(custom-property): return error for empty property_value instead of panicking
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.
1 parent 18178b1 commit f9ee181

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

github/resource_github_repository_custom_property.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ func resourceGithubRepositoryCustomPropertyCreate(d *schema.ResourceData, meta a
6969
// The propertyValue can either be a list of strings or a string
7070
switch propertyType {
7171
case github.PropertyValueTypeString, github.PropertyValueTypeSingleSelect, github.PropertyValueTypeURL, github.PropertyValueTypeTrueFalse:
72+
if len(propertyValue) == 0 {
73+
return fmt.Errorf("property_value must contain at least one element for property_type %q", propertyType)
74+
}
7275
customProperty.Value = propertyValue[0]
7376
case github.PropertyValueTypeMultiSelect:
7477
customProperty.Value = propertyValue

0 commit comments

Comments
 (0)