diff --git a/extensionimpl/attribute.go b/extensionimpl/attribute.go index 89ddbd1..0bdeb43 100644 --- a/extensionimpl/attribute.go +++ b/extensionimpl/attribute.go @@ -67,7 +67,7 @@ func (a *attribute) DefaultValue() string { } func (a *attribute) NeedsDefaultValue() bool { - return !a.IsPointer() && a.Optional() + return !a.IsPointer() && !a.TypeValue().IsList() && !a.TypeValue().IsMap() && !a.TypeValue().IsNestedSingleObject() } func (a *attribute) Computed() bool { diff --git a/gocode/tmpls/data_source.tmpl b/gocode/tmpls/data_source.tmpl index fe33de8..0015c6b 100644 --- a/gocode/tmpls/data_source.tmpl +++ b/gocode/tmpls/data_source.tmpl @@ -81,7 +81,8 @@ func (d *{{ .Block.GoName }}) ValidateConfig(ctx context.Context, req datasource } func (d *{{ .Block.GoName }}) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { - data, diagnostics := gotf.GetModel[{{ .Block.ModelGoName }}](ctx, req.Config.Raw, req.Config.Get) + data := &{{ .Block.ModelGoName }}{} + diagnostics := gotf.GetModel(ctx, req.Config.Raw, data, req.Config.Get) if diagnostics.HasError() { resp.Diagnostics.Append(diagnostics...) return diff --git a/gocode/tmpls/proto_tf.tmpl b/gocode/tmpls/proto_tf.tmpl index c5b3381..6c437c6 100644 --- a/gocode/tmpls/proto_tf.tmpl +++ b/gocode/tmpls/proto_tf.tmpl @@ -103,7 +103,7 @@ func (x *{{ .Message.GoIdent.GoName }}) ResourceSchema() map[string]rschema.Attr } {{- end }} -func (x {{ .Message.GoIdent.GoName }}) AttributeDefaultValues(ctx context.Context) map[string]tftypes.Value { +func (x *{{ .Message.GoIdent.GoName }}) AttributeDefaultValues(ctx context.Context) map[string]tftypes.Value { attributes := map[string]tftypes.Value{ {{- range .Attributes }} {{- if .NeedsDefaultValue }} diff --git a/gocode/tmpls/provider.tmpl b/gocode/tmpls/provider.tmpl index f1a1960..f159c18 100644 --- a/gocode/tmpls/provider.tmpl +++ b/gocode/tmpls/provider.tmpl @@ -59,7 +59,8 @@ func (p *{{ .Provider.GoName }}Provider) Configure(ctx context.Context, req prov return } {{- if .Provider.HasServiceClient }} - data, diagnostics := gotf.GetModel[{{ .Provider.ModelGoName }}](ctx, req.Config.Raw, req.Config.Get) + data := &{{ .Provider.ModelGoName }}{} + diagnostics := gotf.GetModel(ctx, req.Config.Raw, data, req.Config.Get) if diagnostics.HasError() { resp.Diagnostics.Append(diagnostics...) return diff --git a/gocode/tmpls/resource.tmpl b/gocode/tmpls/resource.tmpl index 90cbdbd..cb13202 100644 --- a/gocode/tmpls/resource.tmpl +++ b/gocode/tmpls/resource.tmpl @@ -105,7 +105,8 @@ func (r *{{ .Block.GoName }}Resource) UpgradeState(ctx context.Context) map[int6 } func (r *{{ .Block.GoName }}Resource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { - data, diagnostics := gotf.GetModel[{{ .Block.ModelGoName }}](ctx, req.State.Raw, req.State.Get) + data := &{{ .Block.ModelGoName }}{} + diagnostics := gotf.GetModel(ctx, req.State.Raw, data, req.State.Get) if diagnostics.HasError() { resp.Diagnostics.Append(diagnostics...) return @@ -120,7 +121,8 @@ func (r *{{ .Block.GoName }}Resource) Read(ctx context.Context, req resource.Rea } func (r *{{ .Block.GoName }}Resource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { - data, diagnostics := gotf.GetModel[{{ .Block.ModelGoName }}](ctx, req.Config.Raw, req.Config.Get) + data := &{{ .Block.ModelGoName }}{} + diagnostics := gotf.GetModel(ctx, req.Config.Raw, data, req.Config.Get) if diagnostics.HasError() { resp.Diagnostics.Append(diagnostics...) return @@ -135,7 +137,8 @@ func (r *{{ .Block.GoName }}Resource) Create(ctx context.Context, req resource.C } func (r *{{ .Block.GoName }}Resource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { - data, diagnostics := gotf.GetModel[{{ .Block.ModelGoName }}](ctx, req.Config.Raw, req.Config.Get) + data := &{{ .Block.ModelGoName }}{} + diagnostics := gotf.GetModel(ctx, req.Config.Raw, data, req.Config.Get) if diagnostics.HasError() { resp.Diagnostics.Append(diagnostics...) return @@ -150,7 +153,8 @@ func (r *{{ .Block.GoName }}Resource) Update(ctx context.Context, req resource.U } func (r *{{ .Block.GoName }}Resource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { - data, diagnostics := gotf.GetModel[{{ .Block.ModelGoName }}](ctx, req.State.Raw, req.State.Get) + data := &{{ .Block.ModelGoName }}{} + diagnostics := gotf.GetModel(ctx, req.State.Raw, data, req.State.Get) if diagnostics.HasError() { resp.Diagnostics.Append(diagnostics...) return