From fadb7c9feecd79cde0beea6a9d93498a532b9710 Mon Sep 17 00:00:00 2001 From: Omer Lachish <289488+rauchy@users.noreply.github.com> Date: Mon, 9 Dec 2024 15:37:00 +0100 Subject: [PATCH] [Internal] Move TFSDK model template to universe (#4303) ## Changes In order to get ready for auto-generating resources, we're relocating the templates for our plugin framework models to an internal repository. ## Tests Verified that generating an SDK before and after this change resulted in a no-op. - [x] `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 --- .codegen.json | 3 -- .codegen/model.go.tmpl | 103 ----------------------------------------- 2 files changed, 106 deletions(-) delete mode 100644 .codegen/model.go.tmpl diff --git a/.codegen.json b/.codegen.json index a1f1732c6..3a5a817d3 100644 --- a/.codegen.json +++ b/.codegen.json @@ -1,9 +1,6 @@ { "formatter": "make fmt", "mode": "tf_v1", - "packages": { - ".codegen/model.go.tmpl": "internal/service/{{.Name}}_tf/model.go" - }, "changelog_config": ".codegen/changelog_config.yml", "version": { "common/version.go": "version = \"$VERSION\"" diff --git a/.codegen/model.go.tmpl b/.codegen/model.go.tmpl deleted file mode 100644 index ffdd7e1ce..000000000 --- a/.codegen/model.go.tmpl +++ /dev/null @@ -1,103 +0,0 @@ -// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. -/* -These generated types are for terraform plugin framework to interact with the terraform state conveniently. - -These types follow the same structure as the types in go-sdk. -The only difference is that the primitive types are no longer using the go-native types, but with tfsdk types. -Plus the json tags get converted into tfsdk tags. -We use go-native types for lists and maps intentionally for the ease for converting these types into the go-sdk types. -*/ - -package {{.Name}}_tf - -import ( - {{range .ImportedPackages}} - "github.com/databricks/databricks-sdk-go/service/{{.}}"{{end}} - "github.com/databricks/databricks-sdk-go/service/{{.Name}}" - "io" - "github.com/databricks/databricks-sdk-go/marshal" - "github.com/hashicorp/terraform-plugin-framework/types" -) -{{range .Types}} -{{- if or .Fields .IsEmpty}} -{{.Comment "// " 80}} -type {{.PascalName}} struct { - {{- range .Fields}} - {{.Comment " // " 80}} - {{- $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 (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}} -} - -func (newState *{{.PascalName}}) SyncEffectiveFieldsDuringRead(existingState {{.PascalName}}) { - {{- range .Fields -}} - {{- 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}} - {{- if .Entity.IsInt64}}{{$type = "Int64"}}{{end}} - {{- if .Entity.IsFloat64}}{{$type = "Float64"}}{{end}} - {{- if .Entity.IsInt}}{{$type = "Int64"}}{{end}} - {{- if .Entity.Enum}}{{$type = "String"}}{{end}} - newState.Effective{{.PascalName}} = existingState.Effective{{.PascalName}} - if existingState.Effective{{.PascalName}}.Value{{$type}}() == newState.{{.PascalName}}.Value{{$type}}() { - newState.{{.PascalName}} = existingState.{{.PascalName}} - } - {{- end}} - {{- end}} -} - -{{end}} -{{end}} - -{{- define "field" -}} -{{if .effective}}Effective{{end}}{{.field.PascalName}} {{template "type" .field.Entity}} `{{template "field-tag" . }}` -{{- end -}} - -{{- define "field-tag" -}} - {{- $annotations := "" -}} - {{- if or .field.Entity.IsComputed .effective -}} - {{- $annotations = (printf "%scomputed,optional," $annotations) -}} - {{- else -}} - {{- if not .field.Required -}} - {{- $annotations = (printf "%soptional," $annotations) -}} - {{- end -}} - {{- if .field.Entity.IsObject -}} - {{- $annotations = (printf "%sobject," $annotations) -}} - {{- end -}} - {{- end -}} - {{- if gt (len $annotations) 0 -}} - {{- $annotations = (printf "%s" (trimSuffix "," $annotations)) -}} - {{- end -}} - {{if .field.IsJson}}tfsdk:"{{if and (ne .field.Entity.Terraform nil) (ne .field.Entity.Terraform.Alias "") }}{{.field.Entity.Terraform.Alias}}{{else}}{{if .effective}}effective_{{end}}{{.field.Name}}{{end}}" tf:"{{$annotations}}"{{else}}tfsdk:"-"{{end -}} -{{- end -}} - -{{- define "type" -}} - {{- if not . }}any /* ERROR */ - {{- else if .IsExternal }}{{.Package.Name}}.{{.PascalName}} - {{- else if .IsAny}}any - {{- else if .IsEmpty}}[]{{.PascalName}} - {{- else if .IsString}}types.String - {{- else if .IsBool}}types.Bool - {{- else if .IsInt64}}types.Int64 - {{- else if .IsFloat64}}types.Float64 - {{- else if .IsInt}}types.Int64 - {{- else if .IsByteStream}}io.ReadCloser - {{- else if .ArrayValue }} - {{- if .ArrayValue.IsObject }}{{template "type" .ArrayValue}} - {{- else }}[]{{template "type" .ArrayValue}} - {{- end }} - {{- else if .MapValue }}map[string]{{template "type" .MapValue}} - {{- else if .IsObject }}[]{{.PascalName}} - {{- else if .Enum }}types.String - {{- else}}any /* MISSING TYPE */ - {{- end -}} -{{- end -}}