resource-generator: SubParams → nested SingleNestedAttribute/ListNestedAttribute + bump 5.0.73
This commit is contained in:
@@ -38,6 +38,17 @@ type {{ToCamel .Name}}Resource struct {
|
||||
client *core.UniversalClient
|
||||
}
|
||||
|
||||
{{- range .SchemaParams }}
|
||||
{{- if .IsNested }}
|
||||
// {{NestedModelName $.Name .Code}} — вложенная модель для map-fixed параметра {{.Code}}.
|
||||
type {{NestedModelName $.Name .Code}} struct {
|
||||
{{- range .SubParams }}
|
||||
{{ToCamel .Code}} {{ParamType .}} ` + "`" + `tfsdk:"{{ToSnake .Code}}" json:"{{.Code}}"` + "`" + `
|
||||
{{- end }}
|
||||
}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
type {{ToCamel .Name}}Model struct {
|
||||
ID types.String ` + "`" + `tfsdk:"id"` + "`" + `
|
||||
ResourceName types.String ` + "`" + `tfsdk:"resource_name"` + "`" + `
|
||||
@@ -50,8 +61,12 @@ type {{ToCamel .Name}}Model struct {
|
||||
GitRevision types.String ` + "`" + `tfsdk:"git_revision"` + "`" + `
|
||||
{{- end }}
|
||||
{{- range .SchemaParams }}
|
||||
{{- if .IsNested }}
|
||||
{{ToCamel .Code}} {{NestedTfType . $.Name}} ` + "`" + `tfsdk:"{{ToSnake .Code}}"` + "`" + `
|
||||
{{- else }}
|
||||
{{ToCamel .Code}} {{ParamType .}} ` + "`" + `tfsdk:"{{ToSnake .Code}}"` + "`" + `
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
SuspendOnDestroy types.Bool ` + "`" + `tfsdk:"suspend_on_destroy"` + "`" + `
|
||||
AdoptExistingOnCreate types.Bool ` + "`" + `tfsdk:"adopt_existing_on_create"` + "`" + `
|
||||
{{- range .OutputParams }}
|
||||
@@ -74,6 +89,16 @@ func (r *{{ToCamel .Name}}Resource) Schema(ctx context.Context, req resource.Sch
|
||||
"operation_timeout": schema.StringAttribute{Optional: true},
|
||||
"log_level": schema.StringAttribute{Optional: true, MarkdownDescription: "Operation stages log level: none (default), info, debug. Overrides provider-level log_level."},
|
||||
{{- range .SchemaParams }}
|
||||
{{- if .IsNested }}
|
||||
"{{ToSnake .Code}}": {{NestedSchemaBlock .}}
|
||||
{{- range .SubParams }}
|
||||
"{{ToSnake .Code}}": schema.{{SubSchemaType .}}Attribute{
|
||||
{{- if .Default }}Optional: true, Computed: true, Default: {{SubDefaultExpr .}},{{else if .Required}}Required: true,{{else}}Optional: true,{{end}}
|
||||
{{- if ne (ParamDescription .) "" }}MarkdownDescription: {{ParamDescription .}},{{end}}
|
||||
},
|
||||
{{- end }}
|
||||
{{NestedSchemaEnd .}}
|
||||
{{- else }}
|
||||
"{{ToSnake .Code}}": schema.{{if eq (ParamType .) "types.Bool"}}Bool{{else if eq (ParamType .) "types.Int64"}}Int64{{else}}String{{end}}Attribute{
|
||||
{{- if and .Required (eq (ParamDefaultExpr .) "") (eq .RefSvcId 0) }}Required: true,{{else}}Optional: true,{{end}}
|
||||
{{- if ne (ParamDefaultExpr .) "" }}Computed: true, Default: {{ParamDefaultExpr .}},{{- else if or .IsJson (gt .RefSvcId 0) }}Computed: true,{{- end }}
|
||||
@@ -82,6 +107,7 @@ func (r *{{ToCamel .Name}}Resource) Schema(ctx context.Context, req resource.Sch
|
||||
{{- if .IsJson }}PlanModifiers: []planmodifier.String{resources_core.JsonNormalize()},{{- end }}
|
||||
},
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- if .HasRedeploy }}
|
||||
// --- Redeploy support (ARCHITECTURE.md) ---
|
||||
// При изменении git_revision вызывается redeploy вместо modify.
|
||||
@@ -204,8 +230,12 @@ func (r *{{ToCamel .Name}}Resource) ModifyPlan(ctx context.Context, req resource
|
||||
{{- end }}
|
||||
params := map[int]string{
|
||||
{{- range .CreateParams }}
|
||||
{{- if .IsNested }}
|
||||
{{.ID}}: {{NestedJSONExpr . "config"}},
|
||||
{{- else }}
|
||||
{{.ID}}: {{ParamFormat . (printf "config.%s" (ToCamel .Code))}},
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
}
|
||||
desiredDomain := ""
|
||||
{{- if .HasDomainParam }}
|
||||
@@ -290,8 +320,12 @@ func (r *{{ToCamel .Name}}Resource) Create(ctx context.Context, req resource.Cre
|
||||
|
||||
params := map[int]string{
|
||||
{{- range .CreateParams }}
|
||||
{{- if .IsNested }}
|
||||
{{.ID}}: {{NestedJSONExpr . "data"}},
|
||||
{{- else }}
|
||||
{{.ID}}: {{ParamFormat . (printf "data.%s" (ToCamel .Code))}},
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
}
|
||||
|
||||
operationTimeout := ""
|
||||
@@ -506,8 +540,12 @@ 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 }}
|
||||
{{.ID}}: {{ParamFormat . (printf "plan.%s" (ToCamel .Code))}},
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
}
|
||||
if err := resources_core.UpdateResourceWithTimeout(ctx, r.client, instanceID.ValueString(), params, operationTimeout); err != nil {
|
||||
resp.Diagnostics.AddError("Ошибка клиента", err.Error())
|
||||
|
||||
Reference in New Issue
Block a user