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,146 @@
|
||||
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: nodejs
|
||||
// Action: redeploy
|
||||
|
||||
var _ resource.Resource = &NodejsRedeployResource{}
|
||||
|
||||
// NodejsRedeployResource triggers a one-time action.
|
||||
type NodejsRedeployResource struct {
|
||||
client *core.UniversalClient
|
||||
}
|
||||
|
||||
type NodejsRedeployModel struct {
|
||||
ID types.String `tfsdk:"id"`
|
||||
NodejsID types.String `tfsdk:"nodejs_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"`
|
||||
ResourceRealm types.String `tfsdk:"resource_realm"`
|
||||
}
|
||||
|
||||
func NewNodejsRedeployResource() resource.Resource {
|
||||
return &NodejsRedeployResource{}
|
||||
}
|
||||
|
||||
func (r *NodejsRedeployResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_nodejs_redeploy"
|
||||
}
|
||||
|
||||
func (r *NodejsRedeployResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||
attrs := map[string]schema.Attribute{
|
||||
"id": schema.StringAttribute{Computed: true},
|
||||
"nodejs_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."},
|
||||
"resource_realm": schema.StringAttribute{Required: true, MarkdownDescription: "Платформа для развертывания"},
|
||||
}
|
||||
resp.Schema = schema.Schema{Attributes: attrs}
|
||||
}
|
||||
|
||||
func (r *NodejsRedeployResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
|
||||
var plan NodejsRedeployModel
|
||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
if plan.ResourceRealm.IsNull() || plan.ResourceRealm.IsUnknown() {
|
||||
resp.Diagnostics.AddError("Missing required attribute", "resource_realm is required.")
|
||||
return
|
||||
}
|
||||
|
||||
instanceUID := strings.TrimSpace(plan.NodejsID.ValueString())
|
||||
runID := strings.TrimSpace(plan.RunID.ValueString())
|
||||
if instanceUID == "" || runID == "" {
|
||||
resp.Diagnostics.AddError("Ошибка клиента", "отсутствует идентификатор экземпляра или run_id")
|
||||
return
|
||||
}
|
||||
|
||||
params := map[string]string{
|
||||
"resourceRealm": resources_core.FormatString(plan.ResourceRealm),
|
||||
}
|
||||
|
||||
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, "redeploy", params, operationTimeout); err != nil {
|
||||
resp.Diagnostics.AddError("Ошибка клиента", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
plan.ID = types.StringValue(resources_core.BuildActionID(instanceUID, "redeploy", runID))
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
|
||||
}
|
||||
|
||||
func (r *NodejsRedeployResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
|
||||
var state NodejsRedeployModel
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
}
|
||||
|
||||
func (r *NodejsRedeployResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
|
||||
var plan NodejsRedeployModel
|
||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
instanceUID := strings.TrimSpace(plan.NodejsID.ValueString())
|
||||
runID := strings.TrimSpace(plan.RunID.ValueString())
|
||||
if instanceUID == "" || runID == "" {
|
||||
resp.Diagnostics.AddError("Ошибка клиента", "отсутствует идентификатор экземпляра или run_id")
|
||||
return
|
||||
}
|
||||
|
||||
params := map[string]string{
|
||||
"resourceRealm": resources_core.FormatString(plan.ResourceRealm),
|
||||
}
|
||||
|
||||
if err := resources_core.RunOperationByCode(ctx, r.client, instanceUID, "redeploy", params); err != nil {
|
||||
resp.Diagnostics.AddError("Ошибка клиента", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
plan.ID = types.StringValue(resources_core.BuildActionID(instanceUID, "redeploy", runID))
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
|
||||
}
|
||||
|
||||
func (r *NodejsRedeployResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
|
||||
// No-op: removing the resource does not trigger a remote action.
|
||||
}
|
||||
|
||||
func (r *NodejsRedeployResource) 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