1.0.0
This commit is contained in:
91
internal/service/cloudbroker/stack/data_sourse_stack.go
Normal file
91
internal/service/cloudbroker/stack/data_sourse_stack.go
Normal 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")
|
||||
}
|
||||
89
internal/service/cloudbroker/stack/data_sourse_stack_list.go
Normal file
89
internal/service/cloudbroker/stack/data_sourse_stack_list.go
Normal 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")
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
18
internal/service/cloudbroker/stack/flattens/flatten_eco.go
Normal file
18
internal/service/cloudbroker/stack/flattens/flatten_eco.go
Normal 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 ""
|
||||
}
|
||||
}
|
||||
@@ -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"`
|
||||
}
|
||||
@@ -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"`
|
||||
}
|
||||
@@ -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,
|
||||
},
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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,
|
||||
},
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user