integrations / integrations/terraform-provider-github

github_organization_custom_properties Read doesn't handle 404, breaking recovery after deletion

Open Beginner friendly
#3,641 1 comment 0 reactions 0 assignees View on GitHub
r/organization_custom_properties Type: Bug
Dominant language
Go
Stars
1.2k
Forks
1k
Avg merge
1d 14h
Merged PRs (30d)
8

Description

## Description

`resourceGithubCustomPropertiesRead` in [`resource_github_organization_custom_properties.go`](https://github.com/integrations/terraform-provider-github/blob/v6.13.0/github/resource_github_organization_custom_properties.go#L113-L135) propagates any error from `client.Organizations.GetCustomProperty` verbatim, without checking for a 404 (not found) response:

```go
func resourceGithubCustomPropertiesRead(d *schema.ResourceData, meta any) error {
ctx := context.Background()
client := meta.(*Owner).v3client
ownerName := meta.(*Owner).name

customProperty, _, err := client.Organizations.GetCustomProperty(ctx, ownerName, d.Get("property_name").(string))
if err != nil {
return err // <-- no 404 handling; should clear state (d.SetId("")) and return nil
}
...
}
```

This violates the standard Terraform provider idiom: when `Read` gets a 404 for a resource that no longer exists (e.g., because it was deleted out-of-band, or because a prior `Delete` succeeded but something is re-verifying), it should call `d.SetId("")` and return `nil`, signaling "no longer exists" rather than a hard error. The closely related **repo-scoped** sibling, [`resource_github_repository_custom_property.go`](https://github.com/integrations/terraform-provider-github/blob/v6.13.0/github/resource_github_repository_custom_property.go#L154-L166), correctly does:

```go
if err, ok := errors.AsType[*github.ErrorResponse](err); ok && err.Response.StatusCode == 404 {
// clears state
}
```

## Impact

Any tool that relies on this resource's Read returning a clean "not found" for a deleted `github_organization_custom_properties` resource gets stuck: after a successful `Delete`, the next `Read`/refresh gets a 404 from GitHub (correctly, since the delete succeeded), but the 404 is returned as an error instead of "resource gone."

## Steps to reproduce

1. `terraform import` or create a `github_organization_custom_properties` resource.
2. Delete the underlying property directly via the GitHub API (or via `terraform destroy`, then attempt a subsequent plan/refresh).
3. Observe that `Read` returns a hard error (`404 Not Found`) instead of clearing resource state.

## Expected behavior

`Read` should detect a 404 from `GetCustomProperty` and call `d.SetId("")`, returning `nil`, consistent with `resource_github_repository_custom_property.go`'s handling.

## Suggested fix

```go
customProperty, resp, err := client.Organizations.GetCustomProperty(ctx, ownerName, d.Get("property_name").(string))
if err != nil {
if resp != nil && resp.StatusCode == http.StatusNotFound {
d.SetId("")
return nil
}
return err
}
```

## Environment

- `terraform-provider-github` v6.13.0

Contributor guide

Open the contributing guide

Research direction

Start in github/resource_github_organization_custom_properties.go at resourceGithubCustomPropertiesRead, then compare its error handling with resource_github_repository_custom_property.go. Verify how GetCustomProperty reports a 404 and confirm the resource clears its state and returns no error for a missing property while preserving other errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
github, go, terraform
Domain
infrastructure, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
85/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.