feat: provider v0.1.9 — namespace removed from resources, moved to provider block

This commit is contained in:
“Naeel”
2026-03-09 15:12:07 +04:00
parent 0aaeb47b3b
commit 17d32fcb39
23 changed files with 138 additions and 141 deletions
@@ -49,7 +49,6 @@ func NewJobResource() resource.Resource {
// JobModel — модель состояния terraform для sless_job.
type JobModel struct {
Namespace types.String `tfsdk:"namespace"`
Name types.String `tfsdk:"name"`
Function types.String `tfsdk:"function"`
EventJSON types.String `tfsdk:"event_json"`
@@ -73,12 +72,7 @@ func (r *JobResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *
MarkdownDescription: "Одноразовый запуск serverless функции. terraform apply блокируется до завершения джоба.",
Attributes: map[string]schema.Attribute{
// Все input-поля immutable — джоб нельзя "изменить", только пересоздать.
"namespace": schema.StringAttribute{
Required: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
},
"name": schema.StringAttribute{
Required: true,
PlanModifiers: []planmodifier.String{
@@ -160,7 +154,7 @@ func (r *JobResource) Create(ctx context.Context, req resource.CreateRequest, re
return
}
ns := plan.Namespace.ValueString()
ns := r.client.Namespace
eventJSON := plan.EventJSON.ValueString()
if eventJSON == "" {
eventJSON = "{}"
@@ -188,7 +182,6 @@ func (r *JobResource) Create(ctx context.Context, req resource.CreateRequest, re
waitTimeoutSec = types.Int64Value(defaultWaitTimeoutSec)
}
resp.Diagnostics.Append(resp.State.Set(ctx, JobModel{
Namespace: types.StringValue(plan.Namespace.ValueString()),
Name: types.StringValue(plan.Name.ValueString()),
Function: types.StringValue(plan.Function.ValueString()),
EventJSON: plan.EventJSON,
@@ -223,7 +216,7 @@ func (r *JobResource) Read(ctx context.Context, req resource.ReadRequest, resp *
return
}
j, err := r.client.GetJob(ctx, state.Namespace.ValueString(), state.Name.ValueString())
j, err := r.client.GetJob(ctx, r.client.Namespace, state.Name.ValueString())
if err != nil {
resp.Diagnostics.AddError("read job", err.Error())
return
@@ -250,7 +243,7 @@ func (r *JobResource) Delete(ctx context.Context, req resource.DeleteRequest, re
return
}
if err := r.client.DeleteJob(ctx, state.Namespace.ValueString(), state.Name.ValueString()); err != nil {
if err := r.client.DeleteJob(ctx, r.client.Namespace, state.Name.ValueString()); err != nil {
resp.Diagnostics.AddError("delete job", err.Error())
}
}
@@ -262,7 +255,6 @@ func jobToModel(plan JobModel, j *client.JobResponse) JobModel {
waitTimeoutSec = types.Int64Value(defaultWaitTimeoutSec)
}
return JobModel{
Namespace: types.StringValue(j.Namespace),
Name: types.StringValue(j.Name),
Function: types.StringValue(j.FunctionRef),
EventJSON: plan.EventJSON,