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,512 @@
|
||||
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/resource/schema/stringdefault"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
// Code generated by tools/gen_v2. DO NOT EDIT.
|
||||
// Service: vc_vdc
|
||||
// Service ID: 21
|
||||
|
||||
var _ resource.Resource = &VcVdcResource{}
|
||||
var _ resource.ResourceWithModifyPlan = &VcVdcResource{}
|
||||
var _ resource.ResourceWithImportState = &VcVdcResource{}
|
||||
|
||||
type VcVdcResource struct {
|
||||
client *core.UniversalClient
|
||||
}
|
||||
|
||||
type VcVdcModel struct {
|
||||
ID types.String `tfsdk:"id"`
|
||||
ResourceName types.String `tfsdk:"resource_name"`
|
||||
OperationTimeout types.String `tfsdk:"operation_timeout"`
|
||||
LogLevel types.String `tfsdk:"log_level"`
|
||||
CpuAllocated types.Int64 `tfsdk:"cpu_allocated"`
|
||||
CpuGuaranteed types.Int64 `tfsdk:"cpu_guaranteed"`
|
||||
MemAllocated types.Int64 `tfsdk:"mem_allocated"`
|
||||
NetworkProvider types.String `tfsdk:"network_provider"`
|
||||
OrganizationUid types.String `tfsdk:"organization_uid"`
|
||||
ProviderVdc types.String `tfsdk:"provider_vdc"`
|
||||
StorageConfig types.String `tfsdk:"storage_config"`
|
||||
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 NewVcVdcResource() resource.Resource {
|
||||
return &VcVdcResource{}
|
||||
}
|
||||
|
||||
func (r *VcVdcResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_vc_vdc"
|
||||
}
|
||||
|
||||
func (r *VcVdcResource) 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."},
|
||||
"cpu_allocated": schema.Int64Attribute{Optional: true, Computed: true, Default: int64default.StaticInt64(10), MarkdownDescription: "шт"},
|
||||
"cpu_guaranteed": schema.Int64Attribute{Optional: true, Computed: true, Default: int64default.StaticInt64(20), MarkdownDescription: "% резервирования Не изменяется после создания."},
|
||||
"mem_allocated": schema.Int64Attribute{Optional: true, Computed: true, Default: int64default.StaticInt64(20), MarkdownDescription: "gb"},
|
||||
"network_provider": schema.StringAttribute{Required: true, MarkdownDescription: "Не изменяется после создания."},
|
||||
"organization_uid": schema.StringAttribute{Required: true, MarkdownDescription: "Для создания VDC предварительно необходимо создать организацию через услугу `Организация в Cloud Director` Не изменяется после создания."},
|
||||
"provider_vdc": schema.StringAttribute{Required: true, MarkdownDescription: "Приписка `2.8` - Скорость vCPU - 2800MHz<br/>И так далее...<br/> Не изменяется после создания."},
|
||||
"storage_config": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("[{}]"), MarkdownDescription: "Первая политика в списке указывается как "По умолчанию""},
|
||||
"suspend_on_destroy": schema.BoolAttribute{Optional: true, Computed: true, Default: booldefault.StaticBool(true)},
|
||||
"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 *VcVdcResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) {
|
||||
if r.client == nil {
|
||||
return
|
||||
}
|
||||
|
||||
var config *VcVdcModel
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &config)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
if config == nil {
|
||||
return
|
||||
}
|
||||
|
||||
var state *VcVdcModel
|
||||
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 VcVdcModel
|
||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
planChanged := false
|
||||
if !plan.OrganizationUid.IsNull() && !plan.OrganizationUid.IsUnknown() {
|
||||
resolvedOrganizationUid, err := r.client.ResolveRefSvcParamValue(ctx, 19, plan.OrganizationUid.ValueString())
|
||||
if err != nil {
|
||||
resp.Diagnostics.AddWarning("Failed to resolve organization_uid", err.Error())
|
||||
} else if resolvedOrganizationUid != "" && resolvedOrganizationUid != plan.OrganizationUid.ValueString() {
|
||||
plan.OrganizationUid = types.StringValue(resolvedOrganizationUid)
|
||||
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.CpuGuaranteed.IsNull() && !plan.CpuGuaranteed.IsUnknown() && !state.CpuGuaranteed.IsNull() && !state.CpuGuaranteed.IsUnknown() {
|
||||
if plan.CpuGuaranteed.ValueInt64() != state.CpuGuaranteed.ValueInt64() {
|
||||
resp.Diagnostics.AddError("Нельзя изменить cpu_guaranteed", "Параметр задается при создании и не может быть изменен.")
|
||||
return
|
||||
}
|
||||
}
|
||||
if !plan.NetworkProvider.IsNull() && !plan.NetworkProvider.IsUnknown() && !state.NetworkProvider.IsNull() && !state.NetworkProvider.IsUnknown() {
|
||||
if plan.NetworkProvider.ValueString() != state.NetworkProvider.ValueString() {
|
||||
resp.Diagnostics.AddError("Нельзя изменить network_provider", "Параметр задается при создании и не может быть изменен.")
|
||||
return
|
||||
}
|
||||
}
|
||||
if !plan.OrganizationUid.IsNull() && !plan.OrganizationUid.IsUnknown() && !state.OrganizationUid.IsNull() && !state.OrganizationUid.IsUnknown() {
|
||||
if plan.OrganizationUid.ValueString() != state.OrganizationUid.ValueString() {
|
||||
resp.Diagnostics.AddError("Нельзя изменить organization_uid", "Параметр задается при создании и не может быть изменен.")
|
||||
return
|
||||
}
|
||||
}
|
||||
if !plan.ProviderVdc.IsNull() && !plan.ProviderVdc.IsUnknown() && !state.ProviderVdc.IsNull() && !state.ProviderVdc.IsUnknown() {
|
||||
if plan.ProviderVdc.ValueString() != state.ProviderVdc.ValueString() {
|
||||
resp.Diagnostics.AddError("Нельзя изменить provider_vdc", "Параметр задается при создании и не может быть изменен.")
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
if config.NetworkProvider.IsNull() || config.NetworkProvider.IsUnknown() {
|
||||
resp.Diagnostics.AddError("Missing required attribute", "network_provider is required.")
|
||||
return
|
||||
}
|
||||
if config.OrganizationUid.IsNull() || config.OrganizationUid.IsUnknown() {
|
||||
resp.Diagnostics.AddError("Missing required attribute", "organization_uid is required.")
|
||||
return
|
||||
}
|
||||
if config.ProviderVdc.IsNull() || config.ProviderVdc.IsUnknown() {
|
||||
resp.Diagnostics.AddError("Missing required attribute", "provider_vdc 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.OrganizationUid.IsNull() && !config.OrganizationUid.IsUnknown() {
|
||||
resolvedOrganizationUid, err := r.client.ResolveRefSvcParamValue(ctx, 19, config.OrganizationUid.ValueString())
|
||||
if err != nil {
|
||||
resp.Diagnostics.AddWarning("Failed to resolve organization_uid", err.Error())
|
||||
} else if resolvedOrganizationUid != "" && resolvedOrganizationUid != config.OrganizationUid.ValueString() {
|
||||
config.OrganizationUid = types.StringValue(resolvedOrganizationUid)
|
||||
}
|
||||
}
|
||||
params := map[int]string{
|
||||
30: resources_core.FormatString(config.OrganizationUid),
|
||||
335: resources_core.FormatString(config.ProviderVdc),
|
||||
361: resources_core.FormatString(config.StorageConfig),
|
||||
397: resources_core.FormatInt64(config.CpuGuaranteed),
|
||||
557: resources_core.FormatInt64(config.CpuAllocated),
|
||||
558: resources_core.FormatInt64(config.MemAllocated),
|
||||
746: resources_core.FormatString(config.NetworkProvider),
|
||||
}
|
||||
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, 21, config.ResourceName.ValueString(), adoptExistingOnCreate, params, desiredDomain, domainServiceIDs)...)
|
||||
}
|
||||
|
||||
func (r *VcVdcResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
|
||||
var data VcVdcModel
|
||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
if data.NetworkProvider.IsNull() || data.NetworkProvider.IsUnknown() {
|
||||
resp.Diagnostics.AddError("Missing required attribute", "network_provider is required.")
|
||||
return
|
||||
}
|
||||
if data.OrganizationUid.IsNull() || data.OrganizationUid.IsUnknown() {
|
||||
resp.Diagnostics.AddError("Missing required attribute", "organization_uid is required.")
|
||||
return
|
||||
}
|
||||
if data.ProviderVdc.IsNull() || data.ProviderVdc.IsUnknown() {
|
||||
resp.Diagnostics.AddError("Missing required attribute", "provider_vdc is required.")
|
||||
return
|
||||
}
|
||||
if !data.OrganizationUid.IsNull() && !data.OrganizationUid.IsUnknown() {
|
||||
resolvedOrganizationUid, err := r.client.ResolveRefSvcParamValue(ctx, 19, data.OrganizationUid.ValueString())
|
||||
if err != nil {
|
||||
resp.Diagnostics.AddError("Ошибка клиента", err.Error())
|
||||
return
|
||||
}
|
||||
if resolvedOrganizationUid != "" && resolvedOrganizationUid != data.OrganizationUid.ValueString() {
|
||||
data.OrganizationUid = types.StringValue(resolvedOrganizationUid)
|
||||
}
|
||||
}
|
||||
|
||||
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, 21, resourceName, data.AdoptExistingOnCreate.ValueBool(), desiredDomain, domainServiceIDs)...)
|
||||
|
||||
params := map[int]string{
|
||||
30: resources_core.FormatString(data.OrganizationUid),
|
||||
335: resources_core.FormatString(data.ProviderVdc),
|
||||
361: resources_core.FormatString(data.StorageConfig),
|
||||
397: resources_core.FormatInt64(data.CpuGuaranteed),
|
||||
557: resources_core.FormatInt64(data.CpuAllocated),
|
||||
558: resources_core.FormatInt64(data.MemAllocated),
|
||||
746: resources_core.FormatString(data.NetworkProvider),
|
||||
}
|
||||
|
||||
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, 21, 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, 21, 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: "cpuAllocated", Field: "CpuAllocated", Type: "int64"},
|
||||
{Code: "cpuGuaranteed", Field: "CpuGuaranteed", Type: "int64"},
|
||||
{Code: "memAllocated", Field: "MemAllocated", Type: "int64"},
|
||||
{Code: "networkProvider", Field: "NetworkProvider", Type: "string"},
|
||||
{Code: "organizationUid", Field: "OrganizationUid", Type: "string"},
|
||||
{Code: "providerVdc", Field: "ProviderVdc", Type: "string"},
|
||||
{Code: "storageConfig", Field: "StorageConfig", Type: "string"},
|
||||
})
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
if !state.OrganizationUid.IsNull() && !state.OrganizationUid.IsUnknown() {
|
||||
resolvedOrganizationUid, err := r.client.ResolveRefSvcParamValue(ctx, 19, state.OrganizationUid.ValueString())
|
||||
if err != nil {
|
||||
resp.Diagnostics.AddWarning("Failed to resolve organization_uid", err.Error())
|
||||
} else if resolvedOrganizationUid != "" && resolvedOrganizationUid != state.OrganizationUid.ValueString() {
|
||||
state.OrganizationUid = types.StringValue(resolvedOrganizationUid)
|
||||
}
|
||||
}
|
||||
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
}
|
||||
|
||||
func (r *VcVdcResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
|
||||
var state VcVdcModel
|
||||
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(), 21, 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: "cpuAllocated", Field: "CpuAllocated", Type: "int64"},
|
||||
{Code: "cpuGuaranteed", Field: "CpuGuaranteed", Type: "int64"},
|
||||
{Code: "memAllocated", Field: "MemAllocated", Type: "int64"},
|
||||
{Code: "networkProvider", Field: "NetworkProvider", Type: "string"},
|
||||
{Code: "organizationUid", Field: "OrganizationUid", Type: "string"},
|
||||
{Code: "providerVdc", Field: "ProviderVdc", Type: "string"},
|
||||
{Code: "storageConfig", Field: "StorageConfig", Type: "string"},
|
||||
})
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
if !newState.OrganizationUid.IsNull() && !newState.OrganizationUid.IsUnknown() {
|
||||
resolvedOrganizationUid, err := r.client.ResolveRefSvcParamValue(ctx, 19, newState.OrganizationUid.ValueString())
|
||||
if err != nil {
|
||||
resp.Diagnostics.AddWarning("Failed to resolve organization_uid", err.Error())
|
||||
} else if resolvedOrganizationUid != "" && resolvedOrganizationUid != newState.OrganizationUid.ValueString() {
|
||||
newState.OrganizationUid = types.StringValue(resolvedOrganizationUid)
|
||||
}
|
||||
}
|
||||
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &newState)...)
|
||||
}
|
||||
|
||||
func (r *VcVdcResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
|
||||
var plan VcVdcModel
|
||||
var state VcVdcModel
|
||||
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 {
|
||||
if plan.CpuAllocated.IsNull() != state.CpuAllocated.IsNull() || plan.CpuAllocated.IsUnknown() != state.CpuAllocated.IsUnknown() {
|
||||
hasServiceParamChanges = true
|
||||
} else if !plan.CpuAllocated.IsNull() && !plan.CpuAllocated.IsUnknown() && !state.CpuAllocated.IsNull() && !state.CpuAllocated.IsUnknown() {
|
||||
if plan.CpuAllocated.ValueInt64() != state.CpuAllocated.ValueInt64() {
|
||||
hasServiceParamChanges = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if !hasServiceParamChanges {
|
||||
if plan.MemAllocated.IsNull() != state.MemAllocated.IsNull() || plan.MemAllocated.IsUnknown() != state.MemAllocated.IsUnknown() {
|
||||
hasServiceParamChanges = true
|
||||
} else if !plan.MemAllocated.IsNull() && !plan.MemAllocated.IsUnknown() && !state.MemAllocated.IsNull() && !state.MemAllocated.IsUnknown() {
|
||||
if plan.MemAllocated.ValueInt64() != state.MemAllocated.ValueInt64() {
|
||||
hasServiceParamChanges = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if !hasServiceParamChanges {
|
||||
if plan.StorageConfig.IsNull() != state.StorageConfig.IsNull() || plan.StorageConfig.IsUnknown() != state.StorageConfig.IsUnknown() {
|
||||
hasServiceParamChanges = true
|
||||
} else if !plan.StorageConfig.IsNull() && !plan.StorageConfig.IsUnknown() && !state.StorageConfig.IsNull() && !state.StorageConfig.IsUnknown() {
|
||||
if plan.StorageConfig.ValueString() != state.StorageConfig.ValueString() {
|
||||
hasServiceParamChanges = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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{
|
||||
560: resources_core.FormatInt64(plan.CpuAllocated),
|
||||
561: resources_core.FormatInt64(plan.MemAllocated),
|
||||
562: resources_core.FormatString(plan.StorageConfig),
|
||||
}
|
||||
|
||||
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(), 21, 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: "cpuAllocated", Field: "CpuAllocated", Type: "int64"},
|
||||
{Code: "cpuGuaranteed", Field: "CpuGuaranteed", Type: "int64"},
|
||||
{Code: "memAllocated", Field: "MemAllocated", Type: "int64"},
|
||||
{Code: "networkProvider", Field: "NetworkProvider", Type: "string"},
|
||||
{Code: "organizationUid", Field: "OrganizationUid", Type: "string"},
|
||||
{Code: "providerVdc", Field: "ProviderVdc", Type: "string"},
|
||||
{Code: "storageConfig", Field: "StorageConfig", Type: "string"},
|
||||
})
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
if !state.OrganizationUid.IsNull() && !state.OrganizationUid.IsUnknown() {
|
||||
resolvedOrganizationUid, err := r.client.ResolveRefSvcParamValue(ctx, 19, state.OrganizationUid.ValueString())
|
||||
if err != nil {
|
||||
resp.Diagnostics.AddWarning("Failed to resolve organization_uid", err.Error())
|
||||
} else if resolvedOrganizationUid != "" && resolvedOrganizationUid != state.OrganizationUid.ValueString() {
|
||||
state.OrganizationUid = types.StringValue(resolvedOrganizationUid)
|
||||
}
|
||||
}
|
||||
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
}
|
||||
|
||||
func (r *VcVdcResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
|
||||
var state VcVdcModel
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
if state.ID.IsNull() || state.ID.IsUnknown() {
|
||||
return
|
||||
}
|
||||
deleteMode := "state_only"
|
||||
if !state.SuspendOnDestroy.IsNull() && !state.SuspendOnDestroy.IsUnknown() && state.SuspendOnDestroy.ValueBool() {
|
||||
deleteMode = "suspend"
|
||||
}
|
||||
|
||||
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 *VcVdcResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
|
||||
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
|
||||
}
|
||||
|
||||
func (r *VcVdcResource) 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