This commit is contained in:
asteam
2024-12-04 13:18:58 +03:00
parent 003e4d656e
commit 76ea459b3d
417 changed files with 30051 additions and 975 deletions

View File

@@ -0,0 +1,59 @@
package flattens
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/k8ci/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/k8ci/utilities"
)
// K8CIDataSource flattens data source for K8CI.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func K8CIDataSource(ctx context.Context, state *models.DataSourceK8CIModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.K8CIDataSource")
diags := diag.Diagnostics{}
k8ciID := uint64(state.K8ciID.ValueInt64())
recordK8ci, diags := utilities.K8ciDataSourceCheckPresence(ctx, k8ciID, c)
if diags.HasError() {
return diags
}
tflog.Info(ctx, "flattens.K8CIDataSource: before flatten")
id := uuid.New()
*state = models.DataSourceK8CIModel{
K8ciID: state.K8ciID,
Timeouts: state.Timeouts,
Description: types.StringValue(recordK8ci.Description),
GID: types.Int64Value(int64(recordK8ci.GID)),
GUID: types.Int64Value(int64(recordK8ci.GUID)),
Id: types.StringValue(id.String()),
LBImageID: types.Int64Value(int64(recordK8ci.LBImageID)),
MasterDriver: types.StringValue(recordK8ci.MasterDriver),
MasterImageId: types.Int64Value(int64(recordK8ci.MasterImageID)),
MaxMasterCount: types.Int64Value(int64(recordK8ci.MaxMasterCount)),
MaxWorkerCount: types.Int64Value(int64(recordK8ci.MaxWorkerCount)),
Milestones: types.Int64Value(int64(recordK8ci.Milestones)),
Name: types.StringValue(recordK8ci.Name),
NetworkPlugins: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &recordK8ci.NetworkPlugins),
SharedWith: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &recordK8ci.SharedWith),
Status: types.StringValue(recordK8ci.Status),
Version: types.StringValue(recordK8ci.Version),
WorkerDriver: types.StringValue(recordK8ci.WorkerDriver),
WorkerImageId: types.Int64Value(int64(recordK8ci.WorkerImageID)),
}
tflog.Info(ctx, "End flattens.K8CIDataSource")
return nil
}

View File

@@ -0,0 +1,75 @@
package flattens
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/k8ci/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/k8ci/utilities"
)
// K8CIListDataSource flattens data source for k8ci list.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func K8CIListDataSource(ctx context.Context, state *models.DataSourceK8CIListModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.K8CIListDataSource")
diags := diag.Diagnostics{}
k8ciList, diags := utilities.K8CIListDataSourceCheckPresence(ctx, state, c)
if diags.HasError() {
return diags
}
tflog.Info(ctx, "flattens.K8CIListDataSource: before flatten")
id := uuid.New()
*state = models.DataSourceK8CIListModel{
ByID: state.ByID,
Name: state.Name,
Status: state.Status,
WorkerDriver: state.WorkerDriver,
MasterDriver: state.MasterDriver,
NetworkPlugin: state.NetworkPlugin,
IncludeDisabled: state.IncludeDisabled,
SortBy: state.SortBy,
Page: state.Page,
Size: state.Size,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),
EntryCount: types.Int64Value(int64(k8ciList.EntryCount)),
}
items := make([]models.ItemK8ciModel, 0, len(k8ciList.Data))
for _, item := range k8ciList.Data {
v := models.ItemK8ciModel{
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
Description: types.StringValue(item.Description),
GID: types.Int64Value(int64(item.GID)),
GUID: types.Int64Value(int64(item.GUID)),
K8ciID: types.Int64Value(int64(item.ID)),
LBImageID: types.Int64Value(int64(item.LBImageID)),
MasterDriver: types.StringValue(item.MasterDriver),
MasterImageId: types.Int64Value(int64(item.MasterImageID)),
MaxMasterCount: types.Int64Value(int64(item.MaxMasterCount)),
MaxWorkerCount: types.Int64Value(int64(item.MaxWorkerCount)),
Name: types.StringValue(item.Name),
SharedWith: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &item.SharedWith),
Status: types.StringValue(item.Status),
Version: types.StringValue(item.Version),
WorkerDriver: types.StringValue(item.WorkerDriver),
WorkerImageId: types.Int64Value(int64(item.WorkerImageID)),
}
items = append(items, v)
}
state.Items = items
tflog.Info(ctx, "End flattens.K8CIListDataSource")
return nil
}

