Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Internal] Generate Effective Fields (#4057)
This PR introduces changes to the TFSDK generator to support “effective fields” for server-provided values. When fields are marked with the new proto annotation `ServerProposedIfEmpty` (name pending final decision, until then the `computed` annotation is used to indicate these fields, while specific fields are excluded), the generator will create an additional computed field (e.g., `Effective<FieldName>`) and add two sync functions to ensure proper handling of user-provided and server-determined values. ### Generated Struct: ``` type ResourceModel struct { OriginalField types.String `tfsdk:"original_field" tf:"optional"` EffectiveField types.String `tfsdk:"effective_field" tf:"computed"` } ``` ### Sync Functions: ``` func (newState *ResourceModel) SyncEffectiveFieldsDuringCreateOrUpdate(plan ResourceModel) { newState.EffectiveField = newState.OriginalField newState.OriginalField = plan.OriginalField } func (newState *ResourceModel) SyncEffectiveFieldsDuringRead(existingState ResourceModel) { if existingState.EffectiveField.ValueString() == newState.OriginalField.ValueString() { newState.OriginalField = existingState.OriginalField } } ``` ## Changes <!-- Summary of your changes that are easy to understand --> ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [ ] `make test` run locally - [ ] relevant change in `docs/` folder - [ ] covered with integration tests in `internal/acceptance` - [ ] relevant acceptance tests are passing - [ ] using Go SDK --------- Co-authored-by: Omer Lachish <[email protected]>
- Loading branch information