This commit is contained in:
asteam
2024-07-25 14:33:38 +03:00
commit 6f40af6a5f
946 changed files with 98335 additions and 0 deletions

View File

@@ -0,0 +1,91 @@
package cbAccount
import (
"context"
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-log/tflog"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/schemas"
)
// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &dataSourceAccount{}
)
func NewDataSourceAccount() datasource.DataSource {
return &dataSourceAccount{}
}
// dataSourceAccount is the data source implementation.
type dataSourceAccount struct {
client *decort.DecortClient
}
func (d *dataSourceAccount) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
// Read Terraform configuration data into the model
var state models.DataSourceAccountModel
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read DataSourceCbAccountModel: Error get state")
return
}
accountId := uint64(state.AccountID.ValueInt64())
tflog.Info(ctx, "Read DataSourceCbAccountModel: got state successfully", map[string]any{"account_id": accountId})
// Set timeouts
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout30s)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read DataSourceCbAccountModel: Error set timeout")
return
}
tflog.Info(ctx, "Read DataSourceCbAccountModel: set timeouts successfully", map[string]any{
"account_id": accountId,
"readTimeout": readTimeout})
ctx, cancel := context.WithTimeout(ctx, readTimeout)
defer cancel()
// Map response body to schema
resp.Diagnostics.Append(flattens.AccountDataSource(ctx, &state, d.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read DataSourceCbAccountModel: Error flatten data source account")
return
}
// Set refreshed state
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read DataSourceCbAccountModel: Error set state")
return
}
tflog.Info(ctx, "End read DataSourceCbAccountModel", map[string]any{"account_id": accountId})
}
func (d *dataSourceAccount) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: schemas.MakeSchemaDataSourceAccount(),
Blocks: map[string]schema.Block{
"timeouts": timeouts.Block(ctx),
},
}
}
func (d *dataSourceAccount) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_cb_account"
}
// Configure adds the provider configured client to the data source.
func (d *dataSourceAccount) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
tflog.Info(ctx, "Get Configure DataSourceCbAccountModel")
d.client = client.DataSource(ctx, &req, resp)
tflog.Info(ctx, "Getting Configure DataSourceCbAccountModel successfully")
}

View File

@@ -0,0 +1,88 @@
package cbAccount
import (
"context"
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-log/tflog"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/schemas"
)
// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &dataSourceAccountList{}
)
func NewDataSourceAccountList() datasource.DataSource {
return &dataSourceAccountList{}
}
// NewDataSourceAccountList is the data source implementation.
type dataSourceAccountList struct {
client *decort.DecortClient
}
func (d *dataSourceAccountList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
// Read Terraform configuration data into the model
var state models.DataSourceAccountListModel
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceAccountList: Error get state")
return
}
tflog.Info(ctx, "Read dataSourceAccountList: got state successfully")
// Set timeouts
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout30s)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceAccountList: Error set timeout")
return
}
tflog.Info(ctx, "Read dataSourceAccountList: set timeouts successfully", map[string]any{"readTimeout": readTimeout})
ctx, cancel := context.WithTimeout(ctx, readTimeout)
defer cancel()
// Map response body to schema
resp.Diagnostics.Append(flattens.AccountListDataSource(ctx, &state, d.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceAccountList: Error flatten data source")
return
}
// Set refreshed state
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceAccountList: Error set state")
return
}
tflog.Info(ctx, "End read dataSourceAccountList")
}
func (d *dataSourceAccountList) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: schemas.MakeSchemaDataSourceAccountList(),
Blocks: map[string]schema.Block{
"timeouts": timeouts.Block(ctx),
},
}
}
func (d *dataSourceAccountList) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_cb_account_list"
}
// Configure adds the provider configured client to the data source.
func (d *dataSourceAccountList) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
tflog.Info(ctx, "Get Configure dataSourceAccountList")
d.client = client.DataSource(ctx, &req, resp)
tflog.Info(ctx, "Getting Configure dataSourceAccountList successfully")
}

View File

@@ -0,0 +1,91 @@
package cbAccount
import (
"context"
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-log/tflog"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/schemas"
)
// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &dataSourceAccountVinsList{}
)
func NewDataSourceAccountVinsList() datasource.DataSource {
return &dataSourceAccountVinsList{}
}
// dataSourceAccountVinsList is the data source implementation.
type dataSourceAccountVinsList struct {
client *decort.DecortClient
}
func (d *dataSourceAccountVinsList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
// Read Terraform configuration data into the model
var state models.DataSourceAccountVinsListModel
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceAccountVinsList: Error get state")
return
}
accountId := uint64(state.AccountID.ValueInt64())
tflog.Info(ctx, "Read dataSourceAccountVinsList: got state successfully", map[string]any{"account_id": accountId})
// Set timeouts
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout30s)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceAccountVinsList: Error set timeout")
return
}
tflog.Info(ctx, "Read dataSourceAccountVinsList: set timeouts successfully", map[string]any{
"account_id": accountId,
"readTimeout": readTimeout})
ctx, cancel := context.WithTimeout(ctx, readTimeout)
defer cancel()
// Map response body to schema
resp.Diagnostics.Append(flattens.AccountVinsListDataSource(ctx, &state, d.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceAccountVinsList: Error flatten data source account")
return
}
// Set refreshed state
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceAccountVinsList: Error set state")
return
}
tflog.Info(ctx, "End read dataSourceAccountVinsList", map[string]any{"account_id": accountId})
}
func (d *dataSourceAccountVinsList) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: schemas.MakeSchemaDataSourceAccountVinsList(),
Blocks: map[string]schema.Block{
"timeouts": timeouts.Block(ctx),
},
}
}
func (d *dataSourceAccountVinsList) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_cb_account_vins_list"
}
// Configure adds the provider configured client to the data source.
func (d *dataSourceAccountVinsList) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
tflog.Info(ctx, "Get Configure dataSourceAccountVinsList")
d.client = client.DataSource(ctx, &req, resp)
tflog.Info(ctx, "Getting Configure dataSourceAccountVinsList successfully")
}

View File

