1.0.1
This commit is contained in:
@@ -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 = &dataSourceAccountAuditsList{}
|
||||
)
|
||||
|
||||
func NewDataSourceAccountAuditsList() datasource.DataSource {
|
||||
return &dataSourceAccountAuditsList{}
|
||||
}
|
||||
|
||||
// dataSourceAccountAuditsList is the data source implementation.
|
||||
type dataSourceAccountAuditsList struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountAuditsList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
// Read Terraform configuration data into the model
|
||||
var state models.DataSourceAccountAuditsListModel
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountAuditsList: Error get state")
|
||||
return
|
||||
}
|
||||
accountId := uint64(state.AccountID.ValueInt64())
|
||||
tflog.Info(ctx, "Read dataSourceAccountAuditsList: 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 dataSourceAccountAuditsList: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceAccountAuditsList: 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.AccountAuditsDataSourceList(ctx, &state, d.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountAuditsList: Error flatten")
|
||||
return
|
||||
}
|
||||
|
||||
// Set refreshed state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountAuditsList: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read dataSourceAccountAuditsList", map[string]any{"account_id": accountId})
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountAuditsList) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaDataSourceAccountAuditsList(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountAuditsList) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_cb_account_audits_list"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (d *dataSourceAccountAuditsList) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure dataSourceAccountAuditsList")
|
||||
d.client = client.DataSource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure dataSourceAccountAuditsList successfully")
|
||||
}
|
||||
@@ -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 = &dataSourceAccountAvailableTemplatesListDataSource{}
|
||||
)
|
||||
|
||||
func NewDataSourceAccountAvailableTemplatesListDataSource() datasource.DataSource {
|
||||
return &dataSourceAccountAvailableTemplatesListDataSource{}
|
||||
}
|
||||
|
||||
// dataSourceAccountAvailableTemplatesListDataSource is the data source implementation.
|
||||
type dataSourceAccountAvailableTemplatesListDataSource struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountAvailableTemplatesListDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
// Read Terraform configuration data into the model
|
||||
var state models.DataSourceAccountAvailableTemplatesListModel
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read DataSourceAccountAvailableTemplatesListModel: Error get state")
|
||||
return
|
||||
}
|
||||
accountID := uint64(state.AccountID.ValueInt64())
|
||||
tflog.Info(ctx, "Read DataSourceAccountAvailableTemplatesListModel: 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 DataSourceAccountAvailableTemplatesListModel: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read DataSourceAccountAvailableTemplatesListModel: 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.AccountAvailableTemplatesListDataSource(ctx, &state, d.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read DataSourceAccountAvailableTemplatesListModel: Error flatten data source AccountAvailableTemplatesListDataSource")
|
||||
return
|
||||
}
|
||||
|
||||
// Set refreshed state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read DataSourceAccountAvailableTemplatesListModel: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read DataSourceAccountAvailableTemplatesListModel", map[string]any{"account_id": accountID})
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountAvailableTemplatesListDataSource) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaDataSourceAccountAvailableTemplatesList(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountAvailableTemplatesListDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_cb_account_available_templates_list"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (d *dataSourceAccountAvailableTemplatesListDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure DataSourceAccountAvailableTemplatesListModel")
|
||||
d.client = client.DataSource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure DataSourceAccountAvailableTemplatesListModel successfully")
|
||||
}
|
||||
@@ -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 = &dataSourceAccountComputesList{}
|
||||
)
|
||||
|
||||
func NewDataSourceAccountComputesList() datasource.DataSource {
|
||||
return &dataSourceAccountComputesList{}
|
||||
}
|
||||
|
||||
// NewDataSourceAccountComputesList is the data source implementation.
|
||||
type dataSourceAccountComputesList struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountComputesList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
// Read Terraform configuration data into the model
|
||||
var state models.ListComputesModel
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountComputesList: Error get state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceAccountComputesList: 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 dataSourceAccountComputesList: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceAccountComputesList: 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.AccountComputesListDataSource(ctx, &state, d.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountComputesList: Error flatten data source")
|
||||
return
|
||||
}
|
||||
|
||||
// Set refreshed state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountComputesList: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read dataSourceAccountComputesList")
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountComputesList) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaDataSourceAccountComputesList(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountComputesList) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_cb_account_computes_list"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (d *dataSourceAccountComputesList) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure dataSourceAccountComputesList")
|
||||
d.client = client.DataSource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure dataSourceAccountComputesList successfully")
|
||||
}
|
||||
@@ -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 = &dataSourceAccountDisksList{}
|
||||
)
|
||||
|
||||
func NewDataSourceAccountDisksList() datasource.DataSource {
|
||||
return &dataSourceAccountDisksList{}
|
||||
}
|
||||
|
||||
// dataSourceAccountDisksList is the data source implementation.
|
||||
type dataSourceAccountDisksList struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountDisksList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
// Read Terraform configuration data into the model
|
||||
var state models.DataSourceAccountDisksListModel
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountDisksList: Error get state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceAccountDisksList: 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 dataSourceAccountDisksList: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceAccountDisksList: 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.AccountDisksListDataSource(ctx, &state, d.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountDisksList: Error flatten data source account disks list")
|
||||
return
|
||||
}
|
||||
|
||||
// Set refreshed state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountDisksList: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read dataSourceAccountDisksList")
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountDisksList) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaDataSourceAccountDisksList(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountDisksList) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_cb_account_disks_list"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (d *dataSourceAccountDisksList) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure dataSourceAccountDisksList")
|
||||
d.client = client.DataSource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure dataSourceAccountDisksList successfully")
|
||||
}
|
||||
@@ -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 = &dataSourceAccountFlipgroupsList{}
|
||||
)
|
||||
|
||||
func NewDataSourceAccountFlipgroupsList() datasource.DataSource {
|
||||
return &dataSourceAccountFlipgroupsList{}
|
||||
}
|
||||
|
||||
// dataSourceAccountFlipgroupsList is the data source implementation.
|
||||
type dataSourceAccountFlipgroupsList struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountFlipgroupsList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
// Read Terraform configuration data into the model
|
||||
var state models.DataSourceAccountFlipgroupsListModel
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountFlipgroupsList: Error get state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceAccountFlipgroupsList: 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 dataSourceAccountFlipgroupsList: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceAccountFlipgroupsList: 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.AccountFlipgroupsListDataSource(ctx, &state, d.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountFlipgroupsList: Error flatten data source")
|
||||
return
|
||||
}
|
||||
|
||||
// Set refreshed state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountFlipgroupsList: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read dataSourceAccountFlipgroupsList")
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountFlipgroupsList) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaDataSourceAccountFlipgroupsList(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountFlipgroupsList) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_cb_account_flipgroups_list"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (d *dataSourceAccountFlipgroupsList) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure dataSourceAccountFlipgroupsList")
|
||||
d.client = client.DataSource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure dataSourceAccountFlipgroupsList successfully")
|
||||
}
|
||||
@@ -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 = &dataSourceAccountGetResourceConsumption{}
|
||||
)
|
||||
|
||||
func NewDataSourceAccountGetResourceConsumption() datasource.DataSource {
|
||||
return &dataSourceAccountGetResourceConsumption{}
|
||||
}
|
||||
|
||||
// dataSourceAccountGetResourceConsumption is the data source implementation.
|
||||
type dataSourceAccountGetResourceConsumption struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountGetResourceConsumption) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
// Read Terraform configuration data into the model
|
||||
var state models.AccountGetResourceConsumptionModel
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountGetResourceConsumption: Error get state")
|
||||
return
|
||||
}
|
||||
accountId := uint64(state.AccountID.ValueInt64())
|
||||
tflog.Info(ctx, "Read dataSourceAccountGetResourceConsumption: 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 dataSourceAccountGetResourceConsumption: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceAccountGetResourceConsumption: 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.AccountGetResourceConsumptionDataSource(ctx, &state, d.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountGetResourceConsumption: 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 dataSourceAccountGetResourceConsumption: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read dataSourceAccountGetResourceConsumption", map[string]any{"account_id": accountId})
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountGetResourceConsumption) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaDataSourceAccountGetResourceConsumption(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountGetResourceConsumption) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_cb_account_resource_consumption_get"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (d *dataSourceAccountGetResourceConsumption) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure dataSourceAccountGetResourceConsumption")
|
||||
d.client = client.DataSource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure dataSourceAccountGetResourceConsumption successfully")
|
||||
}
|
||||
@@ -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 = &dataSourceAccountListDeleted{}
|
||||
)
|
||||
|
||||
func NewDataSourceAccountListDeleted() datasource.DataSource {
|
||||
return &dataSourceAccountListDeleted{}
|
||||
}
|
||||
|
||||
// dataSourceAccountListDeleted is the data source implementation.
|
||||
type dataSourceAccountListDeleted struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountListDeleted) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
// Read Terraform configuration data into the model
|
||||
var state models.DataSourceAccountListDeletedModel
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountListDeleted: Error get state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceAccountListDeleted: 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 dataSourceAccountListDeleted: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceAccountListDeleted: 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.AccountListDeletedDataSource(ctx, &state, d.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountListDeleted: Error flatten data source")
|
||||
return
|
||||
}
|
||||
|
||||
// Set refreshed state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountListDeleted: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read dataSourceAccountListDeleted")
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountListDeleted) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaDataSourceAccountListDeleted(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountListDeleted) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_cb_account_list_deleted"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (d *dataSourceAccountListDeleted) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure dataSourceAccountListDeleted")
|
||||
d.client = client.DataSource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure dataSourceAccountListDeleted successfully")
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
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 = &dataSourceAccountGetResourceConsumptionList{}
|
||||
)
|
||||
|
||||
func NewDataSourceAccountGetResourceConsumptionList() datasource.DataSource {
|
||||
return &dataSourceAccountGetResourceConsumptionList{}
|
||||
}
|
||||
|
||||
// dataSourceAccountGetResourceConsumptionList is the data source implementation.
|
||||
type dataSourceAccountGetResourceConsumptionList struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountGetResourceConsumptionList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
// Read Terraform configuration data into the model
|
||||
var state models.AccountGetResourceConsumptionListModel
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountGetResourceConsumptionList: Error get state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceAccountGetResourceConsumptionList: 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 dataSourceAccountGetResourceConsumptionList: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceAccountGetResourceConsumptionList: 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.AccountGetResourceConsumptionList(ctx, &state, d.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountGetResourceConsumptionList: 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 dataSourceAccountGetResourceConsumptionList: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read dataSourceAccountGetResourceConsumptionList")
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountGetResourceConsumptionList) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaDataSourceAccountGetResourceListConsumption(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountGetResourceConsumptionList) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_cb_account_resource_consumption_list"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (d *dataSourceAccountGetResourceConsumptionList) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure dataSourceAccountGetResourceConsumptionList")
|
||||
d.client = client.DataSource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure dataSourceAccountGetResourceConsumptionList successfully")
|
||||
}
|
||||
@@ -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 = &dataSourceAccountRGList{}
|
||||
)
|
||||
|
||||
func NewDataSourceAccountRGList() datasource.DataSource {
|
||||
return &dataSourceAccountRGList{}
|
||||
}
|
||||
|
||||
// dataSourceAccountList is the data source implementation.
|
||||
type dataSourceAccountRGList struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountRGList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
// Read Terraform configuration data into the model
|
||||
var state models.DataSourceAccountRGListModel
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountRGList: Error get state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceAccountRGList: 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 dataSourceAccountRGList: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceAccountRGList: 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.AccountRGListDataSource(ctx, &state, d.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountRGList: Error flatten data source")
|
||||
return
|
||||
}
|
||||
|
||||
// Set refreshed state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountRGList: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read dataSourceAccountRGList")
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountRGList) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaDataSourceAccountRGList(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountRGList) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_cb_account_rg_list"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (d *dataSourceAccountRGList) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure dataSourceAccountRGList")
|
||||
d.client = client.DataSource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure dataSourceAccountRGList successfully")
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/utilities"
|
||||
)
|
||||
|
||||
// AccountAuditsDataSourceList flattens data source for account audits.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func AccountAuditsDataSourceList(ctx context.Context, state *models.DataSourceAccountAuditsListModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.AccountAuditsDataSourceList")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
accountId := uint64(state.AccountID.ValueInt64())
|
||||
|
||||
auditsList, err := utilities.AccountAuditsListDataSourceCheckPresence(ctx, accountId, c)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about account audits with account ID %v", accountId), err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountAuditsDataSourceList: before flatten", map[string]any{"account_id": accountId})
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceAccountAuditsListModel{
|
||||
AccountID: state.AccountID,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
}
|
||||
|
||||
items := make([]models.ItemAuditModel, 0, len(*auditsList))
|
||||
for _, item := range *auditsList {
|
||||
i := models.ItemAuditModel{
|
||||
Call: types.StringValue(item.Call),
|
||||
ResponseTime: types.Float64Value(item.ResponseTime),
|
||||
StatusCode: types.Int64Value(int64(item.StatusCode)),
|
||||
Timestamp: types.Float64Value(item.Timestamp),
|
||||
User: types.StringValue(item.User),
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
state.Items = items
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountAuditsDataSourceList: after flatten", map[string]any{"account_id": state.Id.ValueString()})
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountAuditsDataSourceList", map[string]any{"account_id": state.Id.ValueString()})
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
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/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"
|
||||
)
|
||||
|
||||
// AccountAvailableTemplatesListDataSource flattens data source for templates list.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func AccountAvailableTemplatesListDataSource(ctx context.Context, state *models.DataSourceAccountAvailableTemplatesListModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.AccountAvailableTemplatesListDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
templatesList, err := utilities.AccountAvailableTemplatesListDataSourceCheckPresence(ctx, uint64(state.AccountID.ValueInt64()), c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about templates list", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountAvailableTemplatesListDataSource: before flatten")
|
||||
|
||||
*state = models.DataSourceAccountAvailableTemplatesListModel{
|
||||
AccountID: state.AccountID,
|
||||
Timeouts: state.Timeouts,
|
||||
Items: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, templatesList),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountAvailableTemplatesListDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountAvailableTemplatesListDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// AccountComputesListDataSource flattens data source for account computes list.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func AccountComputesListDataSource(ctx context.Context, state *models.ListComputesModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.AccountComputesListDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
cList, err := utilities.AccountComputesListDataSourceCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about computes list", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountComputesListDataSource: before flatten")
|
||||
|
||||
*state = models.ListComputesModel{
|
||||
AccountID: state.AccountID,
|
||||
Name: state.Name,
|
||||
RGName: state.RGName,
|
||||
RGID: state.RGID,
|
||||
TechStatus: state.TechStatus,
|
||||
IpAddress: state.IpAddress,
|
||||
ExtNetName: state.ExtNetName,
|
||||
ExtNetID: state.ExtNetID,
|
||||
SortBy: state.SortBy,
|
||||
Page: state.Page,
|
||||
Size: state.Size,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
EntryCount: types.Int64Value(int64(cList.EntryCount)),
|
||||
}
|
||||
|
||||
data := make([]models.ItemComputeModel, 0, len(cList.Data))
|
||||
|
||||
for _, v := range cList.Data {
|
||||
item := models.ItemComputeModel{
|
||||
AccountID: types.Int64Value(int64(v.AccountID)),
|
||||
AccountName: types.StringValue(v.AccountName),
|
||||
CPUs: types.Int64Value(int64(v.CPUs)),
|
||||
CreatedBy: types.StringValue(v.CreatedBy),
|
||||
CreatedTime: types.Int64Value(int64(v.CreatedTime)),
|
||||
DeletedBy: types.StringValue(v.DeletedBy),
|
||||
DeletedTime: types.Int64Value(int64(v.DeletedTime)),
|
||||
ID: types.Int64Value(int64(v.ID)),
|
||||
Name: types.StringValue(v.Name),
|
||||
RAM: types.Int64Value(int64(v.RAM)),
|
||||
Registered: types.BoolValue(v.Registered),
|
||||
RGID: types.Int64Value(int64(v.RGID)),
|
||||
RgName: types.StringValue(v.RgName),
|
||||
Status: types.StringValue(v.Status),
|
||||
TechStatus: types.StringValue(v.TechStatus),
|
||||
TotalDisksSize: types.Int64Value(int64(v.TotalDisksSize)),
|
||||
UpdatedBy: types.StringValue(v.UpdatedBy),
|
||||
UpdatedTime: types.Int64Value(int64(v.UpdatedTime)),
|
||||
UserManaged: types.BoolValue(v.UserManaged),
|
||||
VINSConnected: types.Int64Value(int64(v.VINSConnected)),
|
||||
}
|
||||
data = append(data, item)
|
||||
}
|
||||
|
||||
state.Items = data
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountComputesListDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountComputesListDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/utilities"
|
||||
)
|
||||
|
||||
// AccountDisksListDataSource flattens data source for account disks list.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func AccountDisksListDataSource(ctx context.Context, state *models.DataSourceAccountDisksListModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.AccountDisksListDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
disksList, err := utilities.AccountDisksListCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("flattens.AccountDisksListDataSource: Cannot get info", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountDisksListDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceAccountDisksListModel{
|
||||
AccountID: state.AccountID,
|
||||
DiskID: state.DiskID,
|
||||
Name: state.Name,
|
||||
DiskMaxSize: state.DiskMaxSize,
|
||||
Type: state.Type,
|
||||
Page: state.Page,
|
||||
Size: state.Size,
|
||||
Timeouts: state.Timeouts,
|
||||
SortBy: state.SortBy,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
EntryCount: types.Int64Value(int64(disksList.EntryCount)),
|
||||
}
|
||||
|
||||
items := make([]models.ItemDiskModel, 0, len(disksList.Data))
|
||||
for _, item := range disksList.Data {
|
||||
i := models.ItemDiskModel{
|
||||
DiskID: types.Int64Value(int64(item.ID)),
|
||||
DiskName: types.StringValue(item.Name),
|
||||
Pool: types.StringValue(item.Pool),
|
||||
SEPID: types.Int64Value(int64(item.SepID)),
|
||||
Shareable: types.BoolValue(item.Shareable),
|
||||
SizeMax: types.Int64Value(int64(item.SizeMax)),
|
||||
Type: types.StringValue(item.Type),
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
state.Items = items
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountDisksListDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountDisksListDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/utilities"
|
||||
)
|
||||
|
||||
// AccountFlipgroupsListDataSource flattens data source for account flipgroups list.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func AccountFlipgroupsListDataSource(ctx context.Context, state *models.DataSourceAccountFlipgroupsListModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.AccountFlipgroupsListDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
flipgroups, err := utilities.AccountFlipgroupsListCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about account flipgroups list", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountFlipgroupsListDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceAccountFlipgroupsListModel{
|
||||
AccountID: state.AccountID,
|
||||
Name: state.Name,
|
||||
VINSID: state.VINSID,
|
||||
VINSName: state.VINSName,
|
||||
ExtNetID: state.ExtNetID,
|
||||
ByIP: state.ByIP,
|
||||
FLIPGroupID: state.FLIPGroupID,
|
||||
SortBy: state.SortBy,
|
||||
Page: state.Page,
|
||||
Size: state.Size,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
EntryCount: types.Int64Value(int64(flipgroups.EntryCount)),
|
||||
}
|
||||
|
||||
items := make([]models.ItemAccountFlipgroupModel, 0, len(flipgroups.Data))
|
||||
for _, item := range flipgroups.Data {
|
||||
i := models.ItemAccountFlipgroupModel{
|
||||
AccountID: types.Int64Value(int64(item.AccountID)),
|
||||
ClientType: types.StringValue(item.ClientType),
|
||||
ConnType: types.StringValue(item.ConnType),
|
||||
CreatedBy: types.StringValue(item.CreatedBy),
|
||||
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
|
||||
DefaultGW: types.StringValue(item.DefaultGW),
|
||||
DeletedBy: types.StringValue(item.DeletedBy),
|
||||
DeletedTime: types.Int64Value(int64(item.DeletedTime)),
|
||||
Description: types.StringValue(item.Description),
|
||||
GID: types.Int64Value(int64(item.GID)),
|
||||
GUID: types.Int64Value(int64(item.GUID)),
|
||||
ID: types.Int64Value(int64(item.ID)),
|
||||
IP: types.StringValue(item.IP),
|
||||
Milestones: types.Int64Value(int64(item.Milestones)),
|
||||
Name: types.StringValue(item.Name),
|
||||
NetID: types.Int64Value(int64(item.NetID)),
|
||||
NetType: types.StringValue(item.NetType),
|
||||
NetMask: types.Int64Value(int64(item.Netmask)),
|
||||
Status: types.StringValue(item.Status),
|
||||
UpdatedBy: types.StringValue(item.UpdatedBy),
|
||||
UpdatedTime: types.Int64Value(int64(item.UpdatedTime)),
|
||||
}
|
||||
|
||||
items = append(items, i)
|
||||
}
|
||||
state.Items = items
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountFlipgroupsListDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
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/service/cloudbroker/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/utilities"
|
||||
)
|
||||
|
||||
// AccountGetResourceConsumptionDataSource flattens data source for account.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func AccountGetResourceConsumptionDataSource(ctx context.Context, state *models.AccountGetResourceConsumptionModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.AccountGetResourceConsumptionDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
accountId := uint64(state.AccountID.ValueInt64())
|
||||
|
||||
record, err := utilities.AccountGetResourceConsumptionDataSourceCheckPresence(ctx, accountId, c)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about account with ID %v", accountId), err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountGetResourceConsumptionDataSource: before flatten", map[string]any{"account_id": accountId, "record": record})
|
||||
|
||||
*state = models.AccountGetResourceConsumptionModel{
|
||||
AccountID: state.AccountID,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Consumed: &models.ResourceConsumptionModel{
|
||||
CPU: types.Int64Value(record.Consumed.CPU),
|
||||
DiskSize: types.Float64Value(record.Consumed.DiskSize),
|
||||
DiskSizeMax: types.Float64Value(record.Consumed.DiskSizeMax),
|
||||
ExtIPs: types.Int64Value(record.Consumed.ExtIPs),
|
||||
ExtTraffic: types.Int64Value(record.Consumed.ExtTraffic),
|
||||
GPU: types.Int64Value(record.Consumed.GPU),
|
||||
RAM: types.Int64Value(record.Consumed.RAM),
|
||||
SEPs: flattenResourceConsumptionSep(ctx, record.Consumed.SEPs),
|
||||
},
|
||||
Limits: &models.ResourceConsumptionLimitsModel{
|
||||
CUC: types.Float64Value(record.ResourceLimits.CuC),
|
||||
CUD: types.Float64Value(record.ResourceLimits.CuD),
|
||||
CUI: types.Float64Value(record.ResourceLimits.CuI),
|
||||
CUM: types.Float64Value(record.ResourceLimits.CuM),
|
||||
CUDM: types.Float64Value(record.ResourceLimits.CuDM),
|
||||
CUNP: types.Float64Value(record.ResourceLimits.CuNP),
|
||||
GPUUnits: types.Float64Value(record.ResourceLimits.GPUUnits),
|
||||
},
|
||||
Reserved: &models.ResourceConsumptionModel{
|
||||
CPU: types.Int64Value(record.Reserved.CPU),
|
||||
DiskSize: types.Float64Value(record.Reserved.DiskSize),
|
||||
DiskSizeMax: types.Float64Value(record.Reserved.DiskSizeMax),
|
||||
ExtIPs: types.Int64Value(record.Reserved.ExtIPs),
|
||||
ExtTraffic: types.Int64Value(record.Reserved.ExtTraffic),
|
||||
GPU: types.Int64Value(record.Reserved.GPU),
|
||||
RAM: types.Int64Value(record.Reserved.RAM),
|
||||
SEPs: flattenResourceConsumptionSep(ctx, record.Reserved.SEPs),
|
||||
},
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountGetResourceConsumptionDataSource: after flatten", map[string]any{"account_id": state.AccountID.ValueInt64()})
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountGetResourceConsumptionDataSource", map[string]any{"account_id": state.AccountID.ValueInt64()})
|
||||
return nil
|
||||
}
|
||||
|
||||
func flattenResourceConsumptionSep(ctx context.Context, seps map[string]map[string]account.DiskUsage) []models.ResourceConsumptionSepModel {
|
||||
tflog.Info(ctx, "Start flattenResourceConsumption")
|
||||
res := make([]models.ResourceConsumptionSepModel, 0, len(seps))
|
||||
for sepId := range seps {
|
||||
for poolName, diskData := range seps[sepId] {
|
||||
s := models.ResourceConsumptionSepModel{
|
||||
SepID: types.StringValue(sepId),
|
||||
PoolName: types.StringValue(poolName),
|
||||
DiskSize: types.Float64Value(diskData.DiskSize),
|
||||
DiskSizeMax: types.Float64Value(diskData.DiskSizeMax),
|
||||
}
|
||||
res = append(res, s)
|
||||
}
|
||||
}
|
||||
tflog.Info(ctx, "End flattenResourceConsumption")
|
||||
return res
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/utilities"
|
||||
)
|
||||
|
||||
// AccountListDeletedDataSource flattens data source for account list deleted.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func AccountListDeletedDataSource(ctx context.Context, state *models.DataSourceAccountListDeletedModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.AccountListDeletedDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
accListDel, err := utilities.AccountListDeletedCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about account list deleted", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountListDeletedDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceAccountListDeletedModel{
|
||||
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(accListDel.EntryCount)),
|
||||
}
|
||||
|
||||
items := make([]models.ItemAccountListDeletedModel, 0, len(accListDel.Data))
|
||||
for _, item := range accListDel.Data {
|
||||
i := models.ItemAccountListDeletedModel{
|
||||
DCLocation: types.StringValue(item.DCLocation),
|
||||
Ckey: types.StringValue(item.CKey),
|
||||
Meta: flattens.FlattenSimpleTypeToList(ctx, types.StringType, item.Meta),
|
||||
ComputeFeatures: flattens.FlattenSimpleTypeToList(ctx, types.StringType, item.ComputeFeatures),
|
||||
Company: types.StringValue(item.Company),
|
||||
Companyurl: types.StringValue(item.CompanyURL),
|
||||
CpuAllocationParameter: types.StringValue(item.CPUAllocationParameter),
|
||||
CpuAllocationRatio: types.Float64Value(float64(item.CPUAllocationRatio)),
|
||||
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
|
||||
CreatedBy: types.StringValue(item.CreatedBy),
|
||||
DeletedTime: types.Int64Value(int64(item.DeletedTime)),
|
||||
DeletedBy: types.StringValue(item.DeletedBy),
|
||||
AccountID: types.Int64Value(int64(item.ID)),
|
||||
GUID: types.Int64Value(int64(item.GUID)),
|
||||
AccountName: types.StringValue(item.Name),
|
||||
Status: types.StringValue(item.Status),
|
||||
UpdatedTime: types.Int64Value(int64(item.UpdatedTime)),
|
||||
ResourceLimits: &models.AccountLimitsModel{
|
||||
CUC: types.Float64Value(float64(item.ResourceLimits.CuC)),
|
||||
CUD: types.Float64Value(float64(item.ResourceLimits.CuD)),
|
||||
CUI: types.Float64Value(float64(item.ResourceLimits.CuI)),
|
||||
CUM: types.Float64Value(float64(item.ResourceLimits.CuM)),
|
||||
CUDM: types.Float64Value(float64(item.ResourceLimits.CuDM)),
|
||||
CUNP: types.Float64Value(float64(item.ResourceLimits.CuNP)),
|
||||
GPUUnits: types.Float64Value(float64(item.ResourceLimits.GPUUnits)),
|
||||
},
|
||||
ResourceTypes: flattens.FlattenSimpleTypeToList(ctx, types.StringType, item.ResTypes),
|
||||
SendAccessEmails: types.BoolValue(item.SendAccessEmails),
|
||||
UniqPools: flattens.FlattenSimpleTypeToList(ctx, types.StringType, item.UniqPools),
|
||||
Version: types.Int64Value(int64(item.Version)),
|
||||
Vins: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, item.VINS),
|
||||
}
|
||||
|
||||
aclList := make([]models.RecordACLModel, 0, len(item.ACL))
|
||||
for _, acl := range item.ACL {
|
||||
a := models.RecordACLModel{
|
||||
Explicit: types.BoolValue(acl.Explicit),
|
||||
GUID: types.StringValue(acl.GUID),
|
||||
Right: types.StringValue(acl.Right),
|
||||
Status: types.StringValue(acl.Status),
|
||||
Type: types.StringValue(acl.Type),
|
||||
UserGroupID: types.StringValue(acl.UserGroupID),
|
||||
}
|
||||
aclList = append(aclList, a)
|
||||
}
|
||||
|
||||
i.ACL = aclList
|
||||
items = append(items, i)
|
||||
}
|
||||
state.Items = items
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountListDeletedDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountListDeletedDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// AccountGetResourceConsumptionList flattens data source for rg get resource consumption.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func AccountGetResourceConsumptionList(ctx context.Context, state *models.AccountGetResourceConsumptionListModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.AccountGetResourceConsumptionList")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
resConsList, err := utilities.AccountGetResourceConsumptionListDataSourceCheckPresence(ctx, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about resource consumptions", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountGetResourceConsumptionList: before flatten")
|
||||
|
||||
*state = models.AccountGetResourceConsumptionListModel{
|
||||
EntryCount: state.EntryCount,
|
||||
Timeouts: state.Timeouts,
|
||||
}
|
||||
|
||||
items := make([]models.AccountGetResourceConsumptionListItemModel, 0, len(resConsList.Data))
|
||||
for _, resConsItem := range resConsList.Data {
|
||||
item := models.AccountGetResourceConsumptionListItemModel{
|
||||
AccountId: types.Int64Value(int64(resConsItem.AccountID)),
|
||||
Consumed: &models.ResourceConsumptionListModel{
|
||||
CPU: types.Int64Value(resConsItem.Consumed.CPU),
|
||||
DiskSize: types.Float64Value(resConsItem.Consumed.DiskSize),
|
||||
DiskSizeMax: types.Float64Value(resConsItem.Consumed.DiskSizeMax),
|
||||
ExtIPs: types.Int64Value(resConsItem.Consumed.ExtIPs),
|
||||
ExtTraffic: types.Int64Value(resConsItem.Consumed.ExtTraffic),
|
||||
GPU: types.Int64Value(resConsItem.Consumed.GPU),
|
||||
RAM: types.Int64Value(resConsItem.Consumed.RAM),
|
||||
},
|
||||
Reserved: &models.ResourceConsumptionListModel{
|
||||
CPU: types.Int64Value(resConsItem.Reserved.CPU),
|
||||
DiskSize: types.Float64Value(resConsItem.Reserved.DiskSize),
|
||||
DiskSizeMax: types.Float64Value(resConsItem.Reserved.DiskSizeMax),
|
||||
ExtIPs: types.Int64Value(resConsItem.Reserved.ExtIPs),
|
||||
ExtTraffic: types.Int64Value(resConsItem.Reserved.ExtTraffic),
|
||||
GPU: types.Int64Value(resConsItem.Reserved.GPU),
|
||||
RAM: types.Int64Value(resConsItem.Reserved.RAM),
|
||||
},
|
||||
}
|
||||
|
||||
sepsConsumed := make([]models.ResourceConsumptionSepListModel, 0, len(resConsItem.Consumed.SEPs))
|
||||
for sepId, data := range resConsItem.Consumed.SEPs {
|
||||
for dataName, diskData := range data {
|
||||
sepItem := models.ResourceConsumptionSepListModel{
|
||||
SepID: types.StringValue(sepId),
|
||||
PoolName: types.StringValue(dataName),
|
||||
DiskSize: types.Float64Value(diskData.DiskSize),
|
||||
DiskSizeMax: types.Float64Value(diskData.DiskSizeMax),
|
||||
}
|
||||
sepsConsumed = append(sepsConsumed, sepItem)
|
||||
}
|
||||
}
|
||||
item.Consumed.SEPs = sepsConsumed
|
||||
|
||||
sepsReserved := make([]models.ResourceConsumptionSepListModel, 0, len(resConsItem.Reserved.SEPs))
|
||||
for sepId, data := range resConsItem.Reserved.SEPs {
|
||||
for dataName, diskData := range data {
|
||||
sepItem := models.ResourceConsumptionSepListModel{
|
||||
SepID: types.StringValue(sepId),
|
||||
PoolName: types.StringValue(dataName),
|
||||
DiskSize: types.Float64Value(diskData.DiskSize),
|
||||
DiskSizeMax: types.Float64Value(diskData.DiskSizeMax),
|
||||
}
|
||||
sepsReserved = append(sepsReserved, sepItem)
|
||||
}
|
||||
}
|
||||
item.Reserved.SEPs = sepsReserved
|
||||
|
||||
items = append(items, item)
|
||||
}
|
||||
|
||||
state.Items = items
|
||||
state.EntryCount = types.Int64Value(int64(resConsList.EntryCount))
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountGetResourceConsumptionList: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountGetResourceConsumptionList")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/account"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/utilities"
|
||||
)
|
||||
|
||||
// AccountRGListDataSource flattens data source for account rg list.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func AccountRGListDataSource(ctx context.Context, state *models.DataSourceAccountRGListModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.AccountRGListDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
rgList, err := utilities.AccountRGListCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about account rg list", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountRGListDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceAccountRGListModel{
|
||||
AccountID: state.AccountID,
|
||||
RGID: state.RGID,
|
||||
VinsID: state.VinsID,
|
||||
VMID: state.VMID,
|
||||
Name: state.Name,
|
||||
Status: state.Status,
|
||||
Page: state.Page,
|
||||
Size: state.Size,
|
||||
Timeouts: state.Timeouts,
|
||||
SortBy: state.SortBy,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
EntryCount: types.Int64Value(int64(rgList.EntryCount)),
|
||||
}
|
||||
|
||||
items := make([]models.ItemAccountRGModel, 0, len(rgList.Data))
|
||||
for _, item := range rgList.Data {
|
||||
i := models.ItemAccountRGModel{
|
||||
Computes: &models.RGComputesModel{
|
||||
Started: types.Int64Value(int64(item.Computes.Started)),
|
||||
Stopped: types.Int64Value(int64(item.Computes.Stopped)),
|
||||
},
|
||||
Resources: &models.RGResourcesModel{
|
||||
Consumed: &models.ResourceModel{
|
||||
CPU: types.Int64Value(item.Resources.Consumed.CPU),
|
||||
DiskSize: types.Float64Value(item.Resources.Consumed.DiskSize),
|
||||
DiskSizeMax: types.Float64Value(item.Resources.Consumed.DiskSizeMax),
|
||||
ExtIPs: types.Int64Value(item.Resources.Consumed.ExtIPs),
|
||||
ExtTraffic: types.Int64Value(item.Resources.Consumed.ExtTraffic),
|
||||
GPU: types.Int64Value(item.Resources.Consumed.GPU),
|
||||
RAM: types.Int64Value(item.Resources.Consumed.RAM),
|
||||
SEPs: flattenSep(item.Resources.Consumed.SEPs),
|
||||
},
|
||||
Limits: &models.LimitsRGModel{
|
||||
CPU: types.Int64Value(item.Resources.Limits.CPU),
|
||||
DiskSize: types.Int64Value(item.Resources.Limits.DiskSize),
|
||||
DiskSizeMax: types.Int64Value(item.Resources.Limits.DiskSizeMax),
|
||||
ExtIPs: types.Int64Value(item.Resources.Limits.ExtIPs),
|
||||
ExtTraffic: types.Int64Value(item.Resources.Limits.ExtTraffic),
|
||||
GPU: types.Int64Value(item.Resources.Limits.GPU),
|
||||
RAM: types.Int64Value(item.Resources.Limits.RAM),
|
||||
SEPs: types.Int64Value(int64(item.Resources.Limits.SEPs)),
|
||||
},
|
||||
Reserved: &models.ResourceModel{
|
||||
CPU: types.Int64Value(item.Resources.Reserved.CPU),
|
||||
DiskSize: types.Float64Value(item.Resources.Reserved.DiskSize),
|
||||
DiskSizeMax: types.Float64Value(item.Resources.Reserved.DiskSizeMax),
|
||||
ExtIPs: types.Int64Value(item.Resources.Reserved.ExtIPs),
|
||||
ExtTraffic: types.Int64Value(item.Resources.Reserved.ExtTraffic),
|
||||
GPU: types.Int64Value(item.Resources.Reserved.GPU),
|
||||
RAM: types.Int64Value(item.Resources.Reserved.RAM),
|
||||
SEPs: flattenSep(item.Resources.Reserved.SEPs),
|
||||
},
|
||||
},
|
||||
CreatedBy: types.StringValue(item.CreatedBy),
|
||||
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
|
||||
DeletedBy: types.StringValue(item.DeletedBy),
|
||||
DeletedTime: types.Int64Value(int64(item.DeletedTime)),
|
||||
RGID: types.Int64Value(int64(item.ID)),
|
||||
Milestones: types.Int64Value(int64(item.Milestones)),
|
||||
RGName: types.StringValue(item.Name),
|
||||
Status: types.StringValue(item.Status),
|
||||
UpdatedBy: types.StringValue(item.UpdatedBy),
|
||||
UpdatedTime: types.Int64Value(int64(item.UpdatedTime)),
|
||||
VINSes: types.Int64Value(int64(item.VINSes)),
|
||||
}
|
||||
|
||||
items = append(items, i)
|
||||
}
|
||||
state.Items = items
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountRGListDataSource")
|
||||
return nil
|
||||
}
|
||||
|
||||
func flattenSep(seps map[string]map[string]account.DiskUsage) []models.SepModel {
|
||||
res := make([]models.SepModel, 0, len(seps))
|
||||
for sepId := range seps {
|
||||
for poolName, diskData := range seps[sepId] {
|
||||
s := models.SepModel{
|
||||
SepID: types.StringValue(sepId),
|
||||
PoolName: types.StringValue(poolName),
|
||||
DiskSize: types.Float64Value(diskData.DiskSize),
|
||||
DiskSizeMax: types.Float64Value(diskData.DiskSizeMax),
|
||||
}
|
||||
res = append(res, s)
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
// AccountResource flattens resource for account.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func AccountResource(ctx context.Context, state *models.ResourceAccountModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.AccountResource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
accountId := uint64(state.AccountID.ValueInt64())
|
||||
if accountId == 0 {
|
||||
id, err := strconv.Atoi(state.Id.ValueString())
|
||||
if err != nil {
|
||||
diags.AddError(
|
||||
"flattens.AccountResource: cannot parse resource ID from state",
|
||||
err.Error())
|
||||
return diags
|
||||
}
|
||||
accountId = uint64(id)
|
||||
}
|
||||
|
||||
recordAccount, err := utilities.AccountResourceCheckPresence(ctx, accountId, c)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("flattens.AccountResource: Cannot get info about resource with ID %v", accountId), err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountResource: before flatten", map[string]any{"account_id": accountId, "recordAccount": recordAccount})
|
||||
|
||||
*state = models.ResourceAccountModel{
|
||||
AccountName: types.StringValue(recordAccount.Name),
|
||||
Username: state.Username,
|
||||
EmailAddress: state.EmailAddress,
|
||||
SendAccessEmails: state.SendAccessEmails,
|
||||
Users: state.Users,
|
||||
Restore: state.Restore,
|
||||
Permanently: state.Permanently,
|
||||
Enable: state.Enable,
|
||||
ResourceLimits: flattenResourceLimitsInAccountResource(ctx, recordAccount.ResourceLimits, state),
|
||||
AvailableTemplates: state.AvailableTemplates,
|
||||
Timeouts: state.Timeouts,
|
||||
Id: types.StringValue(strconv.Itoa(int(accountId))),
|
||||
AccountID: types.Int64Value(int64(recordAccount.ID)),
|
||||
DCLocation: types.StringValue(recordAccount.DCLocation),
|
||||
CKey: types.StringValue(recordAccount.CKey),
|
||||
ACL: resourceFlattenACLInAccount(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)),
|
||||
Status: types.StringValue(recordAccount.Status),
|
||||
UpdatedTime: types.Int64Value(int64(recordAccount.UpdatedTime)),
|
||||
Version: types.Int64Value(int64(recordAccount.Version)),
|
||||
}
|
||||
|
||||
state.VINS, diags = types.ListValueFrom(ctx, types.Int64Type, recordAccount.VINS)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, fmt.Sprint("flattens.AccountResource: cannot flatten recordAccount.VINS to state.VINS", diags))
|
||||
}
|
||||
|
||||
state.UniqPools, diags = types.ListValueFrom(ctx, types.StringType, recordAccount.UniqPools)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, fmt.Sprint("flattens.AccountResource: cannot flatten recordAccount.UniqPools to state.UniqPools", diags))
|
||||
}
|
||||
|
||||
state.ResourceTypes, diags = types.ListValueFrom(ctx, types.Int64Type, recordAccount.ResTypes)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, fmt.Sprint("flattens.AccountResource: cannot flatten recordAccount.ResTypes to state.ResourceTypes", diags))
|
||||
}
|
||||
|
||||
state.ComputeFeatures, diags = types.SetValueFrom(ctx, types.StringType, recordAccount.ComputeFeatures)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, fmt.Sprint("flattens.AccountResource: cannot flatten recordAccount.ComputeFeatures to state.ComputeFeatures", diags))
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountResource: after flatten", map[string]any{"account_id": state.Id.ValueString()})
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountResource", map[string]any{"account_id": state.Id.ValueString()})
|
||||
return nil
|
||||
}
|
||||
|
||||
func flattenResourceLimitsInAccountResource(ctx context.Context, limits account.ResourceLimits, state *models.ResourceAccountModel) types.Object {
|
||||
tflog.Info(ctx, "Start flattenResourceLimitsInAccountResource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
var resourceLimits models.ResourceLimitsInAccountResourceModel
|
||||
diags.Append(state.ResourceLimits.As(ctx, &resourceLimits, basetypes.ObjectAsOptions{})...)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, "flattenResourceLimitsInAccountResource: cannot populate resourceLimits with plan.ResourceLimits object element")
|
||||
}
|
||||
|
||||
if resourceLimits.CUC.ValueFloat64() == 0 {
|
||||
resourceLimits.CUC = types.Float64Value(limits.CuC)
|
||||
}
|
||||
if resourceLimits.CUD.ValueFloat64() == 0 {
|
||||
resourceLimits.CUD = types.Float64Value(limits.CuD)
|
||||
}
|
||||
if resourceLimits.CUI.ValueFloat64() == 0 {
|
||||
resourceLimits.CUI = types.Float64Value(limits.CuI)
|
||||
}
|
||||
if resourceLimits.CUM.ValueFloat64() == 0 {
|
||||
resourceLimits.CUM = types.Float64Value(limits.CuM)
|
||||
}
|
||||
if resourceLimits.CUNP.ValueFloat64() == 0 {
|
||||
resourceLimits.CUNP = types.Float64Value(limits.CuNP)
|
||||
}
|
||||
if resourceLimits.GPUUnits.ValueFloat64() == 0 {
|
||||
resourceLimits.GPUUnits = types.Float64Value(limits.GPUUnits)
|
||||
}
|
||||
|
||||
res, err := types.ObjectValueFrom(ctx, models.ItemResourceLimitsInAccountResource, resourceLimits)
|
||||
if err != nil {
|
||||
tflog.Error(ctx, fmt.Sprint("Error flattenResourceLimitsInAccountResource struct to obj", err))
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattenResourceLimitsInAccountResource")
|
||||
return res
|
||||
}
|
||||
|
||||
func resourceFlattenACLInAccount(ctx context.Context, aclList []account.ACL) types.List {
|
||||
tflog.Info(ctx, "Start flattenACLInAccount")
|
||||
tempSlice := make([]types.Object, 0, len(aclList))
|
||||
for _, item := range aclList {
|
||||
temp := models.ACLInAccountModel{
|
||||
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),
|
||||
}
|
||||
obj, diags := types.ObjectValueFrom(ctx, models.ItemACLInAccount, temp)
|
||||
if diags != nil {
|
||||
tflog.Error(ctx, fmt.Sprint("Error flattenACLInAccount struct to obj", diags))
|
||||
}
|
||||
tempSlice = append(tempSlice, obj)
|
||||
}
|
||||
|
||||
res, diags := types.ListValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemACLInAccount}, tempSlice)
|
||||
if diags != nil {
|
||||
tflog.Error(ctx, fmt.Sprint("Error flattenACLInAccount", diags))
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattenACLInAccount")
|
||||
return res
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type DataSourceAccountAuditsListModel struct {
|
||||
// request fields
|
||||
AccountID types.Int64 `tfsdk:"account_id"`
|
||||
Timeouts timeouts.Value `tfsdk:"timeouts"`
|
||||
|
||||
// response fields
|
||||
Id types.String `tfsdk:"id"`
|
||||
Items []ItemAuditModel `tfsdk:"items"`
|
||||
}
|
||||
|
||||
type ItemAuditModel struct {
|
||||
Call types.String `tfsdk:"call"`
|
||||
ResponseTime types.Float64 `tfsdk:"responsetime"`
|
||||
StatusCode types.Int64 `tfsdk:"statuscode"`
|
||||
Timestamp types.Float64 `tfsdk:"timestamp"`
|
||||
User types.String `tfsdk:"user"`
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type DataSourceAccountAvailableTemplatesListModel struct {
|
||||
// request fields
|
||||
AccountID types.Int64 `tfsdk:"account_id"`
|
||||
Timeouts timeouts.Value `tfsdk:"timeouts"`
|
||||
|
||||
// response fields
|
||||
Items types.List `tfsdk:"items"`
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type ListComputesModel struct {
|
||||
// request fields
|
||||
AccountID types.Int64 `tfsdk:"account_id"`
|
||||
ComputeID types.Int64 `tfsdk:"compute_id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
RGName types.String `tfsdk:"rg_name"`
|
||||
RGID types.Int64 `tfsdk:"rg_id"`
|
||||
TechStatus types.String `tfsdk:"tech_status"`
|
||||
IpAddress types.String `tfsdk:"ip_address"`
|
||||
ExtNetName types.String `tfsdk:"extnet_name"`
|
||||
ExtNetID types.Int64 `tfsdk:"extnet_id"`
|
||||
SortBy types.String `tfsdk:"sort_by"`
|
||||
Page types.Int64 `tfsdk:"page"`
|
||||
Size types.Int64 `tfsdk:"size"`
|
||||
Timeouts timeouts.Value `tfsdk:"timeouts"`
|
||||
|
||||
// response fields
|
||||
Items []ItemComputeModel `tfsdk:"items"`
|
||||
EntryCount types.Int64 `tfsdk:"entry_count"`
|
||||
}
|
||||
|
||||
type ItemComputeModel struct {
|
||||
AccountID types.Int64 `tfsdk:"account_id"`
|
||||
AccountName types.String `tfsdk:"account_name"`
|
||||
CPUs types.Int64 `tfsdk:"cpus"`
|
||||
CreatedBy types.String `tfsdk:"created_by"`
|
||||
CreatedTime types.Int64 `tfsdk:"created_time"`
|
||||
DeletedBy types.String `tfsdk:"deleted_by"`
|
||||
DeletedTime types.Int64 `tfsdk:"deleted_time"`
|
||||
ID types.Int64 `tfsdk:"compute_id"`
|
||||
Name types.String `tfsdk:"compute_name"`
|
||||
RAM types.Int64 `tfsdk:"ram"`
|
||||
Registered types.Bool `tfsdk:"registered"`
|
||||
RGID types.Int64 `tfsdk:"rg_id"`
|
||||
RgName types.String `tfsdk:"rg_name"`
|
||||
Status types.String `tfsdk:"status"`
|
||||
TechStatus types.String `tfsdk:"tech_status"`
|
||||
TotalDisksSize types.Int64 `tfsdk:"total_disks_size"`
|
||||
UpdatedBy types.String `tfsdk:"updated_by"`
|
||||
UpdatedTime types.Int64 `tfsdk:"updated_time"`
|
||||
UserManaged types.Bool `tfsdk:"user_managed"`
|
||||
VINSConnected types.Int64 `tfsdk:"vins_connected"`
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type DataSourceAccountDisksListModel struct {
|
||||
// required fields
|
||||
AccountID types.Int64 `tfsdk:"account_id"`
|
||||
|
||||
// optional fields
|
||||
DiskID types.Int64 `tfsdk:"disk_id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
DiskMaxSize types.Int64 `tfsdk:"disk_max_size"`
|
||||
Type types.String `tfsdk:"type"`
|
||||
Page types.Int64 `tfsdk:"page"`
|
||||
Size types.Int64 `tfsdk:"size"`
|
||||
Timeouts timeouts.Value `tfsdk:"timeouts"`
|
||||
SortBy types.String `tfsdk:"sort_by"`
|
||||
|
||||
// response fields
|
||||
Id types.String `tfsdk:"id"`
|
||||
Items []ItemDiskModel `tfsdk:"items"`
|
||||
EntryCount types.Int64 `tfsdk:"entry_count"`
|
||||
}
|
||||
|
||||
type ItemDiskModel struct {
|
||||
DiskID types.Int64 `tfsdk:"disk_id"`
|
||||
DiskName types.String `tfsdk:"disk_name"`
|
||||
Pool types.String `tfsdk:"pool"`
|
||||
SEPID types.Int64 `tfsdk:"sep_id"`
|
||||
Shareable types.Bool `tfsdk:"shareable"`
|
||||
SizeMax types.Int64 `tfsdk:"size_max"`
|
||||
Type types.String `tfsdk:"type"`
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type DataSourceAccountFlipgroupsListModel struct {
|
||||
// optional and required fields
|
||||
AccountID types.Int64 `tfsdk:"account_id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
VINSID types.Int64 `tfsdk:"vins_id"`
|
||||
VINSName types.String `tfsdk:"vins_name"`
|
||||
ExtNetID types.Int64 `tfsdk:"extnet_id"`
|
||||
ByIP types.String `tfsdk:"by_ip"`
|
||||
FLIPGroupID types.Int64 `tfsdk:"flipgroup_id"`
|
||||
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 []ItemAccountFlipgroupModel `tfsdk:"items"`
|
||||
EntryCount types.Int64 `tfsdk:"entry_count"`
|
||||
}
|
||||
|
||||
type ItemAccountFlipgroupModel struct {
|
||||
AccountID types.Int64 `tfsdk:"account_id"`
|
||||
ClientType types.String `tfsdk:"client_type"`
|
||||
ConnType types.String `tfsdk:"conn_type"`
|
||||
CreatedBy types.String `tfsdk:"created_by"`
|
||||
CreatedTime types.Int64 `tfsdk:"created_time"`
|
||||
DefaultGW types.String `tfsdk:"default_gw"`
|
||||
DeletedBy types.String `tfsdk:"deleted_by"`
|
||||
DeletedTime types.Int64 `tfsdk:"deleted_time"`
|
||||
Description types.String `tfsdk:"desc"`
|
||||
GID types.Int64 `tfsdk:"gid"`
|
||||
GUID types.Int64 `tfsdk:"guid"`
|
||||
ID types.Int64 `tfsdk:"fg_id"`
|
||||
IP types.String `tfsdk:"ip"`
|
||||
Milestones types.Int64 `tfsdk:"milestones"`
|
||||
Name types.String `tfsdk:"fg_name"`
|
||||
NetID types.Int64 `tfsdk:"net_id"`
|
||||
NetType types.String `tfsdk:"net_type"`
|
||||
NetMask types.Int64 `tfsdk:"netmask"`
|
||||
Status types.String `tfsdk:"status"`
|
||||
UpdatedBy types.String `tfsdk:"updated_by"`
|
||||
UpdatedTime types.Int64 `tfsdk:"updated_time"`
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type AccountGetResourceConsumptionModel struct {
|
||||
// request fields
|
||||
AccountID types.Int64 `tfsdk:"account_id"`
|
||||
Timeouts timeouts.Value `tfsdk:"timeouts"`
|
||||
|
||||
// response fields
|
||||
Consumed *ResourceConsumptionModel `tfsdk:"consumed"`
|
||||
Reserved *ResourceConsumptionModel `tfsdk:"reserved"`
|
||||
Limits *ResourceConsumptionLimitsModel `tfsdk:"resource_limits"`
|
||||
}
|
||||
|
||||
type ResourceConsumptionModel struct {
|
||||
CPU types.Int64 `tfsdk:"cpu"`
|
||||
DiskSize types.Float64 `tfsdk:"disksize"`
|
||||
DiskSizeMax types.Float64 `tfsdk:"disksizemax"`
|
||||
ExtIPs types.Int64 `tfsdk:"extips"`
|
||||
ExtTraffic types.Int64 `tfsdk:"exttraffic"`
|
||||
GPU types.Int64 `tfsdk:"gpu"`
|
||||
RAM types.Int64 `tfsdk:"ram"`
|
||||
SEPs []ResourceConsumptionSepModel `tfsdk:"seps"`
|
||||
}
|
||||
|
||||
type ResourceConsumptionSepModel struct {
|
||||
SepID types.String `tfsdk:"sep_id"`
|
||||
PoolName types.String `tfsdk:"data_name"`
|
||||
DiskSize types.Float64 `tfsdk:"disk_size"`
|
||||
DiskSizeMax types.Float64 `tfsdk:"disk_size_max"`
|
||||
}
|
||||
|
||||
type ResourceConsumptionLimitsModel struct {
|
||||
CUC types.Float64 `tfsdk:"cu_c"`
|
||||
CUD types.Float64 `tfsdk:"cu_d"`
|
||||
CUI types.Float64 `tfsdk:"cu_i"`
|
||||
CUM types.Float64 `tfsdk:"cu_m"`
|
||||
CUDM types.Float64 `tfsdk:"cu_dm"`
|
||||
CUNP types.Float64 `tfsdk:"cu_np"`
|
||||
GPUUnits types.Float64 `tfsdk:"gpu_units"`
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type DataSourceAccountListDeletedModel struct {
|
||||
// optional fields
|
||||
ByID types.Int64 `tfsdk:"by_id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
ACL types.String `tfsdk:"acl"`
|
||||
Page types.Int64 `tfsdk:"page"`
|
||||
Size types.Int64 `tfsdk:"size"`
|
||||
Timeouts timeouts.Value `tfsdk:"timeouts"`
|
||||
SortBy types.String `tfsdk:"sort_by"`
|
||||
|
||||
// response fields
|
||||
Id types.String `tfsdk:"id"`
|
||||
Items []ItemAccountListDeletedModel `tfsdk:"items"`
|
||||
EntryCount types.Int64 `tfsdk:"entry_count"`
|
||||
}
|
||||
|
||||
type ItemAccountListDeletedModel struct {
|
||||
DCLocation types.String `tfsdk:"dc_location"`
|
||||
Ckey types.String `tfsdk:"ckey"`
|
||||
Meta types.List `tfsdk:"meta"`
|
||||
ACL []RecordACLModel `tfsdk:"acl"`
|
||||
ComputeFeatures types.List `tfsdk:"compute_features"`
|
||||
Company types.String `tfsdk:"company"`
|
||||
Companyurl types.String `tfsdk:"companyurl"`
|
||||
CpuAllocationParameter types.String `tfsdk:"cpu_allocation_parameter"`
|
||||
CpuAllocationRatio types.Float64 `tfsdk:"cpu_allocation_ratio"`
|
||||
CreatedTime types.Int64 `tfsdk:"created_time"`
|
||||
CreatedBy types.String `tfsdk:"created_by"`
|
||||
DeletedTime types.Int64 `tfsdk:"deleted_time"`
|
||||
DeletedBy types.String `tfsdk:"deleted_by"`
|
||||
AccountID types.Int64 `tfsdk:"account_id"`
|
||||
GUID types.Int64 `tfsdk:"guid"`
|
||||
AccountName types.String `tfsdk:"account_name"`
|
||||
Status types.String `tfsdk:"status"`
|
||||
UpdatedTime types.Int64 `tfsdk:"updated_time"`
|
||||
ResourceLimits *AccountLimitsModel `tfsdk:"resource_limits"`
|
||||
ResourceTypes types.List `tfsdk:"resource_types"`
|
||||
SendAccessEmails types.Bool `tfsdk:"send_access_emails"`
|
||||
UniqPools types.List `tfsdk:"uniq_pools"`
|
||||
Version types.Int64 `tfsdk:"version"`
|
||||
Vins types.List `tfsdk:"vins"`
|
||||
}
|
||||
|
||||
type RecordACLModel 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 AccountLimitsModel struct {
|
||||
CUC types.Float64 `tfsdk:"cu_c"`
|
||||
CUD types.Float64 `tfsdk:"cu_d"`
|
||||
CUI types.Float64 `tfsdk:"cu_i"`
|
||||
CUM types.Float64 `tfsdk:"cu_m"`
|
||||
CUDM types.Float64 `tfsdk:"cu_dm"`
|
||||
CUNP types.Float64 `tfsdk:"cu_np"`
|
||||
GPUUnits types.Float64 `tfsdk:"gpu_units"`
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type AccountGetResourceConsumptionListModel struct {
|
||||
// request fields
|
||||
Timeouts timeouts.Value `tfsdk:"timeouts"`
|
||||
|
||||
// response fields
|
||||
Items []AccountGetResourceConsumptionListItemModel `tfsdk:"items"`
|
||||
EntryCount types.Int64 `tfsdk:"entry_count"`
|
||||
}
|
||||
|
||||
type AccountGetResourceConsumptionListItemModel struct {
|
||||
// response fields
|
||||
AccountId types.Int64 `tfsdk:"account_id"`
|
||||
Consumed *ResourceConsumptionListModel `tfsdk:"consumed"`
|
||||
Reserved *ResourceConsumptionListModel `tfsdk:"reserved"`
|
||||
}
|
||||
|
||||
type ResourceConsumptionListModel struct {
|
||||
CPU types.Int64 `tfsdk:"cpu"`
|
||||
DiskSize types.Float64 `tfsdk:"disksize"`
|
||||
DiskSizeMax types.Float64 `tfsdk:"disksizemax"`
|
||||
ExtIPs types.Int64 `tfsdk:"extips"`
|
||||
ExtTraffic types.Int64 `tfsdk:"exttraffic"`
|
||||
GPU types.Int64 `tfsdk:"gpu"`
|
||||
RAM types.Int64 `tfsdk:"ram"`
|
||||
SEPs []ResourceConsumptionSepListModel `tfsdk:"seps"`
|
||||
}
|
||||
|
||||
type ResourceConsumptionSepListModel struct {
|
||||
SepID types.String `tfsdk:"sep_id"`
|
||||
PoolName types.String `tfsdk:"data_name"`
|
||||
DiskSize types.Float64 `tfsdk:"disk_size"`
|
||||
DiskSizeMax types.Float64 `tfsdk:"disk_size_max"`
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type DataSourceAccountRGListModel struct {
|
||||
// optional and required fields
|
||||
AccountID types.Int64 `tfsdk:"account_id"`
|
||||
RGID types.Int64 `tfsdk:"rg_id"`
|
||||
VinsID types.Int64 `tfsdk:"vins_id"`
|
||||
VMID types.Int64 `tfsdk:"vm_id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
Status types.String `tfsdk:"status"`
|
||||
Page types.Int64 `tfsdk:"page"`
|
||||
Size types.Int64 `tfsdk:"size"`
|
||||
Timeouts timeouts.Value `tfsdk:"timeouts"`
|
||||
SortBy types.String `tfsdk:"sort_by"`
|
||||
|
||||
// response fields
|
||||
Id types.String `tfsdk:"id"`
|
||||
Items []ItemAccountRGModel `tfsdk:"items"`
|
||||
EntryCount types.Int64 `tfsdk:"entry_count"`
|
||||
}
|
||||
|
||||
type ItemAccountRGModel struct {
|
||||
Computes *RGComputesModel `tfsdk:"computes"`
|
||||
Resources *RGResourcesModel `tfsdk:"resources"`
|
||||
CreatedBy types.String `tfsdk:"created_by"`
|
||||
CreatedTime types.Int64 `tfsdk:"created_time"`
|
||||
DeletedBy types.String `tfsdk:"deleted_by"`
|
||||
DeletedTime types.Int64 `tfsdk:"deleted_time"`
|
||||
RGID types.Int64 `tfsdk:"rg_id"`
|
||||
Milestones types.Int64 `tfsdk:"milestones"`
|
||||
RGName types.String `tfsdk:"rg_name"`
|
||||
Status types.String `tfsdk:"status"`
|
||||
UpdatedBy types.String `tfsdk:"updated_by"`
|
||||
UpdatedTime types.Int64 `tfsdk:"updated_time"`
|
||||
VINSes types.Int64 `tfsdk:"vinses"`
|
||||
}
|
||||
|
||||
type RGComputesModel struct {
|
||||
Started types.Int64 `tfsdk:"started"`
|
||||
Stopped types.Int64 `tfsdk:"stopped"`
|
||||
}
|
||||
|
||||
type RGResourcesModel struct {
|
||||
Consumed *ResourceModel `tfsdk:"consumed"`
|
||||
Limits *LimitsRGModel `tfsdk:"limits"`
|
||||
Reserved *ResourceModel `tfsdk:"reserved"`
|
||||
}
|
||||
|
||||
type LimitsRGModel struct {
|
||||
CPU types.Int64 `tfsdk:"cpu"`
|
||||
DiskSize types.Int64 `tfsdk:"disksize"`
|
||||
DiskSizeMax types.Int64 `tfsdk:"disksizemax"`
|
||||
ExtIPs types.Int64 `tfsdk:"extips"`
|
||||
ExtTraffic types.Int64 `tfsdk:"exttraffic"`
|
||||
GPU types.Int64 `tfsdk:"gpu"`
|
||||
RAM types.Int64 `tfsdk:"ram"`
|
||||
SEPs types.Int64 `tfsdk:"seps"`
|
||||
}
|
||||
|
||||
type ResourceModel struct {
|
||||
CPU types.Int64 `tfsdk:"cpu"`
|
||||
DiskSize types.Float64 `tfsdk:"disksize"`
|
||||
DiskSizeMax types.Float64 `tfsdk:"disksizemax"`
|
||||
ExtIPs types.Int64 `tfsdk:"extips"`
|
||||
ExtTraffic types.Int64 `tfsdk:"exttraffic"`
|
||||
GPU types.Int64 `tfsdk:"gpu"`
|
||||
RAM types.Int64 `tfsdk:"ram"`
|
||||
SEPs []SepModel `tfsdk:"seps"`
|
||||
}
|
||||
|
||||
type SepModel struct {
|
||||
SepID types.String `tfsdk:"sep_id"`
|
||||
PoolName types.String `tfsdk:"data_name"`
|
||||
DiskSize types.Float64 `tfsdk:"disk_size"`
|
||||
DiskSizeMax types.Float64 `tfsdk:"disk_size_max"`
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type ResourceAccountModel struct {
|
||||
// request fields - required
|
||||
AccountName types.String `tfsdk:"account_name"`
|
||||
Username types.String `tfsdk:"username"`
|
||||
|
||||
// request fields - optional
|
||||
EmailAddress types.String `tfsdk:"emailaddress"`
|
||||
SendAccessEmails types.Bool `tfsdk:"send_access_emails"`
|
||||
Users types.List `tfsdk:"users"`
|
||||
UniqPools types.List `tfsdk:"uniq_pools"`
|
||||
CPUAllocationParameter types.String `tfsdk:"cpu_allocation_parameter"`
|
||||
CPUAllocationRatio types.Float64 `tfsdk:"cpu_allocation_ratio"`
|
||||
AvailableTemplates types.Set `tfsdk:"available_templates"`
|
||||
Restore types.Bool `tfsdk:"restore"`
|
||||
Permanently types.Bool `tfsdk:"permanently"`
|
||||
Enable types.Bool `tfsdk:"enable"`
|
||||
ResourceLimits types.Object `tfsdk:"resource_limits"`
|
||||
ComputeFeatures types.Set `tfsdk:"compute_features"`
|
||||
Timeouts timeouts.Value `tfsdk:"timeouts"`
|
||||
|
||||
// response fields
|
||||
Id types.String `tfsdk:"id"`
|
||||
DCLocation types.String `tfsdk:"dc_location"`
|
||||
AccountID types.Int64 `tfsdk:"account_id"`
|
||||
CKey types.String `tfsdk:"ckey"`
|
||||
ACL types.List `tfsdk:"acl"`
|
||||
Company types.String `tfsdk:"company"`
|
||||
CompanyURL types.String `tfsdk:"companyurl"`
|
||||
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"`
|
||||
ResourceTypes types.List `tfsdk:"resource_types"`
|
||||
Status types.String `tfsdk:"status"`
|
||||
UpdatedTime types.Int64 `tfsdk:"updated_time"`
|
||||
Version types.Int64 `tfsdk:"version"`
|
||||
VINS types.List `tfsdk:"vins"`
|
||||
}
|
||||
|
||||
type UsersModel struct {
|
||||
UserID types.String `tfsdk:"user_id"`
|
||||
AccessType types.String `tfsdk:"access_type"`
|
||||
RecursiveDelete types.Bool `tfsdk:"recursive_delete"`
|
||||
}
|
||||
|
||||
type ResourceLimitsInAccountResourceModel struct {
|
||||
CUC types.Float64 `tfsdk:"cu_c"`
|
||||
CUD types.Float64 `tfsdk:"cu_d"`
|
||||
CUI types.Float64 `tfsdk:"cu_i"`
|
||||
CUM types.Float64 `tfsdk:"cu_m"`
|
||||
CUNP types.Float64 `tfsdk:"cu_np"`
|
||||
GPUUnits types.Float64 `tfsdk:"gpu_units"`
|
||||
}
|
||||
|
||||
var ItemResourceLimitsInAccountResource = map[string]attr.Type{
|
||||
"cu_c": types.Float64Type,
|
||||
"cu_d": types.Float64Type,
|
||||
"cu_i": types.Float64Type,
|
||||
"cu_m": types.Float64Type,
|
||||
"cu_np": types.Float64Type,
|
||||
"gpu_units": types.Float64Type,
|
||||
}
|
||||
|
||||
type ACLInAccountModel 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"`
|
||||
}
|
||||
|
||||
var ItemACLInAccount = map[string]attr.Type{
|
||||
"explicit": types.BoolType,
|
||||
"guid": types.StringType,
|
||||
"right": types.StringType,
|
||||
"status": types.StringType,
|
||||
"type": types.StringType,
|
||||
"user_group_id": types.StringType,
|
||||
}
|
||||
321
internal/service/cloudbroker/account/resource_cb_account.go
Normal file
321
internal/service/cloudbroker/account/resource_cb_account.go
Normal file
@@ -0,0 +1,321 @@
|
||||
package cbAccount
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/path"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-framework/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/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"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/utilities"
|
||||
)
|
||||
|
||||
// Ensure the implementation satisfies the expected interfaces.
|
||||
var (
|
||||
_ resource.Resource = &resourceAccount{}
|
||||
_ resource.ResourceWithImportState = &resourceAccount{}
|
||||
)
|
||||
|
||||
// NewResourceAccount is a helper function to simplify the provider implementation.
|
||||
func NewResourceAccount() resource.Resource {
|
||||
return &resourceAccount{}
|
||||
}
|
||||
|
||||
// resourceAccount is the resource implementation.
|
||||
type resourceAccount struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
// Create creates the resource and sets the initial Terraform state.
|
||||
func (r *resourceAccount) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
|
||||
tflog.Info(ctx, "Create resourceAccount: start creating")
|
||||
var plan models.ResourceAccountModel
|
||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Create resourceAccount: Error receiving the plan")
|
||||
return
|
||||
}
|
||||
|
||||
// Set timeouts
|
||||
createTimeout, diags := plan.Timeouts.Create(ctx, constants.Timeout600s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Create resourceAccount: Error set timeout")
|
||||
return
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(ctx, createTimeout)
|
||||
defer cancel()
|
||||
tflog.Info(ctx, "Create resourceAccount: set timeouts successfully", map[string]any{
|
||||
"createTimeout": createTimeout})
|
||||
|
||||
diags, id := utilities.UtilityAccountCreate(ctx, &plan, r.client)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Create resourceAccount: error with UtilityAccountCreate")
|
||||
return
|
||||
}
|
||||
|
||||
plan.Id = types.StringValue(strconv.Itoa(int(*id)))
|
||||
|
||||
// Map response body to schema and populate Computed attribute values
|
||||
resp.Diagnostics.Append(flattens.AccountResource(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "resourceAccount: Account created", map[string]any{"account_id": id})
|
||||
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Read refreshes the Terraform state with the latest data.
|
||||
func (r *resourceAccount) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
|
||||
// Get current state
|
||||
var state models.ResourceAccountModel
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read resourceAccount: Error get state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read resourceAccount: got state successfully", map[string]any{"account_id": state.Id.ValueString()})
|
||||
|
||||
// Set timeouts
|
||||
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout300s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read resourceAccount: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read resourceAccount: set timeouts successfully", map[string]any{
|
||||
"account_id": state.Id.ValueString(),
|
||||
"readTimeout": readTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, readTimeout)
|
||||
defer cancel()
|
||||
|
||||
// read status
|
||||
resp.Diagnostics.Append(utilities.AccountReadStatus(ctx, &state, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read resourceAccount: Error reading status")
|
||||
return
|
||||
}
|
||||
|
||||
// Overwrite items with refreshed state
|
||||
resp.Diagnostics.Append(flattens.AccountResource(ctx, &state, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read resourceAccount: Error flatten")
|
||||
return
|
||||
}
|
||||
|
||||
// Set refreshed state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read resourceAccount: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read resourceAccount")
|
||||
}
|
||||
|
||||
// Update updates the resource and sets the updated Terraform state on success.
|
||||
func (r *resourceAccount) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
|
||||
// Retrieve values from plan
|
||||
var plan models.ResourceAccountModel
|
||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceAccount: Error receiving the plan")
|
||||
return
|
||||
}
|
||||
|
||||
logMap := map[string]any{"account_id": plan.Id.ValueString()}
|
||||
tflog.Info(ctx, "Update resourceAccount: got plan successfully", logMap)
|
||||
|
||||
// Retrieve values from state
|
||||
var state models.ResourceAccountModel
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceAccount: Error receiving the state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Update resourceAccount: got state successfully", logMap)
|
||||
|
||||
// Set timeouts
|
||||
updateTimeout, diags := plan.Timeouts.Update(ctx, constants.Timeout300s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceAccount: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Update resourceAccount: set timeouts successfully", map[string]any{
|
||||
"account_id": state.Id.ValueString(),
|
||||
"updateTimeout": updateTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, updateTimeout)
|
||||
defer cancel()
|
||||
|
||||
accountId, err := strconv.Atoi(state.Id.ValueString())
|
||||
if err != nil {
|
||||
resp.Diagnostics.AddError("Update resourceAccount: Cannot parse ID from state", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// enable/disable account
|
||||
if !plan.Enable.Equal(state.Enable) && !plan.Enable.IsNull() {
|
||||
resp.Diagnostics.Append(utilities.EnableDisableAccount(ctx, uint64(accountId), plan.Enable.ValueBool(), r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceAccount: Error enabling/disabling account")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// general update account
|
||||
resp.Diagnostics.Append(utilities.UpdateAccount(ctx, uint64(accountId), &plan, &state, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceAccount: Error with general account update")
|
||||
return
|
||||
}
|
||||
|
||||
// cpu_allocation_parameter
|
||||
if !plan.CPUAllocationParameter.Equal(state.CPUAllocationParameter) && !plan.CPUAllocationParameter.IsNull() && plan.CPUAllocationParameter.ValueString() != "" {
|
||||
resp.Diagnostics.Append(utilities.UtilityAccountCPUParameterUpdate(ctx, uint64(state.AccountID.ValueInt64()), &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceAccount: Error update CPUAllocationParameter ")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// cpu_allocation_ratio
|
||||
if !plan.CPUAllocationRatio.Equal(state.CPUAllocationRatio) && !plan.CPUAllocationRatio.IsNull() {
|
||||
resp.Diagnostics.Append(utilities.UtilityAccountCPURatioUpdate(ctx, uint64(accountId), &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceAccount: Error update CPUAllocationRatio ")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// add/delete users
|
||||
if !plan.Users.Equal(state.Users) {
|
||||
resp.Diagnostics.Append(utilities.AddDeleteUsersAccount(ctx, uint64(accountId), &plan, &state, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceAccount: Error adding/deleting users to/from account")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// available_templates
|
||||
if !plan.AvailableTemplates.Equal(state.AvailableTemplates) {
|
||||
resp.Diagnostics.Append(utilities.UtilityAccountAvailiableTemplatesUpdate(ctx, &state, &plan, false, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceAccount: Error update AvailiableTemplates")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// compute_features
|
||||
if !plan.ComputeFeatures.Equal(state.ComputeFeatures) {
|
||||
resp.Diagnostics.Append(utilities.UtilityAccountComputeFeaturesUpdate(ctx, uint64(accountId), &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceAccount: Error update ComputeFeatures")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "Update resourceAccount: account update is completed", logMap)
|
||||
|
||||
// Map response body to schema and populate Computed attribute values
|
||||
resp.Diagnostics.Append(flattens.AccountResource(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
// Set state to fully populated data
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Delete deletes the resource and removes the Terraform state on success.
|
||||
func (r *resourceAccount) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
|
||||
// Get current state
|
||||
var state models.ResourceAccountModel
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Delete resourceAccount: Error get state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Delete resourceAccount: got state successfully", map[string]any{"account_id": state.Id.ValueString()})
|
||||
|
||||
// Set timeouts
|
||||
deleteTimeout, diags := state.Timeouts.Delete(ctx, constants.Timeout300s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Delete resourceAccount: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Delete resourceAccount: set timeouts successfully", map[string]any{
|
||||
"account_id": state.Id.ValueString(),
|
||||
"deleteTimeout": deleteTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, deleteTimeout)
|
||||
defer cancel()
|
||||
|
||||
permanently := state.Permanently.ValueBool()
|
||||
if state.Permanently.IsNull() {
|
||||
permanently = true
|
||||
} // default true
|
||||
|
||||
// Delete existing resource group
|
||||
delReq := account.DeleteRequest{
|
||||
AccountID: uint64(state.AccountID.ValueInt64()),
|
||||
Permanently: permanently,
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "Delete resourceAccount: before CloudBroker().Account().Delete", map[string]any{"req": delReq})
|
||||
_, err := r.client.CloudBroker().Account().Delete(ctx, delReq)
|
||||
if err != nil {
|
||||
resp.Diagnostics.AddError("Delete resourceAccount: Error deleting account with error: ", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End delete resourceAccount", map[string]any{"account_id": state.Id.ValueString()})
|
||||
}
|
||||
|
||||
// Schema defines the schema for the resource.
|
||||
func (r *resourceAccount) Schema(ctx context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaResourceAccount(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx, timeouts.Opts{Create: true, Read: true, Update: true, Delete: true}),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Metadata returns the resource type name.
|
||||
func (r *resourceAccount) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_cb_account"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the resource.
|
||||
func (r *resourceAccount) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure resourceAccount")
|
||||
r.client = client.Resource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure resourceAccount successfully")
|
||||
}
|
||||
|
||||
func (r *resourceAccount) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
|
||||
// Retrieve import ID and save to id attribute
|
||||
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
)
|
||||
|
||||
func MakeSchemaDataSourceAccountAuditsList() map[string]schema.Attribute {
|
||||
return map[string]schema.Attribute{
|
||||
// required attributes
|
||||
"account_id": schema.Int64Attribute{
|
||||
Required: true,
|
||||
Description: "account id",
|
||||
},
|
||||
|
||||
// computed attributes
|
||||
"id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"items": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"call": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"responsetime": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"statuscode": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"timestamp": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"user": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
func MakeSchemaDataSourceAccountAvailableTemplatesList() map[string]schema.Attribute {
|
||||
return map[string]schema.Attribute{
|
||||
"account_id": schema.Int64Attribute{
|
||||
Required: true,
|
||||
},
|
||||
"items": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.Int64Type,
|
||||
},
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
)
|
||||
|
||||
func MakeSchemaDataSourceAccountComputesList() map[string]schema.Attribute {
|
||||
return map[string]schema.Attribute{
|
||||
"account_id": schema.Int64Attribute{
|
||||
Required: true,
|
||||
},
|
||||
"compute_id": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Optional: true,
|
||||
},
|
||||
"rg_name": schema.StringAttribute{
|
||||
Optional: true,
|
||||
},
|
||||
"rg_id": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
},
|
||||
"tech_status": schema.StringAttribute{
|
||||
Optional: true,
|
||||
},
|
||||
"ip_address": schema.StringAttribute{
|
||||
Optional: true,
|
||||
},
|
||||
"extnet_name": schema.StringAttribute{
|
||||
Optional: true,
|
||||
},
|
||||
"extnet_id": schema.Int64Attribute{
|
||||
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,
|
||||
},
|
||||
"cpus": 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,
|
||||
},
|
||||
"compute_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"compute_name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"ram": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"registered": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"rg_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"rg_name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"status": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"tech_status": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"total_disks_size": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"updated_by": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"updated_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"user_managed": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"vins_connected": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"entry_count": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
)
|
||||
|
||||
func MakeSchemaDataSourceAccountDisksList() map[string]schema.Attribute {
|
||||
return map[string]schema.Attribute{
|
||||
// required attributes
|
||||
"account_id": schema.Int64Attribute{
|
||||
Required: true,
|
||||
Description: "account id",
|
||||
},
|
||||
|
||||
// optional attributes
|
||||
"disk_id": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "find by disk id",
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "find by name",
|
||||
},
|
||||
"disk_max_size": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "find by max size disk",
|
||||
},
|
||||
"type": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "find by type of the disks",
|
||||
},
|
||||
"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)",
|
||||
},
|
||||
|
||||
// computed attributes
|
||||
"id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"items": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"disk_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"disk_name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"pool": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"sep_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"shareable": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"size_max": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"type": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"entry_count": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
)
|
||||
|
||||
func MakeSchemaDataSourceAccountFlipgroupsList() map[string]schema.Attribute {
|
||||
return map[string]schema.Attribute{
|
||||
// required attributes
|
||||
"account_id": schema.Int64Attribute{
|
||||
Required: true,
|
||||
Description: "ID of the account",
|
||||
},
|
||||
|
||||
// optional attributes
|
||||
"name": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "find by name",
|
||||
},
|
||||
"vins_id": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "find by vins ID",
|
||||
},
|
||||
"vins_name": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "find by vins name",
|
||||
},
|
||||
"extnet_id": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "find by extnet ID",
|
||||
},
|
||||
"by_ip": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "find by ip address",
|
||||
},
|
||||
"flipgroup_id": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "find by flipgroup id",
|
||||
},
|
||||
"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",
|
||||
},
|
||||
|
||||
// computed attributes
|
||||
"id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"items": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"account_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"client_type": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"conn_type": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"created_by": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"created_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"default_gw": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_by": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"desc": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"gid": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"fg_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"ip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"milestones": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"fg_name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"net_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"net_type": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"netmask": schema.Int64Attribute{
|
||||
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,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
)
|
||||
|
||||
func MakeSchemaDataSourceAccountGetResourceConsumption() map[string]schema.Attribute {
|
||||
return map[string]schema.Attribute{
|
||||
"account_id": schema.Int64Attribute{
|
||||
Required: true,
|
||||
},
|
||||
"consumed": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"cpu": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"disksize": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"disksizemax": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"extips": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"exttraffic": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"gpu": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"ram": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"seps": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"sep_id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"data_name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"disk_size": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"disk_size_max": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
"reserved": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"cpu": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"disk_size": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"disk_size_max": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"ext_ips": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"ext_traffic": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"gpu": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"ram": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"seps": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"sep_id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"data_name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"disk_size": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"disk_size_max": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
"resource_limits": schema.SingleNestedAttribute{
|
||||
Optional: 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,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
func MakeSchemaDataSourceAccountListDeleted() 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",
|
||||
},
|
||||
"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)",
|
||||
},
|
||||
|
||||
// computed attributes
|
||||
"id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"items": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"dc_location": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"ckey": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"meta": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.StringType,
|
||||
},
|
||||
"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,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"compute_features": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.StringType,
|
||||
},
|
||||
"company": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"companyurl": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"cpu_allocation_parameter": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"cpu_allocation_ratio": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"created_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"created_by": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_by": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"account_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"account_name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"updated_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"resource_limits": schema.SingleNestedAttribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"cu_c": schema.Float64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"cu_d": schema.Float64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"cu_dm": schema.Float64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"cu_i": schema.Float64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"cu_m": schema.Float64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"cu_np": schema.Float64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"gpu_units": schema.Float64Attribute{
|
||||
Optional: true,
|
||||
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,
|
||||
},
|
||||
"version": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"vins": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.Int64Type,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"entry_count": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
)
|
||||
|
||||
func MakeSchemaDataSourceAccountGetResourceListConsumption() map[string]schema.Attribute {
|
||||
return map[string]schema.Attribute{
|
||||
"items": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"account_id": schema.Int64Attribute{
|
||||
Required: true,
|
||||
},
|
||||
"consumed": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"cpu": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"disksize": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"disksizemax": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"extips": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"exttraffic": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"gpu": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"ram": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"seps": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"sep_id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"data_name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"disk_size": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"disk_size_max": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"reserved": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"cpu": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"disksize": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"disksizemax": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"extips": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"exttraffic": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"gpu": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"ram": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"seps": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"sep_id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"data_name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"disk_size": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"disk_size_max": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"entry_count": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
)
|
||||
|
||||
func MakeSchemaDataSourceAccountRGList() map[string]schema.Attribute {
|
||||
return map[string]schema.Attribute{
|
||||
// required attributes
|
||||
"account_id": schema.Int64Attribute{
|
||||
Required: true,
|
||||
Description: "ID of the account",
|
||||
},
|
||||
|
||||
// optional attributes
|
||||
"rg_id": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "find by rg id",
|
||||
},
|
||||
"vins_id": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "find by vins id",
|
||||
},
|
||||
"vm_id": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "find by vm id",
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "find by name",
|
||||
},
|
||||
"status": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "find by status",
|
||||
},
|
||||
"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)",
|
||||
},
|
||||
|
||||
// computed attributes
|
||||
"id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"items": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"computes": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"started": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"stopped": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"resources": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"consumed": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"cpu": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"disksize": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"disksizemax": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"extips": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"exttraffic": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"gpu": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"ram": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"seps": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"sep_id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"data_name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"disk_size": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"disk_size_max": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"limits": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"cpu": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"disksize": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"disksizemax": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"extips": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"exttraffic": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"gpu": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"ram": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"seps": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"reserved": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"cpu": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"disksize": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"disksizemax": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"extips": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"exttraffic": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"gpu": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"ram": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"seps": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"sep_id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"data_name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"disk_size": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"disk_size_max": schema.Float64Attribute{
|
||||
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,
|
||||
},
|
||||
"rg_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"milestones": 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,
|
||||
},
|
||||
"vinses": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"entry_count": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
|
||||
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
func MakeSchemaResourceAccount() map[string]schema.Attribute {
|
||||
return map[string]schema.Attribute{
|
||||
// required attributes
|
||||
"account_name": schema.StringAttribute{
|
||||
Required: true,
|
||||
Description: "name of the account",
|
||||
},
|
||||
"username": schema.StringAttribute{
|
||||
Required: true,
|
||||
Description: "username of owner the account",
|
||||
},
|
||||
|
||||
// optional attributes
|
||||
"emailaddress": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "email",
|
||||
},
|
||||
"send_access_emails": schema.BoolAttribute{
|
||||
Optional: true,
|
||||
Description: "if true send emails when a user is granted access to resources",
|
||||
},
|
||||
"uniq_pools": schema.ListAttribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ElementType: types.StringType,
|
||||
},
|
||||
"users": schema.ListNestedAttribute{
|
||||
Optional: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"user_id": schema.StringAttribute{
|
||||
Required: true,
|
||||
},
|
||||
"access_type": schema.StringAttribute{
|
||||
Required: true,
|
||||
},
|
||||
"recursive_delete": schema.BoolAttribute{
|
||||
Optional: true,
|
||||
// default is false
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"cpu_allocation_parameter": schema.StringAttribute{
|
||||
Computed: true,
|
||||
Optional: true,
|
||||
Description: "set cpu allocation parameter",
|
||||
},
|
||||
"cpu_allocation_ratio": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
Optional: true,
|
||||
Description: "set cpu allocation ratio",
|
||||
},
|
||||
"available_templates": schema.SetAttribute{
|
||||
Optional: true,
|
||||
ElementType: types.Int64Type,
|
||||
Description: "Share images with account",
|
||||
},
|
||||
"restore": schema.BoolAttribute{
|
||||
Optional: true,
|
||||
Description: "restore a deleted account",
|
||||
},
|
||||
"permanently": schema.BoolAttribute{
|
||||
Optional: true,
|
||||
Description: "whether to completely delete the account",
|
||||
// default is false
|
||||
},
|
||||
"enable": schema.BoolAttribute{
|
||||
Optional: true,
|
||||
Description: "enable/disable account",
|
||||
},
|
||||
"resource_limits": schema.SingleNestedAttribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"cu_c": schema.Float64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"cu_d": schema.Float64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"cu_i": schema.Float64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"cu_m": schema.Float64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"cu_np": schema.Float64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"gpu_units": schema.Float64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"compute_features": schema.SetAttribute{
|
||||
Optional: true,
|
||||
ElementType: types.StringType,
|
||||
Computed: true,
|
||||
Validators: []validator.Set{
|
||||
setvalidator.ValueStringsAre(stringvalidator.OneOfCaseInsensitive("hugepages", "numa", "cpupin", "vfnic")),
|
||||
},
|
||||
},
|
||||
"account_id": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"dc_location": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"ckey": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
// computed attributes
|
||||
"id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
PlanModifiers: []planmodifier.String{
|
||||
stringplanmodifier.UseStateForUnknown(),
|
||||
},
|
||||
},
|
||||
"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,
|
||||
},
|
||||
"created_by": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"created_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"deactivation_time": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_by": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"displayname": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"resource_types": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.Int64Type,
|
||||
},
|
||||
"status": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"updated_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"version": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"vins": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.Int64Type,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
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 AccountAuditsListDataSourceCheckPresence(ctx context.Context, accountId uint64, c *decort.DecortClient) (*account.ListAudits, error) {
|
||||
tflog.Info(ctx, fmt.Sprintf("AccountAuditsListDataSourceCheckPresence: Get info about account audits with account ID - %v", accountId))
|
||||
|
||||
auditsList, err := c.CloudBroker().Account().Audits(ctx, account.AuditsRequest{AccountID: accountId})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get info about account audits with error: %w", err)
|
||||
}
|
||||
|
||||
return &auditsList, err
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
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 AccountAvailableTemplatesListDataSourceCheckPresence(ctx context.Context, accountId uint64, c *decort.DecortClient) ([]uint64, error) {
|
||||
tflog.Info(ctx, fmt.Sprintf("AccountAvailableTemplatesListDataSourceCheckPresence: Get info about templates with account ID - %v", accountId))
|
||||
|
||||
templatesList, err := c.CloudBroker().Account().ListAvailableTemplates(ctx, account.ListAvailableTemplatesRequest{AccountID: accountId})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get info about templated with error: %w", err)
|
||||
}
|
||||
|
||||
return templatesList, err
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
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 AccountComputesListDataSourceCheckPresence(ctx context.Context, plan *models.ListComputesModel, c *decort.DecortClient) (*account.ListComputes, error) {
|
||||
tflog.Info(ctx, "AccountComputesListDataSourceCheckPresence: Get info about list accounts")
|
||||
req := account.ListComputesRequest{
|
||||
AccountID: uint64(plan.AccountID.ValueInt64()),
|
||||
}
|
||||
|
||||
if !plan.ComputeID.IsNull() {
|
||||
req.ComputeID = uint64(plan.ComputeID.ValueInt64())
|
||||
}
|
||||
if !plan.Name.IsNull() {
|
||||
req.Name = plan.Name.ValueString()
|
||||
}
|
||||
if !plan.RGName.IsNull() {
|
||||
req.RGName = plan.RGName.ValueString()
|
||||
}
|
||||
if !plan.RGID.IsNull() {
|
||||
req.RGID = uint64(plan.RGID.ValueInt64())
|
||||
}
|
||||
if !plan.TechStatus.IsNull() {
|
||||
req.TechStatus = plan.TechStatus.ValueString()
|
||||
}
|
||||
if !plan.IpAddress.IsNull() {
|
||||
req.IPAddress = plan.IpAddress.ValueString()
|
||||
}
|
||||
if !plan.ExtNetName.IsNull() {
|
||||
req.ExtNetName = plan.ExtNetName.ValueString()
|
||||
}
|
||||
if !plan.ExtNetID.IsNull() {
|
||||
req.ExtNetID = uint64(plan.ExtNetID.ValueInt64())
|
||||
}
|
||||
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, "AccountComputesListDataSourceCheckPresence: before call CloudBroker().Account().List", map[string]any{"req": req})
|
||||
|
||||
listComputes, err := c.CloudBroker().Account().ListComputes(ctx, req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get list computes with error: %w", err)
|
||||
}
|
||||
tflog.Info(ctx, "AccountComputesListDataSourceCheckPresence: response from CloudBroker().Account().List")
|
||||
|
||||
return listComputes, err
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
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 AccountDisksListCheckPresence(ctx context.Context, plan *models.DataSourceAccountDisksListModel, c *decort.DecortClient) (*account.ListDisks, error) {
|
||||
tflog.Info(ctx, "AccountDisksListCheckPresence: Get info about account disks list")
|
||||
|
||||
disksListReq := account.ListDisksRequest{
|
||||
AccountID: uint64(plan.AccountID.ValueInt64()),
|
||||
}
|
||||
|
||||
if !plan.DiskID.IsNull() {
|
||||
disksListReq.DiskID = uint64(plan.DiskID.ValueInt64())
|
||||
}
|
||||
if !plan.Name.IsNull() {
|
||||
disksListReq.Name = plan.Name.ValueString()
|
||||
}
|
||||
if !plan.DiskMaxSize.IsNull() {
|
||||
disksListReq.DiskMaxSize = uint64(plan.DiskMaxSize.ValueInt64())
|
||||
}
|
||||
if !plan.Type.IsNull() {
|
||||
disksListReq.Type = plan.Type.ValueString()
|
||||
}
|
||||
if !plan.Page.IsNull() {
|
||||
disksListReq.Page = uint64(plan.Page.ValueInt64())
|
||||
}
|
||||
if !plan.Size.IsNull() {
|
||||
disksListReq.Size = uint64(plan.Size.ValueInt64())
|
||||
}
|
||||
if !plan.SortBy.IsNull() {
|
||||
disksListReq.SortBy = plan.SortBy.ValueString()
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "AccountDisksListCheckPresence: before call CloudBroker().Account().ListDisks", map[string]any{"req": disksListReq})
|
||||
disksList, err := c.CloudBroker().Account().ListDisks(ctx, disksListReq)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get info about account disks list with error: %w", err)
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "AccountDisksListCheckPresence: response from CloudBroker().Account().ListDisks")
|
||||
|
||||
return disksList, err
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
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 AccountFlipgroupsListCheckPresence(ctx context.Context, plan *models.DataSourceAccountFlipgroupsListModel, c *decort.DecortClient) (*account.ListFLIPGroups, error) {
|
||||
tflog.Info(ctx, "AccountFlipgroupsListCheckPresence: Get info about account flipgroups list")
|
||||
|
||||
flipgroupsListReq := account.ListFLIPGroupsRequest{AccountID: uint64(plan.AccountID.ValueInt64())}
|
||||
|
||||
if !plan.Name.IsNull() {
|
||||
flipgroupsListReq.Name = plan.Name.ValueString()
|
||||
}
|
||||
if !plan.VINSID.IsNull() {
|
||||
flipgroupsListReq.VINSID = uint64(plan.VINSID.ValueInt64())
|
||||
}
|
||||
if !plan.VINSName.IsNull() {
|
||||
flipgroupsListReq.VINSName = plan.VINSName.ValueString()
|
||||
}
|
||||
if !plan.ExtNetID.IsNull() {
|
||||
flipgroupsListReq.ExtNetID = uint64(plan.ExtNetID.ValueInt64())
|
||||
}
|
||||
if !plan.ByIP.IsNull() {
|
||||
flipgroupsListReq.ByIP = plan.ByIP.ValueString()
|
||||
}
|
||||
if !plan.FLIPGroupID.IsNull() {
|
||||
flipgroupsListReq.FLIPGroupID = uint64(plan.FLIPGroupID.ValueInt64())
|
||||
}
|
||||
if !plan.SortBy.IsNull() {
|
||||
flipgroupsListReq.SortBy = plan.SortBy.ValueString()
|
||||
}
|
||||
if !plan.Page.IsNull() {
|
||||
flipgroupsListReq.Page = uint64(plan.Page.ValueInt64())
|
||||
}
|
||||
if !plan.Size.IsNull() {
|
||||
flipgroupsListReq.Size = uint64(plan.Size.ValueInt64())
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "AccountListCheckPresence: before call CloudBroker().Account().ListFLIPGroups", map[string]any{"req": flipgroupsListReq})
|
||||
flipgroupsList, err := c.CloudBroker().Account().ListFLIPGroups(ctx, flipgroupsListReq)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get info about account flipgroups list with error: %w", err)
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "AccountListCheckPresence: response from CloudBroker().Account().ListFLIPGroups")
|
||||
|
||||
return flipgroupsList, err
|
||||
}
|
||||
@@ -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 AccountGetResourceConsumptionDataSourceCheckPresence(ctx context.Context, accountId uint64, c *decort.DecortClient) (*account.RecordResourceConsumption, error) {
|
||||
tflog.Info(ctx, fmt.Sprintf("AccountGetResourceConsumptionDataSourceCheckPresence: Get info about account with ID - %v", accountId))
|
||||
|
||||
record, err := c.CloudBroker().Account().GetResourceConsumption(ctx, account.GetResourceConsumptionRequest{AccountID: accountId})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get info about resource with error: %w", err)
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "AccountGetResourceConsumptionDataSourceCheckPresence: response from CloudBroker().Account().GetResourceConsumption",
|
||||
map[string]any{"account_id": accountId, "response": record})
|
||||
|
||||
return record, err
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
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 AccountListDeletedCheckPresence(ctx context.Context, plan *models.DataSourceAccountListDeletedModel, c *decort.DecortClient) (*account.ListAccounts, error) {
|
||||
tflog.Info(ctx, "AccountListDeletedCheckPresence: Get info about account list deleted")
|
||||
|
||||
accListDelReq := account.ListDeletedRequest{}
|
||||
|
||||
if !plan.ByID.IsNull() {
|
||||
accListDelReq.ByID = uint64(plan.ByID.ValueInt64())
|
||||
}
|
||||
if !plan.Name.IsNull() {
|
||||
accListDelReq.Name = plan.Name.ValueString()
|
||||
}
|
||||
if !plan.ACL.IsNull() {
|
||||
accListDelReq.ACL = plan.ACL.ValueString()
|
||||
}
|
||||
if !plan.Page.IsNull() {
|
||||
accListDelReq.Page = uint64(plan.Page.ValueInt64())
|
||||
}
|
||||
if !plan.Size.IsNull() {
|
||||
accListDelReq.Size = uint64(plan.Size.ValueInt64())
|
||||
}
|
||||
if !plan.SortBy.IsNull() {
|
||||
accListDelReq.SortBy = plan.SortBy.ValueString()
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "AccountListDeletedCheckPresence: before call CloudBroker().Account().ListDeleted", map[string]any{"req": accListDelReq})
|
||||
accListDel, err := c.CloudBroker().Account().ListDeleted(ctx, accListDelReq)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get info about account with error: %w", err)
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "AccountListDeletedCheckPresence: response from CloudBroker().Account().ListDeleted")
|
||||
|
||||
return accListDel, err
|
||||
}
|
||||
@@ -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 AccountGetResourceConsumptionListDataSourceCheckPresence(ctx context.Context, c *decort.DecortClient) (*account.ListResources, error) {
|
||||
tflog.Info(ctx, "AccountGetResourceConsumptionListDataSourceCheckPresence: Get info about account resource consumption list")
|
||||
|
||||
record, err := c.CloudBroker().Account().ListResourceConsumption(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get info about resource with error: %w", err)
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "AccountGetResourceConsumptionListDataSourceCheckPresence: response from CloudBroker().Account().ListResourceConsumption",
|
||||
map[string]any{"response": record})
|
||||
|
||||
return record, err
|
||||
}
|
||||
@@ -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 AccountRGListCheckPresence(ctx context.Context, plan *models.DataSourceAccountRGListModel, c *decort.DecortClient) (*account.ListRG, error) {
|
||||
tflog.Info(ctx, "AccountRGListCheckPresence: Get info about account rg list")
|
||||
|
||||
rgListReq := account.ListRGRequest{AccountID: uint64(plan.AccountID.ValueInt64())}
|
||||
|
||||
if !plan.RGID.IsNull() {
|
||||
rgListReq.RGID = uint64(plan.RGID.ValueInt64())
|
||||
}
|
||||
if !plan.VinsID.IsNull() {
|
||||
rgListReq.VINSID = uint64(plan.VinsID.ValueInt64())
|
||||
}
|
||||
if !plan.VMID.IsNull() {
|
||||
rgListReq.VMID = uint64(plan.VMID.ValueInt64())
|
||||
}
|
||||
if !plan.Name.IsNull() {
|
||||
rgListReq.Name = plan.Name.ValueString()
|
||||
}
|
||||
if !plan.Status.IsNull() {
|
||||
rgListReq.Status = plan.Status.ValueString()
|
||||
}
|
||||
if !plan.Page.IsNull() {
|
||||
rgListReq.Page = uint64(plan.Page.ValueInt64())
|
||||
}
|
||||
if !plan.Size.IsNull() {
|
||||
rgListReq.Size = uint64(plan.Size.ValueInt64())
|
||||
}
|
||||
if !plan.SortBy.IsNull() {
|
||||
rgListReq.SortBy = plan.SortBy.ValueString()
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "AccountRGListCheckPresence: before call CloudBroker().Account().ListRG", map[string]any{"req": rgListReq})
|
||||
rgList, err := c.CloudBroker().Account().ListRG(ctx, rgListReq)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get info about account with error: %w", err)
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "AccountRGListCheckPresence: response from CloudBroker().Account().ListRG")
|
||||
|
||||
return rgList, err
|
||||
}
|
||||
@@ -0,0 +1,725 @@
|
||||
package utilities
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
|
||||
"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/ic"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/status"
|
||||
)
|
||||
|
||||
// AccountResourceCheckPresence checks if account with accountId exists
|
||||
func AccountResourceCheckPresence(ctx context.Context, accountId uint64, c *decort.DecortClient) (*account.RecordAccount, error) {
|
||||
tflog.Info(ctx, fmt.Sprintf("AccountResourceCheckPresence: Get info about resource with ID - %v", accountId))
|
||||
|
||||
accountRecord, err := c.CloudBroker().Account().Get(ctx, account.GetRequest{AccountID: accountId})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("AccountResourceCheckPresence: cannot get info about resource with error: %w", err)
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "AccountResourceCheckPresence: response from CloudBroker().Account().Get", map[string]any{"account_id": accountId, "response": accountRecord})
|
||||
|
||||
return accountRecord, err
|
||||
}
|
||||
|
||||
// AccountReadStatus loads account resource by its id, gets it current status. Performs restore and enable if needed for
|
||||
// Deleted status.
|
||||
// In case of failure returns errors.
|
||||
func AccountReadStatus(ctx context.Context, state *models.ResourceAccountModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "AccountReadStatus: Read status resource with ID", map[string]any{"account_id": state.Id.ValueString()})
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
accountId, err := strconv.ParseUint(state.Id.ValueString(), 10, 64)
|
||||
if err != nil {
|
||||
diags.AddError("AccountReadStatus: Cannot parse resource ID from state", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
recordAccount, err := AccountResourceCheckPresence(ctx, accountId, c)
|
||||
if err != nil {
|
||||
diags.AddError("AccountReadStatus: Unable to Read account before status check", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
// check resource status
|
||||
switch recordAccount.Status {
|
||||
case status.Disabled:
|
||||
tflog.Info(ctx, "The account is in status Disabled, troubles may occur with update. Please, enable account first.")
|
||||
|
||||
case status.Deleted:
|
||||
restore := state.Restore.ValueBool()
|
||||
if state.Restore.IsNull() {
|
||||
restore = true
|
||||
} // default true
|
||||
if restore {
|
||||
// attempt to restore account
|
||||
tflog.Info(ctx, "AccountReadStatus: account with status.Deleted is being read, attempt to restore it", map[string]any{
|
||||
"account_id": accountId,
|
||||
"status": recordAccount.Status})
|
||||
diags.Append(RestoreAccount(ctx, accountId, c)...)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, "AccountReadStatus: cannot restore account")
|
||||
return diags
|
||||
}
|
||||
tflog.Info(ctx, "AccountReadStatus: account restored successfully", map[string]any{"account_id": accountId})
|
||||
} else {
|
||||
tflog.Info(ctx, "AccountReadStatus: account is i status Deleted but restore is not specified")
|
||||
}
|
||||
|
||||
case status.Destroyed:
|
||||
diags.AddError(
|
||||
"AccountReadStatus: Account is in status Destroyed",
|
||||
fmt.Sprintf("the resource with account_id %d cannot be read or updated because it has been destroyed", accountId),
|
||||
)
|
||||
return diags
|
||||
|
||||
case status.Destroying:
|
||||
diags.AddError(
|
||||
"AccountReadStatus: Account is in progress with status Destroying",
|
||||
fmt.Sprintf("the resource with account_id %d cannot be read or updated because it is currently being destroyed", accountId),
|
||||
)
|
||||
return diags
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// RestoreAccount performs account Restore request.
|
||||
// Returns error in case of failures.
|
||||
func RestoreAccount(ctx context.Context, accountId uint64, c *decort.DecortClient) diag.Diagnostics {
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
restoreReq := account.RestoreRequest{
|
||||
AccountID: accountId,
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "RestoreAccount: before calling CloudBroker().Account().Restore", map[string]any{"account_id": accountId, "req": restoreReq})
|
||||
|
||||
res, err := c.CloudBroker().Account().Restore(ctx, restoreReq)
|
||||
if err != nil {
|
||||
diags.AddError(
|
||||
"RestoreAccount: cannot restore account",
|
||||
err.Error(),
|
||||
)
|
||||
return diags
|
||||
}
|
||||
tflog.Info(ctx, "RestoreAccount: response from CloudBroker().Account().Restore", map[string]any{"account_id": accountId, "response": res})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// EnableDisableAccount performs account Enable/Disable request.
|
||||
// Returns error in case of failures.
|
||||
func EnableDisableAccount(ctx context.Context, accountId uint64, enable bool, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start EnableDisableAccount", map[string]any{"account_id": accountId})
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
if enable {
|
||||
tflog.Info(ctx, "EnableDisableAccount: before calling CloudBroker().Account().Enable", map[string]any{"account_id": accountId})
|
||||
res, err := c.CloudBroker().Account().Enable(ctx, account.EnableRequest{AccountID: accountId})
|
||||
if err != nil {
|
||||
diags.AddError(
|
||||
"EnableDisableAccount: cannot enable account",
|
||||
err.Error(),
|
||||
)
|
||||
return diags
|
||||
}
|
||||
tflog.Info(ctx, "EnableDisableAccount: response from CloudBroker().Account().Enable", map[string]any{"account_id": accountId, "response": res})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "EnableDisableAccount: before calling CloudBroker().Account().Disable", map[string]any{"account_id": accountId})
|
||||
res, err := c.CloudBroker().Account().Disable(ctx, account.DisableRequest{AccountID: accountId})
|
||||
if err != nil {
|
||||
diags.AddError(
|
||||
"EnableDisableAccount: cannot disable account",
|
||||
err.Error(),
|
||||
)
|
||||
return diags
|
||||
}
|
||||
tflog.Info(ctx, "EnableDisableAccount: response from CloudBroker().Account().Disable", map[string]any{"account_id": accountId, "response": res})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func UtilityAccountCreate(ctx context.Context, plan *models.ResourceAccountModel, c *decort.DecortClient) (diag.Diagnostics, *uint64) {
|
||||
tflog.Info(ctx, "Start UtilityAccountCreate", map[string]any{"account_id": plan.AccountID})
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
req := account.CreateRequest{
|
||||
Name: plan.AccountName.ValueString(),
|
||||
Username: plan.Username.ValueString(),
|
||||
}
|
||||
|
||||
if !plan.EmailAddress.IsUnknown() {
|
||||
req.EmailAddress = plan.EmailAddress.ValueString()
|
||||
}
|
||||
|
||||
if !plan.SendAccessEmails.IsUnknown() {
|
||||
req.SendAccessEmails = plan.SendAccessEmails.ValueBool()
|
||||
}
|
||||
|
||||
if !plan.UniqPools.IsUnknown() {
|
||||
var uniqPools []string
|
||||
diags.Append(plan.UniqPools.ElementsAs(ctx, &uniqPools, true)...)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, "UtilityAccountCreate: cannot populate UniqPools with plan.UniqPools object element")
|
||||
return diags, nil
|
||||
}
|
||||
req.UniqPools = uniqPools
|
||||
}
|
||||
|
||||
if !plan.ResourceLimits.IsUnknown() {
|
||||
var resourceLimitsPlan models.ResourceLimitsInAccountResourceModel
|
||||
diags.Append(plan.ResourceLimits.As(ctx, &resourceLimitsPlan, basetypes.ObjectAsOptions{})...)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, "UtilityAccountCreate: cannot populate ResourceLimits with plan.ResourceLimits object element")
|
||||
return diags, nil
|
||||
}
|
||||
|
||||
if resourceLimitsPlan.CUM.ValueFloat64() == 0 {
|
||||
req.MaxMemoryCapacity = -1
|
||||
} else {
|
||||
req.MaxMemoryCapacity = int64(resourceLimitsPlan.CUM.ValueFloat64())
|
||||
}
|
||||
|
||||
if resourceLimitsPlan.CUD.ValueFloat64() == 0 {
|
||||
req.MaxVDiskCapacity = -1
|
||||
} else {
|
||||
req.MaxVDiskCapacity = int64(resourceLimitsPlan.CUD.ValueFloat64())
|
||||
}
|
||||
|
||||
if resourceLimitsPlan.CUC.ValueFloat64() == 0 {
|
||||
req.MaxCPUCapacity = -1
|
||||
} else {
|
||||
req.MaxCPUCapacity = int64(resourceLimitsPlan.CUC.ValueFloat64())
|
||||
}
|
||||
|
||||
if resourceLimitsPlan.CUI.ValueFloat64() == 0 {
|
||||
req.MaxNumPublicIP = -1
|
||||
} else {
|
||||
req.MaxNumPublicIP = int64(resourceLimitsPlan.CUI.ValueFloat64())
|
||||
}
|
||||
|
||||
if resourceLimitsPlan.CUNP.ValueFloat64() == 0 {
|
||||
req.MaxNetworkPeerTransfer = -1
|
||||
} else {
|
||||
req.MaxNetworkPeerTransfer = int64(resourceLimitsPlan.CUNP.ValueFloat64())
|
||||
}
|
||||
|
||||
if resourceLimitsPlan.GPUUnits.ValueFloat64() == 0 {
|
||||
req.GPUUnits = -1
|
||||
} else {
|
||||
req.GPUUnits = int64(resourceLimitsPlan.GPUUnits.ValueFloat64())
|
||||
}
|
||||
}
|
||||
|
||||
accountId, err := c.CloudBroker().Account().Create(ctx, req)
|
||||
if err != nil {
|
||||
diags.AddError("UtilityAccountCreate: Unable to create account",
|
||||
err.Error())
|
||||
return diags, nil
|
||||
}
|
||||
|
||||
if !plan.Users.IsUnknown() {
|
||||
usersPlan := make([]models.UsersModel, 0, len(plan.Users.Elements()))
|
||||
|
||||
diagsI := plan.Users.ElementsAs(ctx, &usersPlan, true)
|
||||
if diagsI.HasError() {
|
||||
tflog.Error(ctx, "UtilityAccountCreate: cannot populate usersPlan with plan.Users list elements")
|
||||
diags.AddWarning("UtilityAccountCreate: cannot populate usersPlan with plan.Users list elements",
|
||||
fmt.Sprintf("%v", diagsI))
|
||||
return diags, nil
|
||||
}
|
||||
for _, v := range usersPlan {
|
||||
req := account.AddUserRequest{
|
||||
AccountID: accountId,
|
||||
Username: v.UserID.ValueString(),
|
||||
AccessType: v.AccessType.ValueString(),
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().Account().AddUser(ctx, req)
|
||||
if err != nil {
|
||||
diags.AddWarning("UtilityAccountCreate: Unable to add users",
|
||||
err.Error())
|
||||
return diags, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !plan.CPUAllocationParameter.IsUnknown() {
|
||||
req := account.SetCPUAllocationParameterRequest{
|
||||
AccountID: accountId,
|
||||
StrictLoose: plan.CPUAllocationParameter.ValueString(),
|
||||
}
|
||||
_, err := c.CloudBroker().Account().SetCPUAllocationParameter(ctx, req)
|
||||
if err != nil {
|
||||
diags.AddWarning("UtilityAccountCreate: Unable to set CPUAllocationParameter ",
|
||||
err.Error())
|
||||
return diags, nil
|
||||
}
|
||||
}
|
||||
|
||||
if !plan.CPUAllocationRatio.IsUnknown() {
|
||||
req := account.SetCPUAllocationRatioRequest{
|
||||
AccountID: accountId,
|
||||
Ratio: plan.CPUAllocationRatio.ValueFloat64(),
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().Account().SetCPUAllocationRatio(ctx, req)
|
||||
if err != nil {
|
||||
diags.AddWarning("UtilityAccountCreate: Unable to set CPUAllocationRatio ",
|
||||
err.Error())
|
||||
return diags, nil
|
||||
}
|
||||
}
|
||||
|
||||
if !plan.Enable.IsUnknown() && !plan.Enable.ValueBool() {
|
||||
_, err := c.CloudBroker().Account().Disable(ctx, account.DisableRequest{
|
||||
AccountID: accountId,
|
||||
})
|
||||
if err != nil {
|
||||
diags.AddWarning("UtilityAccountCreate: Unable to disable account",
|
||||
err.Error())
|
||||
return diags, nil
|
||||
}
|
||||
}
|
||||
|
||||
if !plan.AvailableTemplates.IsUnknown() {
|
||||
diagsI := UtilityAccountAvailiableTemplatesUpdate(ctx, plan, plan, true, c)
|
||||
if diagsI.HasError() {
|
||||
tflog.Error(ctx, "UtilityAccountCreate: error with utilityAccountAvailiableTemplatesUpdate")
|
||||
diags.AddWarning("UtilityAccountCreate: cannot populate usersPlan with plan.Users list elements", fmt.Sprintf("%v", diagsI))
|
||||
return diags, nil
|
||||
}
|
||||
}
|
||||
tflog.Info(ctx, "End UtilityAccountCreate", map[string]any{"account_id": plan.AccountID.ValueInt64()})
|
||||
return diags, &accountId
|
||||
}
|
||||
|
||||
// UpdateAccount updates disk data: account_name, resource_limits, send_access_emails.
|
||||
// Returns error in case of failures.
|
||||
func UpdateAccount(ctx context.Context, accountId uint64, plan, state *models.ResourceAccountModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start UpdateAccount", map[string]any{"account_id": accountId})
|
||||
|
||||
var diags diag.Diagnostics
|
||||
var updateNeeded bool
|
||||
|
||||
updateReq := account.UpdateRequest{
|
||||
AccountID: accountId,
|
||||
}
|
||||
|
||||
// check if account_name was changed
|
||||
if !plan.AccountName.Equal(state.AccountName) {
|
||||
updateReq.Name = plan.AccountName.ValueString()
|
||||
updateNeeded = true
|
||||
}
|
||||
|
||||
// check if resource_limits were changed
|
||||
if !plan.ResourceLimits.Equal(state.ResourceLimits) && !plan.ResourceLimits.IsUnknown() {
|
||||
tflog.Info(ctx, "UpdateAccount: new ResourceLimits specified", map[string]any{"account_id": accountId})
|
||||
var resourceLimitsPlan models.ResourceLimitsInAccountResourceModel
|
||||
diags.Append(plan.ResourceLimits.As(ctx, &resourceLimitsPlan, basetypes.ObjectAsOptions{})...)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, "UpdateAccount: cannot populate ResourceLimits with plan.ResourceLimits object element")
|
||||
return diags
|
||||
}
|
||||
|
||||
if resourceLimitsPlan.CUM.ValueFloat64() == 0 {
|
||||
updateReq.MaxMemoryCapacity = -1
|
||||
} else {
|
||||
updateReq.MaxMemoryCapacity = int64(resourceLimitsPlan.CUM.ValueFloat64())
|
||||
}
|
||||
|
||||
if resourceLimitsPlan.CUD.ValueFloat64() == 0 {
|
||||
updateReq.MaxVDiskCapacity = -1
|
||||
} else {
|
||||
updateReq.MaxVDiskCapacity = int64(resourceLimitsPlan.CUD.ValueFloat64())
|
||||
}
|
||||
|
||||
if resourceLimitsPlan.CUC.ValueFloat64() == 0 {
|
||||
updateReq.MaxCPUCapacity = -1
|
||||
} else {
|
||||
updateReq.MaxCPUCapacity = int64(resourceLimitsPlan.CUC.ValueFloat64())
|
||||
}
|
||||
|
||||
if resourceLimitsPlan.CUI.ValueFloat64() == 0 {
|
||||
updateReq.MaxNumPublicIP = -1
|
||||
} else {
|
||||
updateReq.MaxNumPublicIP = int64(resourceLimitsPlan.CUI.ValueFloat64())
|
||||
}
|
||||
|
||||
if resourceLimitsPlan.CUNP.ValueFloat64() == 0 {
|
||||
updateReq.MaxNetworkPeerTransfer = -1
|
||||
} else {
|
||||
updateReq.MaxNetworkPeerTransfer = int64(resourceLimitsPlan.CUNP.ValueFloat64())
|
||||
}
|
||||
|
||||
if resourceLimitsPlan.GPUUnits.ValueFloat64() == 0 {
|
||||
updateReq.GPUUnits = -1
|
||||
} else {
|
||||
updateReq.GPUUnits = int64(resourceLimitsPlan.GPUUnits.ValueFloat64())
|
||||
}
|
||||
|
||||
updateNeeded = true
|
||||
}
|
||||
|
||||
// check if send_access_emails was changed
|
||||
if !plan.SendAccessEmails.Equal(state.SendAccessEmails) && !plan.SendAccessEmails.IsNull() {
|
||||
updateReq.SendAccessEmails = plan.SendAccessEmails.ValueBool()
|
||||
updateNeeded = true
|
||||
}
|
||||
|
||||
if !updateNeeded {
|
||||
tflog.Info(ctx, "UpdateAccount: no general account update is needed because neither account_name, nor resource_limits, nor send_access_emails were changed.", map[string]any{
|
||||
"account_id": plan.Id.ValueString(),
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
// perform account update
|
||||
tflog.Info(ctx, "UpdateAccount: before calling CloudBroker().Account().Update", map[string]any{
|
||||
"account_id": accountId,
|
||||
"req": updateReq,
|
||||
})
|
||||
res, err := c.CloudBroker().Account().Update(ctx, updateReq)
|
||||
if err != nil {
|
||||
diags.AddError("UpdateAccount: Unable to update account",
|
||||
err.Error())
|
||||
return diags
|
||||
}
|
||||
tflog.Info(ctx, "UpdateAccount: response from CloudBroker().Account().Update", map[string]any{
|
||||
"account_id": accountId,
|
||||
"response": res})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddDeleteUsersAccount adds/deletes users to/from account.
|
||||
// In case of failure returns errors.
|
||||
func AddDeleteUsersAccount(ctx context.Context, accountId uint64, plan, state *models.ResourceAccountModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start AddDeleteUsersAccount: new users specified", map[string]any{"account_id": accountId})
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
usersPlan := make([]models.UsersModel, 0, len(plan.Users.Elements()))
|
||||
diags.Append(plan.Users.ElementsAs(ctx, &usersPlan, true)...)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, "AddDeleteUsersAccount: cannot populate usersPlan with plan.Users list elements")
|
||||
return diags
|
||||
}
|
||||
|
||||
usersState := make([]models.UsersModel, 0, len(state.Users.Elements()))
|
||||
diags.Append(state.Users.ElementsAs(ctx, &usersState, true)...)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, "AddDeleteUsersAccount: cannot populate usersState with state.Users list elements")
|
||||
return diags
|
||||
}
|
||||
|
||||
// define users to be deleted, added and updated
|
||||
var deletedUsers, addedUsers, updatedUsers []models.UsersModel
|
||||
for _, user := range usersState {
|
||||
if !containsUser(usersPlan, user) {
|
||||
deletedUsers = append(deletedUsers, user)
|
||||
}
|
||||
}
|
||||
for _, user := range usersPlan {
|
||||
if !containsUser(usersState, user) {
|
||||
addedUsers = append(addedUsers, user)
|
||||
} else if isChangedUser(usersState, user) {
|
||||
updatedUsers = append(updatedUsers, user)
|
||||
}
|
||||
}
|
||||
|
||||
// delete users
|
||||
if len(deletedUsers) == 0 {
|
||||
tflog.Info(ctx, "AddDeleteUsersAccount: no users need to be deleted", map[string]any{"account_id": accountId})
|
||||
}
|
||||
if len(deletedUsers) > 0 {
|
||||
tflog.Info(ctx, "AddDeleteUsersAccount: users need to be deleted", map[string]any{
|
||||
"accountId": accountId,
|
||||
"deletedUsers": deletedUsers})
|
||||
|
||||
for _, user := range deletedUsers {
|
||||
delUserReq := account.DeleteUserRequest{
|
||||
AccountID: accountId,
|
||||
UserName: user.UserID.ValueString(),
|
||||
RecursiveDelete: user.RecursiveDelete.ValueBool(), // default false
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "AddDeleteUsersAccount: before calling CloudBroker().Account().DeleteUser", map[string]any{"account_id": accountId, "req": delUserReq})
|
||||
res, err := c.CloudBroker().Account().DeleteUser(ctx, delUserReq)
|
||||
tflog.Info(ctx, "AddDeleteUsersAccount: response from CloudBroker().Account().DeleteUser", map[string]any{"account_id": accountId, "response": res})
|
||||
if err != nil {
|
||||
diags.AddError(
|
||||
"AddDeleteUsersAccount: can not delete user from account",
|
||||
err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add users
|
||||
if len(addedUsers) == 0 {
|
||||
tflog.Info(ctx, "AddDeleteUsersAccount: no users needs to be added", map[string]any{"account_id": accountId})
|
||||
}
|
||||
if len(addedUsers) > 0 {
|
||||
tflog.Info(ctx, "AddDeleteUsersAccount: users need to be added", map[string]any{"account_id": accountId})
|
||||
|
||||
for _, user := range addedUsers {
|
||||
addUserReq := account.AddUserRequest{
|
||||
AccountID: accountId,
|
||||
Username: user.UserID.ValueString(),
|
||||
AccessType: user.AccessType.ValueString(),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "AddDeleteUsersAccount: before calling CloudBroker().Account().AddUser", map[string]any{
|
||||
"account_id": accountId,
|
||||
"addUserReq": addUserReq})
|
||||
res, err := c.CloudBroker().Account().AddUser(ctx, addUserReq)
|
||||
if err != nil {
|
||||
diags.AddError("AddDeleteUsersAccount: Unable to add users to account",
|
||||
err.Error())
|
||||
}
|
||||
tflog.Info(ctx, "AddDeleteUsersAccount: response from CloudBroker().Account().AddUser", map[string]any{
|
||||
"account_id": accountId,
|
||||
"response": res})
|
||||
}
|
||||
}
|
||||
|
||||
// update users
|
||||
if len(updatedUsers) == 0 {
|
||||
tflog.Info(ctx, "AddDeleteUsersAccount: no users needs to be updated", map[string]any{"account_id": accountId})
|
||||
}
|
||||
if len(updatedUsers) > 0 {
|
||||
tflog.Info(ctx, "AddDeleteUsersAccount: users need to be updated", map[string]any{"account_id": accountId})
|
||||
|
||||
for _, user := range updatedUsers {
|
||||
updUserReq := account.UpdateUserRequest{
|
||||
AccountID: accountId,
|
||||
UserID: user.UserID.ValueString(),
|
||||
AccessType: user.AccessType.ValueString(),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "AddDeleteUsersAccount: before calling CloudBroker().Account().UpdateUser", map[string]any{
|
||||
"account_id": accountId,
|
||||
"updatedUsers": updatedUsers})
|
||||
res, err := c.CloudBroker().Account().UpdateUser(ctx, updUserReq)
|
||||
if err != nil {
|
||||
diags.AddError("AddDeleteUsersAccount: Unable to update users",
|
||||
err.Error())
|
||||
}
|
||||
tflog.Info(ctx, "AddDeleteUsersAccount: response from CloudBroker().Account().UpdateUser", map[string]any{
|
||||
"account_id": accountId,
|
||||
"response": res})
|
||||
}
|
||||
}
|
||||
|
||||
return diags
|
||||
}
|
||||
|
||||
func containsUser(users []models.UsersModel, target models.UsersModel) bool {
|
||||
for _, user := range users {
|
||||
if target.UserID == user.UserID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func isChangedUser(users []models.UsersModel, target models.UsersModel) bool {
|
||||
for _, user := range users {
|
||||
if user.UserID.Equal(target.UserID) && !user.AccessType.Equal(target.AccessType) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func UtilityAccountCPUParameterUpdate(ctx context.Context, accountID uint64, plan *models.ResourceAccountModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start utilityAccountCPUParameterUpdate", map[string]any{"account_id": plan.AccountID})
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
_, err := c.CloudBroker().Account().SetCPUAllocationParameter(ctx, account.SetCPUAllocationParameterRequest{
|
||||
AccountID: accountID,
|
||||
StrictLoose: plan.CPUAllocationParameter.ValueString(),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
diags.AddError("utilityAccountCPUParameterUpdate: Unable to update CPUAllocationParameter",
|
||||
err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
return diags
|
||||
}
|
||||
|
||||
func UtilityAccountCPURatioUpdate(ctx context.Context, accountID uint64, plan *models.ResourceAccountModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start utilityAccountCPURatioUpdate", map[string]any{"account_id": plan.AccountID})
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
_, err := c.CloudBroker().Account().SetCPUAllocationRatio(ctx, account.SetCPUAllocationRatioRequest{
|
||||
AccountID: accountID,
|
||||
Ratio: plan.CPUAllocationRatio.ValueFloat64(),
|
||||
})
|
||||
if err != nil {
|
||||
diags.AddError("utilityAccountCPURatioUpdate: Unable to update CPUAllocationRatio",
|
||||
err.Error())
|
||||
return diags
|
||||
}
|
||||
return diags
|
||||
}
|
||||
|
||||
func UtilityAccountAvailiableTemplatesUpdate(ctx context.Context, state, plan *models.ResourceAccountModel, afterCreate bool, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start utilityAccountAvailiableTemplatesUpdate", map[string]any{"account_id": plan.AccountID})
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
if afterCreate {
|
||||
|
||||
imageIds := make([]uint64, 0, len(plan.AvailableTemplates.Elements()))
|
||||
|
||||
diags.Append(plan.AvailableTemplates.ElementsAs(ctx, &imageIds, true)...)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, "UpdateAccount: cannot populate AvailableTemplates with plan.AvailableTemplates object element")
|
||||
return diags
|
||||
}
|
||||
|
||||
if len(imageIds) == 0 {
|
||||
diags.AddError(
|
||||
"you have not been granted access to any images",
|
||||
"len(imageIds) == 0",
|
||||
)
|
||||
return diags
|
||||
}
|
||||
tflog.Error(ctx, "you have not been granted access to any images")
|
||||
if err := ic.ExistImages(ctx, imageIds, c); err != nil {
|
||||
diags.AddError(
|
||||
fmt.Sprintf("can not grant access for available templates: %s", err.Error()),
|
||||
err.Error(),
|
||||
)
|
||||
return diags
|
||||
}
|
||||
tflog.Error(ctx, fmt.Sprint(imageIds))
|
||||
|
||||
req := account.GrantAccessTemplatesRequest{
|
||||
AccountID: uint64(state.AccountID.ValueInt64()),
|
||||
ImageIDs: imageIds,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().Account().GrantAccessTemplates(ctx, req)
|
||||
if err != nil {
|
||||
diags.AddError(
|
||||
fmt.Sprintf("can not grant access for available templates: %s", err.Error()),
|
||||
err.Error(),
|
||||
)
|
||||
return diags
|
||||
}
|
||||
|
||||
return diags
|
||||
}
|
||||
|
||||
var oldSet, newSet []int
|
||||
diags.Append(plan.AvailableTemplates.ElementsAs(ctx, &newSet, true)...)
|
||||
diags.Append(state.AvailableTemplates.ElementsAs(ctx, &oldSet, true)...)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, "UtilityAccountCreate: cannot populate newSet or oldSet with AvailableTemplates")
|
||||
return diags
|
||||
}
|
||||
|
||||
revokeAT := setDifference(oldSet, newSet)
|
||||
if len(revokeAT) > 0 {
|
||||
imageIds := make([]uint64, 0, len(revokeAT))
|
||||
|
||||
for _, imageId := range revokeAT {
|
||||
imageIds = append(imageIds, imageId)
|
||||
}
|
||||
|
||||
if err := ic.ExistImages(ctx, imageIds, c); err != nil {
|
||||
diags.AddError(fmt.Sprintf("can not grant access for available templates: %s", err), err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
req := account.RevokeAccessTemplatesRequest{
|
||||
AccountID: uint64(state.AccountID.ValueInt64()),
|
||||
ImageIDs: imageIds,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().Account().RevokeAccessTemplates(ctx, req)
|
||||
if err != nil {
|
||||
diags.AddError("UtilityAccountCreate: error with RevokeAccessTemplates", err.Error())
|
||||
return diags
|
||||
}
|
||||
}
|
||||
|
||||
addedAT := setDifference(newSet, oldSet)
|
||||
if len(addedAT) > 0 {
|
||||
imageIds := make([]uint64, 0, len(addedAT))
|
||||
|
||||
imageIds = append(imageIds, addedAT...)
|
||||
|
||||
if err := ic.ExistImages(ctx, imageIds, c); err != nil {
|
||||
diags.AddError(fmt.Sprintf("can grant access for available templates: %s", err.Error()), err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
req := account.GrantAccessTemplatesRequest{
|
||||
AccountID: uint64(plan.AccountID.ValueInt64()),
|
||||
ImageIDs: imageIds,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().Account().GrantAccessTemplates(ctx, req)
|
||||
if err != nil {
|
||||
diags.AddError("UtilityAccountCreate: error with GrantAccessTemplates", err.Error())
|
||||
return diags
|
||||
}
|
||||
}
|
||||
|
||||
return diags
|
||||
}
|
||||
|
||||
func setDifference(set, check []int) []uint64 {
|
||||
mapCheck := make(map[int]struct{})
|
||||
for _, id := range check {
|
||||
mapCheck[id] = struct{}{}
|
||||
}
|
||||
var diff []uint64
|
||||
for _, id := range set {
|
||||
if _, ok := mapCheck[id]; !ok {
|
||||
diff = append(diff, uint64(id))
|
||||
}
|
||||
}
|
||||
return diff
|
||||
}
|
||||
|
||||
func UtilityAccountComputeFeaturesUpdate(ctx context.Context, accountID uint64, plan *models.ResourceAccountModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
var compFeatures []string
|
||||
|
||||
diags.Append(plan.ComputeFeatures.ElementsAs(ctx, &compFeatures, true)...)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, "utilityAccountComputeFeaturesUpdate: cannot populate compFeatures with plan.ComputeFeatures object element")
|
||||
return diags
|
||||
}
|
||||
|
||||
req := account.UpdateComputeFeaturesRequest{
|
||||
AccountID: accountID,
|
||||
ComputeFeatures: compFeatures,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().Account().UpdateComputeFeatures(ctx, req)
|
||||
if err != nil {
|
||||
diags.AddError("utilityAccountComputeFeaturesUpdate: error with CloudBroker().Account().UpdateComputeFeatures", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
return diags
|
||||
}
|
||||
Reference in New Issue
Block a user