Skip to content

fix: improve github_organization_custom_properties resource#3234

Open
mkushakov wants to merge 3 commits into
integrations:mainfrom
mkushakov:fix/org-custom-properties-improvements
Open

fix: improve github_organization_custom_properties resource#3234
mkushakov wants to merge 3 commits into
integrations:mainfrom
mkushakov:fix/org-custom-properties-improvements

Conversation

@mkushakov
Copy link
Copy Markdown

@mkushakov mkushakov commented Feb 27, 2026

Summary

Fix several bugs and improve the github_organization_custom_properties resource to handle edge cases correctly and align with GitHub API behavior.

Resolves #2806, #3191

Changes

Bug Fixes

  • Remove broken CustomizeDiff: The existing CustomizeDiff referenced a slug field that does not exist in the schema, causing unnecessary plan diffs. Removed entirely.
  • Fix Update double-read: The Update function was reading the resource state twice unnecessarily. Removed the redundant read.
  • Fix missing 404 handling in Read: If a custom property is deleted outside of Terraform, the Read function now gracefully removes it from state instead of returning an error.
  • Use GetOk for optional fields: Changed allowed_values and default_value reads to use GetOk instead of Get to correctly distinguish between unset and empty values.

Improvements

  • Add ForceNew to immutable fields: property_name and value_type cannot be changed on an existing custom property — they now force recreation.
  • Make value_type Required: This field is required by the GitHub API and should not be optional.
  • Add allowed_values validation: allowed_values is now required when value_type is single_select or multi_select, and rejected for string and true_false types via CustomizeDiff.
  • Add checkOrganization guard: Create/Read/Update/Delete now validate that an organization is configured.
  • Improve error messages: All API errors are now wrapped with fmt.Errorf for better context.
  • Add resource Description.

Tests

  • Added validation test: rejects allowed_values for string type.
  • Added validation test: requires allowed_values for single_select type.

Testing

  • go build ./... — passes
  • go vet ./... — passes
  • New acceptance tests added for validation logic

@github-actions
Copy link
Copy Markdown

👋 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 Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

Comment on lines 17 to 22
Create: resourceGithubCustomPropertiesCreate,
Read: resourceGithubCustomPropertiesRead,
Update: resourceGithubCustomPropertiesUpdate,
Delete: resourceGithubCustomPropertiesDelete,
Importer: &schema.ResourceImporter{
State: resourceGithubCustomPropertiesImport,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refactor to use the Context functions

}
return resourceGithubCustomPropertiesRead(d, meta)
// Create uses the same upsert API, and already calls Read at the end
return resourceGithubCustomPropertiesCreate(d, meta)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: Never call any CRUD function

@deiga deiga added this to the v6 Next milestone Apr 16, 2026
@mkushakov mkushakov force-pushed the fix/org-custom-properties-improvements branch from c8c34c4 to b4fdf7b Compare April 17, 2026 06:56
@deiga deiga removed this from the v6 Next milestone Apr 19, 2026
@mkushakov mkushakov force-pushed the fix/org-custom-properties-improvements branch from a5054a9 to 1267efc Compare April 27, 2026 14:29
- Remove broken CustomizeDiff referencing non-existent 'slug' field
- Make 'property_name' ForceNew (renaming creates a new property, orphans old)
- Make 'value_type' Required and ForceNew (can't create without type, changing type requires recreation)
- Add allowed_values validation: required for select types, rejected for others
- Add checkOrganization guard to all CRUD functions
- Add graceful 404 handling in Read (removes from state instead of erroring)
- Improve error messages with context
- Fix Update double-read (Create already calls Read at the end)
- Add resource Description
- Use GetOk for optional fields to avoid sending zero values

Resolves integrations#2806
@mkushakov mkushakov force-pushed the fix/org-custom-properties-improvements branch from 1267efc to e40236c Compare April 27, 2026 14:33
@stevehipwell
Copy link
Copy Markdown
Collaborator

@mkushakov if you're still interested in contributing this change, I think it may be better to create a new resource named correctly (#2936) and then deprecate this resource. Off the top of my head I think the resource should be github_organization_repository_custom_property so as to not collide with the organization level custom properties (which should probably be github_enterprise_organization_custom_property & github_organization_custom_property respectively).

I've done a full refactor on the github_repository_custom_property resource in #3476, which you could use as a basis. Please note that we've updated the contributing guidelines and added an architecture doc to help contributors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Bug Something isn't working as documented

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: GitHub_organization_custom_properties

3 participants