fix: API validation + Terraform plan-time validators
API (operator v0.1.13): - functions.go: добавлена валидация entrypoint (не пустой) и memory_mb (1-4096). Фиксирует БАГ-1/2/4 из негативных тестов. - triggers.go: добавлена валидация type (только 'http'/'cron'). Фиксирует БАГ-3 (неверное сообщение об ошибке). Провайдер (v0.1.7): - Добавлен пакет terraform-plugin-framework-validators v0.19.0 - function_resource: runtime OneOf, memory_mb 1-4096, timeout_sec 1-900 - trigger_resource: type OneOf(http, cron) - job_resource: run_id AtLeast(0) - examples/main.tf: обновлена версия до ~> 0.1.7 doc/errors/log.md: задокументированы исправления и результаты повторных тестов
This commit is contained in:
@@ -23,12 +23,15 @@ import (
|
||||
|
||||
"terraform-provider-sless/internal/client"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
|
||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
|
||||
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
@@ -90,6 +93,9 @@ func (r *FunctionResource) Schema(_ context.Context, _ resource.SchemaRequest, r
|
||||
PlanModifiers: []planmodifier.String{
|
||||
stringplanmodifier.RequiresReplace(),
|
||||
},
|
||||
Validators: []validator.String{
|
||||
stringvalidator.OneOf("nodejs20", "python3.11", "go1.21"),
|
||||
},
|
||||
},
|
||||
"entrypoint": schema.StringAttribute{
|
||||
Optional: true,
|
||||
@@ -101,10 +107,16 @@ func (r *FunctionResource) Schema(_ context.Context, _ resource.SchemaRequest, r
|
||||
"memory_mb": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Validators: []validator.Int64{
|
||||
int64validator.Between(1, 4096),
|
||||
},
|
||||
},
|
||||
"timeout_sec": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Validators: []validator.Int64{
|
||||
int64validator.Between(1, 900),
|
||||
},
|
||||
},
|
||||
"env_vars": schema.MapAttribute{
|
||||
ElementType: types.StringType,
|
||||
|
||||
Reference in New Issue
Block a user