Skip to content

fix: handle sha_pinning_required=false#3224

Open
sheeeng wants to merge 1 commit intointegrations:mainfrom
sheeeng:fix/sha-pinning-required-false-ignored
Open

fix: handle sha_pinning_required=false#3224
sheeeng wants to merge 1 commit intointegrations:mainfrom
sheeeng:fix/sha-pinning-required-false-ignored

Conversation

@sheeeng
Copy link
Contributor

@sheeeng sheeeng commented Feb 25, 2026

Replace Computed: true with Default: false on the
sha_pinning_required schema field and send it unconditionally
via d.Get() on every API call. The previous d.GetOk() approach
returned ok=false for zero-value booleans, causing
sha_pinning_required=false to be silently ignored.

This ensures both true and false values are correctly applied,
eliminating perpetual drift when disabling SHA pinning enforcement.

Affects github_actions_organization_permissions and
github_actions_repository_permissions resources.

Update tests to use ConfigStateChecks with statecheck package
instead of deprecated Check field, and consolidate duplicate
config templates into single reusable template strings.

Fix #3223.

Resolve #3223.


Before the change?

  • Setting sha_pinning_required = false applied successfully in Terraform, but not actually changed in GitHub resources itself.

After the change?

  • Setting sha_pinning_required = false applied successfully in Terraform, and actually changed in GitHub resources itself.

Pull request checklist

  • Schema migrations have been created if needed (example)
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

Does this introduce a breaking change?

Please see our docs on breaking changes to help!

  • Yes
  • No

@github-actions
Copy link

👋 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! 🚀

@github-actions github-actions bot added the Type: Bug Something isn't working as documented label Feb 25, 2026
@sheeeng sheeeng force-pushed the fix/sha-pinning-required-false-ignored branch from 0dee61f to 3067dd7 Compare February 25, 2026 09:38
@sheeeng sheeeng changed the title fix: handle sha_pinning_required=false fix: handle sha_pinning_required = false Feb 25, 2026
@sheeeng sheeeng changed the title fix: handle sha_pinning_required = false fix: handle sha_pinning_required=false Feb 25, 2026
@sheeeng sheeeng force-pushed the fix/sha-pinning-required-false-ignored branch from 3067dd7 to fd7ac91 Compare February 26, 2026 16:08
@sheeeng sheeeng requested a review from deiga February 26, 2026 16:10
Copy link
Collaborator

@deiga deiga left a comment

Choose a reason for hiding this comment

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

LGTM! @stevehipwell WDYT?

Copy link
Collaborator

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

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

@sheeeng I thought the whole point here was that SHA pinning was dependent on organization configuration? This change would not fix the issue, but would break this resource.

I'm not sure how I missed this in review, but I'll repeat my suggestion to look at how allow_forking works in the repository resource. To fix this you should split the create and update functions in the resource to simplify the logic. Then in create you can use d.GetOkExists() to see if it should be sent. In update you need to check d.Changed() and if it has changed you need to use d.Get() and then send that value.

@sheeeng sheeeng force-pushed the fix/sha-pinning-required-false-ignored branch 14 times, most recently from e5919ce to fef996b Compare February 28, 2026 09:12
Split `CreateOrUpdate` into separate `Create` and `Update` functions
to properly handle the `sha_pinning_required` boolean field's
zero-value problem:

- Use `d.GetOkExists()` in `Create` to only send the field when
  the user explicitly sets it in config, even to `false`.
- Use `d.HasChange()` in `Update` to detect when the value changes
  and `d.Get()` to read the new value.

Keep schema as `Optional` + `Computed` (not `Default: false`) so
the resource inherits the organization-level setting when not
explicitly configured. This follows the same pattern used by
`allow_forking` in `resource_github_repository.go`.

Fixes integrations#3223
@sheeeng sheeeng force-pushed the fix/sha-pinning-required-false-ignored branch from fef996b to 5b44ee6 Compare February 28, 2026 09:14
Copy link
Collaborator

@deiga deiga left a comment

Choose a reason for hiding this comment

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

Partial review. Apply comments suggestions to all applicable sections

Comment on lines -15 to 18
Create: resourceGithubActionsOrganizationPermissionsCreateOrUpdate,
Create: resourceGithubActionsOrganizationPermissionsCreate,
Read: resourceGithubActionsOrganizationPermissionsRead,
Update: resourceGithubActionsOrganizationPermissionsCreateOrUpdate,
Update: resourceGithubActionsOrganizationPermissionsUpdate,
Delete: resourceGithubActionsOrganizationPermissionsDelete,
Copy link
Collaborator

Choose a reason for hiding this comment

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

While you're in here, please refactor these to use the Context-aware functions

if allowedActions == "selected" {
actionsAllowedData := resourceGithubActionsOrganizationAllowedObject(d)
if actionsAllowedData != nil {
log.Printf("[DEBUG] Update `actionsAllowedData` configuration.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use tflog.Debug instead

}
}

d.SetId(orgName)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Update should not be updating resource Id

}

d.SetId(orgName)
return resourceGithubActionsOrganizationPermissionsRead(d, meta)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please set any computed fields in Update, instead of calling Read

Suggested change
return resourceGithubActionsOrganizationPermissionsRead(d, meta)
return nil

Comment on lines -14 to 17
Create: resourceGithubActionsRepositoryPermissionsCreateOrUpdate,
Create: resourceGithubActionsRepositoryPermissionsCreate,
Read: resourceGithubActionsRepositoryPermissionsRead,
Update: resourceGithubActionsRepositoryPermissionsCreateOrUpdate,
Update: resourceGithubActionsRepositoryPermissionsUpdate,
Delete: resourceGithubActionsRepositoryPermissionsDelete,
Copy link
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-aware functions

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]: sha_pinning_required = false is silently ignored due to d.GetOk() zero-value bug

3 participants