feat: add import support and unit tests for provider resources

This commit is contained in:
Naeel
2026-04-14 23:00:46 +03:00
parent a2688e5f2c
commit 81852c28b1
12 changed files with 366 additions and 0 deletions
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"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"
@@ -14,6 +15,7 @@ import (
)
var _ resource.Resource = &HTTPTriggerResource{}
var _ resource.ResourceWithImportState = &HTTPTriggerResource{}
// Изменено: 2026-04-14 20:15 UTC.
// Resource для управления Fission HTTPTrigger через Kubernetes CRD API.
@@ -207,6 +209,19 @@ func (r *HTTPTriggerResource) Delete(ctx context.Context, req resource.DeleteReq
}
}
// ImportState поддерживает импорт ресурса в формате namespace/name.
func (r *HTTPTriggerResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
namespace, name, err := parseImportID(req.ID)
if err != nil {
resp.Diagnostics.AddError("Некорректный формат import ID", err.Error())
return
}
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("namespace"), namespace)...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("name"), name)...)
}
// httpTriggerToUnstructured преобразует Terraform model в Kubernetes CRD payload.
func httpTriggerToUnstructured(ctx context.Context, model httpTriggerResourceModel, namespace string) (*unstructured.Unstructured, error) {
methods := []string{"GET"}