You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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]>
{{if .IsJson}}tfsdk:"{{if and (ne .Entity.Terraform nil) (ne .Entity.Terraform.Alias "") }}{{.Entity.Terraform.Alias}}{{else}}{{.Name}}{{end}}" tf:"{{- $first := true -}}{{- if not .Required -}}{{- if not $first -}},{{end}}optional{{- $first = false -}}{{- end -}}{{- if .Entity.IsObject -}}{{- if not $first -}},{{end}}object{{- $first = false -}}{{- end -}}"{{else}}tfsdk:"-"{{end -}}
0 commit comments