refactor: restructure project — separate tools, config, generated, provider
TOOLS/ — generators + scripts + config + ARCHITECTURE.md ├── yaml-generator/ (code) ├── resource-generator/ (code) ├── docs-generator/ (code) ├── scripts/ (← devops/*.sh) ├── config/ (← devops/profiles/ + devops/config/) │ ├── test/ profile.env, services_list.txt, operation_timeouts.json │ ├── prod/ │ └── dev/ └── ARCHITECTURE.md (← devops/ARCHITECTURE.md) generated/ — pipeline output only (gitignored) ├── test/resources_yaml/, go/, docs/, provider_build/ ├── prod/ └── dev/ provider/ — code only, no generated files resources_yaml/ — DELETED (generated) internal/resources_gen/ — DELETED (generated) devops/ — removed (replaced by TOOLS/scripts + TOOLS/config + generated/) Generators now fail if NUBES_*_DIR not set (no defaults to provider/). Provider requires pipeline to populate resources_gen/ before build.
This commit is contained in:
@@ -0,0 +1,447 @@
|
||||
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/int64default"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
// Code generated by tools/gen_v2. DO NOT EDIT.
|
||||
// Service: redis
|
||||
// Service ID: 91
|
||||
|
||||
var _ resource.Resource = &RedisResource{}
|
||||
var _ resource.ResourceWithModifyPlan = &RedisResource{}
|
||||
var _ resource.ResourceWithImportState = &RedisResource{}
|
||||
|
||||
type RedisResource struct {
|
||||
client *core.UniversalClient
|
||||
}
|
||||
|
||||
type RedisModel struct {
|
||||
ID types.String `tfsdk:"id"`
|
||||
ResourceName types.String `tfsdk:"resource_name"`
|
||||
OperationTimeout types.String `tfsdk:"operation_timeout"`
|
||||
LogLevel types.String `tfsdk:"log_level"`
|
||||
IpSpaceNameMaster types.String `tfsdk:"ip_space_name_master"`
|
||||
IpSpaceNameSlave types.String `tfsdk:"ip_space_name_slave"`
|
||||
NeedExternalAddressMaster types.Bool `tfsdk:"need_external_address_master"`
|
||||
NeedExternalAddressSlave types.Bool `tfsdk:"need_external_address_slave"`
|
||||
ResourceCPU types.Int64 `tfsdk:"resource_c_p_u"`
|
||||
ResourceDisk types.Int64 `tfsdk:"resource_disk"`
|
||||
ResourceInstances types.Int64 `tfsdk:"resource_instances"`
|
||||
ResourceMemory types.Int64 `tfsdk:"resource_memory"`
|
||||
ResourceRealm types.String `tfsdk:"resource_realm"`
|
||||
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 NewRedisResource() resource.Resource {
|
||||
return &RedisResource{}
|
||||
}
|
||||
|
||||
func (r *RedisResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_redis"
|
||||
}
|
||||
|
||||
func (r *RedisResource) 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},
|
||||
"log_level": schema.StringAttribute{Optional: true, MarkdownDescription: "Operation stages log level: none (default), info, debug. Overrides provider-level log_level."},
|
||||
"ip_space_name_master": schema.StringAttribute{Optional: true, MarkdownDescription: "Имя ipSpace для публикации VIP master. Не может быть пустым, если включен needExternalAddressMaster Не изменяется после создания."},
|
||||
"ip_space_name_slave": schema.StringAttribute{Optional: true, MarkdownDescription: "Имя ipSpace для публикации VIP slave. Не может быть пустым, если включен needExternalAddressSlave Не изменяется после создания."},
|
||||
"need_external_address_master": schema.BoolAttribute{Optional: true, Computed: true, Default: booldefault.StaticBool(false), MarkdownDescription: "Выделяет внешний IP для доступа к master Не изменяется после создания."},
|
||||
"need_external_address_slave": schema.BoolAttribute{Optional: true, Computed: true, Default: booldefault.StaticBool(false), MarkdownDescription: "Выделяет внешний IP для доступа к slave. Будет работать если slave в целом есть Не изменяется после создания."},
|
||||
"resource_c_p_u": schema.Int64Attribute{Optional: true, Computed: true, Default: int64default.StaticInt64(1000), MarkdownDescription: "Квота ядра пода (Указывается в mili) Не изменяется после создания."},
|
||||
"resource_disk": schema.Int64Attribute{Optional: true, Computed: true, Default: int64default.StaticInt64(30), MarkdownDescription: "Квота диска (Указывается в GIGAbytes) Не изменяется после создания."},
|
||||
"resource_instances": schema.Int64Attribute{Optional: true, Computed: true, Default: int64default.StaticInt64(1), MarkdownDescription: "Количество узлов Не изменяется после создания."},
|
||||
"resource_memory": schema.Int64Attribute{Optional: true, Computed: true, Default: int64default.StaticInt64(1024), MarkdownDescription: "Квота памяти пода (Указывается в Megabytes) Не изменяется после создания."},
|
||||
"resource_realm": schema.StringAttribute{Required: true, MarkdownDescription: "Платформа для развертывания Не изменяется после создания."},
|
||||
"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 *RedisResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) {
|
||||
if r.client == nil {
|
||||
return
|
||||
}
|
||||
|
||||
var config *RedisModel
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &config)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
if config == nil {
|
||||
return
|
||||
}
|
||||
|
||||
var state *RedisModel
|
||||
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 RedisModel
|
||||
resp.Diagnostics.Append(req.Plan.Get(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.IpSpaceNameMaster.IsNull() && !plan.IpSpaceNameMaster.IsUnknown() && !state.IpSpaceNameMaster.IsNull() && !state.IpSpaceNameMaster.IsUnknown() {
|
||||
if plan.IpSpaceNameMaster.ValueString() != state.IpSpaceNameMaster.ValueString() {
|
||||
resp.Diagnostics.AddError("Нельзя изменить ip_space_name_master", "Параметр задается при создании и не может быть изменен.")
|
||||
return
|
||||
}
|
||||
}
|
||||
if !plan.IpSpaceNameSlave.IsNull() && !plan.IpSpaceNameSlave.IsUnknown() && !state.IpSpaceNameSlave.IsNull() && !state.IpSpaceNameSlave.IsUnknown() {
|
||||
if plan.IpSpaceNameSlave.ValueString() != state.IpSpaceNameSlave.ValueString() {
|
||||
resp.Diagnostics.AddError("Нельзя изменить ip_space_name_slave", "Параметр задается при создании и не может быть изменен.")
|
||||
return
|
||||
}
|
||||
}
|
||||
if !plan.NeedExternalAddressMaster.IsNull() && !plan.NeedExternalAddressMaster.IsUnknown() && !state.NeedExternalAddressMaster.IsNull() && !state.NeedExternalAddressMaster.IsUnknown() {
|
||||
if plan.NeedExternalAddressMaster.ValueBool() != state.NeedExternalAddressMaster.ValueBool() {
|
||||
resp.Diagnostics.AddError("Нельзя изменить need_external_address_master", "Параметр задается при создании и не может быть изменен.")
|
||||
return
|
||||
}
|
||||
}
|
||||
if !plan.NeedExternalAddressSlave.IsNull() && !plan.NeedExternalAddressSlave.IsUnknown() && !state.NeedExternalAddressSlave.IsNull() && !state.NeedExternalAddressSlave.IsUnknown() {
|
||||
if plan.NeedExternalAddressSlave.ValueBool() != state.NeedExternalAddressSlave.ValueBool() {
|
||||
resp.Diagnostics.AddError("Нельзя изменить need_external_address_slave", "Параметр задается при создании и не может быть изменен.")
|
||||
return
|
||||
}
|
||||
}
|
||||
if !plan.ResourceCPU.IsNull() && !plan.ResourceCPU.IsUnknown() && !state.ResourceCPU.IsNull() && !state.ResourceCPU.IsUnknown() {
|
||||
if plan.ResourceCPU.ValueInt64() != state.ResourceCPU.ValueInt64() {
|
||||
resp.Diagnostics.AddError("Нельзя изменить resource_c_p_u", "Параметр задается при создании и не может быть изменен.")
|
||||
return
|
||||
}
|
||||
}
|
||||
if !plan.ResourceDisk.IsNull() && !plan.ResourceDisk.IsUnknown() && !state.ResourceDisk.IsNull() && !state.ResourceDisk.IsUnknown() {
|
||||
if plan.ResourceDisk.ValueInt64() != state.ResourceDisk.ValueInt64() {
|
||||
resp.Diagnostics.AddError("Нельзя изменить resource_disk", "Параметр задается при создании и не может быть изменен.")
|
||||
return
|
||||
}
|
||||
}
|
||||
if !plan.ResourceInstances.IsNull() && !plan.ResourceInstances.IsUnknown() && !state.ResourceInstances.IsNull() && !state.ResourceInstances.IsUnknown() {
|
||||
if plan.ResourceInstances.ValueInt64() != state.ResourceInstances.ValueInt64() {
|
||||
resp.Diagnostics.AddError("Нельзя изменить resource_instances", "Параметр задается при создании и не может быть изменен.")
|
||||
return
|
||||
}
|
||||
}
|
||||
if !plan.ResourceMemory.IsNull() && !plan.ResourceMemory.IsUnknown() && !state.ResourceMemory.IsNull() && !state.ResourceMemory.IsUnknown() {
|
||||
if plan.ResourceMemory.ValueInt64() != state.ResourceMemory.ValueInt64() {
|
||||
resp.Diagnostics.AddError("Нельзя изменить resource_memory", "Параметр задается при создании и не может быть изменен.")
|
||||
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
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
if config.ResourceRealm.IsNull() || config.ResourceRealm.IsUnknown() {
|
||||
resp.Diagnostics.AddError("Missing required attribute", "resource_realm is required.")
|
||||
return
|
||||
}
|
||||
|
||||
if config.ResourceName.IsNull() || config.ResourceName.IsUnknown() {
|
||||
return
|
||||
}
|
||||
adoptExistingOnCreate := false
|
||||
if !config.AdoptExistingOnCreate.IsNull() && !config.AdoptExistingOnCreate.IsUnknown() {
|
||||
adoptExistingOnCreate = config.AdoptExistingOnCreate.ValueBool()
|
||||
}
|
||||
params := map[int]string{
|
||||
112: resources_core.FormatInt64(config.ResourceCPU),
|
||||
113: resources_core.FormatInt64(config.ResourceMemory),
|
||||
114: resources_core.FormatInt64(config.ResourceDisk),
|
||||
181: resources_core.FormatInt64(config.ResourceInstances),
|
||||
182: resources_core.FormatString(config.ResourceRealm),
|
||||
183: resources_core.FormatBool(config.NeedExternalAddressMaster),
|
||||
184: resources_core.FormatBool(config.NeedExternalAddressSlave),
|
||||
548: resources_core.FormatString(config.IpSpaceNameMaster),
|
||||
549: resources_core.FormatString(config.IpSpaceNameSlave),
|
||||
}
|
||||
desiredDomain := ""
|
||||
domainServiceIDs := []int{2, 50, 81, 82, 88, 89, 94, 95, 96, 97, 98, 99, 119, 149, 151, 153}
|
||||
|
||||
resp.Diagnostics.Append(resources_core.PlanExistingResourceDiagnosticsWithParamsAndDomainAndServices(ctx, r.client, 91, config.ResourceName.ValueString(), adoptExistingOnCreate, params, desiredDomain, domainServiceIDs)...)
|
||||
}
|
||||
|
||||
func (r *RedisResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
|
||||
var data RedisModel
|
||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
if data.ResourceRealm.IsNull() || data.ResourceRealm.IsUnknown() {
|
||||
resp.Diagnostics.AddError("Missing required attribute", "resource_realm is required.")
|
||||
return
|
||||
}
|
||||
|
||||
resourceName := data.ResourceName.ValueString()
|
||||
desiredDomain := ""
|
||||
domainServiceIDs := []int{2, 50, 81, 82, 88, 89, 94, 95, 96, 97, 98, 99, 119, 149, 151, 153}
|
||||
resp.Diagnostics.Append(resources_core.CreateExistingResourceDiagnosticsWithDomainAndServices(ctx, r.client, 91, resourceName, data.AdoptExistingOnCreate.ValueBool(), desiredDomain, domainServiceIDs)...)
|
||||
|
||||
params := map[int]string{
|
||||
112: resources_core.FormatInt64(data.ResourceCPU),
|
||||
113: resources_core.FormatInt64(data.ResourceMemory),
|
||||
114: resources_core.FormatInt64(data.ResourceDisk),
|
||||
181: resources_core.FormatInt64(data.ResourceInstances),
|
||||
182: resources_core.FormatString(data.ResourceRealm),
|
||||
183: resources_core.FormatBool(data.NeedExternalAddressMaster),
|
||||
184: resources_core.FormatBool(data.NeedExternalAddressSlave),
|
||||
548: resources_core.FormatString(data.IpSpaceNameMaster),
|
||||
549: resources_core.FormatString(data.IpSpaceNameSlave),
|
||||
}
|
||||
|
||||
operationTimeout := ""
|
||||
if !data.OperationTimeout.IsNull() && !data.OperationTimeout.IsUnknown() {
|
||||
operationTimeout = data.OperationTimeout.ValueString()
|
||||
}
|
||||
if !data.LogLevel.IsNull() && !data.LogLevel.IsUnknown() {
|
||||
ctx = core.CtxWithLogLevel(ctx, data.LogLevel.ValueString())
|
||||
}
|
||||
id, err := resources_core.CreateResourceWithTimeout(ctx, r.client, 91, 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, 91, 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: "ipSpaceNameMaster", Field: "IpSpaceNameMaster", Type: "string"},
|
||||
{Code: "ipSpaceNameSlave", Field: "IpSpaceNameSlave", Type: "string"},
|
||||
{Code: "needExternalAddressMaster", Field: "NeedExternalAddressMaster", Type: "bool"},
|
||||
{Code: "needExternalAddressSlave", Field: "NeedExternalAddressSlave", Type: "bool"},
|
||||
{Code: "resourceCPU", Field: "ResourceCPU", Type: "int64"},
|
||||
{Code: "resourceDisk", Field: "ResourceDisk", Type: "int64"},
|
||||
{Code: "resourceInstances", Field: "ResourceInstances", Type: "int64"},
|
||||
{Code: "resourceMemory", Field: "ResourceMemory", Type: "int64"},
|
||||
{Code: "resourceRealm", Field: "ResourceRealm", Type: "string"},
|
||||
})
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
}
|
||||
|
||||
func (r *RedisResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
|
||||
var state RedisModel
|
||||
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(), 91, 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: "ipSpaceNameMaster", Field: "IpSpaceNameMaster", Type: "string"},
|
||||
{Code: "ipSpaceNameSlave", Field: "IpSpaceNameSlave", Type: "string"},
|
||||
{Code: "needExternalAddressMaster", Field: "NeedExternalAddressMaster", Type: "bool"},
|
||||
{Code: "needExternalAddressSlave", Field: "NeedExternalAddressSlave", Type: "bool"},
|
||||
{Code: "resourceCPU", Field: "ResourceCPU", Type: "int64"},
|
||||
{Code: "resourceDisk", Field: "ResourceDisk", Type: "int64"},
|
||||
{Code: "resourceInstances", Field: "ResourceInstances", Type: "int64"},
|
||||
{Code: "resourceMemory", Field: "ResourceMemory", Type: "int64"},
|
||||
{Code: "resourceRealm", Field: "ResourceRealm", Type: "string"},
|
||||
})
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &newState)...)
|
||||
}
|
||||
|
||||
func (r *RedisResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
|
||||
var plan RedisModel
|
||||
var state RedisModel
|
||||
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 !plan.LogLevel.IsNull() && !plan.LogLevel.IsUnknown() {
|
||||
ctx = core.CtxWithLogLevel(ctx, plan.LogLevel.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(), 91, 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: "ipSpaceNameMaster", Field: "IpSpaceNameMaster", Type: "string"},
|
||||
{Code: "ipSpaceNameSlave", Field: "IpSpaceNameSlave", Type: "string"},
|
||||
{Code: "needExternalAddressMaster", Field: "NeedExternalAddressMaster", Type: "bool"},
|
||||
{Code: "needExternalAddressSlave", Field: "NeedExternalAddressSlave", Type: "bool"},
|
||||
{Code: "resourceCPU", Field: "ResourceCPU", Type: "int64"},
|
||||
{Code: "resourceDisk", Field: "ResourceDisk", Type: "int64"},
|
||||
{Code: "resourceInstances", Field: "ResourceInstances", Type: "int64"},
|
||||
{Code: "resourceMemory", Field: "ResourceMemory", Type: "int64"},
|
||||
{Code: "resourceRealm", Field: "ResourceRealm", Type: "string"},
|
||||
})
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
}
|
||||
|
||||
func (r *RedisResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
|
||||
var state RedisModel
|
||||
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 !state.LogLevel.IsNull() && !state.LogLevel.IsUnknown() {
|
||||
ctx = core.CtxWithLogLevel(ctx, state.LogLevel.ValueString())
|
||||
}
|
||||
if err := resources_core.DeleteResourceWithTimeout(ctx, r.client, state.ID.ValueString(), deleteMode, operationTimeout); err != nil {
|
||||
resp.Diagnostics.AddError("Ошибка клиента", err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (r *RedisResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
|
||||
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
|
||||
}
|
||||
|
||||
func (r *RedisResource) 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