@@ -0,0 +1,106 @@
package flattens
import (
"context"
"fmt"
"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/decort-golang-sdk/pkg/cloudbroker/account"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/utilities"
)
// AccountDataSource flattens data source for account.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func AccountDataSource(ctx context.Context, state *models.DataSourceAccountModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.CbAccountDataSource")
diags := diag.Diagnostics{}
ID := uint64(state.AccountID.ValueInt64())
recordAccount, err := utilities.AccountDataSourceCheckPresence(ctx, ID, c)
if err != nil {
diags.AddError(fmt.Sprintf("Cannot get info about account with ID %v", ID), err.Error())
return diags
}
tflog.Info(ctx, "flattens.AccountDataSource: before flatten", map[string]any{"account_id": ID, "recordAccount": recordAccount})
*state = models.DataSourceAccountModel{
AccountID: state.AccountID,
Timeouts: state.Timeouts,
DCLocation: types.StringValue(recordAccount.DCLocation),
CKey: types.StringValue(recordAccount.CKey),
ACL: flattenACLInAccount(ctx, recordAccount.ACL),
Company: types.StringValue(recordAccount.Company),
CompanyURL: types.StringValue(recordAccount.CompanyURL),
CPUAllocationParameter: types.StringValue(recordAccount.CPUAllocationParameter),
CPUAllocationRatio: types.Float64Value(recordAccount.CPUAllocationRatio),
CreatedBy: types.StringValue(recordAccount.CreatedBy),
CreatedTime: types.Int64Value(int64(recordAccount.CreatedTime)),
DeactivationTime: types.Float64Value(recordAccount.DeactivationTime),
DeletedBy: types.StringValue(recordAccount.DeletedBy),
DeletedTime: types.Int64Value(int64(recordAccount.DeletedTime)),
DisplayName: types.StringValue(recordAccount.DisplayName),
GUID: types.Int64Value(int64(recordAccount.GUID)),
Name: types.StringValue(recordAccount.Name),
ResourceLimits: flattenResourceLimits(ctx, recordAccount.ResourceLimits),
ResTypes: flattens.FlattenSimpleTypeToList(ctx, types.StringType, recordAccount.ResTypes),
SendAccessEmails: types.BoolValue(recordAccount.SendAccessEmails),
Status: types.StringValue(recordAccount.Status),
UniqPools: flattens.FlattenSimpleTypeToList(ctx, types.StringType, recordAccount.UniqPools),
UpdatedTime: types.Int64Value(int64(recordAccount.UpdatedTime)),
Version: types.Int64Value(int64(recordAccount.Version)),
VINS: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, recordAccount.VINS),
}
state.ComputeFeatures, diags = types.ListValueFrom(ctx, types.StringType, recordAccount.ComputeFeatures)
if diags.HasError() {
tflog.Error(ctx, fmt.Sprint("flattens.AccountListDeletedDataSource: cannot flatten recordAccount.ComputeFeatures to state.ComputeFeatures", diags))
}
tflog.Info(ctx, "flattens.AccountDataSource: after flatten", map[string]any{"account_id": state.AccountID.ValueInt64()})
tflog.Info(ctx, "End flattens.AccountDataSource", map[string]any{"account_id": state.AccountID.ValueInt64()})
return nil
}
func flattenResourceLimits(ctx context.Context, limits account.ResourceLimits) *models.ResourceLimitsModel {
tflog.Info(ctx, "Start flattenResourceLimits")
res := models.ResourceLimitsModel{
CuC: types.Float64Value(limits.CuC),
CuD: types.Float64Value(limits.CuD),
CuI: types.Float64Value(limits.CuI),
CuM: types.Float64Value(limits.CuM),
CuDM: types.Float64Value(limits.CuDM),
CuNP: types.Float64Value(limits.CuNP),
GPUUnits: types.Float64Value(limits.GPUUnits),
}
tflog.Info(ctx, "End flattenResourceLimits")
return &res
}
func flattenACLInAccount(ctx context.Context, aclList []account.ACL) []models.ACLModel {
tflog.Info(ctx, "Start flattenACLInAccount")
res := make([]models.ACLModel, 0, len(aclList))
for _, item := range aclList {
temp := models.ACLModel{
Explicit: types.BoolValue(item.Explicit),
GUID: types.StringValue(item.GUID),
Right: types.StringValue(item.Right),
Status: types.StringValue(item.Status),
Type: types.StringValue(item.Type),
UserGroupID: types.StringValue(item.UserGroupID),
}
res = append(res, temp)
}
return res
}

View File

@@ -0,0 +1,129 @@
package flattens
import (
"context"
"fmt"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-framework/attr"
"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/decort-golang-sdk/pkg/cloudbroker/account"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/utilities"
)
// AccountListDataSource flattens data source for account.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func AccountListDataSource(ctx context.Context, state *models.DataSourceAccountListModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.AccountListDataSource")
diags := diag.Diagnostics{}
accList, err := utilities.AccountListDataSourceCheckPresence(ctx, state, c)
if err != nil {
diags.AddError("Cannot get info about account list", err.Error())
return diags
}
tflog.Info(ctx, "flattens.AccountListDataSource: before flatten")
id := uuid.New()
*state = models.DataSourceAccountListModel{
ByID: state.ByID,
Name: state.Name,
ACL: state.ACL,
Page: state.Page,
Size: state.Size,
Timeouts: state.Timeouts,
SortBy: state.SortBy,
Id: types.StringValue(id.String()),
EntryCount: types.Int64Value(int64(accList.EntryCount)),
}
items := make([]models.AccountListElementModel, 0, len(accList.Data))
for _, item := range accList.Data {
i := models.AccountListElementModel{
DCLocation: types.StringValue(item.DCLocation),
CKey: types.StringValue(item.CKey),
ACL: flattenACLInAccountList(ctx, item.ACL),
Company: types.StringValue(item.Company),
CompanyURL: types.StringValue(item.CompanyURL),
CPUAllocationParameter: types.StringValue(item.CPUAllocationParameter),
CPUAllocationRatio: types.Float64Value(item.CPUAllocationRatio),
CreatedBy: types.StringValue(item.CreatedBy),
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
DeactivationTime: types.Float64Value(item.DeactivationTime),
DeletedBy: types.StringValue(item.DeletedBy),
DeletedTime: types.Int64Value(int64(item.DeletedTime)),
DisplayName: types.StringValue(item.DisplayName),
GUID: types.Int64Value(int64(item.GUID)),
Name: types.StringValue(item.Name),
ResourceLimits: flattenAccountListResourceLimits(ctx, item.ResourceLimits),
ResTypes: flattenAccListSimpleType(ctx, types.StringType, item.ResTypes),
SendAccessEmails: types.BoolValue(item.SendAccessEmails),
Status: types.StringValue(item.Status),
UniqPools: flattenAccListSimpleType(ctx, types.StringType, item.UniqPools),
UpdatedTime: types.Int64Value(int64(item.UpdatedTime)),
Version: types.Int64Value(int64(item.Version)),
VINS: flattenAccListSimpleType(ctx, types.Int64Type, item.VINS),
}
i.ComputeFeatures, diags = types.ListValueFrom(ctx, types.StringType, item.ComputeFeatures)
if diags.HasError() {
tflog.Error(ctx, fmt.Sprint("flattens.AccountListDataSource: cannot flatten item.ComputeFeatures to i.ComputeFeatures", diags))
}
items = append(items, i)
}
state.Items = items
tflog.Info(ctx, "flattens.AccountListDataSource: after flatten")
tflog.Info(ctx, "End flattens.AccountListDataSource")
return nil
}
func flattenAccountListResourceLimits(ctx context.Context, limits account.ResourceLimits) *models.AccountListResourceLimitsModel {
tflog.Info(ctx, "Start flattenAccountListResourceLimits")
res := models.AccountListResourceLimitsModel{
CuC: types.Float64Value(limits.CuC),
CuD: types.Float64Value(limits.CuD),
CuI: types.Float64Value(limits.CuI),
CuM: types.Float64Value(limits.CuM),
CuDM: types.Float64Value(limits.CuDM),
CuNP: types.Float64Value(limits.CuNP),
GPUUnits: types.Float64Value(limits.GPUUnits),
}
tflog.Info(ctx, "End flattenAccountListResourceLimits")
return &res
}
func flattenACLInAccountList(ctx context.Context, aclList []account.ACL) []models.AccountListACLModel {
tflog.Info(ctx, "Start flattenACLInAccountList")
res := make([]models.AccountListACLModel, 0, len(aclList))
for _, item := range aclList {
temp := models.AccountListACLModel{
Explicit: types.BoolValue(item.Explicit),
GUID: types.StringValue(item.GUID),
Right: types.StringValue(item.Right),
Status: types.StringValue(item.Status),
Type: types.StringValue(item.Type),
UserGroupID: types.StringValue(item.UserGroupID),
}
res = append(res, temp)
}
return res
}
func flattenAccListSimpleType(ctx context.Context, elementType attr.Type, elements any) types.List {
res, diags := types.ListValueFrom(ctx, elementType, elements)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenAccListSimpleType", diags))
}
return res
}

View File

