fix(organization): apply visibility via AdminEditUser fallback - #142
fix(organization): apply visibility via AdminEditUser fallback#142saada wants to merge 1 commit into
Conversation
Forgejo's PATCH /orgs/{org} endpoint can silently ignore visibility
changes on some versions, causing Terraform's "Provider produced
inconsistent result after apply" error when transitioning between
visibility values (e.g. private -> public). The organization remains
unchanged on the server while the run errors.
Orgs share the underlying user schema in Forgejo, and PATCH
/admin/users/{user} reliably persists visibility writes. The user
resource already routes visibility through that endpoint. Mirror that
pattern here: after EditOrg, if the read-back disagrees with the
planned visibility, retry the visibility update via AdminEditUser.
Non-admin users for whom EditOrg works correctly are unaffected. When
the fallback is needed but the token lacks the write:admin scope, the
error message points the user at the missing scope.
Adds a regression test for the private -> public transition called
out in the bug report.
Closes svalabs#141
|
Hi @saada, thank you very much for creating this workaround! I do have a few concerns, however: Your workaround changes the semantics of the I would be willing to accept this as a temporary workaround. For the temporary nature of this we would need an issue with Forgejo for being able to track progress towards resolution. Please open an issue there, or identify an existing one, describing the exact problem. I guess this would require reproducing the issue with plain API requests, to rule out any misbehavior of the provider and/or the Forgejo SDK it uses. This is to ensure that the workaround is really temporary, while Forgejo works on implementing a proper fix... |
|
Hi @saada - any update on the issue with upstream Forgejo? Do you have questions, or is there anything I can help with? |
Summary
Fixes #141. Changing
visibilityon aforgejo_organization(e.g.private→public) fails with:The Forgejo
PATCH /orgs/{org}endpoint can silently ignore visibility changes on some Forgejo versions —EditOrgreturns success but the org's visibility on the server is unchanged. The post-apply read-back then disagrees with the plan and Terraform aborts.Orgs share the underlying user schema in Forgejo, and
PATCH /admin/users/{user}reliably persists visibility writes. Theforgejo_userresource already routes visibility through that endpoint. This PR mirrors that pattern inUpdate():EditOrgas before (so non-admin users keep working for the non-visibility fields).AdminEditUser, then re-read.Non-admin users whose Forgejo instance applies
EditOrgvisibility correctly are unaffected — the fallback only fires on the broken path. If the fallback is needed but the token lacks thewrite:adminscope, the diagnostic points the user at the missing scope rather than the generic 403.Test plan
go build ./...passesgo vet ./...passesgofmt -lcleanprivate→publicstep toTestAccOrganizationResource(the exact transition reported in forgejo_organization: "Provider produced inconsistent result after apply" when changing visibility #141). Acceptance tests need a Forgejo instance — CI will run them via the existing matrix.public→privatestep so the trailingUseStateForUnknowncheck in the test still proves its original behavior.