From b420d9457ffd2951d911922efaa891aac7f12543 Mon Sep 17 00:00:00 2001 From: Omer Lachish Date: Tue, 26 Nov 2024 12:28:58 +0100 Subject: [PATCH] use isServiceProposedIfEmpty annotations instead of isComputed to generate effective fields --- .codegen/model.go.tmpl | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/.codegen/model.go.tmpl b/.codegen/model.go.tmpl index 714401729..ffdd7e1ce 100644 --- a/.codegen/model.go.tmpl +++ b/.codegen/model.go.tmpl @@ -18,34 +18,28 @@ import ( "github.com/databricks/databricks-sdk-go/marshal" "github.com/hashicorp/terraform-plugin-framework/types" ) -{{- $excluded := dict "ShareInfo" (list "CreatedAt" "CreatedBy" "UpdatedAt" "UpdatedBy") - "SharedDataObject" (list "AddedAt" "AddedBy" "Status") -}} {{range .Types}} {{- if or .Fields .IsEmpty}} {{.Comment "// " 80}} type {{.PascalName}} struct { - {{- $excluded := getOrDefault $excluded .PascalName (list) -}} {{- range .Fields}} {{.Comment " // " 80}} - {{- $data := dict "field" . "excluded" $excluded }} - {{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}} + {{- $data := dict "field" . }} + {{template "field" $data}}{{if and (ne .Entity.Terraform nil) .Entity.Terraform.IsServiceProposedIfEmpty}}{{ $data := dict "field" . "effective" true }}{{printf "\n"}}{{template "field" $data}}{{end}}{{end}} } func (newState *{{.PascalName}}) SyncEffectiveFieldsDuringCreateOrUpdate(plan {{.PascalName}}) { {{- range .Fields -}} - {{- if and .Entity.IsComputed (or .Entity.IsString .Entity.IsBool .Entity.IsInt64 .Entity.IsFloat64 .Entity.IsInt .Entity.Enum) -}} - {{- if not (in $excluded .PascalName)}} + {{- if and (and (ne .Entity.Terraform nil) .Entity.Terraform.IsServiceProposedIfEmpty) (or .Entity.IsString .Entity.IsBool .Entity.IsInt64 .Entity.IsFloat64 .Entity.IsInt .Entity.Enum)}} newState.Effective{{.PascalName}} = newState.{{.PascalName}} newState.{{.PascalName}} = plan.{{.PascalName}} {{- end}} {{- end}} - {{- end}} } func (newState *{{.PascalName}}) SyncEffectiveFieldsDuringRead(existingState {{.PascalName}}) { {{- range .Fields -}} - {{- if and .Entity.IsComputed (or .Entity.IsString .Entity.IsBool .Entity.IsInt64 .Entity.IsFloat64 .Entity.IsInt .Entity.Enum) -}} - {{- if not (in $excluded .PascalName) -}} + {{- if and (and (ne .Entity.Terraform nil) .Entity.Terraform.IsServiceProposedIfEmpty) (or .Entity.IsString .Entity.IsBool .Entity.IsInt64 .Entity.IsFloat64 .Entity.IsInt .Entity.Enum)}} {{- $type := "" -}} {{- if .Entity.IsString}}{{$type = "String"}}{{end}} {{- if .Entity.IsBool}}{{$type = "Bool"}}{{end}} @@ -59,7 +53,6 @@ func (newState *{{.PascalName}}) SyncEffectiveFieldsDuringRead(existingState {{. } {{- end}} {{- end}} - {{- end}} } {{end}} @@ -71,9 +64,7 @@ func (newState *{{.PascalName}}) SyncEffectiveFieldsDuringRead(existingState {{. {{- define "field-tag" -}} {{- $annotations := "" -}} - {{- if in .excluded .field.PascalName -}} - {{- $annotations = (printf "%scomputed,optional," $annotations) -}} - {{- else if .effective -}} + {{- if or .field.Entity.IsComputed .effective -}} {{- $annotations = (printf "%scomputed,optional," $annotations) -}} {{- else -}} {{- if not .field.Required -}}