fix: nil-guard for nested map-fixed params in generated code
This commit is contained in:
@@ -235,13 +235,18 @@ func (r *{{ToCamel .Name}}Resource) ModifyPlan(ctx context.Context, req resource
|
||||
{{- end }}
|
||||
params := map[int]string{
|
||||
{{- range .CreateParams }}
|
||||
{{- if (IsNested .) }}
|
||||
{{.ID}}: {{NestedJSONExpr . "config"}},
|
||||
{{- else }}
|
||||
{{- if not (IsNested .) }}
|
||||
{{.ID}}: {{ParamFormat . (printf "config.%s" (ToCamel .Code))}},
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
}
|
||||
{{- range .CreateParams }}
|
||||
{{- if (IsNested .) }}
|
||||
if config.{{ToCamel .Code}} != nil {
|
||||
params[{{.ID}}] = {{NestedJSONExpr . "config"}}
|
||||
}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
desiredDomain := ""
|
||||
{{- if .HasDomainParam }}
|
||||
if !config.Domain.IsNull() && !config.Domain.IsUnknown() {
|
||||
@@ -325,13 +330,18 @@ func (r *{{ToCamel .Name}}Resource) Create(ctx context.Context, req resource.Cre
|
||||
|
||||
params := map[int]string{
|
||||
{{- range .CreateParams }}
|
||||
{{- if (IsNested .) }}
|
||||
{{.ID}}: {{NestedJSONExpr . "data"}},
|
||||
{{- else }}
|
||||
{{- if not (IsNested .) }}
|
||||
{{.ID}}: {{ParamFormat . (printf "data.%s" (ToCamel .Code))}},
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
}
|
||||
{{- range .CreateParams }}
|
||||
{{- if (IsNested .) }}
|
||||
if data.{{ToCamel .Code}} != nil {
|
||||
params[{{.ID}}] = {{NestedJSONExpr . "data"}}
|
||||
}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
operationTimeout := ""
|
||||
if !data.OperationTimeout.IsNull() && !data.OperationTimeout.IsUnknown() {
|
||||
@@ -547,13 +557,18 @@ func (r *{{ToCamel .Name}}Resource) Update(ctx context.Context, req resource.Upd
|
||||
{{- end }}
|
||||
params := map[int]string{
|
||||
{{- range .ModifyParams }}
|
||||
{{- if (IsNested .) }}
|
||||
{{.ID}}: {{NestedJSONExpr . "plan"}},
|
||||
{{- else }}
|
||||
{{- if not (IsNested .) }}
|
||||
{{.ID}}: {{ParamFormat . (printf "plan.%s" (ToCamel .Code))}},
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
}
|
||||
{{- range .ModifyParams }}
|
||||
{{- if (IsNested .) }}
|
||||
if plan.{{ToCamel .Code}} != nil {
|
||||
params[{{.ID}}] = {{NestedJSONExpr . "plan"}}
|
||||
}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
if err := resources_core.UpdateResourceWithTimeout(ctx, r.client, instanceID.ValueString(), params, operationTimeout); err != nil {
|
||||
resp.Diagnostics.AddError("Ошибка клиента", err.Error())
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user