fix(resources): handle empty/null/unknown IDs in Read methods #6690
+275
−15
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
This PR addresses issues where Terraform/OpenTofu runs refresh before create for new resources, causing API errors when trying to read non-existent resources.
Problem
When using
tofu apply(orterraform apply) with the-refresh=trueflag (which is the default), Terraform attempts to refresh the state of all resources before making changes. For resources that don't yet exist (i.e., resources being created for the first time), theReadmethod is called with an empty/null/unknown ID. Without proper handling, this causes the provider to make API calls with empty identifiers, resulting in errors.Solution
Add early return checks in
Readmethods for 31 resources to gracefully handle null/unknown/empty resource identifiers by callingresp.State.RemoveResource(). This signals to Terraform that the resource needs to be created.Fix
calls_sfu_app: Consolidateapp_idanduidfields (they were duplicates) by mapping the API'suidresponse toapp_idwith properComputed+Optionalschema andUseStateForUnknownplan modifier.Fix
zero_trust_access_service_token: ReplaceAlsoRequiresvalidator with a customConfigValidatorthat only requiresprevious_client_secret_expires_atwhenclient_secret_version > 1(during rotation). The previous validator was problematic becauseclient_secret_versionhas a default value of1, so it's always set, incorrectly triggering the validator on initial creation.Affected Resources
Test Plan
tofu plan/terraform planworks for new resources without errorstofu apply/terraform applysuccessfully creates resourcescalls_sfu_appresource creation and verifyapp_idis properly populatedzero_trust_access_service_tokeninitial creation withoutprevious_client_secret_expires_atzero_trust_access_service_tokenrotation withclient_secret_version > 1requiresprevious_client_secret_expires_at