Fix opslevel_service dropping preferred_api_document_source when api_document_path is unset (#14748)#647
Open
saditya370 wants to merge 4 commits intomainfrom
Open
Conversation
added 2 commits
April 29, 2026 19:01
| return nil | ||
| } | ||
|
|
||
| func serviceApiDocSettingsUpdateInput(plan ServiceResourceModel, state *ServiceResourceModel) (bool, string, *opslevel.ApiDocumentSourceEnum) { |
Contributor
There was a problem hiding this comment.
This helper should live at the bottom of the file since it isn't global.
| return false, "", nil | ||
| } | ||
|
|
||
| managesApiDocPath := !plan.ApiDocumentPath.IsNull() |
Contributor
There was a problem hiding this comment.
The naming for these variables doesn't make much sense as these attributes are always managed.
| return nil | ||
| } | ||
|
|
||
| func serviceApiDocSettingsUpdateInput(plan ServiceResourceModel, state *ServiceResourceModel) (bool, string, *opslevel.ApiDocumentSourceEnum) { |
Contributor
There was a problem hiding this comment.
We can remove the state argument if we put the plan/state equality check into the update lifecycle method.
Collaborator
Author
There was a problem hiding this comment.
Refactored as suggested
- helper moved to bottom of file,
- dropped the state arg,
- equality check moved into Update.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #14748. Configuring
preferred_api_document_sourceonopslevel_servicewithout also settingapi_document_pathcaused apply to fail withProvider produced inconsistent result after apply: .preferred_api_document_source: was cty.StringVal("PUSH"), but now null. The provider was gating theserviceApiDocSettingsUpdatemutation behind a non-emptyapi_document_path, so the user's preferred-source value was never sent to the backend — Terraform's plan/state consistency check then rejected the apply.This is a provider-only fix. The GraphQL backend and
opslevel-goclient already accepted the two arguments independently; only the provider was incorrectly coupling them.Changes
serviceApiDocSettingsUpdateInput(plan, state)helper inopslevel/resource_opslevel_service.gothat decides when to callServiceApiDocSettingsUpdateand with what arguments. ReturnsshouldUpdate=truewhenever either field is configured in plan, or whenever either field was previously managed in state (so unsetting still works).Createnow uses the helper, fixing source-only configs.Updatenow uses the same helper, fixing the prior bug whereapi_document_pathbeing null silently clearedpreferred_api_document_source.Customer-reported repro
Before the fix:
terraform applyerrored with the inconsistent-result message and left an orphaned service in OpsLevel that Terraform did not record in state.After the fix: apply succeeds, and a follow-up
terraform planreportsNo changes.Test plan
serviceApiDocSettingsUpdateInputcovering source-only PUSH, source-only PULL, path-only, unmanaged, unset previously-managed source, and unset previously-managed path — seeopslevel/resource_opslevel_service_test.go.resource_service_create_with_preferred_api_document_source_without_pathreproducing the exact customer config and assertingapi_document_path == nullandpreferred_api_document_source == "PUSH"after apply — seetests/service.tftest.hcl.GOWORK=off go test ./opslevelpasses.GOWORK=off go vet ./...clean.GOWORK=off task testpasses (104 Terraform tests + Go unit tests).PUSHandPULLconfigs apply cleanly, idempotent on re-plan, and the resultingservicesrow in the database has the expectedapi_docs_sourcevalue withapi_docs_pathnull.