fix: remove accidentally committed test-generated files
This commit is contained in:
@@ -1,330 +0,0 @@
|
|||||||
package resources_gen
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"terraform-provider-nubes/internal/core"
|
|
||||||
"terraform-provider-nubes/internal/resources_core"
|
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Code generated by tools/gen_v2. DO NOT EDIT.
|
|
||||||
// Service: postgres
|
|
||||||
// Subresource: backup
|
|
||||||
|
|
||||||
var _ resource.Resource = &PostgresBackupResource{}
|
|
||||||
|
|
||||||
// PostgresBackupResource manages a subresource via operations.
|
|
||||||
type PostgresBackupResource struct {
|
|
||||||
client *core.UniversalClient
|
|
||||||
}
|
|
||||||
|
|
||||||
type PostgresBackupModel struct {
|
|
||||||
ID types.String `tfsdk:"id"`
|
|
||||||
PostgresID types.String `tfsdk:"postgres_id"`
|
|
||||||
AdoptExistingOnCreate types.Bool `tfsdk:"adopt_existing_on_create"`
|
|
||||||
SkipMissingOnDelete types.Bool `tfsdk:"skip_missing_on_delete"`
|
|
||||||
OperationTimeout types.String `tfsdk:"operation_timeout"`
|
|
||||||
LogLevel types.String `tfsdk:"log_level"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewPostgresBackupResource() resource.Resource {
|
|
||||||
return &PostgresBackupResource{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *PostgresBackupResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
|
|
||||||
resp.TypeName = req.ProviderTypeName + "_postgres_backup"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *PostgresBackupResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
|
|
||||||
attrs := map[string]schema.Attribute{
|
|
||||||
"id": schema.StringAttribute{Computed: true, PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()}},
|
|
||||||
"postgres_id": schema.StringAttribute{
|
|
||||||
Required: true,
|
|
||||||
PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()},
|
|
||||||
},
|
|
||||||
"adopt_existing_on_create": schema.BoolAttribute{Optional: true, Computed: true, Default: booldefault.StaticBool(false)},
|
|
||||||
"skip_missing_on_delete": schema.BoolAttribute{Optional: true, Computed: true, Default: booldefault.StaticBool(false)},
|
|
||||||
"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."},
|
|
||||||
}
|
|
||||||
resp.Schema = schema.Schema{Attributes: attrs}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *PostgresBackupResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
|
|
||||||
var plan PostgresBackupModel
|
|
||||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
|
|
||||||
if resp.Diagnostics.HasError() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
instanceUID := strings.TrimSpace(plan.PostgresID.ValueString())
|
|
||||||
if instanceUID == "" {
|
|
||||||
resp.Diagnostics.AddError("Ошибка клиента", "отсутствует идентификатор экземпляра")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
adoptExistingOnCreate := !plan.AdoptExistingOnCreate.IsNull() && !plan.AdoptExistingOnCreate.IsUnknown() && plan.AdoptExistingOnCreate.ValueBool()
|
|
||||||
|
|
||||||
idParams := map[string]string{}
|
|
||||||
identityCodes := []string{}
|
|
||||||
listKey, idKey := resources_core.ResolveSubresourceStateKeys("backup", identityCodes)
|
|
||||||
targetValue := strings.TrimSpace(idParams[idKey])
|
|
||||||
if targetValue == "" {
|
|
||||||
for _, code := range identityCodes {
|
|
||||||
candidate := strings.TrimSpace(idParams[code])
|
|
||||||
if candidate == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
targetValue = candidate
|
|
||||||
idKey = code
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if targetValue != "" {
|
|
||||||
found, known, err := resources_core.FindSubresourceInStateOut(ctx, r.client, instanceUID, listKey, idKey, targetValue)
|
|
||||||
if err != nil {
|
|
||||||
resp.Diagnostics.AddError("Ошибка клиента", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if known && found {
|
|
||||||
if adoptExistingOnCreate {
|
|
||||||
plan.ID = types.StringValue(resources_core.BuildSubresourceID(instanceUID, "backup", idParams))
|
|
||||||
resp.Diagnostics.AddWarning("Подресурс уже существует", "Объект уже есть, выполняется усыновление: "+targetValue)
|
|
||||||
resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
resp.Diagnostics.AddError("Подресурс уже существует", "Найден объект с таким именем: "+targetValue)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
params := resources_core.CompactParams(map[string]string{})
|
|
||||||
|
|
||||||
operationTimeout := ""
|
|
||||||
if !plan.OperationTimeout.IsNull() && !plan.OperationTimeout.IsUnknown() {
|
|
||||||
operationTimeout = plan.OperationTimeout.ValueString()
|
|
||||||
}
|
|
||||||
if !plan.LogLevel.IsNull() && !plan.LogLevel.IsUnknown() {
|
|
||||||
ctx = core.CtxWithLogLevel(ctx, plan.LogLevel.ValueString())
|
|
||||||
}
|
|
||||||
createErr := resources_core.RunOperationByCodeWithTimeout(ctx, r.client, instanceUID, "create_backup", params, operationTimeout)
|
|
||||||
if createErr != nil && resources_core.IsSubresourceTransientDependencyError(createErr) {
|
|
||||||
createErr = resources_core.RunOperationByCodeWithTimeout(ctx, r.client, instanceUID, "create_backup", params, operationTimeout)
|
|
||||||
}
|
|
||||||
if createErr != nil {
|
|
||||||
if targetValue != "" {
|
|
||||||
found, known, checkErr := resources_core.FindSubresourceInStateOut(ctx, r.client, instanceUID, listKey, idKey, targetValue)
|
|
||||||
if checkErr != nil {
|
|
||||||
resp.Diagnostics.AddError("Ошибка клиента", checkErr.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if known && found {
|
|
||||||
plan.ID = types.StringValue(resources_core.BuildSubresourceID(instanceUID, "backup", idParams))
|
|
||||||
resp.Diagnostics.AddWarning("Подресурс подтверждён в state_out", "Операция create вернула ошибку, но объект найден в state_out и принят в state: "+targetValue)
|
|
||||||
resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if adoptExistingOnCreate && resources_core.IsSubresourceAlreadyExistsError(createErr) {
|
|
||||||
if targetValue != "" {
|
|
||||||
found, known, checkErr := resources_core.FindSubresourceInStateOut(ctx, r.client, instanceUID, listKey, idKey, targetValue)
|
|
||||||
if checkErr != nil {
|
|
||||||
resp.Diagnostics.AddError("Ошибка клиента", checkErr.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if known && found {
|
|
||||||
plan.ID = types.StringValue(resources_core.BuildSubresourceID(instanceUID, "backup", idParams))
|
|
||||||
resp.Diagnostics.AddWarning("Подресурс уже существует", "Операция вернула duplicate/exist, объект подтверждён в state_out, выполняется усыновление")
|
|
||||||
resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
resp.Diagnostics.AddError("Нарушена консистентность", "Операция вернула duplicate/exist, но объект не найден в state_out")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
resp.Diagnostics.AddError("Ошибка клиента", createErr.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if targetValue != "" {
|
|
||||||
found, known, err := resources_core.FindSubresourceInStateOut(ctx, r.client, instanceUID, listKey, idKey, targetValue)
|
|
||||||
if err != nil {
|
|
||||||
resp.Diagnostics.AddError("Ошибка клиента", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if known && !found {
|
|
||||||
resp.Diagnostics.AddError("Нарушена консистентность", "Операция create завершилась успешно, но объект не найден в state_out: "+targetValue)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
plan.ID = types.StringValue(resources_core.BuildSubresourceID(instanceUID, "backup", idParams))
|
|
||||||
resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *PostgresBackupResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
|
|
||||||
var state PostgresBackupModel
|
|
||||||
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
|
|
||||||
if resp.Diagnostics.HasError() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *PostgresBackupResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
|
|
||||||
var plan PostgresBackupModel
|
|
||||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
|
|
||||||
if resp.Diagnostics.HasError() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if "" == "" {
|
|
||||||
var state PostgresBackupModel
|
|
||||||
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
|
|
||||||
if resp.Diagnostics.HasError() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if plan.ID.IsNull() || plan.ID.IsUnknown() {
|
|
||||||
plan.ID = state.ID
|
|
||||||
}
|
|
||||||
resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
instanceUID := strings.TrimSpace(plan.PostgresID.ValueString())
|
|
||||||
if instanceUID == "" {
|
|
||||||
resp.Diagnostics.AddError("Ошибка клиента", "отсутствует идентификатор экземпляра")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
params := resources_core.CompactParams(map[string]string{})
|
|
||||||
|
|
||||||
idParams := map[string]string{}
|
|
||||||
|
|
||||||
operationTimeout := ""
|
|
||||||
if !plan.OperationTimeout.IsNull() && !plan.OperationTimeout.IsUnknown() {
|
|
||||||
operationTimeout = plan.OperationTimeout.ValueString()
|
|
||||||
}
|
|
||||||
if !plan.LogLevel.IsNull() && !plan.LogLevel.IsUnknown() {
|
|
||||||
ctx = core.CtxWithLogLevel(ctx, plan.LogLevel.ValueString())
|
|
||||||
}
|
|
||||||
if err := resources_core.RunOperationByCodeWithTimeout(ctx, r.client, instanceUID, "", params, operationTimeout); err != nil {
|
|
||||||
resp.Diagnostics.AddError("Ошибка клиента", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
plan.ID = types.StringValue(resources_core.BuildSubresourceID(instanceUID, "backup", idParams))
|
|
||||||
resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *PostgresBackupResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
|
|
||||||
var state PostgresBackupModel
|
|
||||||
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
|
|
||||||
if resp.Diagnostics.HasError() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if "" == "" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
instanceUID := strings.TrimSpace(state.PostgresID.ValueString())
|
|
||||||
if instanceUID == "" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
skipMissingOnDelete := !state.SkipMissingOnDelete.IsNull() && !state.SkipMissingOnDelete.IsUnknown() && state.SkipMissingOnDelete.ValueBool()
|
|
||||||
|
|
||||||
idParams := map[string]string{}
|
|
||||||
identityCodes := []string{}
|
|
||||||
listKey, idKey := resources_core.ResolveSubresourceStateKeys("backup", identityCodes)
|
|
||||||
targetValue := strings.TrimSpace(idParams[idKey])
|
|
||||||
if targetValue == "" {
|
|
||||||
for _, code := range identityCodes {
|
|
||||||
candidate := strings.TrimSpace(idParams[code])
|
|
||||||
if candidate == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
targetValue = candidate
|
|
||||||
idKey = code
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if targetValue != "" {
|
|
||||||
found, known, err := resources_core.FindSubresourceInStateOut(ctx, r.client, instanceUID, listKey, idKey, targetValue)
|
|
||||||
if err != nil {
|
|
||||||
resp.Diagnostics.AddError("Ошибка клиента", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if known && !found {
|
|
||||||
if skipMissingOnDelete {
|
|
||||||
resp.Diagnostics.AddWarning("Подресурс не найден", "Объект отсутствует и будет пропущен: "+targetValue)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
resp.Diagnostics.AddError("Подресурс не найден", "Объект отсутствует: "+targetValue)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
params := resources_core.CompactParams(map[string]string{})
|
|
||||||
|
|
||||||
operationTimeout := ""
|
|
||||||
if !state.OperationTimeout.IsNull() && !state.OperationTimeout.IsUnknown() {
|
|
||||||
operationTimeout = state.OperationTimeout.ValueString()
|
|
||||||
}
|
|
||||||
if !state.LogLevel.IsNull() && !state.LogLevel.IsUnknown() {
|
|
||||||
ctx = core.CtxWithLogLevel(ctx, state.LogLevel.ValueString())
|
|
||||||
}
|
|
||||||
if err := resources_core.RunOperationByCodeWithTimeout(ctx, r.client, instanceUID, "", params, operationTimeout); err != nil {
|
|
||||||
if resources_core.IsSubresourceMissingError(err) {
|
|
||||||
if targetValue != "" {
|
|
||||||
found, known, checkErr := resources_core.FindSubresourceInStateOut(ctx, r.client, instanceUID, listKey, idKey, targetValue)
|
|
||||||
if checkErr != nil {
|
|
||||||
resp.Diagnostics.AddError("Ошибка клиента", checkErr.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if known && found {
|
|
||||||
resp.Diagnostics.AddError("Нарушена консистентность", "Операция delete вернула not found, но объект всё ещё присутствует в state_out: "+targetValue)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if skipMissingOnDelete {
|
|
||||||
resp.Diagnostics.AddWarning("Подресурс не найден", "Операция delete вернула not found, объект отсутствует в state_out, удаление пропущено")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
resp.Diagnostics.AddError("Ошибка клиента", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if targetValue != "" {
|
|
||||||
found, known, err := resources_core.FindSubresourceInStateOut(ctx, r.client, instanceUID, listKey, idKey, targetValue)
|
|
||||||
if err != nil {
|
|
||||||
resp.Diagnostics.AddError("Ошибка клиента", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if known && found {
|
|
||||||
resp.Diagnostics.AddError("Нарушена консистентность", "Операция delete завершилась успешно, но объект всё ещё присутствует в state_out: "+targetValue)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *PostgresBackupResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
|
|
||||||
if req.ProviderData == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
client, ok := req.ProviderData.(*core.UniversalClient)
|
|
||||||
if !ok {
|
|
||||||
resp.Diagnostics.AddError("Error", "Invalid client type")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
r.client = client
|
|
||||||
}
|
|
||||||
@@ -1,136 +0,0 @@
|
|||||||
package resources_gen
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"terraform-provider-nubes/internal/core"
|
|
||||||
"terraform-provider-nubes/internal/resources_core"
|
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Code generated by tools/gen_v2. DO NOT EDIT.
|
|
||||||
// Service: postgres
|
|
||||||
// Action: reconcile
|
|
||||||
|
|
||||||
var _ resource.Resource = &PostgresReconcileResource{}
|
|
||||||
|
|
||||||
// PostgresReconcileResource triggers a one-time action.
|
|
||||||
type PostgresReconcileResource struct {
|
|
||||||
client *core.UniversalClient
|
|
||||||
}
|
|
||||||
|
|
||||||
type PostgresReconcileModel struct {
|
|
||||||
ID types.String `tfsdk:"id"`
|
|
||||||
PostgresID types.String `tfsdk:"postgres_id"`
|
|
||||||
RunID types.String `tfsdk:"run_id"`
|
|
||||||
AdoptExistingOnCreate types.Bool `tfsdk:"adopt_existing_on_create"`
|
|
||||||
OperationTimeout types.String `tfsdk:"operation_timeout"`
|
|
||||||
LogLevel types.String `tfsdk:"log_level"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewPostgresReconcileResource() resource.Resource {
|
|
||||||
return &PostgresReconcileResource{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *PostgresReconcileResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
|
|
||||||
resp.TypeName = req.ProviderTypeName + "_postgres_reconcile"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *PostgresReconcileResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
|
|
||||||
attrs := map[string]schema.Attribute{
|
|
||||||
"id": schema.StringAttribute{Computed: true},
|
|
||||||
"postgres_id": schema.StringAttribute{Required: true},
|
|
||||||
"run_id": schema.StringAttribute{Required: true},
|
|
||||||
"adopt_existing_on_create": schema.BoolAttribute{Optional: true, Computed: true, Default: booldefault.StaticBool(false)},
|
|
||||||
"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."},
|
|
||||||
}
|
|
||||||
resp.Schema = schema.Schema{Attributes: attrs}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *PostgresReconcileResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
|
|
||||||
var plan PostgresReconcileModel
|
|
||||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
|
|
||||||
if resp.Diagnostics.HasError() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
instanceUID := strings.TrimSpace(plan.PostgresID.ValueString())
|
|
||||||
runID := strings.TrimSpace(plan.RunID.ValueString())
|
|
||||||
if instanceUID == "" || runID == "" {
|
|
||||||
resp.Diagnostics.AddError("Ошибка клиента", "отсутствует идентификатор экземпляра или run_id")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
params := map[string]string{}
|
|
||||||
|
|
||||||
operationTimeout := ""
|
|
||||||
if !plan.OperationTimeout.IsNull() && !plan.OperationTimeout.IsUnknown() {
|
|
||||||
operationTimeout = plan.OperationTimeout.ValueString()
|
|
||||||
}
|
|
||||||
if !plan.LogLevel.IsNull() && !plan.LogLevel.IsUnknown() {
|
|
||||||
ctx = core.CtxWithLogLevel(ctx, plan.LogLevel.ValueString())
|
|
||||||
}
|
|
||||||
if err := resources_core.RunOperationByCodeWithTimeout(ctx, r.client, instanceUID, "reconcile", params, operationTimeout); err != nil {
|
|
||||||
resp.Diagnostics.AddError("Ошибка клиента", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
plan.ID = types.StringValue(resources_core.BuildActionID(instanceUID, "reconcile", runID))
|
|
||||||
resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *PostgresReconcileResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
|
|
||||||
var state PostgresReconcileModel
|
|
||||||
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
|
|
||||||
if resp.Diagnostics.HasError() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *PostgresReconcileResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
|
|
||||||
var plan PostgresReconcileModel
|
|
||||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
|
|
||||||
if resp.Diagnostics.HasError() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
instanceUID := strings.TrimSpace(plan.PostgresID.ValueString())
|
|
||||||
runID := strings.TrimSpace(plan.RunID.ValueString())
|
|
||||||
if instanceUID == "" || runID == "" {
|
|
||||||
resp.Diagnostics.AddError("Ошибка клиента", "отсутствует идентификатор экземпляра или run_id")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
params := map[string]string{}
|
|
||||||
|
|
||||||
if err := resources_core.RunOperationByCode(ctx, r.client, instanceUID, "reconcile", params); err != nil {
|
|
||||||
resp.Diagnostics.AddError("Ошибка клиента", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
plan.ID = types.StringValue(resources_core.BuildActionID(instanceUID, "reconcile", runID))
|
|
||||||
resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *PostgresReconcileResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
|
|
||||||
// No-op: removing the resource does not trigger a remote action.
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *PostgresReconcileResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
|
|
||||||
if req.ProviderData == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
client, ok := req.ProviderData.(*core.UniversalClient)
|
|
||||||
if !ok {
|
|
||||||
resp.Diagnostics.AddError("Error", "Invalid client type")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
r.client = client
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user