View File

@@ -0,0 +1,73 @@
package flattens
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/k8ci/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/k8ci/utilities"
)
// K8CIListDeletedDataSource flattens data source for k8ci deleted list.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func K8CIListDeletedDataSource(ctx context.Context, state *models.DataSourceK8CIListDeletedModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.K8CIListDataSource")
diags := diag.Diagnostics{}
k8ciList, diags := utilities.K8CIListDeletedDataSourceCheckPresence(ctx, state, c)
if diags.HasError() {
return diags
}
tflog.Info(ctx, "flattens.K8CIListDataSource: before flatten")
id := uuid.New()
*state = models.DataSourceK8CIListDeletedModel{
ByID: state.ByID,
Name: state.Name,
WorkerDriver: state.WorkerDriver,
MasterDriver: state.MasterDriver,
NetworkPlugin: state.NetworkPlugin,
SortBy: state.SortBy,
Page: state.Page,
Size: state.Size,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),
EntryCount: types.Int64Value(int64(k8ciList.EntryCount)),
}
items := make([]models.ItemK8ciDeletedModel, 0, len(k8ciList.Data))
for _, item := range k8ciList.Data {
v := models.ItemK8ciDeletedModel{
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
Description: types.StringValue(item.Description),
GID: types.Int64Value(int64(item.GID)),
GUID: types.Int64Value(int64(item.GUID)),
K8ciID: types.Int64Value(int64(item.ID)),
LBImageID: types.Int64Value(int64(item.LBImageID)),
MasterDriver: types.StringValue(item.MasterDriver),
MasterImageId: types.Int64Value(int64(item.MasterImageID)),
MaxMasterCount: types.Int64Value(int64(item.MaxMasterCount)),
MaxWorkerCount: types.Int64Value(int64(item.MaxWorkerCount)),
Name: types.StringValue(item.Name),
SharedWith: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &item.SharedWith),
Status: types.StringValue(item.Status),
Version: types.StringValue(item.Version),
WorkerDriver: types.StringValue(item.WorkerDriver),
WorkerImageId: types.Int64Value(int64(item.WorkerImageID)),
}
items = append(items, v)
}
state.Items = items
tflog.Info(ctx, "End flattens.K8CIListDataSource")
return nil
}

View File

@@ -0,0 +1,59 @@
package flattens
import (
"context"
"strconv"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/k8ci/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/k8ci/utilities"
)
// K8CIResource flattens resource for K8CI.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func K8CIResource(ctx context.Context, state *models.ResourceK8CIModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.K8CIResource")
diags := diag.Diagnostics{}
recordK8ci, diags := utilities.K8CIResourceCheckPresence(ctx, state, c)
if diags.HasError() {
return diags
}
tflog.Info(ctx, "flattens.K8CIResource: before flatten")
*state = models.ResourceK8CIModel{
Name: state.Name,
Version: state.Version,
MasterDriver: state.MasterDriver,
MasterImageId: state.MasterImageId,
MaxMasterCount: state.MaxMasterCount,
MaxWorkerCount: state.MaxWorkerCount,
NetworkPlugins: state.NetworkPlugins,
WorkerDriver: state.WorkerDriver,
WorkerImageId: state.WorkerImageId,
Timeouts: state.Timeouts,
Description: state.Description,
Enabled: state.Enabled,
Permanently: state.Permanently,
Restore: state.Restore,
SharedWith: state.SharedWith,
GID: types.Int64Value(int64(recordK8ci.GID)),
GUID: types.Int64Value(int64(recordK8ci.GUID)),
Id: types.StringValue(strconv.Itoa(int(recordK8ci.ID))),
K8ciID: types.Int64Value(int64(recordK8ci.ID)),
LBImageID: types.Int64Value(int64(recordK8ci.LBImageID)),
Milestones: types.Int64Value(int64(recordK8ci.Milestones)),
Status: types.StringValue(recordK8ci.Status),
}
tflog.Info(ctx, "End flattens.K8CIResource")
return nil
}