package resources_gen import ( "context" "terraform-provider-nubes/internal/core" "terraform-provider-nubes/internal/resources_core" "github.com/hashicorp/terraform-plugin-framework/path" "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/stringdefault" "github.com/hashicorp/terraform-plugin-framework/types" ) // Code generated by tools/gen_v2. DO NOT EDIT. // Service: vmpostgre // Service ID: 32 var _ resource.Resource = &VmpostgreResource{} var _ resource.ResourceWithModifyPlan = &VmpostgreResource{} var _ resource.ResourceWithImportState = &VmpostgreResource{} type VmpostgreResource struct { client *core.UniversalClient } type VmpostgreModel struct { ID types.String `tfsdk:"id"` ResourceName types.String `tfsdk:"resource_name"` OperationTimeout types.String `tfsdk:"operation_timeout"` NsxtUid types.String `tfsdk:"nsxt_uid"` ResourceRealm types.String `tfsdk:"resource_realm"` UserDb types.String `tfsdk:"user_db"` UserLogin types.String `tfsdk:"user_login"` UserPassword types.String `tfsdk:"user_password"` VdcUid types.String `tfsdk:"vdc_uid"` VmUid types.String `tfsdk:"vm_uid"` SuspendOnDestroy types.Bool `tfsdk:"suspend_on_destroy"` AdoptExistingOnCreate types.Bool `tfsdk:"adopt_existing_on_create"` StateParams types.Map `tfsdk:"state_params"` StateOut types.Map `tfsdk:"state_out"` StateParamsFlat types.Map `tfsdk:"state_params_flat"` StateOutFlat types.Map `tfsdk:"state_out_flat"` VaultSecrets types.Map `tfsdk:"vault_secrets"` VaultUrl types.String `tfsdk:"vault_url"` VaultUserPath types.String `tfsdk:"vault_user_path"` VaultFields types.List `tfsdk:"vault_fields"` } func NewVmpostgreResource() resource.Resource { return &VmpostgreResource{} } func (r *VmpostgreResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { resp.TypeName = req.ProviderTypeName + "_vmpostgre" } func (r *VmpostgreResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { attrs := map[string]schema.Attribute{ "id": schema.StringAttribute{Computed: true}, "resource_name": schema.StringAttribute{Required: true}, "operation_timeout": schema.StringAttribute{Optional: true}, "nsxt_uid": schema.StringAttribute{Required: true, MarkdownDescription: "InstanceUid nsxt. Nsxt должен быть создан
Не изменяется после создания."}, "resource_realm": schema.StringAttribute{Required: true, MarkdownDescription: "Ресурсная платформа Не изменяется после создания."}, "user_db": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("servicedb"), MarkdownDescription: "Наименование Базы данных
Не изменяется после создания."}, "user_login": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("serviceuser"), MarkdownDescription: "Пользователь базы данных
Не изменяется после создания."}, "user_password": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("fj29gm48fm!d374mc9"), MarkdownDescription: "Пароль от доступа к Базе данных
Не изменяется после создания."}, "vdc_uid": schema.StringAttribute{Required: true, MarkdownDescription: "InstanceUid vdc. Vdc должен быть создан
Не изменяется после создания."}, "vm_uid": schema.StringAttribute{Required: true, MarkdownDescription: "InstanceUid ВМ. ВМ должна быть создана
Не изменяется после создания."}, "suspend_on_destroy": schema.BoolAttribute{Optional: true, Computed: true, Default: booldefault.StaticBool(false)}, "adopt_existing_on_create": schema.BoolAttribute{Optional: true, Computed: true, Default: booldefault.StaticBool(false)}, "state_params": schema.MapAttribute{Computed: true, ElementType: types.StringType}, "state_out": schema.MapAttribute{Computed: true, ElementType: types.StringType}, "state_params_flat": schema.MapAttribute{Computed: true, ElementType: types.StringType}, "state_out_flat": schema.MapAttribute{Computed: true, ElementType: types.StringType}, "vault_secrets": schema.MapAttribute{Computed: true, ElementType: types.StringType, Sensitive: true}, "vault_url": schema.StringAttribute{Computed: true}, "vault_user_path": schema.StringAttribute{Computed: true}, "vault_fields": schema.ListAttribute{Computed: true, ElementType: types.StringType}, } resp.Schema = schema.Schema{Attributes: attrs} } func (r *VmpostgreResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { if r.client == nil { return } var config *VmpostgreModel resp.Diagnostics.Append(req.Config.Get(ctx, &config)...) if resp.Diagnostics.HasError() { return } if config == nil { return } var state *VmpostgreModel resp.Diagnostics.Append(req.State.Get(ctx, &state)...) if resp.Diagnostics.HasError() { return } if req.State.Raw.IsNull() && req.Plan.Raw.IsNull() { return } if state != nil && !state.ID.IsNull() && !state.ID.IsUnknown() { var plan VmpostgreModel resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) if resp.Diagnostics.HasError() { return } planChanged := false if !plan.NsxtUid.IsNull() && !plan.NsxtUid.IsUnknown() { resolvedNsxtUid, err := r.client.ResolveRefSvcParamValue(ctx, 22, plan.NsxtUid.ValueString()) if err != nil { resp.Diagnostics.AddWarning("Failed to resolve nsxt_uid", err.Error()) } else if resolvedNsxtUid != "" && resolvedNsxtUid != plan.NsxtUid.ValueString() { plan.NsxtUid = types.StringValue(resolvedNsxtUid) planChanged = true } } if !plan.VdcUid.IsNull() && !plan.VdcUid.IsUnknown() { resolvedVdcUid, err := r.client.ResolveRefSvcParamValue(ctx, 21, plan.VdcUid.ValueString()) if err != nil { resp.Diagnostics.AddWarning("Failed to resolve vdc_uid", err.Error()) } else if resolvedVdcUid != "" && resolvedVdcUid != plan.VdcUid.ValueString() { plan.VdcUid = types.StringValue(resolvedVdcUid) planChanged = true } } if !plan.VmUid.IsNull() && !plan.VmUid.IsUnknown() { resolvedVmUid, err := r.client.ResolveRefSvcParamValue(ctx, 23, plan.VmUid.ValueString()) if err != nil { resp.Diagnostics.AddWarning("Failed to resolve vm_uid", err.Error()) } else if resolvedVmUid != "" && resolvedVmUid != plan.VmUid.ValueString() { plan.VmUid = types.StringValue(resolvedVmUid) planChanged = true } } if planChanged { resp.Diagnostics.Append(resp.Plan.Set(ctx, &plan)...) if resp.Diagnostics.HasError() { return } } if !plan.ResourceName.IsNull() && !plan.ResourceName.IsUnknown() && !state.ResourceName.IsNull() && !state.ResourceName.IsUnknown() { if plan.ResourceName.ValueString() != state.ResourceName.ValueString() { resp.Diagnostics.AddError("Нельзя изменить resource_name", "Параметр resource_name задается при создании и не может быть изменен. Создайте новый ресурс с другим именем.") return } } if !plan.NsxtUid.IsNull() && !plan.NsxtUid.IsUnknown() && !state.NsxtUid.IsNull() && !state.NsxtUid.IsUnknown() { if plan.NsxtUid.ValueString() != state.NsxtUid.ValueString() { resp.Diagnostics.AddError("Нельзя изменить nsxt_uid", "Параметр задается при создании и не может быть изменен.") return } } if !plan.ResourceRealm.IsNull() && !plan.ResourceRealm.IsUnknown() && !state.ResourceRealm.IsNull() && !state.ResourceRealm.IsUnknown() { if plan.ResourceRealm.ValueString() != state.ResourceRealm.ValueString() { resp.Diagnostics.AddError("Нельзя изменить resource_realm", "Параметр задается при создании и не может быть изменен.") return } } if !plan.UserDb.IsNull() && !plan.UserDb.IsUnknown() && !state.UserDb.IsNull() && !state.UserDb.IsUnknown() { if plan.UserDb.ValueString() != state.UserDb.ValueString() { resp.Diagnostics.AddError("Нельзя изменить user_db", "Параметр задается при создании и не может быть изменен.") return } } if !plan.UserLogin.IsNull() && !plan.UserLogin.IsUnknown() && !state.UserLogin.IsNull() && !state.UserLogin.IsUnknown() { if plan.UserLogin.ValueString() != state.UserLogin.ValueString() { resp.Diagnostics.AddError("Нельзя изменить user_login", "Параметр задается при создании и не может быть изменен.") return } } if !plan.UserPassword.IsNull() && !plan.UserPassword.IsUnknown() && !state.UserPassword.IsNull() && !state.UserPassword.IsUnknown() { if plan.UserPassword.ValueString() != state.UserPassword.ValueString() { resp.Diagnostics.AddError("Нельзя изменить user_password", "Параметр задается при создании и не может быть изменен.") return } } if !plan.VdcUid.IsNull() && !plan.VdcUid.IsUnknown() && !state.VdcUid.IsNull() && !state.VdcUid.IsUnknown() { if plan.VdcUid.ValueString() != state.VdcUid.ValueString() { resp.Diagnostics.AddError("Нельзя изменить vdc_uid", "Параметр задается при создании и не может быть изменен.") return } } if !plan.VmUid.IsNull() && !plan.VmUid.IsUnknown() && !state.VmUid.IsNull() && !state.VmUid.IsUnknown() { if plan.VmUid.ValueString() != state.VmUid.ValueString() { resp.Diagnostics.AddError("Нельзя изменить vm_uid", "Параметр задается при создании и не может быть изменен.") return } } return } if config.NsxtUid.IsNull() || config.NsxtUid.IsUnknown() { resp.Diagnostics.AddError("Missing required attribute", "nsxt_uid is required.") return } if config.ResourceRealm.IsNull() || config.ResourceRealm.IsUnknown() { resp.Diagnostics.AddError("Missing required attribute", "resource_realm is required.") return } if config.VdcUid.IsNull() || config.VdcUid.IsUnknown() { resp.Diagnostics.AddError("Missing required attribute", "vdc_uid is required.") return } if config.VmUid.IsNull() || config.VmUid.IsUnknown() { resp.Diagnostics.AddError("Missing required attribute", "vm_uid is required.") return } if config.ResourceName.IsNull() || config.ResourceName.IsUnknown() { return } adoptExistingOnCreate := false if !config.AdoptExistingOnCreate.IsNull() && !config.AdoptExistingOnCreate.IsUnknown() { adoptExistingOnCreate = config.AdoptExistingOnCreate.ValueBool() } if !config.NsxtUid.IsNull() && !config.NsxtUid.IsUnknown() { resolvedNsxtUid, err := r.client.ResolveRefSvcParamValue(ctx, 22, config.NsxtUid.ValueString()) if err != nil { resp.Diagnostics.AddWarning("Failed to resolve nsxt_uid", err.Error()) } else if resolvedNsxtUid != "" && resolvedNsxtUid != config.NsxtUid.ValueString() { config.NsxtUid = types.StringValue(resolvedNsxtUid) } } if !config.VdcUid.IsNull() && !config.VdcUid.IsUnknown() { resolvedVdcUid, err := r.client.ResolveRefSvcParamValue(ctx, 21, config.VdcUid.ValueString()) if err != nil { resp.Diagnostics.AddWarning("Failed to resolve vdc_uid", err.Error()) } else if resolvedVdcUid != "" && resolvedVdcUid != config.VdcUid.ValueString() { config.VdcUid = types.StringValue(resolvedVdcUid) } } if !config.VmUid.IsNull() && !config.VmUid.IsUnknown() { resolvedVmUid, err := r.client.ResolveRefSvcParamValue(ctx, 23, config.VmUid.ValueString()) if err != nil { resp.Diagnostics.AddWarning("Failed to resolve vm_uid", err.Error()) } else if resolvedVmUid != "" && resolvedVmUid != config.VmUid.ValueString() { config.VmUid = types.StringValue(resolvedVmUid) } } params := map[int]string{ 43: resources_core.FormatString(config.VdcUid), 44: resources_core.FormatString(config.NsxtUid), 45: resources_core.FormatString(config.VmUid), 46: resources_core.FormatString(config.UserDb), 47: resources_core.FormatString(config.UserLogin), 48: resources_core.FormatString(config.UserPassword), 859: resources_core.FormatString(config.ResourceRealm), } desiredDomain := "" domainServiceIDs := []int{2, 50, 81, 82, 88, 89, 94, 95, 96, 97, 98, 99, 119, 149} resp.Diagnostics.Append(resources_core.PlanExistingResourceDiagnosticsWithParamsAndDomainAndServices(ctx, r.client, 32, config.ResourceName.ValueString(), adoptExistingOnCreate, params, desiredDomain, domainServiceIDs)...) } func (r *VmpostgreResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { var data VmpostgreModel resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) if resp.Diagnostics.HasError() { return } if data.NsxtUid.IsNull() || data.NsxtUid.IsUnknown() { resp.Diagnostics.AddError("Missing required attribute", "nsxt_uid is required.") return } if data.ResourceRealm.IsNull() || data.ResourceRealm.IsUnknown() { resp.Diagnostics.AddError("Missing required attribute", "resource_realm is required.") return } if data.VdcUid.IsNull() || data.VdcUid.IsUnknown() { resp.Diagnostics.AddError("Missing required attribute", "vdc_uid is required.") return } if data.VmUid.IsNull() || data.VmUid.IsUnknown() { resp.Diagnostics.AddError("Missing required attribute", "vm_uid is required.") return } if !data.NsxtUid.IsNull() && !data.NsxtUid.IsUnknown() { resolvedNsxtUid, err := r.client.ResolveRefSvcParamValue(ctx, 22, data.NsxtUid.ValueString()) if err != nil { resp.Diagnostics.AddError("Ошибка клиента", err.Error()) return } if resolvedNsxtUid != "" && resolvedNsxtUid != data.NsxtUid.ValueString() { data.NsxtUid = types.StringValue(resolvedNsxtUid) } } if !data.VdcUid.IsNull() && !data.VdcUid.IsUnknown() { resolvedVdcUid, err := r.client.ResolveRefSvcParamValue(ctx, 21, data.VdcUid.ValueString()) if err != nil { resp.Diagnostics.AddError("Ошибка клиента", err.Error()) return } if resolvedVdcUid != "" && resolvedVdcUid != data.VdcUid.ValueString() { data.VdcUid = types.StringValue(resolvedVdcUid) } } if !data.VmUid.IsNull() && !data.VmUid.IsUnknown() { resolvedVmUid, err := r.client.ResolveRefSvcParamValue(ctx, 23, data.VmUid.ValueString()) if err != nil { resp.Diagnostics.AddError("Ошибка клиента", err.Error()) return } if resolvedVmUid != "" && resolvedVmUid != data.VmUid.ValueString() { data.VmUid = types.StringValue(resolvedVmUid) } } resourceName := data.ResourceName.ValueString() desiredDomain := "" domainServiceIDs := []int{2, 50, 81, 82, 88, 89, 94, 95, 96, 97, 98, 99, 119, 149} resp.Diagnostics.Append(resources_core.CreateExistingResourceDiagnosticsWithDomainAndServices(ctx, r.client, 32, resourceName, data.AdoptExistingOnCreate.ValueBool(), desiredDomain, domainServiceIDs)...) params := map[int]string{ 43: resources_core.FormatString(data.VdcUid), 44: resources_core.FormatString(data.NsxtUid), 45: resources_core.FormatString(data.VmUid), 46: resources_core.FormatString(data.UserDb), 47: resources_core.FormatString(data.UserLogin), 48: resources_core.FormatString(data.UserPassword), 859: resources_core.FormatString(data.ResourceRealm), } operationTimeout := "" if !data.OperationTimeout.IsNull() && !data.OperationTimeout.IsUnknown() { operationTimeout = data.OperationTimeout.ValueString() } id, err := resources_core.CreateResourceWithTimeout(ctx, r.client, 32, resourceName, data.AdoptExistingOnCreate.ValueBool(), params, operationTimeout) if err != nil { resp.Diagnostics.AddError("Ошибка клиента", err.Error()) return } data.ID = types.StringValue(id) state, diags := resources_core.RefreshResourceState(ctx, r.client, id, 32, data, []resources_core.StateField{ {Code: "state_params"}, {Code: "state_out"}, {Code: "state_params_flat"}, {Code: "state_out_flat"}, {Code: "vault_secrets"}, {Code: "vault_url"}, {Code: "vault_user_path"}, {Code: "vault_fields"}, }, []resources_core.InputField{ {Code: "nsxtUid", Field: "NsxtUid", Type: "string"}, {Code: "resourceRealm", Field: "ResourceRealm", Type: "string"}, {Code: "userDb", Field: "UserDb", Type: "string"}, {Code: "userLogin", Field: "UserLogin", Type: "string"}, {Code: "userPassword", Field: "UserPassword", Type: "string"}, {Code: "vdcUid", Field: "VdcUid", Type: "string"}, {Code: "vmUid", Field: "VmUid", Type: "string"}, }) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { return } if !state.NsxtUid.IsNull() && !state.NsxtUid.IsUnknown() { resolvedNsxtUid, err := r.client.ResolveRefSvcParamValue(ctx, 22, state.NsxtUid.ValueString()) if err != nil { resp.Diagnostics.AddWarning("Failed to resolve nsxt_uid", err.Error()) } else if resolvedNsxtUid != "" && resolvedNsxtUid != state.NsxtUid.ValueString() { state.NsxtUid = types.StringValue(resolvedNsxtUid) } } if !state.VdcUid.IsNull() && !state.VdcUid.IsUnknown() { resolvedVdcUid, err := r.client.ResolveRefSvcParamValue(ctx, 21, state.VdcUid.ValueString()) if err != nil { resp.Diagnostics.AddWarning("Failed to resolve vdc_uid", err.Error()) } else if resolvedVdcUid != "" && resolvedVdcUid != state.VdcUid.ValueString() { state.VdcUid = types.StringValue(resolvedVdcUid) } } if !state.VmUid.IsNull() && !state.VmUid.IsUnknown() { resolvedVmUid, err := r.client.ResolveRefSvcParamValue(ctx, 23, state.VmUid.ValueString()) if err != nil { resp.Diagnostics.AddWarning("Failed to resolve vm_uid", err.Error()) } else if resolvedVmUid != "" && resolvedVmUid != state.VmUid.ValueString() { state.VmUid = types.StringValue(resolvedVmUid) } } resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) } func (r *VmpostgreResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { var state VmpostgreModel resp.Diagnostics.Append(req.State.Get(ctx, &state)...) if resp.Diagnostics.HasError() { return } if state.ID.IsNull() || state.ID.IsUnknown() { return } if r.client != nil { remove, err := resources_core.ShouldRemoveFromState(ctx, r.client, state.ID.ValueString()) if err != nil { resp.Diagnostics.AddError("Ошибка клиента", err.Error()) return } if remove { resp.State.RemoveResource(ctx) return } } newState, diags := resources_core.RefreshResourceState(ctx, r.client, state.ID.ValueString(), 32, state, []resources_core.StateField{ {Code: "state_params"}, {Code: "state_out"}, {Code: "state_params_flat"}, {Code: "state_out_flat"}, {Code: "vault_secrets"}, {Code: "vault_url"}, {Code: "vault_user_path"}, {Code: "vault_fields"}, }, []resources_core.InputField{ {Code: "nsxtUid", Field: "NsxtUid", Type: "string"}, {Code: "resourceRealm", Field: "ResourceRealm", Type: "string"}, {Code: "userDb", Field: "UserDb", Type: "string"}, {Code: "userLogin", Field: "UserLogin", Type: "string"}, {Code: "userPassword", Field: "UserPassword", Type: "string"}, {Code: "vdcUid", Field: "VdcUid", Type: "string"}, {Code: "vmUid", Field: "VmUid", Type: "string"}, }) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { return } if !newState.NsxtUid.IsNull() && !newState.NsxtUid.IsUnknown() { resolvedNsxtUid, err := r.client.ResolveRefSvcParamValue(ctx, 22, newState.NsxtUid.ValueString()) if err != nil { resp.Diagnostics.AddWarning("Failed to resolve nsxt_uid", err.Error()) } else if resolvedNsxtUid != "" && resolvedNsxtUid != newState.NsxtUid.ValueString() { newState.NsxtUid = types.StringValue(resolvedNsxtUid) } } if !newState.VdcUid.IsNull() && !newState.VdcUid.IsUnknown() { resolvedVdcUid, err := r.client.ResolveRefSvcParamValue(ctx, 21, newState.VdcUid.ValueString()) if err != nil { resp.Diagnostics.AddWarning("Failed to resolve vdc_uid", err.Error()) } else if resolvedVdcUid != "" && resolvedVdcUid != newState.VdcUid.ValueString() { newState.VdcUid = types.StringValue(resolvedVdcUid) } } if !newState.VmUid.IsNull() && !newState.VmUid.IsUnknown() { resolvedVmUid, err := r.client.ResolveRefSvcParamValue(ctx, 23, newState.VmUid.ValueString()) if err != nil { resp.Diagnostics.AddWarning("Failed to resolve vm_uid", err.Error()) } else if resolvedVmUid != "" && resolvedVmUid != newState.VmUid.ValueString() { newState.VmUid = types.StringValue(resolvedVmUid) } } resp.Diagnostics.Append(resp.State.Set(ctx, &newState)...) } func (r *VmpostgreResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { var plan VmpostgreModel var state VmpostgreModel resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) resp.Diagnostics.Append(req.State.Get(ctx, &state)...) if resp.Diagnostics.HasError() { return } instanceID := state.ID if instanceID.IsNull() || instanceID.IsUnknown() { instanceID = plan.ID } if instanceID.IsNull() || instanceID.IsUnknown() { resp.Diagnostics.AddError("Ошибка клиента", "отсутствует идентификатор экземпляра для modify") return } hasServiceParamChanges := false if !hasServiceParamChanges { plan.ID = instanceID plan.StateParams = state.StateParams plan.StateOut = state.StateOut plan.StateParamsFlat = state.StateParamsFlat plan.StateOutFlat = state.StateOutFlat plan.VaultSecrets = state.VaultSecrets plan.VaultUrl = state.VaultUrl plan.VaultUserPath = state.VaultUserPath plan.VaultFields = state.VaultFields resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...) return } params := map[int]string{} operationTimeout := "" if !plan.OperationTimeout.IsNull() && !plan.OperationTimeout.IsUnknown() { operationTimeout = plan.OperationTimeout.ValueString() } if err := resources_core.UpdateResourceWithTimeout(ctx, r.client, instanceID.ValueString(), params, operationTimeout); err != nil { resp.Diagnostics.AddError("Ошибка клиента", err.Error()) return } plan.ID = instanceID state, diags := resources_core.RefreshResourceState(ctx, r.client, instanceID.ValueString(), 32, plan, []resources_core.StateField{ {Code: "state_params"}, {Code: "state_out"}, {Code: "state_params_flat"}, {Code: "state_out_flat"}, {Code: "vault_secrets"}, {Code: "vault_url"}, {Code: "vault_user_path"}, {Code: "vault_fields"}, }, []resources_core.InputField{ {Code: "nsxtUid", Field: "NsxtUid", Type: "string"}, {Code: "resourceRealm", Field: "ResourceRealm", Type: "string"}, {Code: "userDb", Field: "UserDb", Type: "string"}, {Code: "userLogin", Field: "UserLogin", Type: "string"}, {Code: "userPassword", Field: "UserPassword", Type: "string"}, {Code: "vdcUid", Field: "VdcUid", Type: "string"}, {Code: "vmUid", Field: "VmUid", Type: "string"}, }) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { return } if !state.NsxtUid.IsNull() && !state.NsxtUid.IsUnknown() { resolvedNsxtUid, err := r.client.ResolveRefSvcParamValue(ctx, 22, state.NsxtUid.ValueString()) if err != nil { resp.Diagnostics.AddWarning("Failed to resolve nsxt_uid", err.Error()) } else if resolvedNsxtUid != "" && resolvedNsxtUid != state.NsxtUid.ValueString() { state.NsxtUid = types.StringValue(resolvedNsxtUid) } } if !state.VdcUid.IsNull() && !state.VdcUid.IsUnknown() { resolvedVdcUid, err := r.client.ResolveRefSvcParamValue(ctx, 21, state.VdcUid.ValueString()) if err != nil { resp.Diagnostics.AddWarning("Failed to resolve vdc_uid", err.Error()) } else if resolvedVdcUid != "" && resolvedVdcUid != state.VdcUid.ValueString() { state.VdcUid = types.StringValue(resolvedVdcUid) } } if !state.VmUid.IsNull() && !state.VmUid.IsUnknown() { resolvedVmUid, err := r.client.ResolveRefSvcParamValue(ctx, 23, state.VmUid.ValueString()) if err != nil { resp.Diagnostics.AddWarning("Failed to resolve vm_uid", err.Error()) } else if resolvedVmUid != "" && resolvedVmUid != state.VmUid.ValueString() { state.VmUid = types.StringValue(resolvedVmUid) } } resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) } func (r *VmpostgreResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { var state VmpostgreModel resp.Diagnostics.Append(req.State.Get(ctx, &state)...) if resp.Diagnostics.HasError() { return } if state.ID.IsNull() || state.ID.IsUnknown() { return } deleteMode := "delete" operationTimeout := "" if !state.OperationTimeout.IsNull() && !state.OperationTimeout.IsUnknown() { operationTimeout = state.OperationTimeout.ValueString() } if err := resources_core.DeleteResourceWithTimeout(ctx, r.client, state.ID.ValueString(), deleteMode, operationTimeout); err != nil { resp.Diagnostics.AddError("Ошибка клиента", err.Error()) return } } func (r *VmpostgreResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) } func (r *VmpostgreResource) 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 }