Skip to content

Commit cb8fd95

Browse files
authored
[Internal] Use isServiceProposedIfEmpty annotations for effective fields (#4270)
This PR is a follow-up to #4057 and #4112. We're shifting away from using the "computed" annotation to decide if a field should have "effective field" behavior. Instead, we're adopting the more precise "isServiceProposedIfEmpty" annotation. This lines up better with what we aim to achieve with effective fields, without making all regular computed and non-effective fields generate effective field code. We'll only merge this once the relevant fields are updated accordingly in the OpenAPI spec. ## 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 --> - [x] `make test` run locally - [ ] relevant change in `docs/` folder - [ ] covered with integration tests in `internal/acceptance` - [x] relevant acceptance tests are passing - [ ] using Go SDK Co-authored-by: Omer Lachish <[email protected]>
1 parent 6d5f94a commit cb8fd95

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

.codegen/model.go.tmpl

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,28 @@ import (
1818
"github.com/databricks/databricks-sdk-go/marshal"
1919
"github.com/hashicorp/terraform-plugin-framework/types"
2020
)
21-
{{- $excluded := dict "ShareInfo" (list "CreatedAt" "CreatedBy" "UpdatedAt" "UpdatedBy")
22-
"SharedDataObject" (list "AddedAt" "AddedBy" "Status") -}}
2321
{{range .Types}}
2422
{{- if or .Fields .IsEmpty}}
2523
{{.Comment "// " 80}}
2624
type {{.PascalName}} struct {
27-
{{- $excluded := getOrDefault $excluded .PascalName (list) -}}
2825
{{- range .Fields}}
2926
{{.Comment " // " 80}}
30-
{{- $data := dict "field" . "excluded" $excluded }}
31-
{{template "field" $data}}{{if and .Entity.IsComputed (not (in $excluded .PascalName))}}{{ $data := dict "field" . "excluded" $excluded "effective" true }}{{printf "\n"}}{{template "field" $data}}{{end}}{{end}}
27+
{{- $data := dict "field" . }}
28+
{{template "field" $data}}{{if and (ne .Entity.Terraform nil) .Entity.Terraform.IsServiceProposedIfEmpty}}{{ $data := dict "field" . "effective" true }}{{printf "\n"}}{{template "field" $data}}{{end}}{{end}}
3229
}
3330

3431
func (newState *{{.PascalName}}) SyncEffectiveFieldsDuringCreateOrUpdate(plan {{.PascalName}}) {
3532
{{- range .Fields -}}
36-
{{- if and .Entity.IsComputed (or .Entity.IsString .Entity.IsBool .Entity.IsInt64 .Entity.IsFloat64 .Entity.IsInt .Entity.Enum) -}}
37-
{{- if not (in $excluded .PascalName)}}
33+
{{- if and (and (ne .Entity.Terraform nil) .Entity.Terraform.IsServiceProposedIfEmpty) (or .Entity.IsString .Entity.IsBool .Entity.IsInt64 .Entity.IsFloat64 .Entity.IsInt .Entity.Enum)}}
3834
newState.Effective{{.PascalName}} = newState.{{.PascalName}}
3935
newState.{{.PascalName}} = plan.{{.PascalName}}
4036
{{- end}}
4137
{{- end}}
42-
{{- end}}
4338
}
4439

4540
func (newState *{{.PascalName}}) SyncEffectiveFieldsDuringRead(existingState {{.PascalName}}) {
4641
{{- range .Fields -}}
47-
{{- if and .Entity.IsComputed (or .Entity.IsString .Entity.IsBool .Entity.IsInt64 .Entity.IsFloat64 .Entity.IsInt .Entity.Enum) -}}
48-
{{- if not (in $excluded .PascalName) -}}
42+
{{- if and (and (ne .Entity.Terraform nil) .Entity.Terraform.IsServiceProposedIfEmpty) (or .Entity.IsString .Entity.IsBool .Entity.IsInt64 .Entity.IsFloat64 .Entity.IsInt .Entity.Enum)}}
4943
{{- $type := "" -}}
5044
{{- if .Entity.IsString}}{{$type = "String"}}{{end}}
5145
{{- if .Entity.IsBool}}{{$type = "Bool"}}{{end}}
@@ -59,7 +53,6 @@ func (newState *{{.PascalName}}) SyncEffectiveFieldsDuringRead(existingState {{.
5953
}
6054
{{- end}}
6155
{{- end}}
62-
{{- end}}
6356
}
6457

6558
{{end}}
@@ -71,9 +64,7 @@ func (newState *{{.PascalName}}) SyncEffectiveFieldsDuringRead(existingState {{.
7164

7265
{{- define "field-tag" -}}
7366
{{- $annotations := "" -}}
74-
{{- if in .excluded .field.PascalName -}}
75-
{{- $annotations = (printf "%scomputed,optional," $annotations) -}}
76-
{{- else if .effective -}}
67+
{{- if or .field.Entity.IsComputed .effective -}}
7768
{{- $annotations = (printf "%scomputed,optional," $annotations) -}}
7869
{{- else -}}
7970
{{- if not .field.Required -}}

0 commit comments

Comments
 (0)