v5.0.57: regenerate all from TEST API (NOT PROD)
- 43 YAML, 94 Go, 332 docs from deck-api-test.ngcloud.ru - STANDS.md, TESTING.md, API_TOKENS.md added - Never mix PROD/TEST again
This commit is contained in:
@@ -2,7 +2,6 @@ package resources_gen
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"terraform-provider-nubes/internal/core"
|
||||
"terraform-provider-nubes/internal/resources_core"
|
||||
@@ -33,7 +32,6 @@ type OpenwhiskModel struct {
|
||||
ResourceName types.String `tfsdk:"resource_name"`
|
||||
OperationTimeout types.String `tfsdk:"operation_timeout"`
|
||||
LogLevel types.String `tfsdk:"log_level"`
|
||||
Username types.String `tfsdk:"username"`
|
||||
SuspendOnDestroy types.Bool `tfsdk:"suspend_on_destroy"`
|
||||
AdoptExistingOnCreate types.Bool `tfsdk:"adopt_existing_on_create"`
|
||||
StateParams types.Map `tfsdk:"state_params"`
|
||||
@@ -60,7 +58,6 @@ func (r *OpenwhiskResource) Schema(ctx context.Context, req resource.SchemaReque
|
||||
"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."},
|
||||
"username": schema.StringAttribute{Required: true, MarkdownDescription: "Имя пользователя Openwhisk Не изменяется после создания."},
|
||||
"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},
|
||||
@@ -111,22 +108,6 @@ func (r *OpenwhiskResource) ModifyPlan(ctx context.Context, req resource.ModifyP
|
||||
return
|
||||
}
|
||||
}
|
||||
if !plan.Username.IsNull() && !plan.Username.IsUnknown() && !state.Username.IsNull() && !state.Username.IsUnknown() {
|
||||
// FIX(uuid-case): сравниваем без учёта регистра — API возвращает UUID
|
||||
// в lowercase, пользователь мог написать upper/mixed. Это одно и то же
|
||||
// значение, менять его нельзя только если оно реально другое.
|
||||
if !strings.EqualFold(plan.Username.ValueString(), state.Username.ValueString()) {
|
||||
resp.Diagnostics.AddError("Нельзя изменить username", "Параметр задается при создании и не может быть изменен.")
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
if config.Username.IsNull() {
|
||||
resp.Diagnostics.AddError("Missing required attribute", "username is required.")
|
||||
return
|
||||
}
|
||||
if config.Username.IsUnknown() {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -137,9 +118,7 @@ func (r *OpenwhiskResource) ModifyPlan(ctx context.Context, req resource.ModifyP
|
||||
if !config.AdoptExistingOnCreate.IsNull() && !config.AdoptExistingOnCreate.IsUnknown() {
|
||||
adoptExistingOnCreate = config.AdoptExistingOnCreate.ValueBool()
|
||||
}
|
||||
params := map[int]string{
|
||||
64: resources_core.FormatString(config.Username),
|
||||
}
|
||||
params := map[int]string{}
|
||||
desiredDomain := ""
|
||||
domainServiceIDs := []int{81, 82, 88, 96, 97, 98, 99, 119, 149}
|
||||
|
||||
@@ -152,19 +131,13 @@ func (r *OpenwhiskResource) Create(ctx context.Context, req resource.CreateReque
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
if data.Username.IsNull() || data.Username.IsUnknown() {
|
||||
resp.Diagnostics.AddError("Missing required attribute", "username is required.")
|
||||
return
|
||||
}
|
||||
|
||||
resourceName := data.ResourceName.ValueString()
|
||||
desiredDomain := ""
|
||||
domainServiceIDs := []int{81, 82, 88, 96, 97, 98, 99, 119, 149}
|
||||
resp.Diagnostics.Append(resources_core.CreateExistingResourceDiagnosticsWithDomainAndServices(ctx, r.client, 100, resourceName, data.AdoptExistingOnCreate.ValueBool(), desiredDomain, domainServiceIDs)...)
|
||||
|
||||
params := map[int]string{
|
||||
64: resources_core.FormatString(data.Username),
|
||||
}
|
||||
params := map[int]string{}
|
||||
|
||||
operationTimeout := ""
|
||||
if !data.OperationTimeout.IsNull() && !data.OperationTimeout.IsUnknown() {
|
||||
@@ -189,9 +162,7 @@ func (r *OpenwhiskResource) Create(ctx context.Context, req resource.CreateReque
|
||||
{Code: "vault_url"},
|
||||
{Code: "vault_user_path"},
|
||||
{Code: "vault_fields"},
|
||||
}, []resources_core.InputField{
|
||||
{Code: "username", Field: "Username", Type: "string"},
|
||||
})
|
||||
}, []resources_core.InputField{})
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
@@ -230,9 +201,7 @@ func (r *OpenwhiskResource) Read(ctx context.Context, req resource.ReadRequest,
|
||||
{Code: "vault_url"},
|
||||
{Code: "vault_user_path"},
|
||||
{Code: "vault_fields"},
|
||||
}, []resources_core.InputField{
|
||||
{Code: "username", Field: "Username", Type: "string"},
|
||||
})
|
||||
}, []resources_core.InputField{})
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
@@ -299,9 +268,7 @@ func (r *OpenwhiskResource) Update(ctx context.Context, req resource.UpdateReque
|
||||
{Code: "vault_url"},
|
||||
{Code: "vault_user_path"},
|
||||
{Code: "vault_fields"},
|
||||
}, []resources_core.InputField{
|
||||
{Code: "username", Field: "Username", Type: "string"},
|
||||
})
|
||||
}, []resources_core.InputField{})
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
|
||||
@@ -68,9 +68,9 @@ func (r *VcVdcResource) Schema(ctx context.Context, req resource.SchemaRequest,
|
||||
"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_allocated": schema.Int64Attribute{Optional: true, Computed: true, Default: int64default.StaticInt64(80), 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"},
|
||||
"mem_allocated": schema.Int64Attribute{Optional: true, Computed: true, Default: int64default.StaticInt64(200), MarkdownDescription: "gb"},
|
||||
"network_provider": schema.StringAttribute{Required: true, MarkdownDescription: "Не изменяется после создания."},
|
||||
"organization_uid": schema.StringAttribute{Optional: true, Computed: true, MarkdownDescription: "Для создания VDC предварительно необходимо создать организацию через услугу `Организация в Cloud Director` Не изменяется после создания."},
|
||||
"provider_vdc": schema.StringAttribute{Required: true, MarkdownDescription: "Приписка `2.8` - Скорость vCPU - 2800MHz<br/>И так далее...<br/> Не изменяется после создания."},
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
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: vapp
|
||||
// Action: reconcile
|
||||
|
||||
var _ resource.Resource = &VappReconcileResource{}
|
||||
|
||||
// VappReconcileResource triggers a one-time action.
|
||||
type VappReconcileResource struct {
|
||||
client *core.UniversalClient
|
||||
}
|
||||
|
||||
type VappReconcileModel struct {
|
||||
ID types.String `tfsdk:"id"`
|
||||
VappID types.String `tfsdk:"vapp_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 NewVappReconcileResource() resource.Resource {
|
||||
return &VappReconcileResource{}
|
||||
}
|
||||
|
||||
func (r *VappReconcileResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_vapp_reconcile"
|
||||
}
|
||||
|
||||
func (r *VappReconcileResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||
attrs := map[string]schema.Attribute{
|
||||
"id": schema.StringAttribute{Computed: true},
|
||||
"vapp_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 *VappReconcileResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
|
||||
var plan VappReconcileModel
|
||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
instanceUID := strings.TrimSpace(plan.VappID.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 *VappReconcileResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
|
||||
var state VappReconcileModel
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
}
|
||||
|
||||
func (r *VappReconcileResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
|
||||
var plan VappReconcileModel
|
||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
instanceUID := strings.TrimSpace(plan.VappID.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 *VappReconcileResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
|
||||
// No-op: removing the resource does not trigger a remote action.
|
||||
}
|
||||
|
||||
func (r *VappReconcileResource) 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
|
||||
}
|
||||
@@ -10,7 +10,8 @@ import (
|
||||
"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/resource/schema/planmodifier"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
@@ -30,13 +31,7 @@ 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"`
|
||||
LogLevel types.String `tfsdk:"log_level"`
|
||||
SuspendOnDestroy types.Bool `tfsdk:"suspend_on_destroy"`
|
||||
AdoptExistingOnCreate types.Bool `tfsdk:"adopt_existing_on_create"`
|
||||
StateParams types.Map `tfsdk:"state_params"`
|
||||
@@ -59,16 +54,10 @@ func (r *VmpostgreResource) Metadata(ctx context.Context, req resource.MetadataR
|
||||
|
||||
func (r *VmpostgreResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||
attrs := map[string]schema.Attribute{
|
||||
"id": schema.StringAttribute{Computed: true},
|
||||
"id": schema.StringAttribute{Computed: true, PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()}},
|
||||
"resource_name": schema.StringAttribute{Required: true},
|
||||
"operation_timeout": schema.StringAttribute{Optional: true},
|
||||
"nsxt_uid": schema.StringAttribute{Required: true, MarkdownDescription: "InstanceUid nsxt. Nsxt должен быть создан<br/> Не изменяется после создания."},
|
||||
"resource_realm": schema.StringAttribute{Required: true, MarkdownDescription: "Ресурсная платформа Не изменяется после создания."},
|
||||
"user_db": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("servicedb"), MarkdownDescription: "Наименование Базы данных<br/> Не изменяется после создания."},
|
||||
"user_login": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("serviceuser"), MarkdownDescription: "Пользователь базы данных<br/> Не изменяется после создания."},
|
||||
"user_password": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("fj29gm48fm!d374mc9"), MarkdownDescription: "Пароль от доступа к Базе данных<br/> Не изменяется после создания."},
|
||||
"vdc_uid": schema.StringAttribute{Required: true, MarkdownDescription: "InstanceUid vdc. Vdc должен быть создан<br/> Не изменяется после создания."},
|
||||
"vm_uid": schema.StringAttribute{Required: true, MarkdownDescription: "InstanceUid ВМ. ВМ должна быть создана<br/> Не изменяется после создания."},
|
||||
"log_level": schema.StringAttribute{Optional: true, MarkdownDescription: "Operation stages log level: none (default), info, debug. Overrides provider-level log_level."},
|
||||
"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},
|
||||
@@ -113,104 +102,12 @@ func (r *VmpostgreResource) ModifyPlan(ctx context.Context, req resource.ModifyP
|
||||
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
|
||||
}
|
||||
|
||||
@@ -221,41 +118,11 @@ func (r *VmpostgreResource) ModifyPlan(ctx context.Context, req resource.ModifyP
|
||||
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),
|
||||
}
|
||||
params := map[int]string{}
|
||||
desiredDomain := ""
|
||||
domainServiceIDs := []int{81, 82, 88, 96, 97, 98, 99, 119, 149}
|
||||
|
||||
resp.Diagnostics.Append(resources_core.PlanExistingResourceDiagnosticsWithParams(ctx, r.client, 32, config.ResourceName.ValueString(), adoptExistingOnCreate, params)...)
|
||||
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) {
|
||||
@@ -264,70 +131,21 @@ func (r *VmpostgreResource) Create(ctx context.Context, req resource.CreateReque
|
||||
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()
|
||||
resp.Diagnostics.Append(resources_core.CreateExistingResourceDiagnostics(ctx, r.client, 32, resourceName, data.AdoptExistingOnCreate.ValueBool())...)
|
||||
desiredDomain := ""
|
||||
domainServiceIDs := []int{81, 82, 88, 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),
|
||||
}
|
||||
params := map[int]string{}
|
||||
|
||||
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, 32, resourceName, data.AdoptExistingOnCreate.ValueBool(), params, operationTimeout)
|
||||
if err != nil {
|
||||
resp.Diagnostics.AddError("Ошибка клиента", err.Error())
|
||||
@@ -344,43 +162,11 @@ func (r *VmpostgreResource) Create(ctx context.Context, req resource.CreateReque
|
||||
{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"},
|
||||
})
|
||||
}, []resources_core.InputField{})
|
||||
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)...)
|
||||
}
|
||||
@@ -415,43 +201,11 @@ func (r *VmpostgreResource) Read(ctx context.Context, req resource.ReadRequest,
|
||||
{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"},
|
||||
})
|
||||
}, []resources_core.InputField{})
|
||||
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)...)
|
||||
}
|
||||
@@ -496,6 +250,9 @@ func (r *VmpostgreResource) Update(ctx context.Context, req resource.UpdateReque
|
||||
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
|
||||
@@ -511,43 +268,11 @@ func (r *VmpostgreResource) Update(ctx context.Context, req resource.UpdateReque
|
||||
{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"},
|
||||
})
|
||||
}, []resources_core.InputField{})
|
||||
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)...)
|
||||
}
|
||||
@@ -561,16 +286,15 @@ func (r *VmpostgreResource) Delete(ctx context.Context, req resource.DeleteReque
|
||||
if state.ID.IsNull() || state.ID.IsUnknown() {
|
||||
return
|
||||
}
|
||||
|
||||
deleteMode := "state_only"
|
||||
if !state.SuspendOnDestroy.IsNull() && !state.SuspendOnDestroy.IsUnknown() && state.SuspendOnDestroy.ValueBool() {
|
||||
deleteMode = "suspend"
|
||||
}
|
||||
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
|
||||
|
||||
@@ -68,9 +68,9 @@ func (r *HarborResource) Schema(ctx context.Context, req resource.SchemaRequest,
|
||||
"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."},
|
||||
"domain": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("web01"), MarkdownDescription: "Если будет указан FQDN, то происходят проверки DNS на валидность А-записи, или будет добавлено в зону resourceRealm Не изменяется после создания."},
|
||||
"resource_c_p_u": schema.Int64Attribute{Optional: true, Computed: true, Default: int64default.StaticInt64(100), MarkdownDescription: "Квота ядра пода (Указывается в mili). 1000Mili = 1 Ядро Не изменяется после создания."},
|
||||
"resource_instances": schema.Int64Attribute{Optional: true, Computed: true, Default: int64default.StaticInt64(1), MarkdownDescription: "Количество узлов Не изменяется после создания."},
|
||||
"resource_memory": schema.Int64Attribute{Optional: true, Computed: true, Default: int64default.StaticInt64(200), MarkdownDescription: "Квота памяти пода (Указывается в Megabytes) Не изменяется после создания."},
|
||||
"resource_c_p_u": schema.Int64Attribute{Optional: true, Computed: true, Default: int64default.StaticInt64(100), MarkdownDescription: "Квота ядра пода (Указывается в mili). 1000Mili = 1 Ядро"},
|
||||
"resource_instances": schema.Int64Attribute{Optional: true, Computed: true, Default: int64default.StaticInt64(1), MarkdownDescription: "Количество узлов"},
|
||||
"resource_memory": schema.Int64Attribute{Optional: true, Computed: true, Default: int64default.StaticInt64(200), MarkdownDescription: "Квота памяти пода (Указывается в Megabytes)"},
|
||||
"resource_realm": schema.StringAttribute{Required: true, MarkdownDescription: "Платформа для развертывания Не изменяется после создания."},
|
||||
"s3_uid": schema.StringAttribute{Optional: true, Computed: true, MarkdownDescription: "UUID экземпляра услуги S3 Не изменяется после создания."},
|
||||
"suspend_on_destroy": schema.BoolAttribute{Optional: true, Computed: true, Default: booldefault.StaticBool(false)},
|
||||
@@ -137,24 +137,6 @@ func (r *HarborResource) ModifyPlan(ctx context.Context, req resource.ModifyPlan
|
||||
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.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() {
|
||||
// FIX(uuid-case): сравниваем без учёта регистра — API возвращает UUID
|
||||
// в lowercase, пользователь мог написать upper/mixed. Это одно и то же
|
||||
@@ -366,6 +348,33 @@ func (r *HarborResource) Update(ctx context.Context, req resource.UpdateRequest,
|
||||
}
|
||||
|
||||
hasServiceParamChanges := false
|
||||
if !hasServiceParamChanges {
|
||||
if plan.ResourceInstances.IsNull() != state.ResourceInstances.IsNull() || plan.ResourceInstances.IsUnknown() != state.ResourceInstances.IsUnknown() {
|
||||
hasServiceParamChanges = true
|
||||
} else if !plan.ResourceInstances.IsNull() && !plan.ResourceInstances.IsUnknown() && !state.ResourceInstances.IsNull() && !state.ResourceInstances.IsUnknown() {
|
||||
if plan.ResourceInstances.ValueInt64() != state.ResourceInstances.ValueInt64() {
|
||||
hasServiceParamChanges = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if !hasServiceParamChanges {
|
||||
if plan.ResourceCPU.IsNull() != state.ResourceCPU.IsNull() || plan.ResourceCPU.IsUnknown() != state.ResourceCPU.IsUnknown() {
|
||||
hasServiceParamChanges = true
|
||||
} else if !plan.ResourceCPU.IsNull() && !plan.ResourceCPU.IsUnknown() && !state.ResourceCPU.IsNull() && !state.ResourceCPU.IsUnknown() {
|
||||
if plan.ResourceCPU.ValueInt64() != state.ResourceCPU.ValueInt64() {
|
||||
hasServiceParamChanges = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if !hasServiceParamChanges {
|
||||
if plan.ResourceMemory.IsNull() != state.ResourceMemory.IsNull() || plan.ResourceMemory.IsUnknown() != state.ResourceMemory.IsUnknown() {
|
||||
hasServiceParamChanges = true
|
||||
} else if !plan.ResourceMemory.IsNull() && !plan.ResourceMemory.IsUnknown() && !state.ResourceMemory.IsNull() && !state.ResourceMemory.IsUnknown() {
|
||||
if plan.ResourceMemory.ValueInt64() != state.ResourceMemory.ValueInt64() {
|
||||
hasServiceParamChanges = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !hasServiceParamChanges {
|
||||
plan.ID = instanceID
|
||||
@@ -381,7 +390,11 @@ func (r *HarborResource) Update(ctx context.Context, req resource.UpdateRequest,
|
||||
return
|
||||
}
|
||||
|
||||
params := map[int]string{}
|
||||
params := map[int]string{
|
||||
822: resources_core.FormatInt64(plan.ResourceInstances),
|
||||
823: resources_core.FormatInt64(plan.ResourceCPU),
|
||||
824: resources_core.FormatInt64(plan.ResourceMemory),
|
||||
}
|
||||
|
||||
operationTimeout := ""
|
||||
if !plan.OperationTimeout.IsNull() && !plan.OperationTimeout.IsUnknown() {
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
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: http
|
||||
// Action: reconcile
|
||||
|
||||
var _ resource.Resource = &HttpReconcileResource{}
|
||||
|
||||
// HttpReconcileResource triggers a one-time action.
|
||||
type HttpReconcileResource struct {
|
||||
client *core.UniversalClient
|
||||
}
|
||||
|
||||
type HttpReconcileModel struct {
|
||||
ID types.String `tfsdk:"id"`
|
||||
HttpID types.String `tfsdk:"http_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 NewHttpReconcileResource() resource.Resource {
|
||||
return &HttpReconcileResource{}
|
||||
}
|
||||
|
||||
func (r *HttpReconcileResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_http_reconcile"
|
||||
}
|
||||
|
||||
func (r *HttpReconcileResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||
attrs := map[string]schema.Attribute{
|
||||
"id": schema.StringAttribute{Computed: true},
|
||||
"http_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 *HttpReconcileResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
|
||||
var plan HttpReconcileModel
|
||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
instanceUID := strings.TrimSpace(plan.HttpID.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 *HttpReconcileResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
|
||||
var state HttpReconcileModel
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
}
|
||||
|
||||
func (r *HttpReconcileResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
|
||||
var plan HttpReconcileModel
|
||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
instanceUID := strings.TrimSpace(plan.HttpID.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 *HttpReconcileResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
|
||||
// No-op: removing the resource does not trigger a remote action.
|
||||
}
|
||||
|
||||
func (r *HttpReconcileResource) 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
|
||||
}
|
||||
@@ -47,6 +47,7 @@ func AllResources() []func() resource.Resource {
|
||||
NewVcVmV2Resource,
|
||||
NewVcVmV3Resource,
|
||||
NewVcexternalipResource,
|
||||
NewVmpostgreResource,
|
||||
NewClickhouseDatabaseResource,
|
||||
NewClickhouseUserResource,
|
||||
NewK8sSthutrvalClusterUserResource,
|
||||
@@ -68,6 +69,7 @@ func AllResources() []func() resource.Resource {
|
||||
NewDummyRedeployResource,
|
||||
NewFlaskReconcileResource,
|
||||
NewFlaskRedeployResource,
|
||||
NewHttpReconcileResource,
|
||||
NewHttpRedeployResource,
|
||||
NewK8sSthutrvalClusterReconcileResource,
|
||||
NewLuceeReconcileResource,
|
||||
@@ -86,6 +88,7 @@ func AllResources() []func() resource.Resource {
|
||||
NewRedisReconcileResource,
|
||||
NewS3ReconcileResource,
|
||||
NewTemplateReconcileResource,
|
||||
NewVappReconcileResource,
|
||||
NewVcNsxtReconcileResource,
|
||||
NewVcOrgReconcileResource,
|
||||
NewVcVdcReconcileResource,
|
||||
|
||||
Reference in New Issue
Block a user