@@ -0,0 +1,76 @@
package flattens
import (
"context"
"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/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/utilities"
)
// AccountVinsListDataSource flattens data source for account list.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func AccountVinsListDataSource(ctx context.Context, state *models.DataSourceAccountVinsListModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.AccountVinsListDataSource")
diags := diag.Diagnostics{}
accountVinsList, err := utilities.AccountVinsListCheck(ctx, state, c)
if err != nil {
diags.AddError("Cannot get info about account list", err.Error())
return diags
}
tflog.Info(ctx, "flattens.AccountVinsListDataSource: before flatten")
*state = models.DataSourceAccountVinsListModel{
AccountID: state.AccountID,
VinsID: state.VinsID,
Name: state.Name,
RGID: state.RGID,
ExtIp: state.ExtIp,
SortBy: state.SortBy,
Page: state.Page,
Size: state.Size,
Timeouts: state.Timeouts,
EntryCount: types.Int64Value(int64(accountVinsList.EntryCount)),
}
items := make([]models.ItemVINSModel, 0, len(accountVinsList.Data))
for _, item := range accountVinsList.Data {
i := models.ItemVINSModel{
AccountID: types.Int64Value(int64(item.ID)),
AccountName: types.StringValue(item.Name),
Computes: types.Int64Value(int64(item.Computes)),
CreatedBy: types.StringValue(item.CreatedBy),
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
DeletedBy: types.StringValue(item.DeletedBy),
DeletedTime: types.Int64Value(int64(item.DeletedTime)),
ExternalIP: types.StringValue(item.ExternalIP),
ExtnetId: types.Int64Value(int64(item.ExtnetId)),
FreeIPs: types.Int64Value(int64(item.FreeIPs)),
ID: types.Int64Value(int64(item.ID)),
Name: types.StringValue(item.Name),
Network: types.StringValue(item.Network),
PriVNFDevID: types.Int64Value(int64(item.PriVNFDevID)),
RGID: types.Int64Value(int64(item.RGID)),
RGName: types.StringValue(item.RGName),
Status: types.StringValue(item.Status),
UpdatedBy: types.StringValue(item.UpdatedBy),
UpdatedTime: types.Int64Value(int64(item.UpdatedTime)),
}
items = append(items, i)
}
state.Data = items
tflog.Info(ctx, "flattens.AccountVinsListDataSource: after flatten")
tflog.Info(ctx, "End flattens.AccountVinsListDataSource")
return nil
}

View File

@@ -0,0 +1,58 @@
package models
import (
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type DataSourceAccountModel struct {
// optional fields
AccountID types.Int64 `tfsdk:"account_id"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
// response fields
DCLocation types.String `tfsdk:"dc_location"`
CKey types.String `tfsdk:"ckey"`
ACL []ACLModel `tfsdk:"acl"`
Company types.String `tfsdk:"company"`
CompanyURL types.String `tfsdk:"companyurl"`
ComputeFeatures types.List `tfsdk:"compute_features"`
CPUAllocationParameter types.String `tfsdk:"cpu_allocation_parameter"`
CPUAllocationRatio types.Float64 `tfsdk:"cpu_allocation_ratio"`
CreatedBy types.String `tfsdk:"created_by"`
CreatedTime types.Int64 `tfsdk:"created_time"`
DeactivationTime types.Float64 `tfsdk:"deactivation_time"`
DeletedBy types.String `tfsdk:"deleted_by"`
DeletedTime types.Int64 `tfsdk:"deleted_time"`
DisplayName types.String `tfsdk:"displayname"`
GUID types.Int64 `tfsdk:"guid"`
ID types.Int64 `tfsdk:"id"`
Name types.String `tfsdk:"name"`
ResourceLimits *ResourceLimitsModel `tfsdk:"resource_limits"`
ResTypes types.List `tfsdk:"resource_types"`
SendAccessEmails types.Bool `tfsdk:"send_access_emails"`
Status types.String `tfsdk:"status"`
UniqPools types.List `tfsdk:"uniq_pools"`
UpdatedTime types.Int64 `tfsdk:"updated_time"`
Version types.Int64 `tfsdk:"version"`
VINS types.List `tfsdk:"vins"`
}
type ACLModel struct {
Explicit types.Bool `tfsdk:"explicit"`
GUID types.String `tfsdk:"guid"`
Right types.String `tfsdk:"right"`
Status types.String `tfsdk:"status"`
Type types.String `tfsdk:"type"`
UserGroupID types.String `tfsdk:"user_group_id"`
}
type ResourceLimitsModel struct {
CuC types.Float64 `tfsdk:"cu_c"`
CuD types.Float64 `tfsdk:"cu_d"`
CuDM types.Float64 `tfsdk:"cu_dm"`
CuI types.Float64 `tfsdk:"cu_i"`
CuM types.Float64 `tfsdk:"cu_m"`
CuNP types.Float64 `tfsdk:"cu_np"`
GPUUnits types.Float64 `tfsdk:"gpu_units"`
}

View File

@@ -0,0 +1,70 @@
package models
import (
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type DataSourceAccountListModel struct {
// optional fields
ByID types.Int64 `tfsdk:"by_id"`
Name types.String `tfsdk:"name"`
ACL types.String `tfsdk:"acl"`
Status types.String `tfsdk:"status"`
SortBy types.String `tfsdk:"sort_by"`
Page types.Int64 `tfsdk:"page"`
Size types.Int64 `tfsdk:"size"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
// response fields
Id types.String `tfsdk:"id"`
Items []AccountListElementModel `tfsdk:"items"`
EntryCount types.Int64 `tfsdk:"entry_count"`
}
type AccountListElementModel struct {
DCLocation types.String `tfsdk:"dc_location"`
CKey types.String `tfsdk:"ckey"`
ACL []AccountListACLModel `tfsdk:"acl"`
Company types.String `tfsdk:"company"`
CompanyURL types.String `tfsdk:"companyurl"`
ComputeFeatures types.List `tfsdk:"compute_features"`
CPUAllocationParameter types.String `tfsdk:"cpu_allocation_parameter"`
CPUAllocationRatio types.Float64 `tfsdk:"cpu_allocation_ratio"`
CreatedBy types.String `tfsdk:"created_by"`
CreatedTime types.Int64 `tfsdk:"created_time"`
DeactivationTime types.Float64 `tfsdk:"deactivation_time"`
DeletedBy types.String `tfsdk:"deleted_by"`
DeletedTime types.Int64 `tfsdk:"deleted_time"`
DisplayName types.String `tfsdk:"displayname"`
GUID types.Int64 `tfsdk:"guid"`
ID types.Int64 `tfsdk:"id"`
Name types.String `tfsdk:"name"`
ResourceLimits *AccountListResourceLimitsModel `tfsdk:"resource_limits"`
ResTypes types.List `tfsdk:"resource_types"`
SendAccessEmails types.Bool `tfsdk:"send_access_emails"`
Status types.String `tfsdk:"status"`
UniqPools types.List `tfsdk:"uniq_pools"`
UpdatedTime types.Int64 `tfsdk:"updated_time"`
Version types.Int64 `tfsdk:"version"`
VINS types.List `tfsdk:"vins"`
}
type AccountListACLModel struct {
Explicit types.Bool `tfsdk:"explicit"`
GUID types.String `tfsdk:"guid"`
Right types.String `tfsdk:"right"`
Status types.String `tfsdk:"status"`
Type types.String `tfsdk:"type"`
UserGroupID types.String `tfsdk:"user_group_id"`
}
type AccountListResourceLimitsModel struct {
CuC types.Float64 `tfsdk:"cu_c"`
CuD types.Float64 `tfsdk:"cu_d"`
CuDM types.Float64 `tfsdk:"cu_dm"`
CuI types.Float64 `tfsdk:"cu_i"`
CuM types.Float64 `tfsdk:"cu_m"`
CuNP types.Float64 `tfsdk:"cu_np"`
GPUUnits types.Float64 `tfsdk:"gpu_units"`
}

View File

@@ -0,0 +1,45 @@
package models
import (
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type DataSourceAccountVinsListModel struct {
// optional fields
AccountID types.Int64 `tfsdk:"account_id"`
VinsID types.Int64 `tfsdk:"vins_id"`
Name types.String `tfsdk:"name"`
RGID types.Int64 `tfsdk:"rg_id"`
ExtIp types.String `tfsdk:"ext_ip"`
SortBy types.String `tfsdk:"sort_by"`
Page types.Int64 `tfsdk:"page"`
Size types.Int64 `tfsdk:"size"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
// response fields
Data []ItemVINSModel `tfsdk:"items"`
EntryCount types.Int64 `tfsdk:"entry_count"`
}
type ItemVINSModel struct {
AccountID types.Int64 `tfsdk:"account_id"`
AccountName types.String `tfsdk:"account_name"`
Computes types.Int64 `tfsdk:"computes"`
CreatedBy types.String `tfsdk:"created_by"`
CreatedTime types.Int64 `tfsdk:"created_time"`
DeletedBy types.String `tfsdk:"deleted_by"`
DeletedTime types.Int64 `tfsdk:"deleted_time"`
ExternalIP types.String `tfsdk:"external_ip"`
ExtnetId types.Int64 `tfsdk:"extnet_id"`
FreeIPs types.Int64 `tfsdk:"free_ips"`
ID types.Int64 `tfsdk:"vin_id"`
Name types.String `tfsdk:"vin_name"`
Network types.String `tfsdk:"network"`
PriVNFDevID types.Int64 `tfsdk:"pri_vnf_dev_id"`
RGID types.Int64 `tfsdk:"rg_id"`
RGName types.String `tfsdk:"rg_name"`
Status types.String `tfsdk:"status"`
UpdatedBy types.String `tfsdk:"updated_by"`
UpdatedTime types.Int64 `tfsdk:"updated_time"`
}

View File

@@ -0,0 +1,139 @@
package schemas
import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
)
func MakeSchemaDataSourceAccount() map[string]schema.Attribute {
return map[string]schema.Attribute{
"account_id": schema.Int64Attribute{
Required: true,
},
"dc_location": schema.StringAttribute{
Computed: true,
},
"ckey": schema.StringAttribute{
Computed: true,
},
"acl": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"explicit": schema.BoolAttribute{
Computed: true,
},
"guid": schema.StringAttribute{
Computed: true,
},
"right": schema.StringAttribute{
Computed: true,
},
"status": schema.StringAttribute{
Computed: true,
},
"type": schema.StringAttribute{
Computed: true,
},
"user_group_id": schema.StringAttribute{
Computed: true,
},
},
},
},
"company": schema.StringAttribute{
Computed: true,
},
"companyurl": schema.StringAttribute{
Computed: true,
},
"compute_features": schema.ListAttribute{
Computed: true,
ElementType: types.StringType,
},
"cpu_allocation_parameter": schema.StringAttribute{
Computed: true,
},
"cpu_allocation_ratio": schema.Float64Attribute{
Computed: true,
},
"created_by": schema.StringAttribute{
Computed: true,
},
"created_time": schema.Int64Attribute{
Computed: true,
},
"deactivation_time": schema.Int64Attribute{
Computed: true,
},
"deleted_by": schema.StringAttribute{
Computed: true,
},
"deleted_time": schema.Int64Attribute{
Computed: true,
},
"displayname": schema.StringAttribute{
Computed: true,
},
"guid": schema.Int64Attribute{
Computed: true,
},
"id": schema.Int64Attribute{
Computed: true,
},
"name": schema.StringAttribute{
Computed: true,
},
"resource_limits": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"cu_c": schema.Float64Attribute{
Computed: true,
},
"cu_d": schema.Float64Attribute{
Computed: true,
},
"cu_dm": schema.Float64Attribute{
Computed: true,
},
"cu_i": schema.Float64Attribute{
Computed: true,
},
"cu_m": schema.Float64Attribute{
Computed: true,
},
"cu_np": schema.Float64Attribute{
Computed: true,
},
"gpu_units": schema.Float64Attribute{
Computed: true,
},
},
},
"resource_types": schema.ListAttribute{
Computed: true,
ElementType: types.StringType,
},
"send_access_emails": schema.BoolAttribute{
Computed: true,
},
"status": schema.StringAttribute{
Computed: true,
},
"uniq_pools": schema.ListAttribute{
Computed: true,
ElementType: types.StringType,
},
"updated_time": schema.Int64Attribute{
Computed: true,
},
"version": schema.Int64Attribute{
Computed: true,
},
"vins": schema.ListAttribute{
Computed: true,
ElementType: types.Int64Type,
},
}
}

View File

@@ -0,0 +1,177 @@
package schemas
import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
)
func MakeSchemaDataSourceAccountList() map[string]schema.Attribute {
return map[string]schema.Attribute{
// optional attributes
"by_id": schema.Int64Attribute{
Optional: true,
Description: "filter by id",
},
"name": schema.StringAttribute{
Optional: true,
Description: "filter by name",
},
"acl": schema.StringAttribute{
Optional: true,
Description: "filter by acl",
},
"status": schema.StringAttribute{
Computed: true,
},
"page": schema.Int64Attribute{
Optional: true,
Description: "page number",
},
"size": schema.Int64Attribute{
Optional: true,
Description: "page size",
},
"sort_by": schema.StringAttribute{
Optional: true,
Description: "sort by one of supported fields, format +|-(field)",
},
"items": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"dc_location": schema.StringAttribute{
Computed: true,
},
"ckey": schema.StringAttribute{
Computed: true,
},
"acl": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"explicit": schema.BoolAttribute{
Computed: true,
},
"guid": schema.StringAttribute{
Computed: true,
},
"right": schema.StringAttribute{
Computed: true,
},
"status": schema.StringAttribute{
Computed: true,
},
"type": schema.StringAttribute{
Computed: true,
},
"user_group_id": schema.StringAttribute{
Computed: true,
},
},
},
},
"company": schema.StringAttribute{
Computed: true,
},
"companyurl": schema.StringAttribute{
Computed: true,
},
"compute_features": schema.ListAttribute{
Computed: true,
ElementType: types.StringType,
},
"cpu_allocation_parameter": schema.StringAttribute{
Computed: true,
},
"cpu_allocation_ratio": schema.Float64Attribute{
Computed: true,
},
"created_by": schema.StringAttribute{
Computed: true,
},
"created_time": schema.Int64Attribute{
Computed: true,
},
"deactivation_time": schema.Int64Attribute{
Computed: true,
},
"deleted_by": schema.StringAttribute{
Computed: true,
},
"deleted_time": schema.Int64Attribute{
Computed: true,
},
"displayname": schema.StringAttribute{
Computed: true,
},
"guid": schema.Int64Attribute{
Computed: true,
},
"id": schema.Int64Attribute{
Computed: true,
},
"name": schema.StringAttribute{
Computed: true,
},
"resource_limits": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"cu_c": schema.Float64Attribute{
Computed: true,
},
"cu_d": schema.Float64Attribute{
Computed: true,
},
"cu_dm": schema.Float64Attribute{
Computed: true,
},
"cu_i": schema.Float64Attribute{
Computed: true,
},
"cu_m": schema.Float64Attribute{
Computed: true,
},
"cu_np": schema.Float64Attribute{
Computed: true,
},
"gpu_units": schema.Float64Attribute{
Computed: true,
},
},
},
"resource_types": schema.ListAttribute{
Computed: true,
ElementType: types.StringType,
},
"send_access_emails": schema.BoolAttribute{
Computed: true,
},
"status": schema.StringAttribute{
Computed: true,
},
"uniq_pools": schema.ListAttribute{
Computed: true,
ElementType: types.StringType,
},
"updated_time": schema.Int64Attribute{
Computed: true,
},
"version": schema.Int64Attribute{
Computed: true,
},
"vins": schema.ListAttribute{
Computed: true,
ElementType: types.Int64Type,
},
},
},
},
"id": schema.StringAttribute{
Computed: true,
},
"entry_count": schema.Int64Attribute{
Computed: true,
},
}
}

View File

@@ -0,0 +1,102 @@
package schemas
import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
)
func MakeSchemaDataSourceAccountVinsList() map[string]schema.Attribute {
return map[string]schema.Attribute{
"account_id": schema.Int64Attribute{
Required: true,
},
"vins_id": schema.Int64Attribute{
Optional: true,
},
"name": schema.StringAttribute{
Optional: true,
},
"rg_id": schema.Int64Attribute{
Optional: true,
},
"ext_ip": schema.StringAttribute{
Optional: true,
},
"sort_by": schema.StringAttribute{
Optional: true,
},
"page": schema.Int64Attribute{
Optional: true,
},
"size": schema.Int64Attribute{
Optional: true,
},
"items": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"account_id": schema.Int64Attribute{
Computed: true,
},
"account_name": schema.StringAttribute{
Computed: true,
},
"computes": schema.Int64Attribute{
Computed: true,
},
"created_by": schema.StringAttribute{
Computed: true,
},
"created_time": schema.Int64Attribute{
Computed: true,
},
"deleted_by": schema.StringAttribute{
Computed: true,
},
"deleted_time": schema.Int64Attribute{
Computed: true,
},
"external_ip": schema.StringAttribute{
Computed: true,
},
"extnet_id": schema.Int64Attribute{
Computed: true,
},
"free_ips": schema.Int64Attribute{
Computed: true,
},
"vin_id": schema.Int64Attribute{
Computed: true,
},
"vin_name": schema.StringAttribute{
Computed: true,
},
"network": schema.StringAttribute{
Computed: true,
},
"pri_vnf_dev_id": schema.Int64Attribute{
Computed: true,
},
"rg_id": schema.Int64Attribute{
Computed: true,
},
"rg_name": schema.StringAttribute{
Computed: true,
},
"status": schema.StringAttribute{
Computed: true,
},
"updated_by": schema.StringAttribute{
Computed: true,
},
"updated_time": schema.Int64Attribute{
Computed: true,
},
},
},
},
"entry_count": schema.Int64Attribute{
Computed: true,
},
}
}

View File

@@ -0,0 +1,24 @@
package utilities
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-log/tflog"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/account"
)
func AccountDataSourceCheckPresence(ctx context.Context, accountId uint64, c *decort.DecortClient) (*account.InfoAccount, error) {
tflog.Info(ctx, fmt.Sprintf("CbAccountDataSourceCheckPresence: Get info about account with ID - %v", accountId))
recordAccount, err := c.CloudBroker().Account().Get(ctx, account.GetRequest{AccountID: accountId})
if err != nil {
return nil, fmt.Errorf("cannot get info about account with error: %w", err)
}
tflog.Info(ctx, "CbAccountDataSourceCheckPresence: response from CloudBroker().Account().Get",
map[string]any{"account_id": accountId, "response": recordAccount})
return &recordAccount.InfoAccount, err
}

View File

@@ -0,0 +1,47 @@
package utilities
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-log/tflog"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/account"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/models"
)
func AccountListDataSourceCheckPresence(ctx context.Context, plan *models.DataSourceAccountListModel, c *decort.DecortClient) (*account.ListAccounts, error) {
tflog.Info(ctx, "AccountListDataSourceCheckPresence: Get info about list accounts")
req := account.ListRequest{}
if !plan.ByID.IsNull() {
req.ByID = uint64(plan.ByID.ValueInt64())
}
if !plan.Name.IsNull() {
req.Name = plan.Name.ValueString()
}
if !plan.ACL.IsNull() {
req.ACL = plan.ACL.ValueString()
}
if !plan.Status.IsNull() {
req.Status = plan.Status.ValueString()
}
if !plan.Page.IsNull() {
req.Page = uint64(plan.Page.ValueInt64())
}
if !plan.Size.IsNull() {
req.Size = uint64(plan.Size.ValueInt64())
}
if !plan.SortBy.IsNull() {
req.SortBy = plan.SortBy.ValueString()
}
tflog.Info(ctx, "AccountListDataSourceCheckPresence: before call CloudBroker().Account().List", map[string]any{"req": req})
listAccounts, err := c.CloudBroker().Account().List(ctx, req)
if err != nil {
return nil, fmt.Errorf("cannot get info about accounts with error: %w", err)
}
tflog.Info(ctx, "AccountListDataSourceCheckPresence: response from CloudBroker().Account().List")
return listAccounts, err
}

View File

@@ -0,0 +1,52 @@
package utilities
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-log/tflog"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/account"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/models"
)
func AccountVinsListCheck(ctx context.Context, plan *models.DataSourceAccountVinsListModel, c *decort.DecortClient) (*account.ListVINS, error) {
tflog.Info(ctx, "AccountVinsListCheck: Get info about list vins")
vinsListReq := account.ListVINSRequest{}
if !plan.AccountID.IsNull() {
vinsListReq.AccountID = uint64(plan.AccountID.ValueInt64())
}
if !plan.VinsID.IsNull() {
vinsListReq.VINSID = uint64(plan.VinsID.ValueInt64())
}
if !plan.Name.IsNull() {
vinsListReq.Name = plan.Name.ValueString()
}
if !plan.RGID.IsNull() {
vinsListReq.RGID = uint64(plan.RGID.ValueInt64())
}
if !plan.ExtIp.IsNull() {
vinsListReq.ExtIP = plan.ExtIp.ValueString()
}
if !plan.SortBy.IsNull() {
vinsListReq.SortBy = plan.SortBy.ValueString()
}
if !plan.Page.IsNull() {
vinsListReq.Page = uint64(plan.Page.ValueInt64())
}
if !plan.Size.IsNull() {
vinsListReq.Size = uint64(plan.Size.ValueInt64())
}
tflog.Info(ctx, "AccountVinsListCheck: before call CloudBroker().Account().ListVINS", map[string]any{"req": vinsListReq})
vinsList, err := c.CloudBroker().Account().ListVINS(ctx, vinsListReq)
if err != nil {
return nil, fmt.Errorf("cannot get info about vins list with error: %w", err)
}
tflog.Info(ctx, "AccountVinsListCheck: response from CloudBroker().Account().ListVINS")
return vinsList, err
}

View File

@@ -0,0 +1,91 @@
package cbStack
import (
"context"
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-log/tflog"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/stack/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/stack/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/stack/schemas"
)
// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &dataSourceStack{}
)
func NewDataSourceStack() datasource.DataSource {
return &dataSourceStack{}
}
// dataSourceStack is the data source implementation.
type dataSourceStack struct {
client *decort.DecortClient
}
func (d *dataSourceStack) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
// Read Terraform configuration data into the model
var state models.InfoStackModel
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read DataSourceStackModel: Error get state")
return
}
StackId := uint64(state.StackID.ValueInt64())
tflog.Info(ctx, "Read DataSourceStackModel: got state successfully", map[string]any{"stack_id": StackId})
// Set timeouts
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout30s)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read DataSourceStackModel: Error set timeout")
return
}
tflog.Info(ctx, "Read DataSourceStackModel: set timeouts successfully", map[string]any{
"stack_id": StackId,
"readTimeout": readTimeout})
ctx, cancel := context.WithTimeout(ctx, readTimeout)
defer cancel()
// Map response body to schema
resp.Diagnostics.Append(flattens.StackDataSource(ctx, &state, d.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read DataSourceStackModel: Error flatten data source Stack")
return
}
// Set refreshed state
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read DataSourceStackModel: Error set state")
return
}
tflog.Info(ctx, "End read DataSourceStackModel", map[string]any{"stack_id": StackId})
}
func (d *dataSourceStack) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: schemas.MakeSchemaDataSourceStack(),
Blocks: map[string]schema.Block{
"timeouts": timeouts.Block(ctx),
},
}
}
func (d *dataSourceStack) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_cb_stack"
}
// Configure adds the provider configured client to the data source.
func (d *dataSourceStack) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
tflog.Info(ctx, "Get Configure DataSourceStackModel")
d.client = client.DataSource(ctx, &req, resp)
tflog.Info(ctx, "Getting Configure DataSourceStackModel successfully")
}

View File

@@ -0,0 +1,89 @@
package cbStack
import (
"context"
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-log/tflog"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/stack/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/stack/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/stack/schemas"
)
// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &dataSourceStackList{}
)
func NewDataSourceStackList() datasource.DataSource {
return &dataSourceStackList{}
}
// dataSourceStackList is the data source implementation.
type dataSourceStackList struct {
client *decort.DecortClient
}
func (d *dataSourceStackList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
// Read Terraform configuration data into the model
var state models.DataSourceStackListModel
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceStackListModel: Error get state")
return
}
tflog.Info(ctx, "Read dataSourceStackListModel: got state successfully")
// Set timeouts
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout30s)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceStackListModel: Error set timeout")
return
}
tflog.Info(ctx, "Read dataSourceStackListModel: set timeouts successfully", map[string]any{
"readTimeout": readTimeout})
ctx, cancel := context.WithTimeout(ctx, readTimeout)
defer cancel()
// Map response body to schema
resp.Diagnostics.Append(flattens.StackListDataSource(ctx, &state, d.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceStackListModel: Error flatten data source Stack")
return
}
// Set refreshed state
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceStackListModel: Error set state")
return
}
tflog.Info(ctx, "End read dataSourceStackListModel")
}
func (d *dataSourceStackList) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: schemas.MakeSchemaDataSourceStackList(),
Blocks: map[string]schema.Block{
"timeouts": timeouts.Block(ctx),
},
}
}
func (d *dataSourceStackList) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_cb_stack_list"
}
// Configure adds the provider configured client to the data source.
func (d *dataSourceStackList) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
tflog.Info(ctx, "Get Configure dataSourceStackListModel")
d.client = client.DataSource(ctx, &req, resp)
tflog.Info(ctx, "Getting Configure dataSourceStackListModel successfully")
}

View File

@@ -0,0 +1,103 @@
package flattens
import (
"context"
"fmt"
"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/stack/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/stack/utilities"
)
// StackDataSource flattens data source for Stack.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func StackDataSource(ctx context.Context, state *models.InfoStackModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.StackDataSource")
diags := diag.Diagnostics{}
ID := uint64(state.StackID.ValueInt64())
recordStack, err := utilities.StackDataSourceCheckPresence(ctx, ID, c)
if err != nil {
diags.AddError(fmt.Sprintf("Cannot get info about Stack with ID %v", ID), err.Error())
return diags
}
tflog.Info(ctx, "flattens.StackDataSource: before flatten", map[string]any{"stack_id": ID, "recordStack": recordStack})
*state = models.InfoStackModel{
StackID: state.StackID,
Timeouts: state.Timeouts,
Ckey: types.StringValue(recordStack.Ckey),
Meta: flattens.FlattenSimpleTypeToList(ctx, types.StringType, recordStack.Meta),
APIURL: types.StringValue(recordStack.APIURL),
Apikey: types.StringValue(recordStack.Apikey),
AppID: types.StringValue(recordStack.AppID),
CPUAllocationRatio: types.Float64Value(recordStack.CPUAllocationRatio),
Description: types.StringValue(recordStack.Description),
Descr: types.StringValue(recordStack.Descr),
Drivers: flattens.FlattenSimpleTypeToList(ctx, types.StringType, recordStack.Drivers),
Eco: types.StringValue(flattenEco(recordStack.Eco)),
Error: types.Int64Value(int64(recordStack.Error)),
GID: types.Int64Value(int64(recordStack.GID)),
GUID: types.Int64Value(int64(recordStack.GUID)),
Images: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, recordStack.Images),
Login: types.StringValue(recordStack.Login),
MemAllocationRatio: types.Float64Value(recordStack.MemAllocationRatio),
Name: types.StringValue(recordStack.Name),
Password: types.StringValue(recordStack.Password),
ReferenceID: types.StringValue(recordStack.ReferenceID),
Status: types.StringValue(recordStack.Status),
Type: types.StringValue(recordStack.Type),
}
packages := models.PackagesModel{}
packages.LibvirtBin = &models.LibvirtBinModel{
InstalledSize: types.StringValue(recordStack.Packages.LibvirtBin.InstalledSize),
Ver: types.StringValue(recordStack.Packages.LibvirtBin.Ver),
}
packages.LibvirtDaemon = &models.LibvirtDaemonModel{
InstalledSize: types.StringValue(recordStack.Packages.LibvirtDaemon.InstalledSize),
Ver: types.StringValue(recordStack.Packages.LibvirtDaemon.Ver),
}
packages.Lvm2Lockd = &models.Lvm2LockdModel{
InstalledSize: types.StringValue(recordStack.Packages.Lvm2Lockd.InstalledSize),
Ver: types.StringValue(recordStack.Packages.Lvm2Lockd.Ver),
}
packages.OpenvswitchCommon = &models.OpenvswitchCommonModel{
InstalledSize: types.StringValue(recordStack.Packages.OpenvswitchCommon.InstalledSize),
Ver: types.StringValue(recordStack.Packages.OpenvswitchCommon.Ver),
}
packages.OpenvswitchSwitch = &models.OpenvswitchSwitchModel{
InstalledSize: types.StringValue(recordStack.Packages.OpenvswitchSwitch.InstalledSize),
Ver: types.StringValue(recordStack.Packages.OpenvswitchSwitch.Ver),
}
packages.QemuSystemX86 = &models.QemuSystemX86Model{
InstalledSize: types.StringValue(recordStack.Packages.QemuSystemX86.InstalledSize),
Ver: types.StringValue(recordStack.Packages.QemuSystemX86.Ver),
}
packages.Sanlock = &models.SanlockModel{
InstalledSize: types.StringValue(recordStack.Packages.Sanlock.InstalledSize),
Ver: types.StringValue(recordStack.Packages.Sanlock.Ver),
}
state.Packages = &packages
tflog.Info(ctx, "flattens.StackDataSource: after flatten", map[string]any{"stack_id": state.StackID.ValueInt64()})
tflog.Info(ctx, "End flattens.StackDataSource", map[string]any{"stack_id": state.StackID.ValueInt64()})
return nil
}

View File

@@ -0,0 +1,120 @@
package flattens
import (
"context"
"fmt"
"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/stack/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/stack/utilities"
)
// StackListDataSource flattens data source for Stacks list.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func StackListDataSource(ctx context.Context, state *models.DataSourceStackListModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.StackListDataSource")
diags := diag.Diagnostics{}
record, err := utilities.StackListDataSourceCheckPresence(ctx, state, c)
if err != nil {
diags.AddError(fmt.Sprintf("Cannot get info about Stacks"), err.Error())
return diags
}
tflog.Info(ctx, "flattens.StackListDataSource: before flatten", map[string]any{"recordStacks": record})
*state = models.DataSourceStackListModel{
ByID: state.ByID,
Name: state.Name,
Type: state.Type,
Status: state.Status,
SortBy: state.SortBy,
Page: state.Page,
Size: state.Size,
Timeouts: state.Timeouts,
EntryCount: types.Int64Value(int64(record.EntryCount)),
}
items := make([]models.InfoStackListModel, 0, len(record.Data))
for _, stack := range record.Data {
item := models.InfoStackListModel{
StackID: types.Int64Value(int64(stack.ID)),
Ckey: types.StringValue(stack.Ckey),
Meta: flattens.FlattenSimpleTypeToList(ctx, types.StringType, stack.Meta),
APIURL: types.StringValue(stack.APIURL),
Apikey: types.StringValue(stack.Apikey),
AppID: types.StringValue(stack.AppID),
CPUAllocationRatio: types.Float64Value(stack.CPUAllocationRatio),
Description: types.StringValue(stack.Description),
Descr: types.StringValue(stack.Descr),
Drivers: flattens.FlattenSimpleTypeToList(ctx, types.StringType, stack.Drivers),
Eco: types.StringValue(flattenEco(stack.Eco)),
Error: types.Int64Value(int64(stack.Error)),
GID: types.Int64Value(int64(stack.GID)),
GUID: types.Int64Value(int64(stack.GUID)),
Images: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, stack.Images),
Login: types.StringValue(stack.Login),
MemAllocationRatio: types.Float64Value(stack.MemAllocationRatio),
Name: types.StringValue(stack.Name),
Password: types.StringValue(stack.Password),
ReferenceID: types.StringValue(stack.ReferenceID),
Status: types.StringValue(stack.Status),
Type: types.StringValue(stack.Type),
}
packages := models.PackagesStackListModel{}
packages.LibvirtBin = &models.LibvirtBinStackListModel{
InstalledSize: types.StringValue(stack.Packages.LibvirtBin.InstalledSize),
Ver: types.StringValue(stack.Packages.LibvirtBin.Ver),
}
packages.LibvirtDaemon = &models.LibvirtDaemonStackListModel{
InstalledSize: types.StringValue(stack.Packages.LibvirtDaemon.InstalledSize),
Ver: types.StringValue(stack.Packages.LibvirtDaemon.Ver),
}
packages.Lvm2Lockd = &models.Lvm2LockdStackListModel{
InstalledSize: types.StringValue(stack.Packages.Lvm2Lockd.InstalledSize),
Ver: types.StringValue(stack.Packages.Lvm2Lockd.Ver),
}
packages.OpenvswitchCommon = &models.OpenvswitchCommonStackListModel{
InstalledSize: types.StringValue(stack.Packages.OpenvswitchCommon.InstalledSize),
Ver: types.StringValue(stack.Packages.OpenvswitchCommon.Ver),
}
packages.OpenvswitchSwitch = &models.OpenvswitchSwitchStackListModel{
InstalledSize: types.StringValue(stack.Packages.OpenvswitchSwitch.InstalledSize),
Ver: types.StringValue(stack.Packages.OpenvswitchSwitch.Ver),
}
packages.QemuSystemX86 = &models.QemuSystemX86StackListModel{
InstalledSize: types.StringValue(stack.Packages.QemuSystemX86.InstalledSize),
Ver: types.StringValue(stack.Packages.QemuSystemX86.Ver),
}
packages.Sanlock = &models.SanlockStackListModel{
InstalledSize: types.StringValue(stack.Packages.Sanlock.InstalledSize),
Ver: types.StringValue(stack.Packages.Sanlock.Ver),
}
item.Packages = &packages
items = append(items, item)
}
state.Items = items
tflog.Info(ctx, "flattens.StackListDataSource: after flatten")
tflog.Info(ctx, "End flattens.StackListDataSource")
return nil
}

View File

@@ -0,0 +1,18 @@
package flattens
import "strconv"
func flattenEco(m interface{}) string {
switch d := m.(type) {
case string:
return d
case int:
return strconv.Itoa(d)
case int64:
return strconv.FormatInt(d, 10)
case float64:
return strconv.FormatInt(int64(d), 10)
default:
return ""
}
}

View File

@@ -0,0 +1,81 @@
package models
import (
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type InfoStackModel struct {
//required and optional fields
StackID types.Int64 `tfsdk:"stack_id"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
//computed fields
Ckey types.String `tfsdk:"ckey"`
Meta types.List `tfsdk:"meta"`
APIURL types.String `tfsdk:"api_url"`
Apikey types.String `tfsdk:"api_key"`
AppID types.String `tfsdk:"app_id"`
CPUAllocationRatio types.Float64 `tfsdk:"cpu_allocation_ratio"`
Description types.String `tfsdk:"description"`
Descr types.String `tfsdk:"descr"`
Drivers types.List `tfsdk:"drivers"`
Eco types.String `tfsdk:"eco"`
Error types.Int64 `tfsdk:"error"`
GID types.Int64 `tfsdk:"gid"`
GUID types.Int64 `tfsdk:"guid"`
Images types.List `tfsdk:"images"`
Login types.String `tfsdk:"login"`
MemAllocationRatio types.Float64 `tfsdk:"mem_allocation_ratio"`
Name types.String `tfsdk:"name"`
Packages *PackagesModel `tfsdk:"packages"`
Password types.String `tfsdk:"passwd"`
ReferenceID types.String `tfsdk:"reference_id"`
Status types.String `tfsdk:"status"`
Type types.String `tfsdk:"type"`
}
type PackagesModel struct {
LibvirtBin *LibvirtBinModel `tfsdk:"libvirt_bin"`
LibvirtDaemon *LibvirtDaemonModel `tfsdk:"libvirt_daemon"`
Lvm2Lockd *Lvm2LockdModel `tfsdk:"lvm2_lockd"`
OpenvswitchCommon *OpenvswitchCommonModel `tfsdk:"openvswitch_common"`
OpenvswitchSwitch *OpenvswitchSwitchModel `tfsdk:"openvswitch_switch"`
QemuSystemX86 *QemuSystemX86Model `tfsdk:"qemu_system_x86"`
Sanlock *SanlockModel `tfsdk:"sanlock"`
}
type LibvirtBinModel struct {
InstalledSize types.String `tfsdk:"installed_size"`
Ver types.String `tfsdk:"ver"`
}
type LibvirtDaemonModel struct {
InstalledSize types.String `tfsdk:"installed_size"`
Ver types.String `tfsdk:"ver"`
}
type Lvm2LockdModel struct {
InstalledSize types.String `tfsdk:"installed_size"`
Ver types.String `tfsdk:"ver"`
}
type OpenvswitchCommonModel struct {
InstalledSize types.String `tfsdk:"installed_size"`
Ver types.String `tfsdk:"ver"`
}
type OpenvswitchSwitchModel struct {
InstalledSize types.String `tfsdk:"installed_size"`
Ver types.String `tfsdk:"ver"`
}
type QemuSystemX86Model struct {
InstalledSize types.String `tfsdk:"installed_size"`
Ver types.String `tfsdk:"ver"`
}
type SanlockModel struct {
InstalledSize types.String `tfsdk:"installed_size"`
Ver types.String `tfsdk:"ver"`
}

View File

@@ -0,0 +1,93 @@
package models
import (
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type DataSourceStackListModel struct {
// optional fields
ByID types.Int64 `tfsdk:"by_id"`
Name types.String `tfsdk:"name"`
Type types.String `tfsdk:"type"`
Status types.String `tfsdk:"status"`
SortBy types.String `tfsdk:"sort_by"`
Page types.Int64 `tfsdk:"page"`
Size types.Int64 `tfsdk:"size"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
// response fields
Items []InfoStackListModel `tfsdk:"items"`
EntryCount types.Int64 `tfsdk:"entry_count"`
}
type InfoStackListModel struct {
StackID types.Int64 `tfsdk:"stack_id"`
Ckey types.String `tfsdk:"ckey"`
Meta types.List `tfsdk:"meta"`
APIURL types.String `tfsdk:"api_url"`
Apikey types.String `tfsdk:"api_key"`
AppID types.String `tfsdk:"app_id"`
CPUAllocationRatio types.Float64 `tfsdk:"cpu_allocation_ratio"`
Description types.String `tfsdk:"description"`
Descr types.String `tfsdk:"descr"`
Drivers types.List `tfsdk:"drivers"`
Eco types.String `tfsdk:"eco"`
Error types.Int64 `tfsdk:"error"`
GID types.Int64 `tfsdk:"gid"`
GUID types.Int64 `tfsdk:"guid"`
Images types.List `tfsdk:"images"`
Login types.String `tfsdk:"login"`
MemAllocationRatio types.Float64 `tfsdk:"mem_allocation_ratio"`
Name types.String `tfsdk:"name"`
Packages *PackagesStackListModel `tfsdk:"packages"`
Password types.String `tfsdk:"passwd"`
ReferenceID types.String `tfsdk:"reference_id"`
Status types.String `tfsdk:"status"`
Type types.String `tfsdk:"type"`
}
type PackagesStackListModel struct {
LibvirtBin *LibvirtBinStackListModel `tfsdk:"libvirt_bin"`
LibvirtDaemon *LibvirtDaemonStackListModel `tfsdk:"libvirt_daemon"`
Lvm2Lockd *Lvm2LockdStackListModel `tfsdk:"lvm2_lockd"`
OpenvswitchCommon *OpenvswitchCommonStackListModel `tfsdk:"openvswitch_common"`
OpenvswitchSwitch *OpenvswitchSwitchStackListModel `tfsdk:"openvswitch_switch"`
QemuSystemX86 *QemuSystemX86StackListModel `tfsdk:"qemu_system_x86"`
Sanlock *SanlockStackListModel `tfsdk:"sanlock"`
}
type LibvirtBinStackListModel struct {
InstalledSize types.String `tfsdk:"installed_size"`
Ver types.String `tfsdk:"ver"`
}
type LibvirtDaemonStackListModel struct {
InstalledSize types.String `tfsdk:"installed_size"`
Ver types.String `tfsdk:"ver"`
}
type Lvm2LockdStackListModel struct {
InstalledSize types.String `tfsdk:"installed_size"`
Ver types.String `tfsdk:"ver"`
}
type OpenvswitchCommonStackListModel struct {
InstalledSize types.String `tfsdk:"installed_size"`
Ver types.String `tfsdk:"ver"`
}
type OpenvswitchSwitchStackListModel struct {
InstalledSize types.String `tfsdk:"installed_size"`
Ver types.String `tfsdk:"ver"`
}
type QemuSystemX86StackListModel struct {
InstalledSize types.String `tfsdk:"installed_size"`
Ver types.String `tfsdk:"ver"`
}
type SanlockStackListModel struct {
InstalledSize types.String `tfsdk:"installed_size"`
Ver types.String `tfsdk:"ver"`
}

View File

@@ -0,0 +1,163 @@
package schemas
import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
)
func MakeSchemaDataSourceStack() map[string]schema.Attribute {
return map[string]schema.Attribute{
"stack_id": schema.Int64Attribute{
Required: true,
},
"ckey": schema.StringAttribute{
Computed: true,
},
"meta": schema.ListAttribute{
Computed: true,
ElementType: types.StringType,
},
"api_url": schema.StringAttribute{
Computed: true,
},
"api_key": schema.StringAttribute{
Computed: true,
},
"app_id": schema.StringAttribute{
Computed: true,
},
"cpu_allocation_ratio": schema.Float64Attribute{
Computed: true,
},
"description": schema.StringAttribute{
Computed: true,
},
"descr": schema.StringAttribute{
Computed: true,
},
"drivers": schema.ListAttribute{
Computed: true,
ElementType: types.StringType,
},
"eco": schema.StringAttribute{
Computed: true,
},
"error": schema.Int64Attribute{
Computed: true,
},
"gid": schema.Int64Attribute{
Computed: true,
},
"guid": schema.Int64Attribute{
Computed: true,
},
"images": schema.ListAttribute{
Computed: true,
ElementType: types.Int64Type,
},
"login": schema.StringAttribute{
Computed: true,
},
"mem_allocation_ratio": schema.Float64Attribute{
Computed: true,
},
"name": schema.StringAttribute{
Computed: true,
},
"packages": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"libvirt_bin": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"installed_size": schema.StringAttribute{
Computed: true,
},
"ver": schema.StringAttribute{
Computed: true,
},
},
},
"libvirt_daemon": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"installed_size": schema.StringAttribute{
Computed: true,
},
"ver": schema.StringAttribute{
Computed: true,
},
},
},
"lvm2_lockd": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"installed_size": schema.StringAttribute{
Computed: true,
},
"ver": schema.StringAttribute{
Computed: true,
},
},
},
"openvswitch_common": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"installed_size": schema.StringAttribute{
Computed: true,
},
"ver": schema.StringAttribute{
Computed: true,
},
},
},
"openvswitch_switch": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"installed_size": schema.StringAttribute{
Computed: true,
},
"ver": schema.StringAttribute{
Computed: true,
},
},
},
"qemu_system_x86": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"installed_size": schema.StringAttribute{
Computed: true,
},
"ver": schema.StringAttribute{
Computed: true,
},
},
},
"sanlock": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"installed_size": schema.StringAttribute{
Computed: true,
},
"ver": schema.StringAttribute{
Computed: true,
},
},
},
},
},
"passwd": schema.StringAttribute{
Computed: true,
},
"reference_id": schema.StringAttribute{
Computed: true,
},
"status": schema.StringAttribute{
Computed: true,
},
"type": schema.StringAttribute{
Computed: true,
},
}
}

View File

@@ -0,0 +1,200 @@
package schemas
import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
)
func MakeSchemaDataSourceStackList() map[string]schema.Attribute {
return map[string]schema.Attribute{
// optional attributes
"by_id": schema.Int64Attribute{
Optional: true,
Description: "filter by id",
},
"name": schema.StringAttribute{
Optional: true,
Description: "filter by name",
},
"type": schema.StringAttribute{
Computed: true,
},
"status": schema.StringAttribute{
Computed: true,
},
"sort_by": schema.StringAttribute{
Optional: true,
Description: "sort by one of supported fields, format +|-(field)",
},
"page": schema.Int64Attribute{
Optional: true,
Description: "page number",
},
"size": schema.Int64Attribute{
Optional: true,
Description: "page size",
},
"items": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"stack_id": schema.Int64Attribute{
Required: true,
},
"ckey": schema.StringAttribute{
Computed: true,
},
"meta": schema.ListAttribute{
Computed: true,
ElementType: types.StringType,
},
"api_url": schema.StringAttribute{
Computed: true,
},
"api_key": schema.StringAttribute{
Computed: true,
},
"app_id": schema.StringAttribute{
Computed: true,
},
"cpu_allocation_ratio": schema.Float64Attribute{
Computed: true,
},
"description": schema.StringAttribute{
Computed: true,
},
"descr": schema.StringAttribute{
Computed: true,
},
"drivers": schema.ListAttribute{
Computed: true,
ElementType: types.StringType,
},
"eco": schema.StringAttribute{
Computed: true,
},
"error": schema.Int64Attribute{
Computed: true,
},
"gid": schema.Int64Attribute{
Computed: true,
},
"guid": schema.Int64Attribute{
Computed: true,
},
"images": schema.ListAttribute{
Computed: true,
ElementType: types.Int64Type,
},
"login": schema.StringAttribute{
Computed: true,
},
"mem_allocation_ratio": schema.Float64Attribute{
Computed: true,
},
"name": schema.StringAttribute{
Computed: true,
},
"packages": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"libvirt_bin": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"installed_size": schema.StringAttribute{
Computed: true,
},
"ver": schema.StringAttribute{
Computed: true,
},
},
},
"libvirt_daemon": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"installed_size": schema.StringAttribute{
Computed: true,
},
"ver": schema.StringAttribute{
Computed: true,
},
},
},
"lvm2_lockd": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"installed_size": schema.StringAttribute{
Computed: true,
},
"ver": schema.StringAttribute{
Computed: true,
},
},
},
"openvswitch_common": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"installed_size": schema.StringAttribute{
Computed: true,
},
"ver": schema.StringAttribute{
Computed: true,
},
},
},
"openvswitch_switch": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"installed_size": schema.StringAttribute{
Computed: true,
},
"ver": schema.StringAttribute{
Computed: true,
},
},
},
"qemu_system_x86": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"installed_size": schema.StringAttribute{
Computed: true,
},
"ver": schema.StringAttribute{
Computed: true,
},
},
},
"sanlock": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"installed_size": schema.StringAttribute{
Computed: true,
},
"ver": schema.StringAttribute{
Computed: true,
},
},
},
},
},
"passwd": schema.StringAttribute{
Computed: true,
},
"reference_id": schema.StringAttribute{
Computed: true,
},
"status": schema.StringAttribute{
Computed: true,
},
"type": schema.StringAttribute{
Computed: true,
},
},
},
},
"entry_count": schema.Int64Attribute{
Computed: true,
},
}
}

View File

@@ -0,0 +1,24 @@
package utilities
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-log/tflog"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/stack"
)
func StackDataSourceCheckPresence(ctx context.Context, stackID uint64, c *decort.DecortClient) (*stack.InfoStack, error) {
tflog.Info(ctx, fmt.Sprintf("StackDataSourceCheckPresence: Get info about stack with ID - %v", stackID))
record, err := c.CloudBroker().Stack().Get(ctx, stack.GetRequest{StackId: stackID})
if err != nil {
return nil, fmt.Errorf("cannot get info about stack with error: %w", err)
}
tflog.Info(ctx, "StackDataSourceCheckPresence: response from CloudBroker().Stack().Get",
map[string]any{"stack_id": stackID, "response": record})
return record, err
}

View File

@@ -0,0 +1,47 @@
package utilities
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-log/tflog"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/stack"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/stack/models"
)
func StackListDataSourceCheckPresence(ctx context.Context, plan *models.DataSourceStackListModel, c *decort.DecortClient) (*stack.ListStacks, error) {
tflog.Info(ctx, "StackListDataSourceCheckPresence: Get info about list stacks")
req := stack.ListRequest{}
if !plan.ByID.IsNull() {
req.ByID = uint64(plan.ByID.ValueInt64())
}
if !plan.Name.IsNull() {
req.Name = plan.Name.ValueString()
}
if !plan.Type.IsNull() {
req.Type = plan.Type.ValueString()
}
if !plan.Status.IsNull() {
req.Status = plan.Status.ValueString()
}
if !plan.Page.IsNull() {
req.Page = uint64(plan.Page.ValueInt64())
}
if !plan.Size.IsNull() {
req.Size = uint64(plan.Size.ValueInt64())
}
if !plan.SortBy.IsNull() {
req.SortBy = plan.SortBy.ValueString()
}
tflog.Info(ctx, "StackListDataSourceCheckPresence: before call CloudBroker().Stack().List", map[string]any{"req": req})
listStacks, err := c.CloudBroker().Stack().List(ctx, req)
if err != nil {
return nil, fmt.Errorf("cannot get info about stack with error: %w", err)
}
tflog.Info(ctx, "StackListDataSourceCheckPresence: response from CloudBroker().Stack().List")
return listStacks, err
}