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

View File

@@ -0,0 +1,91 @@
package account
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/cloudapi/account/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/schemas"
)
// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &dataSourceAccount{}
)
func NewDataSourceAccount() datasource.DataSource {
return &dataSourceAccount{}
}
// dataSourceAccount is the data source implementation.
type dataSourceAccount struct {
client *decort.DecortClient
}
func (d *dataSourceAccount) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
// Read Terraform configuration data into the model
var state models.DataSourceAccountModel
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceAccount: Error get state")
return
}
accountId := uint64(state.AccountID.ValueInt64())
tflog.Info(ctx, "Read dataSourceAccount: 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 dataSourceAccount: Error set timeout")
return
}
tflog.Info(ctx, "Read dataSourceAccount: set timeouts successfully", map[string]any{
"account_id": accountId,
"readTimeout": readTimeout})
ctx, cancel := context.WithTimeout(ctx, readTimeout)
defer cancel()
// Map response body to schema
resp.Diagnostics.Append(flattens.AccountDataSource(ctx, &state, d.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceAccount: 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 dataSourceAccount: Error set state")
return
}
tflog.Info(ctx, "End read dataSourceAccount", map[string]any{"account_id": accountId})
}
func (d *dataSourceAccount) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: schemas.MakeSchemaDataSourceAccount(),
Blocks: map[string]schema.Block{
"timeouts": timeouts.Block(ctx),
},
}
}
func (d *dataSourceAccount) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_account"
}
// Configure adds the provider configured client to the data source.
func (d *dataSourceAccount) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
tflog.Info(ctx, "Get Configure dataSourceAccount")
d.client = client.DataSource(ctx, &req, resp)
tflog.Info(ctx, "Getting Configure dataSourceAccount successfully")
}

View File

@@ -0,0 +1,91 @@
package account
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/cloudapi/account/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/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 + "_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")
}

View File

@@ -0,0 +1,88 @@
package account
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/cloudapi/account/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/schemas"
)
// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &dataSourceAccountComputesList{}
)
func NewDataSourceAccountComputesList() datasource.DataSource {
return &dataSourceAccountComputesList{}
}
// dataSourceAccountComputesList 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.DataSourceAccountComputesListModel
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 account computes list")
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 + "_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")
}

View File

@@ -0,0 +1,88 @@
package account
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/cloudapi/account/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/schemas"
)
// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &dataSourceAccountConsumedUnitsByType{}
)
func NewDataSourceAccountConsumedUnitsByType() datasource.DataSource {
return &dataSourceAccountConsumedUnitsByType{}
}
// dataSourceAccountConsumedUnitsByType is the data source implementation.
type dataSourceAccountConsumedUnitsByType struct {
client *decort.DecortClient
}
func (d *dataSourceAccountConsumedUnitsByType) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
// Read Terraform configuration data into the model
var state models.DataSourceAccountConsumedUnitsByTypeModel
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceAccountConsumedUnitsByType: Error get state")
return
}
tflog.Info(ctx, "Read dataSourceAccountConsumedUnitsByType: 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 dataSourceAccountConsumedUnitsByType: Error set timeout")
return
}
tflog.Info(ctx, "Read dataSourceAccountConsumedUnitsByType: 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.AccountConsumedUnitsByTypeDataSource(ctx, &state, d.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceAccountConsumedUnitsByType: Error flatten data source")
return
}
// Set refreshed state
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceAccountConsumedUnitsByType: Error set state")
return
}
tflog.Info(ctx, "End read dataSourceAccountConsumedUnitsByType")
}
func (d *dataSourceAccountConsumedUnitsByType) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: schemas.MakeSchemaDataSourceAccountConsumedUnitsByType(),
Blocks: map[string]schema.Block{
"timeouts": timeouts.Block(ctx),
},
}
}
func (d *dataSourceAccountConsumedUnitsByType) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_account_consumed_units_by_type"
}
// Configure adds the provider configured client to the data source.
func (d *dataSourceAccountConsumedUnitsByType) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
tflog.Info(ctx, "Get Configure dataSourceAccountConsumedUnitsByType")
d.client = client.DataSource(ctx, &req, resp)
tflog.Info(ctx, "Getting Configure dataSourceAccountConsumedUnitsByType successfully")
}

View File

@@ -0,0 +1,91 @@
package account
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/cloudapi/account/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/schemas"
)
// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &dataSourceAccountConsumedUints{}
)
func NewDataSourceAccountConsumedUnits() datasource.DataSource {
return &dataSourceAccountConsumedUints{}
}
// dataSourceAccountConsumedUints is the data source implementation.
type dataSourceAccountConsumedUints struct {
client *decort.DecortClient
}
func (d *dataSourceAccountConsumedUints) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
// Read Terraform configuration data into the model
var state models.DataSourceAccountConsumedUnitsModel
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceAccountConsumedUints: Error get state")
return
}
accountId := uint64(state.AccountID.ValueInt64())
tflog.Info(ctx, "Read dataSourceAccountConsumedUints: 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 dataSourceAccountConsumedUints: Error set timeout")
return
}
tflog.Info(ctx, "Read dataSourceAccountConsumedUints: 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.AccountConsumedUnitsDataSource(ctx, &state, d.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceAccountConsumedUints: Error flatten data source")
return
}
// Set refreshed state
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceAccountConsumedUints: Error set state")
return
}
tflog.Info(ctx, "End read dataSourceAccountConsumedUints", map[string]any{"account_id": accountId})
}
func (d *dataSourceAccountConsumedUints) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: schemas.MakeSchemaDataSourceAccountConsumedUnits(),
Blocks: map[string]schema.Block{
"timeouts": timeouts.Block(ctx),
},
}
}
func (d *dataSourceAccountConsumedUints) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_account_consumed_units"
}
// Configure adds the provider configured client to the data source.
func (d *dataSourceAccountConsumedUints) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
tflog.Info(ctx, "Get Configure dataSourceAccountConsumedUints")
d.client = client.DataSource(ctx, &req, resp)
tflog.Info(ctx, "Getting Configure dataSourceAccountConsumedUints successfully")
}

View File

@@ -0,0 +1,88 @@
package account
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/cloudapi/account/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/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 + "_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")
}

View File

@@ -0,0 +1,88 @@
package account
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/cloudapi/account/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/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 + "_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")
}

View File

@@ -0,0 +1,91 @@
package account
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/cloudapi/account/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/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 + "_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")
}

View File

@@ -0,0 +1,89 @@
package account
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/cloudapi/account/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/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 + "_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")
}

View File

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

View File

@@ -0,0 +1,88 @@
package account
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/cloudapi/account/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/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 + "_account_deleted_list"
}
// 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")
}

View File

@@ -0,0 +1,91 @@
package account
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/cloudapi/account/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/schemas"
)
// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &dataSourceAccountReservedUnits{}
)
func NewDataSourceAccountReservedUnits() datasource.DataSource {
return &dataSourceAccountReservedUnits{}
}
// dataSourceAccount is the data source implementation.
type dataSourceAccountReservedUnits struct {
client *decort.DecortClient
}
func (d *dataSourceAccountReservedUnits) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
// Read Terraform configuration data into the model
var state models.DataSourceAccountReservedUnitsModel
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceAccountReservedUnits: Error get state")
return
}
accountId := uint64(state.AccountID.ValueInt64())
tflog.Info(ctx, "Read dataSourceAccountReservedUnits: 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 dataSourceAccountReservedUnits: Error set timeout")
return
}
tflog.Info(ctx, "Read dataSourceAccountReservedUnits: 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.AccountReservedUnitsDataSource(ctx, &state, d.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceAccountReservedUnits: 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 dataSourceAccountReservedUnits: Error set state")
return
}
tflog.Info(ctx, "End read dataSourceAccountReservedUnits", map[string]any{"account_id": accountId})
}
func (d *dataSourceAccountReservedUnits) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: schemas.MakeSchemaDataSourceAccountReservedUnits(),
Blocks: map[string]schema.Block{
"timeouts": timeouts.Block(ctx),
},
}
}
func (d *dataSourceAccountReservedUnits) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_account_reserved_units"
}
// Configure adds the provider configured client to the data source.
func (d *dataSourceAccountReservedUnits) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
tflog.Info(ctx, "Get Configure dataSourceAccountReservedUnits")
d.client = client.DataSource(ctx, &req, resp)
tflog.Info(ctx, "Getting Configure dataSourceAccountReservedUnits successfully")
}

View File

@@ -0,0 +1,88 @@
package account
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/cloudapi/account/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/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 + "_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")
}

View File

@@ -0,0 +1,88 @@
package account
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/cloudapi/account/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/schemas"
)
// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &dataSourceAccountTemplatesList{}
)
func NewDataSourceAccountTemplatesList() datasource.DataSource {
return &dataSourceAccountTemplatesList{}
}
// dataSourceAccountTemplatesList is the data source implementation.
type dataSourceAccountTemplatesList struct {
client *decort.DecortClient
}
func (d *dataSourceAccountTemplatesList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
// Read Terraform configuration data into the model
var state models.DataSourceAccountTemplatesListModel
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceAccountTemplatesList: Error get state")
return
}
tflog.Info(ctx, "Read dataSourceAccountTemplatesList: 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 dataSourceAccountTemplatesList: Error set timeout")
return
}
tflog.Info(ctx, "Read dataSourceAccountTemplatesList: 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.AccountTemplatesListDataSource(ctx, &state, d.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceAccountTemplatesList: Error flatten data source")
return
}
// Set refreshed state
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceAccountTemplatesList: Error set state")
return
}
tflog.Info(ctx, "End read dataSourceAccountList")
}
func (d *dataSourceAccountTemplatesList) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: schemas.MakeSchemaDataSourceAccountTemplatesList(),
Blocks: map[string]schema.Block{
"timeouts": timeouts.Block(ctx),
},
}
}
func (d *dataSourceAccountTemplatesList) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_account_templates_list"
}
// Configure adds the provider configured client to the data source.
func (d *dataSourceAccountTemplatesList) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
tflog.Info(ctx, "Get Configure dataSourceAccountTemplatesList")
d.client = client.DataSource(ctx, &req, resp)
tflog.Info(ctx, "Getting Configure dataSourceAccountTemplatesList successfully")
}

View File

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

View File

@@ -0,0 +1,84 @@
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/cloudapi/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/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{
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
DeletedTime: types.Int64Value(int64(item.DeletedTime)),
AccountID: types.Int64Value(int64(item.ID)),
AccountName: types.StringValue(item.Name),
Status: types.StringValue(item.Status),
UpdatedTime: types.Int64Value(int64(item.UpdatedTime)),
}
i.ComputeFeatures, diags = types.ListValueFrom(ctx, types.StringType, item.ComputeFeatures)
if diags.HasError() {
tflog.Error(ctx, fmt.Sprint("flattens.AccountListDeletedDataSource: cannot flatten item.ComputeFeatures to i.ComputeFeatures", diags))
}
aclList := make([]models.RecordACLModel, 0, len(item.ACL))
for _, acl := range item.ACL {
a := models.RecordACLModel{
Explicit: types.BoolValue(acl.IsExplicit),
GUID: types.StringValue(acl.GUID),
Right: types.StringValue(acl.Rights),
Status: types.StringValue(acl.Status),
Type: types.StringValue(acl.Type),
UserGroupID: types.StringValue(acl.UgroupID),
}
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
}

View File

@@ -0,0 +1,162 @@
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/decort-golang-sdk/pkg/cloudapi/account"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/utilities"
)
// AccountDataSource flattens data source for account.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func AccountDataSource(ctx context.Context, state *models.DataSourceAccountModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.AccountDataSource")
diags := diag.Diagnostics{}
accountId := uint64(state.AccountID.ValueInt64())
recordAccount, err := utilities.AccountDataSourceCheckPresence(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.AccountDataSource: before flatten", map[string]any{"account_id": accountId, "recordAccount": recordAccount})
id := uuid.New()
*state = models.DataSourceAccountModel{
AccountID: state.AccountID,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),
DCLocation: types.StringValue(recordAccount.DCLocation),
CKey: types.StringValue(recordAccount.CKey),
ACL: flattenACLInAccount(ctx, recordAccount.ACL),
Company: types.StringValue(recordAccount.Company),
CompanyURL: types.StringValue(recordAccount.CompanyURL),
Computes: flattenComputes(ctx, recordAccount.Computes),
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)),
Machines: flattenMachines(ctx, recordAccount.Machines),
AccountName: types.StringValue(recordAccount.Name),
ResourceLimits: flattenResourceLimits(ctx, recordAccount.ResourceLimits),
SendAccessEmails: types.BoolValue(recordAccount.SendAccessEmails),
Status: types.StringValue(recordAccount.Status),
UpdatedTime: types.Int64Value(int64(recordAccount.UpdatedTime)),
Version: types.Int64Value(int64(recordAccount.Version)),
VINSes: types.Int64Value(int64(recordAccount.VINSes)),
}
state.VINS, diags = types.ListValueFrom(ctx, types.Int64Type, recordAccount.VINS)
if diags.HasError() {
tflog.Error(ctx, fmt.Sprint("flattens.AccountDataSource: cannot flatten recordAccount.VINS to state.VINS", diags))
}
state.ComputeFeatures, diags = types.ListValueFrom(ctx, types.StringType, recordAccount.ComputeFeatures)
if diags.HasError() {
tflog.Error(ctx, fmt.Sprint("flattens.AccountDataSource: cannot flatten recordAccount.ComputeFeatures to state.ComputeFeatures", diags))
}
tflog.Info(ctx, "flattens.AccountDataSource: after flatten", map[string]any{"account_id": state.Id.ValueString()})
tflog.Info(ctx, "End flattens.AccountDataSource", map[string]any{"account_id": state.Id.ValueString()})
return nil
}
func flattenComputes(ctx context.Context, computes account.Computes) types.Object {
tflog.Info(ctx, "Start flattenComputes")
temp := models.ComputesInAccountModel{
Started: types.Int64Value(int64(computes.Started)),
Stopped: types.Int64Value(int64(computes.Stopped)),
}
res, err := types.ObjectValueFrom(ctx, models.ItemComputesInAccount, temp)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenComputes struct to obj", err))
}
tflog.Info(ctx, "End flattenComputes")
return res
}
func flattenMachines(ctx context.Context, machines account.Machines) types.Object {
tflog.Info(ctx, "Start flattenMachines")
temp := models.MachinesInAccountModel{
Running: types.Int64Value(int64(machines.Running)),
Halted: types.Int64Value(int64(machines.Halted)),
}
res, err := types.ObjectValueFrom(ctx, models.ItemMachinesInAccount, temp)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenMachines struct to obj", err))
}
tflog.Info(ctx, "End flattenMachines")
return res
}
func flattenResourceLimits(ctx context.Context, limits account.ResourceLimits) types.Object {
tflog.Info(ctx, "Start flattenResourceLimits")
temp := models.ResourceLimitsInAccountModel{
CUC: types.Float64Value(limits.CUC),
CUD: types.Float64Value(limits.CUD),
CUI: types.Float64Value(limits.CUI),
CUM: types.Float64Value(limits.CUM),
CUDM: types.Float64Value(limits.CUDM),
CUNP: types.Float64Value(limits.CUNP),
GPUUnits: types.Float64Value(limits.GPUUnits),
}
res, err := types.ObjectValueFrom(ctx, models.ItemResourceLimitsInAccount, temp)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenResourceLimits struct to obj", err))
}
tflog.Info(ctx, "End flattenResourceLimits")
return res
}
func flattenACLInAccount(ctx context.Context, aclList []account.RecordACL) 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.IsExplicit),
GUID: types.StringValue(item.GUID),
Right: types.StringValue(item.Rights),
Status: types.StringValue(item.Status),
Type: types.StringValue(item.Type),
UserGroupID: types.StringValue(item.UgroupID),
CanBeDeleted: types.BoolValue(item.CanBeDeleted),
}
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
}

View File

@@ -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/cloudapi/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/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
}

View File

@@ -0,0 +1,83 @@
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/cloudapi/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/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.DataSourceAccountComputesListModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.AccountComputesListDataSource")
diags := diag.Diagnostics{}
computesList, err := utilities.AccountComputesListCheckPresence(ctx, state, c)
if err != nil {
diags.AddError("Cannot get info about account computes list", err.Error())
return diags
}
tflog.Info(ctx, "flattens.AccountComputesListDataSource: before flatten")
id := uuid.New()
*state = models.DataSourceAccountComputesListModel{
AccountID: state.AccountID,
ComputeID: state.ComputeID,
Name: state.Name,
RGName: state.RGName,
RGID: state.RGID,
TechStatus: state.TechStatus,
IPAddress: state.IPAddress,
ExtNetName: state.ExtNetName,
ExtNetID: state.ExtNetID,
Page: state.Page,
Size: state.Size,
Timeouts: state.Timeouts,
SortBy: state.SortBy,
Id: types.StringValue(id.String()),
EntryCount: types.Int64Value(int64(computesList.EntryCount)),
}
items := make([]models.ItemComputeModel, 0, len(computesList.Data))
for _, item := range computesList.Data {
i := models.ItemComputeModel{
AccountID: types.Int64Value(int64(item.AccountID)),
AccountName: types.StringValue(item.AccountName),
CPUs: types.Int64Value(int64(item.CPUs)),
CreatedBy: types.StringValue(item.CreatedBy),
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
DeletedBy: types.StringValue(item.DeletedBy),
DeletedTime: types.Int64Value(int64(item.DeletedTime)),
ComputeID: types.Int64Value(int64(item.ComputeID)),
ComputeName: types.StringValue(item.ComputeName),
RAM: types.Int64Value(int64(item.RAM)),
Registered: types.BoolValue(item.Registered),
RGID: types.Int64Value(int64(item.RGID)),
RGName: types.StringValue(item.RGName),
Status: types.StringValue(item.Status),
TechStatus: types.StringValue(item.TechStatus),
TotalDisksSize: types.Int64Value(int64(item.TotalDisksSize)),
UpdatedBy: types.StringValue(item.UpdatedBy),
UpdatedTime: types.Int64Value(int64(item.UpdatedTime)),
UserManaged: types.BoolValue(item.UserManaged),
VINSConnected: types.Int64Value(int64(item.VINSConnected)),
}
items = append(items, i)
}
state.Items = items
tflog.Info(ctx, "flattens.AccountComputesListDataSource: after flatten")
tflog.Info(ctx, "End flattens.AccountComputesListDataSource")
return nil
}

View File

@@ -0,0 +1,49 @@
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/cloudapi/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/utilities"
)
// AccountConsumedUnitsDataSource flattens data source for account consumed units.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func AccountConsumedUnitsDataSource(ctx context.Context, state *models.DataSourceAccountConsumedUnitsModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.AccountConsumedUnitsDataSource")
diags := diag.Diagnostics{}
accountId := uint64(state.AccountID.ValueInt64())
limits, err := utilities.AccountConsumedUnitsDataSourceCheckPresence(ctx, accountId, c)
if err != nil {
diags.AddError(fmt.Sprintf("Cannot get info about account consumed units with account ID %v", accountId), err.Error())
return diags
}
id := uuid.New()
*state = models.DataSourceAccountConsumedUnitsModel{
AccountID: state.AccountID,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),
CUC: types.Float64Value(limits.CUC),
CUD: types.Float64Value(limits.CUD),
CUDM: types.Float64Value(limits.CUDM),
CUI: types.Float64Value(limits.CUI),
CUM: types.Float64Value(limits.CUM),
CUNP: types.Float64Value(limits.CUNP),
GPUUnits: types.Float64Value(limits.GPUUnits),
}
tflog.Info(ctx, "End flattens.AccountConsumedUnitsDataSource", map[string]any{"account_id": state.Id.ValueString()})
return nil
}

View File

@@ -0,0 +1,47 @@
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/cloudapi/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/utilities"
)
// AccountConsumedUnitsByTypeDataSource flattens data source for account consumed units by type.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func AccountConsumedUnitsByTypeDataSource(ctx context.Context, state *models.DataSourceAccountConsumedUnitsByTypeModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.AccountConsumedUnitsByTypeDataSource")
diags := diag.Diagnostics{}
accountId := uint64(state.AccountID.ValueInt64())
cuType := state.CUType.ValueString()
res, err := utilities.AccountConsumedUnitsByTypeDataSourceCheckPresence(ctx, accountId, cuType, c)
if err != nil {
diags.AddError(fmt.Sprintf("Cannot get info about account consumed units by type with account ID %v", accountId), err.Error())
return diags
}
tflog.Info(ctx, "flattens.AccountConsumedUnitsByTypeDataSource: before flatten", map[string]any{"account_id": accountId, "res": res})
id := uuid.New()
*state = models.DataSourceAccountConsumedUnitsByTypeModel{
AccountID: state.AccountID,
CUType: state.CUType,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),
CUResult: types.Float64Value(res),
}
tflog.Info(ctx, "End flattens.AccountConsumedUnitsByTypeDataSource", map[string]any{"account_id": state.Id.ValueString()})
return nil
}

View File

@@ -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/cloudapi/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/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
}

View File

@@ -0,0 +1,80 @@
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/cloudapi/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/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,
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
}

View File

@@ -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/cloudapi/account"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/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
}

View File

@@ -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/cloudapi/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/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
}

View File

@@ -0,0 +1,83 @@
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/cloudapi/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/utilities"
)
// AccountListDataSource flattens data source for account list.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func AccountListDataSource(ctx context.Context, state *models.DataSourceAccountListModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.AccountListDataSource")
diags := diag.Diagnostics{}
accountList, err := utilities.AccountListCheckPresence(ctx, state, c)
if err != nil {
diags.AddError("Cannot get info about account list", err.Error())
return diags
}
tflog.Info(ctx, "flattens.AccountListDataSource: before flatten")
id := uuid.New()
*state = models.DataSourceAccountListModel{
ByID: state.ByID,
Name: state.Name,
ACL: state.ACL,
Status: state.Status,
Page: state.Page,
Size: state.Size,
Timeouts: state.Timeouts,
SortBy: state.SortBy,
Id: types.StringValue(id.String()),
EntryCount: types.Int64Value(int64(accountList.EntryCount)),
}
items := make([]models.ItemAccountListModel, 0, len(accountList.Data))
for _, item := range accountList.Data {
i := models.ItemAccountListModel{
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
DeletedTime: types.Int64Value(int64(item.DeletedTime)),
AccountID: types.Int64Value(int64(item.ID)),
AccountName: types.StringValue(item.Name),
Status: types.StringValue(item.Status),
UpdatedTime: types.Int64Value(int64(item.UpdatedTime)),
}
i.ComputeFeatures, diags = types.ListValueFrom(ctx, types.StringType, item.ComputeFeatures)
if diags.HasError() {
tflog.Error(ctx, fmt.Sprint("flattens.AccountListDataSource: cannot flatten item.ComputeFeatures to i.ComputeFeatures", diags))
}
aclList := make([]models.RecordACLModel, 0, len(item.ACL))
for _, acl := range item.ACL {
a := models.RecordACLModel{
Explicit: types.BoolValue(acl.IsExplicit),
GUID: types.StringValue(acl.GUID),
Right: types.StringValue(acl.Rights),
Status: types.StringValue(acl.Status),
Type: types.StringValue(acl.Type),
UserGroupID: types.StringValue(acl.UgroupID),
}
aclList = append(aclList, a)
}
i.ACL = aclList
items = append(items, i)
}
state.Items = items
tflog.Info(ctx, "flattens.AccountListDataSource: after flatten")
tflog.Info(ctx, "End flattens.AccountListDataSource")
return nil
}

View File

@@ -0,0 +1,50 @@
package flattens
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/utilities"
)
// AccountReservedUnitsDataSource flattens data source for account.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func AccountReservedUnitsDataSource(ctx context.Context, state *models.DataSourceAccountReservedUnitsModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.AccountReservedUnitsDataSource")
diags := diag.Diagnostics{}
accountId := uint64(state.AccountID.ValueInt64())
recordAccount, err := utilities.AccountReservedUnitsCheck(ctx, state, 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.AccountReservedUnitsDataSource: before flatten", map[string]any{"account_id": accountId, "recordAccount": recordAccount})
*state = models.DataSourceAccountReservedUnitsModel{
AccountID: state.AccountID,
Timeouts: state.Timeouts,
CUC: types.Float64Value(recordAccount.CUC),
CUD: types.Float64Value(recordAccount.CUD),
CUI: types.Float64Value(recordAccount.CUI),
CUM: types.Float64Value(recordAccount.CUM),
CUDM: types.Float64Value(recordAccount.CUDM),
CUNP: types.Float64Value(recordAccount.CUNP),
GPUUnits: types.Float64Value(recordAccount.GPUUnits),
}
tflog.Info(ctx, "flattens.AccountReservedUnitsDataSource: after flatten", map[string]any{"account_id": state.AccountID.ValueInt64()})
tflog.Info(ctx, "End flattens.AccountReservedUnitsDataSource", map[string]any{"account_id": state.AccountID.ValueInt64()})
return nil
}

View File

@@ -0,0 +1,124 @@
package flattens
import (
"context"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/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/cloudapi/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/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.RGID)),
Milestones: types.Int64Value(int64(item.Milestones)),
RGName: types.StringValue(item.RGName),
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
}

View File

@@ -0,0 +1,68 @@
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/cloudapi/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/utilities"
)
// AccountTemplatesListDataSource flattens data source for account templates list.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func AccountTemplatesListDataSource(ctx context.Context, state *models.DataSourceAccountTemplatesListModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.AccountTemplatesListDataSource")
diags := diag.Diagnostics{}
templatesList, err := utilities.AccountTemplatesListCheckPresence(ctx, state, c)
if err != nil {
diags.AddError("Cannot get info about account templates list", err.Error())
return diags
}
tflog.Info(ctx, "flattens.AccountTemplatesListDataSource: before flatten")
id := uuid.New()
*state = models.DataSourceAccountTemplatesListModel{
AccountID: state.AccountID,
IncludeDeleted: state.IncludeDeleted,
ImageID: state.ImageID,
Name: state.Name,
Type: state.Type,
SortBy: state.SortBy,
Page: state.Page,
Size: state.Size,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),
EntryCount: types.Int64Value(int64(templatesList.EntryCount)),
}
items := make([]models.ItemTemplateModel, 0, len(templatesList.Data))
for _, item := range templatesList.Data {
i := models.ItemTemplateModel{
UNCPath: types.StringValue(item.UNCPath),
AccountID: types.Int64Value(int64(item.AccountID)),
Description: types.StringValue(item.Description),
ID: types.Int64Value(int64(item.ID)),
Name: types.StringValue(item.Name),
Public: types.BoolValue(item.Public),
Size: types.Int64Value(int64(item.Size)),
Status: types.StringValue(item.Status),
Type: types.StringValue(item.Type),
Username: types.StringValue(item.Username),
}
items = append(items, i)
}
state.Items = items
tflog.Info(ctx, "End flattens.AccountTemplatesListDataSource")
return nil
}

View File

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

View File

@@ -0,0 +1,139 @@
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/cloudapi/account"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/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{
// request fields
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),
Timeouts: state.Timeouts,
// response fields
Id: types.StringValue(strconv.Itoa(int(accountId))),
LastUpdated: state.LastUpdated,
AccountID: types.Int64Value(int64(recordAccount.ID)),
DCLocation: types.StringValue(recordAccount.DCLocation),
CKey: types.StringValue(recordAccount.CKey),
ACL: flattenACLInAccount(ctx, recordAccount.ACL),
Company: types.StringValue(recordAccount.Company),
CompanyURL: types.StringValue(recordAccount.CompanyURL),
Computes: flattenComputes(ctx, recordAccount.Computes),
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)),
Machines: flattenMachines(ctx, recordAccount.Machines),
Status: types.StringValue(recordAccount.Status),
UpdatedTime: types.Int64Value(int64(recordAccount.UpdatedTime)),
Version: types.Int64Value(int64(recordAccount.Version)),
VINSes: types.Int64Value(int64(recordAccount.VINSes)),
}
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.ComputeFeatures, diags = types.ListValueFrom(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
}

View File

@@ -0,0 +1,101 @@
package models
import (
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type DataSourceAccountModel struct {
// request fields
AccountID types.Int64 `tfsdk:"account_id"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
// response fields
Id types.String `tfsdk:"id"`
DCLocation types.String `tfsdk:"dc_location"`
CKey types.String `tfsdk:"ckey"`
ACL types.List `tfsdk:"acl"`
Company types.String `tfsdk:"company"`
CompanyURL types.String `tfsdk:"companyurl"`
ComputeFeatures types.List `tfsdk:"compute_features"`
Computes types.Object `tfsdk:"computes"`
CPUAllocationParameter types.String `tfsdk:"cpu_allocation_parameter"`
CPUAllocationRatio types.Float64 `tfsdk:"cpu_allocation_ratio"`
CreatedBy types.String `tfsdk:"created_by"`
CreatedTime types.Int64 `tfsdk:"created_time"`
DeactivationTime types.Float64 `tfsdk:"deactivation_time"`
DeletedBy types.String `tfsdk:"deleted_by"`
DeletedTime types.Int64 `tfsdk:"deleted_time"`
DisplayName types.String `tfsdk:"displayname"`
GUID types.Int64 `tfsdk:"guid"`
Machines types.Object `tfsdk:"machines"`
AccountName types.String `tfsdk:"account_name"`
ResourceLimits types.Object `tfsdk:"resource_limits"`
SendAccessEmails types.Bool `tfsdk:"send_access_emails"`
Status types.String `tfsdk:"status"`
UpdatedTime types.Int64 `tfsdk:"updated_time"`
Version types.Int64 `tfsdk:"version"`
VINS types.List `tfsdk:"vins"`
VINSes types.Int64 `tfsdk:"vinses"`
}
type ResourceLimitsInAccountModel 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"`
}
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"`
CanBeDeleted types.Bool `tfsdk:"can_be_deleted"`
}
type ComputesInAccountModel struct {
Started types.Int64 `tfsdk:"started"`
Stopped types.Int64 `tfsdk:"stopped"`
}
type MachinesInAccountModel struct {
Running types.Int64 `tfsdk:"running"`
Halted types.Int64 `tfsdk:"halted"`
}
var ItemResourceLimitsInAccount = map[string]attr.Type{
"cu_c": types.Float64Type,
"cu_d": types.Float64Type,
"cu_i": types.Float64Type,
"cu_m": types.Float64Type,
"cu_dm": types.Float64Type,
"cu_np": types.Float64Type,
"gpu_units": types.Float64Type,
}
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,
"can_be_deleted": types.BoolType,
}
var ItemComputesInAccount = map[string]attr.Type{
"started": types.Int64Type,
"stopped": types.Int64Type,
}
var ItemMachinesInAccount = map[string]attr.Type{
"running": types.Int64Type,
"halted": types.Int64Type,
}

View File

@@ -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"`
}

View File

@@ -0,0 +1,53 @@
package models
import (
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type DataSourceAccountComputesListModel struct {
// required fields
AccountID types.Int64 `tfsdk:"account_id"`
// optional fields
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"`
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 []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"`
ComputeID types.Int64 `tfsdk:"compute_id"`
ComputeName 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"`
}

View File

@@ -0,0 +1,22 @@
package models
import (
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type DataSourceAccountConsumedUnitsModel struct {
// request fields
AccountID types.Int64 `tfsdk:"account_id"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
// response fields
Id types.String `tfsdk:"id"`
CUC types.Float64 `tfsdk:"cu_c"`
CUD types.Float64 `tfsdk:"cu_d"`
CUDM types.Float64 `tfsdk:"cu_dm"`
CUI types.Float64 `tfsdk:"cu_i"`
CUM types.Float64 `tfsdk:"cu_m"`
CUNP types.Float64 `tfsdk:"cu_np"`
GPUUnits types.Float64 `tfsdk:"gpu_units"`
}

View File

@@ -0,0 +1,17 @@
package models
import (
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type DataSourceAccountConsumedUnitsByTypeModel struct {
// optional fields
AccountID types.Int64 `tfsdk:"account_id"`
CUType types.String `tfsdk:"cu_type"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
// response fields
Id types.String `tfsdk:"id"`
CUResult types.Float64 `tfsdk:"cu_result"`
}

View File

@@ -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"`
}

View File

@@ -0,0 +1,49 @@
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"`
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"`
}

View File

@@ -0,0 +1,45 @@
package models
import (
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type 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:"disk_size"`
DiskSizeMax types.Float64 `tfsdk:"disk_size_max"`
ExtIPs types.Int64 `tfsdk:"ext_ips"`
ExtTraffic types.Int64 `tfsdk:"ext_traffic"`
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"`
}

View File

@@ -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:"disk_size"`
DiskSizeMax types.Float64 `tfsdk:"disk_size_max"`
ExtIPs types.Int64 `tfsdk:"ext_ips"`
ExtTraffic types.Int64 `tfsdk:"ext_traffic"`
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"`
}

View File

@@ -0,0 +1,43 @@
package models
import (
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type DataSourceAccountListModel struct {
// optional fields
ByID types.Int64 `tfsdk:"by_id"`
Name types.String `tfsdk:"name"`
ACL types.String `tfsdk:"acl"`
Status types.String `tfsdk:"status"`
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 []ItemAccountListModel `tfsdk:"items"`
EntryCount types.Int64 `tfsdk:"entry_count"`
}
type ItemAccountListModel struct {
ACL []RecordACLModel `tfsdk:"acl"`
CreatedTime types.Int64 `tfsdk:"created_time"`
DeletedTime types.Int64 `tfsdk:"deleted_time"`
AccountID types.Int64 `tfsdk:"account_id"`
AccountName types.String `tfsdk:"account_name"`
Status types.String `tfsdk:"status"`
UpdatedTime types.Int64 `tfsdk:"updated_time"`
ComputeFeatures types.List `tfsdk:"compute_features"`
}
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"`
}

View File

@@ -0,0 +1,33 @@
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 {
ACL []RecordACLModel `tfsdk:"acl"`
CreatedTime types.Int64 `tfsdk:"created_time"`
DeletedTime types.Int64 `tfsdk:"deleted_time"`
AccountID types.Int64 `tfsdk:"account_id"`
AccountName types.String `tfsdk:"account_name"`
Status types.String `tfsdk:"status"`
UpdatedTime types.Int64 `tfsdk:"updated_time"`
ComputeFeatures types.List `tfsdk:"compute_features"`
}

View File

@@ -0,0 +1,21 @@
package models
import (
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type DataSourceAccountReservedUnitsModel struct {
// optional and required fields
AccountID types.Int64 `tfsdk:"account_id"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
// response fields
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"`
}

View File

@@ -0,0 +1,81 @@
package models
import (
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type 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:"pool_name"`
DiskSize types.Float64 `tfsdk:"disksize"`
DiskSizeMax types.Float64 `tfsdk:"disksizemax"`
}

View File

@@ -0,0 +1,39 @@
package models
import (
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type DataSourceAccountTemplatesListModel struct {
// required fields
AccountID types.Int64 `tfsdk:"account_id"`
// optional fields
IncludeDeleted types.Bool `tfsdk:"include_deleted"`
ImageID types.Int64 `tfsdk:"image_id"`
Name types.String `tfsdk:"name"`
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 []ItemTemplateModel `tfsdk:"items"`
EntryCount types.Int64 `tfsdk:"entry_count"`
}
type ItemTemplateModel struct {
UNCPath types.String `tfsdk:"unc_path"`
AccountID types.Int64 `tfsdk:"account_id"`
Description types.String `tfsdk:"desc"`
ID types.Int64 `tfsdk:"template_id"`
Name types.String `tfsdk:"template_name"`
Public types.Bool `tfsdk:"public"`
Size types.Int64 `tfsdk:"size"`
Status types.String `tfsdk:"status"`
Type types.String `tfsdk:"type"`
Username types.String `tfsdk:"username"`
}

View File

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

View File

@@ -0,0 +1,74 @@
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"`
Restore types.Bool `tfsdk:"restore"`
Permanently types.Bool `tfsdk:"permanently"`
Enable types.Bool `tfsdk:"enable"`
ResourceLimits types.Object `tfsdk:"resource_limits"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
// response fields
Id types.String `tfsdk:"id"`
LastUpdated types.String `tfsdk:"last_updated"`
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"`
ComputeFeatures types.List `tfsdk:"compute_features"`
Computes types.Object `tfsdk:"computes"`
CPUAllocationParameter types.String `tfsdk:"cpu_allocation_parameter"`
CPUAllocationRatio types.Float64 `tfsdk:"cpu_allocation_ratio"`
CreatedBy types.String `tfsdk:"created_by"`
CreatedTime types.Int64 `tfsdk:"created_time"`
DeactivationTime types.Float64 `tfsdk:"deactivation_time"`
DeletedBy types.String `tfsdk:"deleted_by"`
DeletedTime types.Int64 `tfsdk:"deleted_time"`
DisplayName types.String `tfsdk:"displayname"`
GUID types.Int64 `tfsdk:"guid"`
Machines types.Object `tfsdk:"machines"`
Status types.String `tfsdk:"status"`
UpdatedTime types.Int64 `tfsdk:"updated_time"`
Version types.Int64 `tfsdk:"version"`
VINS types.List `tfsdk:"vins"`
VINSes types.Int64 `tfsdk:"vinses"`
}
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,
}

View File

@@ -0,0 +1,253 @@
package account
import (
"context"
"strconv"
"time"
"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/cloudapi/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/cloudapi/account/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/schemas"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/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) {
resp.Diagnostics.AddError(
"Only users with admin privileges are able to create accounts. Contact your platform administrator or import existing account.",
"Use 'terraform import basis_account.<NAME> <ID>' command to import existing account configuration",
)
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
}
// 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
}
}
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 data last update
plan.LastUpdated = types.StringValue(time.Now().Format(time.RFC850))
// 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 call CloudAPI().Account().Delete", map[string]any{"req": delReq})
_, err := r.client.CloudAPI().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 + "_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)
}

View File

@@ -0,0 +1,162 @@
package schemas
import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
)
func MakeSchemaDataSourceAccount() map[string]schema.Attribute {
return map[string]schema.Attribute{
// required attributes
"account_id": schema.Int64Attribute{
Required: true,
Description: "account id",
},
// computed attributes
"id": schema.StringAttribute{
Computed: true,
},
"dc_location": schema.StringAttribute{
Computed: true,
},
"ckey": schema.StringAttribute{
Computed: true,
},
"acl": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"can_be_deleted": schema.BoolAttribute{
Computed: true,
},
"explicit": schema.BoolAttribute{
Computed: true,
},
"guid": schema.StringAttribute{
Computed: true,
},
"right": schema.StringAttribute{
Computed: true,
},
"status": schema.StringAttribute{
Computed: true,
},
"type": schema.StringAttribute{
Computed: true,
},
"user_group_id": schema.StringAttribute{
Computed: true,
},
},
},
},
"company": schema.StringAttribute{
Computed: true,
},
"companyurl": schema.StringAttribute{
Computed: true,
},
"compute_features": schema.ListAttribute{
Computed: true,
ElementType: types.StringType,
},
"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,
},
"account_name": schema.StringAttribute{
Computed: true,
},
"resource_limits": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"cu_c": schema.Float64Attribute{
Computed: true,
},
"cu_d": schema.Float64Attribute{
Computed: true,
},
"cu_i": schema.Float64Attribute{
Computed: true,
},
"cu_m": schema.Float64Attribute{
Computed: true,
},
"cu_dm": schema.Float64Attribute{
Computed: true,
},
"cu_np": schema.Float64Attribute{
Computed: true,
},
"gpu_units": schema.Float64Attribute{
Computed: true,
},
},
},
"send_access_emails": schema.BoolAttribute{
Computed: true,
},
"status": schema.StringAttribute{
Computed: true,
},
"updated_time": schema.Int64Attribute{
Computed: true,
},
"version": schema.Int64Attribute{
Computed: true,
},
"vins": schema.ListAttribute{
Computed: true,
ElementType: types.Int64Type,
},
"computes": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"started": schema.Int64Attribute{
Computed: true,
},
"stopped": schema.Int64Attribute{
Computed: true,
},
},
},
"machines": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"halted": schema.Int64Attribute{
Computed: true,
},
"running": schema.Int64Attribute{
Computed: true,
},
},
},
"vinses": schema.Int64Attribute{
Computed: true,
},
"cpu_allocation_parameter": schema.StringAttribute{
Computed: true,
},
"cpu_allocation_ratio": schema.Float64Attribute{
Computed: true,
},
}
}

View File

@@ -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,
},
},
},
},
}
}

View File

@@ -0,0 +1,136 @@
package schemas
import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
)
func MakeSchemaDataSourceAccountComputesList() map[string]schema.Attribute {
return map[string]schema.Attribute{
// required attributes
"account_id": schema.Int64Attribute{
Required: true,
Description: "account id",
},
// optional attributes
"compute_id": schema.Int64Attribute{
Optional: true,
Description: "find by compute id",
},
"name": schema.StringAttribute{
Optional: true,
Description: "find by name",
},
"rg_name": schema.StringAttribute{
Optional: true,
Description: "find by resource group name",
},
"rg_id": schema.Int64Attribute{
Optional: true,
Description: "find by resource group id",
},
"tech_status": schema.StringAttribute{
Optional: true,
Description: "find by tech status",
},
"ip_address": schema.StringAttribute{
Optional: true,
Description: "find by ip address",
},
"extnet_name": schema.StringAttribute{
Optional: true,
Description: "find by external network name",
},
"extnet_id": schema.Int64Attribute{
Optional: true,
Description: "find by external network 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,
},
"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,
},
}
}

View File

@@ -0,0 +1,41 @@
package schemas
import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
)
func MakeSchemaDataSourceAccountConsumedUnits() 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,
},
"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,
},
}
}

View File

@@ -0,0 +1,27 @@
package schemas
import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
)
func MakeSchemaDataSourceAccountConsumedUnitsByType() map[string]schema.Attribute {
return map[string]schema.Attribute{
// required attributes
"account_id": schema.Int64Attribute{
Required: true,
Description: "account id",
},
"cu_type": schema.StringAttribute{
Required: true,
Description: "cloud unit resource type",
},
// computed attributes
"id": schema.StringAttribute{
Computed: true,
},
"cu_result": schema.Float64Attribute{
Computed: true,
},
}
}

View File

@@ -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,
},
}
}

View File

@@ -0,0 +1,127 @@
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",
},
"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,
},
}
}

View File

@@ -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,
},
"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,
},
},
},
},
},
},
"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,
},
},
},
}
}

View File

@@ -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,
},
"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,
},
},
},
},
},
},
"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,
},
},
},
},
},
},
},
},
},
"entry_count": schema.Int64Attribute{
Computed: true,
},
}
}

View File

@@ -0,0 +1,102 @@
package schemas
import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
)
func MakeSchemaDataSourceAccountList() map[string]schema.Attribute {
return map[string]schema.Attribute{
// optional attributes
"by_id": schema.Int64Attribute{
Optional: true,
Description: "filter by id",
},
"name": schema.StringAttribute{
Optional: true,
Description: "filter by name",
},
"acl": schema.StringAttribute{
Optional: true,
Description: "filter by acl",
},
"status": schema.StringAttribute{
Optional: true,
Description: "filter 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{
"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,
},
"created_time": schema.Int64Attribute{
Computed: true,
},
"deleted_time": schema.Int64Attribute{
Computed: true,
},
"account_id": schema.Int64Attribute{
Computed: true,
},
"account_name": schema.StringAttribute{
Computed: true,
},
"status": schema.StringAttribute{
Computed: true,
},
"updated_time": schema.Int64Attribute{
Computed: true,
},
},
},
},
"entry_count": schema.Int64Attribute{
Computed: true,
},
}
}

View File

@@ -0,0 +1,98 @@
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{
"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,
},
},
},
},
"created_time": schema.Int64Attribute{
Computed: true,
},
"deleted_time": schema.Int64Attribute{
Computed: true,
},
"account_id": schema.Int64Attribute{
Computed: true,
},
"account_name": schema.StringAttribute{
Computed: true,
},
"status": schema.StringAttribute{
Computed: true,
},
"updated_time": schema.Int64Attribute{
Computed: true,
},
"compute_features": schema.ListAttribute{
Computed: true,
ElementType: types.StringType,
},
},
},
},
"entry_count": schema.Int64Attribute{
Computed: true,
},
}
}

View File

@@ -0,0 +1,37 @@
package schemas
import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
)
func MakeSchemaDataSourceAccountReservedUnits() map[string]schema.Attribute {
return map[string]schema.Attribute{
// required attributes
"account_id": schema.Int64Attribute{
Required: true,
},
// computed attributes
"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,
},
}
}

View File

@@ -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,
},
"pool_name": schema.StringAttribute{
Computed: true,
},
"disksize": schema.Float64Attribute{
Computed: true,
},
"disksizemax": 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,
},
"pool_name": schema.StringAttribute{
Computed: true,
},
"disksize": schema.Float64Attribute{
Computed: true,
},
"disksizemax": 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,
},
}
}

View File

@@ -0,0 +1,90 @@
package schemas
import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
)
func MakeSchemaDataSourceAccountTemplatesList() map[string]schema.Attribute {
return map[string]schema.Attribute{
// required attributes
"account_id": schema.Int64Attribute{
Required: true,
Description: "ID of the account",
},
// optional attributes
"include_deleted": schema.BoolAttribute{
Optional: true,
Description: "include deleted images",
},
"image_id": schema.Int64Attribute{
Optional: true,
Description: "find by image id",
},
"name": schema.StringAttribute{
Optional: true,
Description: "find by name",
},
"type": schema.StringAttribute{
Optional: true,
Description: "find by type",
},
"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{
"unc_path": schema.StringAttribute{
Computed: true,
},
"account_id": schema.Int64Attribute{
Computed: true,
},
"desc": schema.StringAttribute{
Computed: true,
},
"template_id": schema.Int64Attribute{
Computed: true,
},
"template_name": schema.StringAttribute{
Computed: true,
},
"public": schema.BoolAttribute{
Computed: true,
},
"size": schema.Int64Attribute{
Computed: true,
},
"status": schema.StringAttribute{
Computed: true,
},
"type": schema.StringAttribute{
Computed: true,
},
"username": schema.StringAttribute{
Computed: true,
},
},
},
},
"entry_count": schema.Int64Attribute{
Computed: true,
},
}
}

View File

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

View File

@@ -0,0 +1,216 @@
package schemas
import (
"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/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",
},
"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
},
},
},
},
"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,
},
},
},
// computed attributes
"id": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"last_updated": schema.StringAttribute{
Computed: true,
Description: "Timestamp of the last Terraform update of the disk resource.",
},
"account_id": schema.Int64Attribute{
Computed: true,
},
"dc_location": schema.StringAttribute{
Computed: true,
},
"ckey": schema.StringAttribute{
Computed: true,
},
"acl": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"can_be_deleted": schema.BoolAttribute{
Computed: true,
},
"explicit": schema.BoolAttribute{
Computed: true,
},
"guid": schema.StringAttribute{
Computed: true,
},
"right": schema.StringAttribute{
Computed: true,
},
"status": schema.StringAttribute{
Computed: true,
},
"type": schema.StringAttribute{
Computed: true,
},
"user_group_id": schema.StringAttribute{
Computed: true,
},
},
},
},
"company": schema.StringAttribute{
Computed: true,
},
"companyurl": schema.StringAttribute{
Computed: true,
},
"compute_features": schema.ListAttribute{
Computed: true,
ElementType: types.StringType,
},
"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,
},
"status": schema.StringAttribute{
Computed: true,
},
"updated_time": schema.Int64Attribute{
Computed: true,
},
"version": schema.Int64Attribute{
Computed: true,
},
"vins": schema.ListAttribute{
Computed: true,
ElementType: types.Int64Type,
},
"computes": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"started": schema.Int64Attribute{
Computed: true,
},
"stopped": schema.Int64Attribute{
Computed: true,
},
},
},
"machines": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"halted": schema.Int64Attribute{
Computed: true,
},
"running": schema.Int64Attribute{
Computed: true,
},
},
},
"vinses": schema.Int64Attribute{
Computed: true,
},
"cpu_allocation_parameter": schema.StringAttribute{
Computed: true,
},
"cpu_allocation_ratio": schema.Float64Attribute{
Computed: true,
},
}
}

View File

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

View File

@@ -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/cloudapi/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.CloudAPI().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
}

View File

@@ -0,0 +1,63 @@
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/cloudapi/account"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/models"
)
func AccountComputesListCheckPresence(ctx context.Context, plan *models.DataSourceAccountComputesListModel, c *decort.DecortClient) (*account.ListComputes, error) {
tflog.Info(ctx, "AccountComputesListCheckPresence: Get info about account computes list")
computesListReq := account.ListComputesRequest{
AccountID: uint64(plan.AccountID.ValueInt64()),
}
if !plan.ComputeID.IsNull() {
computesListReq.ComputeID = uint64(plan.ComputeID.ValueInt64())
}
if !plan.Name.IsNull() {
computesListReq.Name = plan.Name.ValueString()
}
if !plan.RGName.IsNull() {
computesListReq.RGName = plan.RGName.ValueString()
}
if !plan.RGID.IsNull() {
computesListReq.RGID = uint64(plan.RGID.ValueInt64())
}
if !plan.TechStatus.IsNull() {
computesListReq.TechStatus = plan.TechStatus.ValueString()
}
if !plan.IPAddress.IsNull() {
computesListReq.IPAddress = plan.IPAddress.ValueString()
}
if !plan.ExtNetName.IsNull() {
computesListReq.ExtNetName = plan.ExtNetName.ValueString()
}
if !plan.ExtNetID.IsNull() {
computesListReq.ExtNetID = uint64(plan.ExtNetID.ValueInt64())
}
if !plan.Page.IsNull() {
computesListReq.Page = uint64(plan.Page.ValueInt64())
}
if !plan.SortBy.IsNull() {
computesListReq.SortBy = plan.SortBy.ValueString()
}
if !plan.Size.IsNull() {
computesListReq.Size = uint64(plan.Size.ValueInt64())
}
tflog.Info(ctx, "AccountComputesListCheckPresence: before call CloudAPI().Account().ListComputes", map[string]any{"req": computesListReq})
computesList, err := c.CloudAPI().Account().ListComputes(ctx, computesListReq)
if err != nil {
return nil, fmt.Errorf("cannot get info about account computes list with error: %w", err)
}
tflog.Info(ctx, "AccountComputesListCheckPresence: response from CloudAPI().Account().ListComputes")
return computesList, err
}

View File

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

View File

@@ -0,0 +1,32 @@
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/cloudapi/account"
)
func AccountConsumedUnitsByTypeDataSourceCheckPresence(ctx context.Context, accountId uint64, cuType string, c *decort.DecortClient) (float64, error) {
tflog.Info(ctx, fmt.Sprintf("AccountConsumedUnitsByTypeDataSourceCheckPresence: Get info about account with ID - %v", accountId))
req := account.GetConsumedCloudUnitsByTypeRequest{
AccountID: accountId,
CUType: cuType,
}
tflog.Info(ctx, "AccountConsumedUnitsByTypeDataSourceCheckPresence: before call to from CloudAPI().Account().GetConsumedCloudUnitsByType",
map[string]any{"account_id": accountId, "req": req})
res, err := c.CloudAPI().Account().GetConsumedCloudUnitsByType(ctx, req)
if err != nil {
return 0, fmt.Errorf("cannot get info about account consumed units by type with error: %w", err)
}
tflog.Info(ctx, "AccountConsumedUnitsByTypeDataSourceCheckPresence: response from CloudAPI().Account().GetConsumedCloudUnitsByType",
map[string]any{"account_id": accountId, "response": res})
return res, err
}

View File

@@ -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/cloudapi/account"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/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 CloudAPI().Account().ListDisks", map[string]any{"req": disksListReq})
disksList, err := c.CloudAPI().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 CloudAPI().Account().ListDisks")
return disksList, err
}

View File

@@ -0,0 +1,52 @@
package utilities
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-log/tflog"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/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.Page.IsNull() {
flipgroupsListReq.Page = uint64(plan.Page.ValueInt64())
}
if !plan.Size.IsNull() {
flipgroupsListReq.Size = uint64(plan.Size.ValueInt64())
}
tflog.Info(ctx, "AccountListCheckPresence: before call CloudAPI().Account().ListFLIPGroups", map[string]any{"req": flipgroupsListReq})
flipgroupsList, err := c.CloudAPI().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 CloudAPI().Account().ListFLIPGroups")
return flipgroupsList, err
}

View File

@@ -0,0 +1,24 @@
package utilities
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-log/tflog"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/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.CloudAPI().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 CloudAPI().Account().GetResourceConsumption",
map[string]any{"account_id": accountId, "response": record})
return record, err
}

View File

@@ -0,0 +1,24 @@
package utilities
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-log/tflog"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
)
func AccountGetResourceConsumptionListDataSourceCheckPresence(ctx context.Context, c *decort.DecortClient) (*account.ListResourceConsumption, error) {
tflog.Info(ctx, fmt.Sprintf("AccountGetResourceConsumptionListDataSourceCheckPresence: Get info about account resource consumption list"))
record, err := c.CloudAPI().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 CloudAPI().Account().ListResourceConsumption",
map[string]any{"response": record})
return record, err
}

View File

@@ -0,0 +1,49 @@
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/cloudapi/account"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/models"
)
func AccountListCheckPresence(ctx context.Context, plan *models.DataSourceAccountListModel, c *decort.DecortClient) (*account.ListAccounts, error) {
tflog.Info(ctx, "AccountListCheckPresence: Get info about account list")
accListReq := account.ListRequest{}
if !plan.ByID.IsNull() {
accListReq.ByID = uint64(plan.ByID.ValueInt64())
}
if !plan.Name.IsNull() {
accListReq.Name = plan.Name.ValueString()
}
if !plan.ACL.IsNull() {
accListReq.ACL = plan.ACL.ValueString()
}
if !plan.Status.IsNull() {
accListReq.Status = plan.Status.ValueString()
}
if !plan.Page.IsNull() {
accListReq.Page = uint64(plan.Page.ValueInt64())
}
if !plan.Size.IsNull() {
accListReq.Size = uint64(plan.Size.ValueInt64())
}
if !plan.SortBy.IsNull() {
accListReq.SortBy = plan.SortBy.ValueString()
}
tflog.Info(ctx, "AccountListCheckPresence: before call CloudAPI().Account().List", map[string]any{"req": accListReq})
accList, err := c.CloudAPI().Account().List(ctx, accListReq)
if err != nil {
return nil, fmt.Errorf("cannot get info about account with error: %w", err)
}
tflog.Info(ctx, "AccountListCheckPresence: response from CloudAPI().Account().List")
return accList, err
}

View File

@@ -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/cloudapi/account"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/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 CloudAPI().Account().ListDeleted", map[string]any{"req": accListDelReq})
accListDel, err := c.CloudAPI().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 CloudAPI().Account().ListDeleted")
return accListDel, err
}

View File

@@ -0,0 +1,29 @@
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/cloudapi/account"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/models"
)
func AccountReservedUnitsCheck(ctx context.Context, plan *models.DataSourceAccountReservedUnitsModel, c *decort.DecortClient) (*account.ResourceLimits, error) {
tflog.Info(ctx, "AccountReservedUnitsCheck: Get info about account units")
req := account.GetReservedAccountUnitsRequest{
AccountID: uint64(plan.AccountID.ValueInt64()),
}
tflog.Info(ctx, "AccountReservedUnitsCheck: before call CloudAPI().Account().GetReservedAccountUnits", map[string]any{"req": req})
accountUnits, err := c.CloudAPI().Account().GetReservedAccountUnits(ctx, req)
if err != nil {
return nil, fmt.Errorf("cannot get info about account units: %w", err)
}
tflog.Info(ctx, "AccountReservedUnitsCheck: response from CloudAPI().Account().GetReservedAccountUnits")
return accountUnits, err
}

View File

@@ -0,0 +1,52 @@
package utilities
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-log/tflog"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/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 CloudAPI().Account().ListRG", map[string]any{"req": rgListReq})
rgList, err := c.CloudAPI().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 CloudAPI().Account().ListRG")
return rgList, err
}

View File

@@ -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/cloudapi/account"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/models"
)
func AccountTemplatesListCheckPresence(ctx context.Context, plan *models.DataSourceAccountTemplatesListModel, c *decort.DecortClient) (*account.ListTemplates, error) {
tflog.Info(ctx, "AccountTemplatesListCheckPresence: Get info about account templates list")
tempListReq := account.ListTemplatesRequest{
AccountID: uint64(plan.AccountID.ValueInt64()),
}
if !plan.IncludeDeleted.IsNull() {
tempListReq.IncludeDeleted = plan.IncludeDeleted.ValueBool()
}
if !plan.ImageID.IsNull() {
tempListReq.ImageID = uint64(plan.ImageID.ValueInt64())
}
if !plan.Name.IsNull() {
tempListReq.Name = plan.Name.ValueString()
}
if !plan.Type.IsNull() {
tempListReq.Type = plan.Type.ValueString()
}
if !plan.Page.IsNull() {
tempListReq.Page = uint64(plan.Page.ValueInt64())
}
if !plan.Size.IsNull() {
tempListReq.Size = uint64(plan.Size.ValueInt64())
}
if !plan.SortBy.IsNull() {
tempListReq.SortBy = plan.SortBy.ValueString()
}
tflog.Info(ctx, "AccountTemplatesListCheckPresence: before call CloudAPI().Account().ListTemplates", map[string]any{"req": tempListReq})
tempList, err := c.CloudAPI().Account().ListTemplates(ctx, tempListReq)
if err != nil {
return nil, fmt.Errorf("cannot get info about account templates list with error: %w", err)
}
tflog.Info(ctx, "AccountTemplatesListCheckPresence: response from CloudAPI().Account().ListTemplates")
return tempList, err
}

View File

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

View File

@@ -0,0 +1,392 @@
package utilities
import (
"context"
"fmt"
"strconv"
"time"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"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/cloudapi/account"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/models"
"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.CloudAPI().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 CloudAPI().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})
state.LastUpdated = types.StringValue(time.Now().Format(time.RFC850))
} 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 CloudAPI().Account().Restore", map[string]any{"account_id": accountId, "req": restoreReq})
res, err := c.CloudAPI().Account().Restore(ctx, restoreReq)
if err != nil {
diags.AddError(
"RestoreAccount: cannot restore account",
err.Error(),
)
return diags
}
tflog.Info(ctx, "RestoreAccount: response from CloudAPI().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 CloudAPI().Account().Enable", map[string]any{"account_id": accountId})
res, err := c.CloudAPI().Account().Enable(ctx, account.DisableEnableRequest{AccountID: accountId})
if err != nil {
diags.AddError(
"EnableDisableAccount: cannot enable account",
err.Error(),
)
return diags
}
tflog.Info(ctx, "EnableDisableAccount: response from CloudAPI().Account().Enable", map[string]any{"account_id": accountId, "response": res})
return nil
}
tflog.Info(ctx, "EnableDisableAccount: before calling CloudAPI().Account().Disable", map[string]any{"account_id": accountId})
res, err := c.CloudAPI().Account().Disable(ctx, account.DisableEnableRequest{AccountID: accountId})
if err != nil {
diags.AddError(
"EnableDisableAccount: cannot disable account",
err.Error(),
)
return diags
}
tflog.Info(ctx, "EnableDisableAccount: response from CloudAPI().Account().Disable", map[string]any{"account_id": accountId, "response": res})
return nil
}
// 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 CloudAPI().Account().Update", map[string]any{
"account_id": accountId,
"req": updateReq,
})
res, err := c.CloudAPI().Account().Update(ctx, updateReq)
if err != nil {
diags.AddError("UpdateAccount: Unable to update account",
err.Error())
return diags
}
tflog.Info(ctx, "UpdateAccount: response from CloudAPI().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,
UserID: user.UserID.ValueString(),
RecursiveDelete: user.RecursiveDelete.ValueBool(), // default false
}
tflog.Info(ctx, "AddDeleteUsersAccount: before calling CloudAPI().Account().DeleteUser", map[string]any{"account_id": accountId, "req": delUserReq})
res, err := c.CloudAPI().Account().DeleteUser(ctx, delUserReq)
tflog.Info(ctx, "AddDeleteUsersAccount: response from CloudAPI().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,
UserID: user.UserID.ValueString(),
AccessType: user.AccessType.ValueString(),
}
tflog.Info(ctx, "AddDeleteUsersAccount: before calling CloudAPI().Account().AddUser", map[string]any{
"account_id": accountId,
"addUserReq": addUserReq})
res, err := c.CloudAPI().Account().AddUser(ctx, addUserReq)
if err != nil {
diags.AddError("AddDeleteUsersAccount: Unable to add users to account",
err.Error())
}
tflog.Info(ctx, "AddDeleteUsersAccount: response from CloudAPI().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 CloudAPI().Account().UpdateUser", map[string]any{
"account_id": accountId,
"updatedUsers": updatedUsers})
res, err := c.CloudAPI().Account().UpdateUser(ctx, updUserReq)
if err != nil {
diags.AddError("AddDeleteUsersAccount: Unable to update users",
err.Error())
}
tflog.Info(ctx, "AddDeleteUsersAccount: response from CloudAPI().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
}

View File

@@ -0,0 +1,91 @@
package bservice
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/cloudapi/bservice/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/bservice/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/bservice/schemas"
)
// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &dataSourceBService{}
)
func NewDataSourceBService() datasource.DataSource {
return &dataSourceBService{}
}
// dataSourceBService is the data source implementation.
type dataSourceBService struct {
client *decort.DecortClient
}
func (d *dataSourceBService) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
// Read Terraform configuration data into the model
var state models.RecordBasicServiceModel
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceBService: Error get state")
return
}
bserviceId := uint64(state.ServiceId.ValueInt64())
tflog.Info(ctx, "Read dataSourceBService: got state successfully", map[string]any{"service_id": bserviceId})
// Set timeouts
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout30s)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceBService: Error set timeout")
return
}
tflog.Info(ctx, "Read dataSourceBService: set timeouts successfully", map[string]any{
"service_id": bserviceId,
"readTimeout": readTimeout})
ctx, cancel := context.WithTimeout(ctx, readTimeout)
defer cancel()
// Map response body to schema
resp.Diagnostics.Append(flattens.BServiceDataSource(ctx, &state, d.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceBService: Error flatten data source bservice")
return
}
// Set refreshed state
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceBService: Error set state")
return
}
tflog.Info(ctx, "End read dataSourceBService", map[string]any{"service_id": bserviceId})
}
func (d *dataSourceBService) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: schemas.MakeSchemaDataSourceBService(),
Blocks: map[string]schema.Block{
"timeouts": timeouts.Block(ctx),
},
}
}
func (d *dataSourceBService) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_bservice"
}
// Configure adds the provider configured client to the data source.
func (d *dataSourceBService) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
tflog.Info(ctx, "Get Configure dataSourceBService")
d.client = client.DataSource(ctx, &req, resp)
tflog.Info(ctx, "Getting Configure dataSourceBService successfully")
}

View File

@@ -0,0 +1,89 @@
package bservice
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/cloudapi/bservice/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/bservice/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/bservice/schemas"
)
// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &dataSourceBServiceDeletedList{}
)
func NewDataSourceBServiceDeletedList() datasource.DataSource {
return &dataSourceBServiceDeletedList{}
}
// dataSourceBServiceDeletedList is the data source implementation.
type dataSourceBServiceDeletedList struct {
client *decort.DecortClient
}
func (d *dataSourceBServiceDeletedList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
// Read Terraform configuration data into the model
var state models.ListBasicServicesDelModel
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceBServiceDeletedList: Error get state")
return
}
tflog.Info(ctx, "Read dataSourceBServiceDeletedList: 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 dataSourceBServiceDeletedList: Error set timeout")
return
}
tflog.Info(ctx, "Read dataSourceBServiceDeletedList: 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.BServicesDeletedListDataSource(ctx, &state, d.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceBServiceDeletedList: Error flatten data source bservice list")
return
}
// Set refreshed state
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceBServiceDeletedList: Error set state")
return
}
tflog.Info(ctx, "End read dataSourceBServiceDeletedList")
}
func (d *dataSourceBServiceDeletedList) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: schemas.MakeSchemaDataSourceBServiceDeletedList(),
Blocks: map[string]schema.Block{
"timeouts": timeouts.Block(ctx),
},
}
}
func (d *dataSourceBServiceDeletedList) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_bservice_deleted_list"
}
// Configure adds the provider configured client to the data source.
func (d *dataSourceBServiceDeletedList) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
tflog.Info(ctx, "Get Configure dataSourceBServiceDeletedList")
d.client = client.DataSource(ctx, &req, resp)
tflog.Info(ctx, "Getting Configure dataSourceBServiceDeletedList successfully")
}

View File

@@ -0,0 +1,91 @@
package bservice
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/cloudapi/bservice/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/bservice/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/bservice/schemas"
)
// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &dataSourceBServiceGroup{}
)
func NewDataSourceBServiceGroup() datasource.DataSource {
return &dataSourceBServiceGroup{}
}
// dataSourceBServiceGroup is the data source implementation.
type dataSourceBServiceGroup struct {
client *decort.DecortClient
}
func (d *dataSourceBServiceGroup) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
// Read Terraform configuration data into the model
var state models.RecordGroupModel
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceBServiceGroup: Error get state")
return
}
bserviceId := uint64(state.ServiceID.ValueInt64())
tflog.Info(ctx, "Read dataSourceBServiceGroup: got state successfully", map[string]any{"service_id": bserviceId})
// Set timeouts
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout30s)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceBServiceGroup: Error set timeout")
return
}
tflog.Info(ctx, "Read dataSourceBServiceGroup: set timeouts successfully", map[string]any{
"service_id": bserviceId,
"readTimeout": readTimeout})
ctx, cancel := context.WithTimeout(ctx, readTimeout)
defer cancel()
// Map response body to schema
resp.Diagnostics.Append(flattens.BServiceGroupDataSource(ctx, &state, d.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceBServiceGroup: Error flatten data source bservice group")
return
}
// Set refreshed state
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceBServiceGroup: Error set state")
return
}
tflog.Info(ctx, "End read dataSourceBServiceGroup", map[string]any{"service_id": bserviceId})
}
func (d *dataSourceBServiceGroup) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: schemas.MakeSchemaDataSourceBServiceGroup(),
Blocks: map[string]schema.Block{
"timeouts": timeouts.Block(ctx),
},
}
}
func (d *dataSourceBServiceGroup) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_bservice_group"
}
// Configure adds the provider configured client to the data source.
func (d *dataSourceBServiceGroup) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
tflog.Info(ctx, "Get Configure dataSourceBServiceGroup")
d.client = client.DataSource(ctx, &req, resp)
tflog.Info(ctx, "Getting Configure dataSourceBServiceGroup successfully")
}

View File

@@ -0,0 +1,89 @@
package bservice
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/cloudapi/bservice/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/bservice/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/bservice/schemas"
)
// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &dataSourceBServiceList{}
)
func NewDataSourceBServiceList() datasource.DataSource {
return &dataSourceBServiceList{}
}
// dataSourceBServiceList is the data source implementation.
type dataSourceBServiceList struct {
client *decort.DecortClient
}
func (d *dataSourceBServiceList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
// Read Terraform configuration data into the model
var state models.ListBasicServicesModel
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceBServiceList: Error get state")
return
}
tflog.Info(ctx, "Read dataSourceBServiceList: 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 dataSourceBServiceList: Error set timeout")
return
}
tflog.Info(ctx, "Read dataSourceBServiceList: 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.BServicesListDataSource(ctx, &state, d.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceBServiceList: Error flatten data source bservice list")
return
}
// Set refreshed state
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceBServiceList: Error set state")
return
}
tflog.Info(ctx, "End read dataSourceBServiceList")
}
func (d *dataSourceBServiceList) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: schemas.MakeSchemaDataSourceBServiceList(),
Blocks: map[string]schema.Block{
"timeouts": timeouts.Block(ctx),
},
}
}
func (d *dataSourceBServiceList) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_bservice_list"
}
// Configure adds the provider configured client to the data source.
func (d *dataSourceBServiceList) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
tflog.Info(ctx, "Get Configure dataSourceBServiceList")
d.client = client.DataSource(ctx, &req, resp)
tflog.Info(ctx, "Getting Configure dataSourceBServiceList successfully")
}

View File

@@ -0,0 +1,91 @@
package bservice
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/cloudapi/bservice/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/bservice/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/bservice/schemas"
)
// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &dataSourceBServiceSnapshotList{}
)
func NewDataSourceBServiceSnapshotList() datasource.DataSource {
return &dataSourceBServiceSnapshotList{}
}
// dataSourceBServiceSnapshotList is the data source implementation.
type dataSourceBServiceSnapshotList struct {
client *decort.DecortClient
}
func (d *dataSourceBServiceSnapshotList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
// Read Terraform configuration data into the model
var state models.ListInfoSnapshotsModel
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceBServiceSnapshotList: Error get state")
return
}
bserviceId := uint64(state.ServiceID.ValueInt64())
tflog.Info(ctx, "Read dataSourceBServiceSnapshotList: got state successfully", map[string]any{"service_id": bserviceId})
// Set timeouts
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout30s)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceBServiceSnapshotList: Error set timeout")
return
}
tflog.Info(ctx, "Read dataSourceBServiceSnapshotList: set timeouts successfully", map[string]any{
"service_id": bserviceId,
"readTimeout": readTimeout})
ctx, cancel := context.WithTimeout(ctx, readTimeout)
defer cancel()
// Map response body to schema
resp.Diagnostics.Append(flattens.BServiceSnapshotListDataSource(ctx, &state, d.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceBServiceSnapshotList: Error flatten data source bservice")
return
}
// Set refreshed state
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceBServiceSnapshotList: Error set state")
return
}
tflog.Info(ctx, "End read dataSourceBServiceSnapshotList", map[string]any{"service_id": bserviceId})
}
func (d *dataSourceBServiceSnapshotList) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: schemas.MakeSchemaDataSourceBServiceSnapshotList(),
Blocks: map[string]schema.Block{
"timeouts": timeouts.Block(ctx),
},
}
}
func (d *dataSourceBServiceSnapshotList) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_bservice_snapshot_list"
}
// Configure adds the provider configured client to the data source.
func (d *dataSourceBServiceSnapshotList) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
tflog.Info(ctx, "Get Configure dataSourceBServiceSnapshotList")
d.client = client.DataSource(ctx, &req, resp)
tflog.Info(ctx, "Getting Configure dataSourceBServiceSnapshotList successfully")
}

View File

@@ -0,0 +1,116 @@
package flattens
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/bservice/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/bservice/utilities"
)
// BServiceDataSource flattens data source for bservice.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func BServiceDataSource(ctx context.Context, state *models.RecordBasicServiceModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.BServiceDataSource")
diags := diag.Diagnostics{}
serivceId := uint64(state.ServiceId.ValueInt64())
record, err := utilities.BServiceDataSourceCheckPresence(ctx, serivceId, c)
if err != nil {
diags.AddError(fmt.Sprintf("Cannot get info about bservice with ID %v", serivceId), err.Error())
return diags
}
tflog.Info(ctx, "flattens.BServiceDataSource: before flatten", map[string]any{"service_id": serivceId, "record": record})
*state = models.RecordBasicServiceModel{
ServiceId: state.ServiceId,
Timeouts: state.Timeouts,
AccountID: types.Int64Value(int64(record.AccountID)),
AccountName: types.StringValue(record.AccountName),
BaseDomain: types.StringValue(record.BaseDomain),
CPUTotal: types.Int64Value(int64(record.CPUTotal)),
CreatedBy: types.StringValue(record.CreatedBy),
CreatedTime: types.Int64Value(int64(record.CreatedTime)),
DeletedBy: types.StringValue(record.DeletedBy),
DeletedTime: types.Int64Value(int64(record.DeletedTime)),
DiskTotal: types.Int64Value(int64(record.DiskTotal)),
GID: types.Int64Value(int64(record.GID)),
GUID: types.Int64Value(int64(record.GUID)),
Milestones: types.Int64Value(int64(record.Milestones)),
Name: types.StringValue(record.Name),
ParentSrvID: types.Int64Value(int64(record.ParentSrvID)),
ParentSrvType: types.StringValue(record.ParentSrvType),
RAMTotal: types.Int64Value(int64(record.RAMTotal)),
RGID: types.Int64Value(int64(record.RGID)),
RGName: types.StringValue(record.RGName),
SSHKey: types.StringValue(record.SSHKey),
SSHUser: types.StringValue(record.SSHUser),
Status: types.StringValue(record.Status),
TechStatus: types.StringValue(record.TechStatus),
UpdatedBy: types.StringValue(record.UpdatedBy),
UpdatedTime: types.Int64Value(int64(record.UpdatedTime)),
UserManaged: types.BoolValue(record.UserManaged),
}
computesList := make([]models.ItemComputeModel, 0, len(record.Computes))
for _, v := range record.Computes {
temp := models.ItemComputeModel{
AccountID: types.Int64Value(int64(v.AccountID)),
Architecture: types.StringValue(v.Architecture),
CompGroupID: types.Int64Value(int64(v.CompGroupID)),
CompGroupName: types.StringValue(v.CompGroupName),
CompGroupRole: types.StringValue(v.CompGroupRole),
ID: types.Int64Value(int64(v.ID)),
Name: types.StringValue(v.Name),
RGID: types.Int64Value(int64(v.RGID)),
StackID: types.Int64Value(int64(v.StackID)),
Status: types.StringValue(v.Status),
TechStatus: types.StringValue(v.TechStatus),
}
computesList = append(computesList, temp)
}
state.Computes = computesList
groupsList := make([]models.ItemGroupModel, 0, len(record.Groups))
for _, v := range record.Groups {
temp := models.ItemGroupModel{
Computes: types.Int64Value(int64(v.Computes)),
Consistency: types.BoolValue(v.Consistency),
ID: types.Int64Value(int64(v.ID)),
Name: types.StringValue(v.Name),
Status: types.StringValue(v.Status),
TechStatus: types.StringValue(v.TechStatus),
}
groupsList = append(groupsList, temp)
}
state.Groups = groupsList
snapshotsList := make([]models.ItemSnapshotModel, 0, len(record.Snapshots))
for _, v := range record.Snapshots {
temp := models.ItemSnapshotModel{
GUID: types.StringValue(v.GUID),
Label: types.StringValue(v.Label),
Timestamp: types.Int64Value(int64(v.Timestamp)),
Valid: types.BoolValue(v.Valid),
}
snapshotsList = append(snapshotsList, temp)
}
state.Snapshots = snapshotsList
tflog.Info(ctx, "flattens.BServiceDataSource: after flatten", map[string]any{"service_id": state.ServiceId.ValueInt64()})
tflog.Info(ctx, "End flattens.BServiceDataSource", map[string]any{"service_id": state.ServiceId.ValueInt64()})
return nil
}

View File

@@ -0,0 +1,75 @@
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/cloudapi/bservice/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/bservice/utilities"
)
// BServicesDeletedListDataSource flattens data source for a list of basic services.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func BServicesDeletedListDataSource(ctx context.Context, state *models.ListBasicServicesDelModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.BServicesDeletedListDataSource")
diags := diag.Diagnostics{}
// Fetch the list of basic services from the API
recordList, err := utilities.BServiceDeletedListDataSourceCheckPresence(ctx, *state, c)
if err != nil {
diags.AddError("Cannot get list of basic services", err.Error())
return diags
}
tflog.Info(ctx, "flattens.BServicesDeletedListDataSource: before flatten", map[string]any{"record_list": recordList})
// Flatten the fetched data into the state
var itemList []models.ItemBasicServiceDelModel
for _, record := range recordList.Data {
item := models.ItemBasicServiceDelModel{
AccountID: types.Int64Value(int64(record.AccountID)),
AccountName: types.StringValue(record.AccountName),
BaseDomain: types.StringValue(record.BaseDomain),
CreatedBy: types.StringValue(record.CreatedBy),
CreatedTime: types.Int64Value(int64(record.CreatedTime)),
DeletedBy: types.StringValue(record.DeletedBy),
DeletedTime: types.Int64Value(int64(record.DeletedTime)),
GID: types.Int64Value(int64(record.GID)),
GUID: types.Int64Value(int64(record.GUID)),
ID: types.Int64Value(int64(record.ID)),
Name: types.StringValue(record.Name),
ParentSrvID: types.Int64Value(int64(record.ParentSrvID)),
ParentSrvType: types.StringValue(record.ParentSrvType),
RGID: types.Int64Value(int64(record.RGID)),
RGName: types.StringValue(record.RGName),
SSHUser: types.StringValue(record.SSHUser),
Status: types.StringValue(record.Status),
TechStatus: types.StringValue(record.TechStatus),
UpdatedBy: types.StringValue(record.UpdatedBy),
UpdatedTime: types.Int64Value(int64(record.UpdatedTime)),
UserManaged: types.BoolValue(record.UserManaged),
}
// Handle groups as a list of strings
groupList := make([]types.Int64, len(record.Groups))
for i, group := range record.Groups {
groupList[i] = types.Int64Value(int64(group))
}
itemList = append(itemList, item)
}
// Update state with the flattened data
state.Data = itemList
state.EntryCount = types.Int64Value(int64(len(itemList)))
tflog.Info(ctx, "flattens.BServicesDeletedListDataSource: after flatten", map[string]any{"entry_count": state.EntryCount.ValueInt64()})
tflog.Info(ctx, "End flattens.BServicesDeletedListDataSource")
return nil
}

View File

@@ -0,0 +1,118 @@
package flattens
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/bservice/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/bservice/utilities"
)
// BServiceGroupDataSource flattens data source for a group.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func BServiceGroupDataSource(ctx context.Context, state *models.RecordGroupModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.BServiceGroupDataSource")
diags := diag.Diagnostics{}
serviceId := uint64(state.ServiceID.ValueInt64())
record, err := utilities.BServiceGroupDataSourceCheckPresence(ctx, *state, c)
if err != nil {
diags.AddError(fmt.Sprintf("Cannot get info about group with ID %v", serviceId), err.Error())
return diags
}
tflog.Info(ctx, "flattens.BServiceGroupDataSource: before flatten", map[string]any{"service_id": serviceId, "record": record})
*state = models.RecordGroupModel{
ServiceID: state.ServiceID,
ID: state.ID,
Timeouts: state.Timeouts,
AccountID: types.Int64Value(int64(record.AccountID)),
AccountName: types.StringValue(record.AccountName),
Consistency: types.BoolValue(record.Consistency),
CPU: types.Int64Value(int64(record.CPU)),
CreatedBy: types.StringValue(record.CreatedBy),
CreatedTime: types.Int64Value(int64(record.CreatedTime)),
DeletedBy: types.StringValue(record.DeletedBy),
DeletedTime: types.Int64Value(int64(record.DeletedTime)),
Disk: types.Int64Value(int64(record.Disk)),
Driver: types.StringValue(record.Driver),
GID: types.Int64Value(int64(record.GID)),
GUID: types.Int64Value(int64(record.GUID)),
ImageID: types.Int64Value(int64(record.ImageID)),
Milestones: types.Int64Value(int64(record.Milestones)),
Name: types.StringValue(record.Name),
RAM: types.Int64Value(int64(record.RAM)),
RGID: types.Int64Value(int64(record.RGID)),
RGName: types.StringValue(record.RGName),
Role: types.StringValue(record.Role),
SEPID: types.Int64Value(int64(record.SEPID)),
SeqNo: types.Int64Value(int64(record.SeqNo)),
Status: types.StringValue(record.Status),
TechStatus: types.StringValue(record.TechStatus),
TimeoutStart: types.Int64Value(int64(record.TimeoutStart)),
UpdatedBy: types.StringValue(record.UpdatedBy),
UpdatedTime: types.Int64Value(int64(record.UpdatedTime)),
}
// Handle computes
computesList := make([]models.ItemGroupComputeModel, 0, len(record.Computes))
for _, v := range record.Computes {
ipAddresses := make([]types.String, len(v.IPAddresses))
for i, ip := range v.IPAddresses {
ipAddresses[i] = types.StringValue(ip)
}
osUsers := make([]models.ItemOSUserModel, len(v.OSUsers))
for j, user := range v.OSUsers {
osUsers[j] = models.ItemOSUserModel{
Login: types.StringValue(user.Login),
Password: types.StringValue(user.Password),
}
}
temp := models.ItemGroupComputeModel{
ID: types.Int64Value(int64(v.ID)),
IPAddresses: flattens.FlattenSimpleTypeToList(ctx, types.StringType, ipAddresses),
Name: types.StringValue(v.Name),
OSUsers: osUsers,
}
computesList = append(computesList, temp)
}
state.Computes = computesList
// Handle ExtNets
extNetsList := make([]types.Int64, len(record.ExtNets))
for i, extNet := range record.ExtNets {
extNetsList[i] = types.Int64Value(int64(extNet))
}
state.ExtNets = flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, extNetsList)
// Handle Parents
parentsList := make([]types.Int64, len(record.Parents))
for i, parent := range record.Parents {
parentsList[i] = types.Int64Value(int64(parent))
}
state.Parents = flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, parentsList)
// Handle VINSes
vinsesList := make([]types.Int64, len(record.VINSes))
for i, vins := range record.VINSes {
vinsesList[i] = types.Int64Value(int64(vins))
}
state.VINSes = flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, vinsesList)
tflog.Info(ctx, "flattens.BServiceGroupDataSource: after flatten", map[string]any{"service_id": state.ID.ValueInt64()})
tflog.Info(ctx, "End flattens.BServiceGroupDataSource", map[string]any{"service_id": state.ID.ValueInt64()})
return nil
}

View File

@@ -0,0 +1,75 @@
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/cloudapi/bservice/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/bservice/utilities"
)
// BServicesListDataSource flattens data source for a list of basic services.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func BServicesListDataSource(ctx context.Context, state *models.ListBasicServicesModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.BServicesListDataSource")
diags := diag.Diagnostics{}
// Fetch the list of basic services from the API
recordList, err := utilities.BServiceListDataSourceCheckPresence(ctx, *state, c)
if err != nil {
diags.AddError("Cannot get list of basic services", err.Error())
return diags
}
tflog.Info(ctx, "flattens.BServicesListDataSource: before flatten", map[string]any{"record_list": recordList})
// Flatten the fetched data into the state
var itemList []models.ItemBasicServiceModel
for _, record := range recordList.Data {
item := models.ItemBasicServiceModel{
AccountID: types.Int64Value(int64(record.AccountID)),
AccountName: types.StringValue(record.AccountName),
BaseDomain: types.StringValue(record.BaseDomain),
CreatedBy: types.StringValue(record.CreatedBy),
CreatedTime: types.Int64Value(int64(record.CreatedTime)),
DeletedBy: types.StringValue(record.DeletedBy),
DeletedTime: types.Int64Value(int64(record.DeletedTime)),
GID: types.Int64Value(int64(record.GID)),
GUID: types.Int64Value(int64(record.GUID)),
ID: types.Int64Value(int64(record.ID)),
Name: types.StringValue(record.Name),
ParentSrvID: types.Int64Value(int64(record.ParentSrvID)),
ParentSrvType: types.StringValue(record.ParentSrvType),
RGID: types.Int64Value(int64(record.RGID)),
RGName: types.StringValue(record.RGName),
SSHUser: types.StringValue(record.SSHUser),
Status: types.StringValue(record.Status),
TechStatus: types.StringValue(record.TechStatus),
UpdatedBy: types.StringValue(record.UpdatedBy),
UpdatedTime: types.Int64Value(int64(record.UpdatedTime)),
UserManaged: types.BoolValue(record.UserManaged),
}
// Handle groups as a list of strings
groupList := make([]types.Int64, len(record.Groups))
for i, group := range record.Groups {
groupList[i] = types.Int64Value(int64(group))
}
itemList = append(itemList, item)
}
// Update state with the flattened data
state.Data = itemList
state.EntryCount = types.Int64Value(int64(len(itemList)))
tflog.Info(ctx, "flattens.BServicesListDataSource: after flatten", map[string]any{"entry_count": state.EntryCount.ValueInt64()})
tflog.Info(ctx, "End flattens.BServicesListDataSource")
return nil
}

View File

@@ -0,0 +1,56 @@
package flattens
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/bservice/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/bservice/utilities"
)
// BServiceSnapshotListDataSource flattens data source for account.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func BServiceSnapshotListDataSource(ctx context.Context, state *models.ListInfoSnapshotsModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.BServiceSnapshotListDataSource")
diags := diag.Diagnostics{}
serivceId := uint64(state.ServiceID.ValueInt64())
record, err := utilities.BServiceSnapshotListDataSourceCheckPresence(ctx, serivceId, c)
if err != nil {
diags.AddError(fmt.Sprintf("Cannot get info about bservice with ID %v", serivceId), err.Error())
return diags
}
tflog.Info(ctx, "flattens.BServiceSnapshotListDataSource: before flatten", map[string]any{"service_id": serivceId, "record": record})
*state = models.ListInfoSnapshotsModel{
ServiceID: state.ServiceID,
Timeouts: state.Timeouts,
EntryCount: types.Int64Value(int64(record.EntryCount)),
}
dataList := make([]models.ItemSnapshotsModel, 0, len(record.Data))
for _, v := range record.Data {
temp := models.ItemSnapshotsModel{
GUID: types.StringValue(v.GUID),
Label: types.StringValue(v.Label),
Timestamp: types.Int64Value(int64(v.Timestamp)),
Valid: types.BoolValue(v.Valid),
}
dataList = append(dataList, temp)
}
state.Data = dataList
tflog.Info(ctx, "flattens.BServiceSnapshotListDataSource: after flatten", map[string]any{"service_id": state.ServiceID.ValueInt64()})
tflog.Info(ctx, "End flattens.BServiceSnapshotListDataSource", map[string]any{"service_id": state.ServiceID.ValueInt64()})
return nil
}

View File

@@ -0,0 +1,144 @@
package flattens
import (
"context"
"fmt"
"strconv"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/bservice"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/bservice/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/bservice/utilities"
)
func BServiceResource(ctx context.Context, state *models.RecordBasicServiceResourceModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.BServiceResource")
diags := diag.Diagnostics{}
serviceId := uint64(state.ServiceId.ValueInt64())
if serviceId == 0 {
id, err := strconv.Atoi(state.ID.ValueString())
if err != nil {
diags.AddError(
"flattens.BServiceResource: cannot parse resource ID from state",
err.Error())
return diags
}
serviceId = uint64(id)
}
recordBService, err := utilities.BServiceResourceCheckPresence(ctx, serviceId, c)
if err != nil {
diags.AddError(fmt.Sprintf("flattens.BServiceResource: Cannot get info about resource with ID %v", serviceId), err.Error())
return diags
}
tflog.Info(ctx, "flattens.BServiceResource: before flatten", map[string]any{"service_id": serviceId, "recordBService": recordBService})
*state = models.RecordBasicServiceResourceModel{
Name: state.Name,
RGID: state.RGID,
Permanently: state.Permanently,
Enable: state.Enable,
Restore: state.Restore,
Start: state.Start,
Snapshots: state.Snapshots,
Timeouts: state.Timeouts,
SSHKey: types.StringValue(recordBService.SSHKey),
SSHUser: types.StringValue(recordBService.SSHUser),
ServiceId: types.Int64Value(int64(recordBService.ID)),
AccountID: types.Int64Value(int64(recordBService.AccountID)),
Computes: flattenComputes(ctx, recordBService.Computes),
Groups: flattenGroups(ctx, recordBService.Groups),
AccountName: types.StringValue(recordBService.Name),
BaseDomain: types.StringValue(recordBService.BaseDomain),
CPUTotal: types.Int64Value(int64(recordBService.CPUTotal)),
CreatedBy: types.StringValue(recordBService.CreatedBy),
CreatedTime: types.Int64Value(int64(recordBService.CreatedTime)),
DeletedBy: types.StringValue(recordBService.DeletedBy),
DeletedTime: types.Int64Value(int64(recordBService.DeletedTime)),
DiskTotal: types.Int64Value(int64(recordBService.DiskTotal)),
GID: types.Int64Value(int64(recordBService.GID)),
GUID: types.Int64Value(int64(recordBService.GUID)),
Milestones: types.Int64Value(int64(recordBService.Milestones)),
ParentSrvID: types.Int64Value(int64(recordBService.ParentSrvID)),
ParentSrvType: types.StringValue(recordBService.ParentSrvType),
RAMTotal: types.Int64Value(int64(recordBService.RAMTotal)),
RGName: types.StringValue(recordBService.RGName),
Status: types.StringValue(recordBService.Status),
TechStatus: types.StringValue(recordBService.TechStatus),
UpdatedBy: types.StringValue(recordBService.UpdatedBy),
UpdatedTime: types.Int64Value(int64(recordBService.UpdatedTime)),
UserManaged: types.BoolValue(recordBService.UserManaged),
ID: types.StringValue(strconv.Itoa(int(serviceId))),
}
tflog.Info(ctx, "flattens.BServiceResource: after flatten", map[string]any{"service_id": state.ID.ValueString()})
tflog.Info(ctx, "End flattens.BServiceResource", map[string]any{"service_id": state.ID.ValueString()})
return nil
}
func flattenComputes(ctx context.Context, items bservice.ListComputes) types.List {
tflog.Info(ctx, "Start flattenComputes")
tempSlice := make([]types.Object, 0, len(items))
for _, v := range items {
temp := models.ItemComputeResourceModel{
AccountID: types.Int64Value(int64(v.AccountID)),
Architecture: types.StringValue(v.Architecture),
CompGroupID: types.Int64Value(int64(v.CompGroupID)),
CompGroupName: types.StringValue(v.CompGroupName),
CompGroupRole: types.StringValue(v.CompGroupRole),
ID: types.Int64Value(int64(v.ID)),
Name: types.StringValue(v.Name),
RGID: types.Int64Value(int64(v.RGID)),
StackID: types.Int64Value(int64(v.StackID)),
Status: types.StringValue(v.Status),
TechStatus: types.StringValue(v.TechStatus),
}
obj, diags := types.ObjectValueFrom(ctx, models.ItemComputeResource, temp)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenComputes struct to obj", diags))
}
tempSlice = append(tempSlice, obj)
}
res, diags := types.ListValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemComputeResource}, tempSlice)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenComputes", diags))
}
tflog.Info(ctx, "End flattenComputes")
return res
}
func flattenGroups(ctx context.Context, items bservice.ListGroups) types.List {
tflog.Info(ctx, "Start flattenGroups")
tempSlice := make([]types.Object, 0, len(items))
for _, v := range items {
temp := models.ItemGroupResourceModel{
Computes: types.Int64Value(int64(v.Computes)),
Consistency: types.BoolValue(v.Consistency),
ID: types.Int64Value(int64(v.ID)),
Name: types.StringValue(v.Name),
Status: types.StringValue(v.Status),
TechStatus: types.StringValue(v.TechStatus),
}
obj, diags := types.ObjectValueFrom(ctx, models.ItemGroupResource, temp)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenGroups struct to obj", diags))
}
tempSlice = append(tempSlice, obj)
}
res, diags := types.ListValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemGroupResource}, tempSlice)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenGroups", diags))
}
tflog.Info(ctx, "End flattenGroups")
return res
}

View File

@@ -0,0 +1,151 @@
package flattens
import (
"context"
"fmt"
"strconv"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/bservice"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/bservice/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/bservice/utilities"
)
func BServiceGroupResource(ctx context.Context, plan *models.ResourceRecordGroupModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start BServiceGroupResource", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": plan.CompgroupID.ValueInt64()})
diags := diag.Diagnostics{}
serviceID := plan.ServiceID.ValueInt64()
comgroupID := plan.CompgroupID.ValueInt64()
if serviceID == 0 {
id, err := strconv.Atoi(plan.SID.ValueString())
if err != nil {
diags.AddError(
"flattens.BServiceGroupResource: cannot parse resource ID from state",
err.Error())
return diags
}
serviceID = int64(id)
}
if comgroupID == 0 {
id, err := strconv.Atoi(plan.ID.ValueString())
if err != nil {
diags.AddError(
"flattens.BServiceGroupResource: cannot parse resource ID from state",
err.Error())
return diags
}
comgroupID = int64(id)
}
recordResourceGroup, err := utilities.BServiceGroupResourceCheckPresence(ctx, uint64(serviceID), uint64(comgroupID), c)
if err != nil {
diags.AddError(fmt.Sprintf("Cannot get info about bservice group with service_id %d and compgroup_id %d", serviceID, comgroupID), err.Error())
return diags
}
*plan = models.ResourceRecordGroupModel{
ServiceID: plan.ServiceID,
CompCount: plan.CompCount,
Name: plan.Name,
CPU: plan.CPU,
RAM: plan.RAM,
Disk: plan.Disk,
ImageID: plan.ImageID,
Driver: plan.Driver,
SEPID: types.Int64Value(int64(recordResourceGroup.SEPID)),
SepPool: types.StringValue(recordResourceGroup.PoolName),
CloudInit: plan.CloudInit,
Role: types.StringValue(recordResourceGroup.Role),
TimeoutStart: types.Int64Value(int64(recordResourceGroup.TimeoutStart)),
VINSes: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, recordResourceGroup.VINSes),
ExtNets: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, recordResourceGroup.ExtNets),
Mode: plan.Mode,
Start: plan.Start,
ForceStop: plan.ForceStop,
ForceUpdate: plan.ForceUpdate,
Parents: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, recordResourceGroup.Parents),
RemoveComputes: plan.RemoveComputes,
CompgroupID: plan.CompgroupID,
ID: types.StringValue(strconv.Itoa(int(plan.CompgroupID.ValueInt64()))),
SID: types.StringValue(strconv.Itoa(int(plan.ServiceID.ValueInt64()))),
Timeouts: plan.Timeouts,
AccountID: types.Int64Value(int64(recordResourceGroup.AccountID)),
AccountName: types.StringValue(recordResourceGroup.AccountName),
Computes: flattenGroupComputes(ctx, recordResourceGroup.Computes),
Consistency: types.BoolValue(recordResourceGroup.Consistency),
CreatedBy: types.StringValue(recordResourceGroup.CreatedBy),
CreatedTime: types.Int64Value(int64(recordResourceGroup.CreatedTime)),
DeletedBy: types.StringValue(recordResourceGroup.DeletedBy),
DeletedTime: types.Int64Value(int64(recordResourceGroup.DeletedTime)),
GID: types.Int64Value(int64(recordResourceGroup.GID)),
GUID: types.Int64Value(int64(recordResourceGroup.GUID)),
Milestones: types.Int64Value(int64(recordResourceGroup.Milestones)),
RGID: types.Int64Value(int64(recordResourceGroup.RGID)),
RGName: types.StringValue(recordResourceGroup.RGName),
SeqNo: types.Int64Value(int64(recordResourceGroup.SeqNo)),
Status: types.StringValue(recordResourceGroup.Status),
TechStatus: types.StringValue(recordResourceGroup.TechStatus),
UpdatedBy: types.StringValue(recordResourceGroup.UpdatedBy),
UpdatedTime: types.Int64Value(int64(recordResourceGroup.UpdatedTime)),
}
tflog.Info(ctx, "End BServiceGroupResource", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": plan.CompgroupID.ValueInt64()})
return nil
}
func flattenGroupComputes(ctx context.Context, items bservice.ListGroupComputes) types.List {
tflog.Info(ctx, "Start flattenGroupComputes")
tempSlice := make([]types.Object, 0, len(items))
for _, v := range items {
temp := models.ResourceItemGroupComputeModel{
ID: types.Int64Value(int64(v.ID)),
Name: types.StringValue(v.Name),
IPAddresses: flattens.FlattenSimpleTypeToList(ctx, types.StringType, v.IPAddresses),
OSUsers: flattenOSuser(ctx, v.OSUsers),
}
obj, diags := types.ObjectValueFrom(ctx, models.ResourceItemGroupCompute, temp)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenGroupComputes struct to obj", diags))
}
tempSlice = append(tempSlice, obj)
}
res, diags := types.ListValueFrom(ctx, types.ObjectType{AttrTypes: models.ResourceItemGroupCompute}, tempSlice)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenGroupComputes", diags))
}
tflog.Info(ctx, "End flattenGroupComputes")
return res
}
func flattenOSuser(ctx context.Context, items bservice.ListOSUsers) types.List {
tflog.Info(ctx, "Start flattenOSuser")
tempSlice := make([]types.Object, 0, len(items))
for _, v := range items {
temp := models.ResourceItemOSUserModel{
Login: types.StringValue(v.Login),
Password: types.StringValue(v.Password),
}
obj, diags := types.ObjectValueFrom(ctx, models.ResourceItemOSUser, temp)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenOSuser struct to obj", diags))
}
tempSlice = append(tempSlice, obj)
}
res, diags := types.ListValueFrom(ctx, types.ObjectType{AttrTypes: models.ResourceItemOSUser}, tempSlice)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenOSuser", diags))
}
tflog.Info(ctx, "End flattenOSuser")
return res
}

View File

@@ -0,0 +1,69 @@
package models
import (
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type RecordBasicServiceModel struct {
ServiceId types.Int64 `tfsdk:"service_id"`
AccountID types.Int64 `tfsdk:"account_id"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
AccountName types.String `tfsdk:"account_name"`
BaseDomain types.String `tfsdk:"base_domain"`
Computes []ItemComputeModel `tfsdk:"computes"`
CPUTotal types.Int64 `tfsdk:"cpu_total"`
CreatedBy types.String `tfsdk:"created_by"`
CreatedTime types.Int64 `tfsdk:"created_time"`
DeletedBy types.String `tfsdk:"deleted_by"`
DeletedTime types.Int64 `tfsdk:"deleted_time"`
DiskTotal types.Int64 `tfsdk:"disk_total"`
GID types.Int64 `tfsdk:"gid"`
Groups []ItemGroupModel `tfsdk:"groups"`
GUID types.Int64 `tfsdk:"guid"`
Milestones types.Int64 `tfsdk:"milestones"`
Name types.String `tfsdk:"service_name"`
ParentSrvID types.Int64 `tfsdk:"parent_srv_id"`
ParentSrvType types.String `tfsdk:"parent_srv_type"`
RAMTotal types.Int64 `tfsdk:"ram_total"`
RGID types.Int64 `tfsdk:"rg_id"`
RGName types.String `tfsdk:"rg_name"`
Snapshots []ItemSnapshotModel `tfsdk:"snapshots"`
SSHKey types.String `tfsdk:"ssh_key"`
SSHUser types.String `tfsdk:"ssh_user"`
Status types.String `tfsdk:"status"`
TechStatus types.String `tfsdk:"tech_status"`
UpdatedBy types.String `tfsdk:"updated_by"`
UpdatedTime types.Int64 `tfsdk:"updated_time"`
UserManaged types.Bool `tfsdk:"user_managed"`
}
type ItemComputeModel struct {
AccountID types.Int64 `tfsdk:"account_id"`
Architecture types.String `tfsdk:"architecture"`
CompGroupID types.Int64 `tfsdk:"compgroup_id"`
CompGroupName types.String `tfsdk:"compgroup_name"`
CompGroupRole types.String `tfsdk:"compgroup_role"`
ID types.Int64 `tfsdk:"id"`
Name types.String `tfsdk:"name"`
RGID types.Int64 `tfsdk:"rg_id"`
StackID types.Int64 `tfsdk:"stack_id"`
Status types.String `tfsdk:"status"`
TechStatus types.String `tfsdk:"tech_status"`
}
type ItemGroupModel struct {
Computes types.Int64 `tfsdk:"computes"`
Consistency types.Bool `tfsdk:"consistency"`
ID types.Int64 `tfsdk:"id"`
Name types.String `tfsdk:"name"`
Status types.String `tfsdk:"status"`
TechStatus types.String `tfsdk:"tech_status"`
}
type ItemSnapshotModel struct {
GUID types.String `tfsdk:"guid"`
Label types.String `tfsdk:"label"`
Timestamp types.Int64 `tfsdk:"timestamp"`
Valid types.Bool `tfsdk:"valid"`
}

View File

@@ -0,0 +1,45 @@
package models
import (
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type ListBasicServicesDelModel struct {
//optional fields
AccountID types.Int64 `tfsdk:"account_id"`
RGID types.Int64 `tfsdk:"rg_id"`
SortBy types.String `tfsdk:"sort_by"`
Page types.Int64 `tfsdk:"page"`
Size types.Int64 `tfsdk:"size"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
//computed fields
Data []ItemBasicServiceDelModel `tfsdk:"items"`
EntryCount types.Int64 `tfsdk:"entry_count"`
}
type ItemBasicServiceDelModel struct {
AccountID types.Int64 `tfsdk:"account_id"`
AccountName types.String `tfsdk:"account_name"`
BaseDomain types.String `tfsdk:"base_domain"`
CreatedBy types.String `tfsdk:"created_by"`
CreatedTime types.Int64 `tfsdk:"created_time"`
DeletedBy types.String `tfsdk:"deleted_by"`
DeletedTime types.Int64 `tfsdk:"deleted_time"`
GID types.Int64 `tfsdk:"gid"`
Groups []uint64 `tfsdk:"groups"`
GUID types.Int64 `tfsdk:"guid"`
ID types.Int64 `tfsdk:"service_id"`
Name types.String `tfsdk:"service_name"`
ParentSrvID types.Int64 `tfsdk:"parent_srv_id"`
ParentSrvType types.String `tfsdk:"parent_srv_type"`
RGID types.Int64 `tfsdk:"rg_id"`
RGName types.String `tfsdk:"rg_name"`
SSHUser types.String `tfsdk:"ssh_user"`
Status types.String `tfsdk:"status"`
TechStatus types.String `tfsdk:"tech_status"`
UpdatedBy types.String `tfsdk:"updated_by"`
UpdatedTime types.Int64 `tfsdk:"updated_time"`
UserManaged types.Bool `tfsdk:"user_managed"`
}

View File

@@ -0,0 +1,57 @@
package models
import (
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type RecordGroupModel struct {
//required and optional fields
ServiceID types.Int64 `tfsdk:"service_id"`
ID types.Int64 `tfsdk:"compgroup_id"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
//compute fields
AccountID types.Int64 `tfsdk:"account_id"`
AccountName types.String `tfsdk:"account_name"`
Computes []ItemGroupComputeModel `tfsdk:"computes"`
Consistency types.Bool `tfsdk:"consistency"`
CPU types.Int64 `tfsdk:"cpu"`
CreatedBy types.String `tfsdk:"created_by"`
CreatedTime types.Int64 `tfsdk:"created_time"`
DeletedBy types.String `tfsdk:"deleted_by"`
DeletedTime types.Int64 `tfsdk:"deleted_time"`
Disk types.Int64 `tfsdk:"disk"`
Driver types.String `tfsdk:"driver"`
ExtNets types.List `tfsdk:"extnets"`
GID types.Int64 `tfsdk:"gid"`
GUID types.Int64 `tfsdk:"guid"`
ImageID types.Int64 `tfsdk:"image_id"`
Milestones types.Int64 `tfsdk:"milestones"`
Name types.String `tfsdk:"compgroup_name"`
Parents types.List `tfsdk:"parents"`
RAM types.Int64 `tfsdk:"ram"`
RGID types.Int64 `tfsdk:"rg_id"`
RGName types.String `tfsdk:"rg_name"`
Role types.String `tfsdk:"role"`
SEPID types.Int64 `tfsdk:"sep_id"`
SeqNo types.Int64 `tfsdk:"seq_no"`
Status types.String `tfsdk:"status"`
TechStatus types.String `tfsdk:"tech_status"`
TimeoutStart types.Int64 `tfsdk:"timeout_start"`
UpdatedBy types.String `tfsdk:"updated_by"`
UpdatedTime types.Int64 `tfsdk:"updated_time"`
VINSes types.List `tfsdk:"vinses"`
}
type ItemGroupComputeModel struct {
ID types.Int64 `tfsdk:"id"`
IPAddresses types.List `tfsdk:"ip_addresses"`
Name types.String `tfsdk:"name"`
OSUsers []ItemOSUserModel `tfsdk:"os_users"`
}
type ItemOSUserModel struct {
Login types.String `tfsdk:"login"`
Password types.String `tfsdk:"password"`
}

View File

@@ -0,0 +1,48 @@
package models
import (
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type ListBasicServicesModel struct {
ByID types.Int64 `tfsdk:"by_id"`
Name types.String `tfsdk:"name"`
RGName types.String `tfsdk:"rg_name"`
Status types.String `tfsdk:"status"`
TechStatus types.String `tfsdk:"tech_status"`
AccountName types.String `tfsdk:"account_name"`
AccountID types.Int64 `tfsdk:"account_id"`
RGID types.Int64 `tfsdk:"rg_id"`
SortBy types.String `tfsdk:"sort_by"`
Page types.Int64 `tfsdk:"page"`
Size types.Int64 `tfsdk:"size"`
Data []ItemBasicServiceModel `tfsdk:"items"`
EntryCount types.Int64 `tfsdk:"entry_count"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
}
type ItemBasicServiceModel struct {
AccountID types.Int64 `tfsdk:"account_id"`
AccountName types.String `tfsdk:"account_name"`
BaseDomain types.String `tfsdk:"base_domain"`
CreatedBy types.String `tfsdk:"created_by"`
CreatedTime types.Int64 `tfsdk:"created_time"`
DeletedBy types.String `tfsdk:"deleted_by"`
DeletedTime types.Int64 `tfsdk:"deleted_time"`
GID types.Int64 `tfsdk:"gid"`
Groups []uint64 `tfsdk:"groups"`
GUID types.Int64 `tfsdk:"guid"`
ID types.Int64 `tfsdk:"service_id"`
Name types.String `tfsdk:"service_name"`
ParentSrvID types.Int64 `tfsdk:"parent_srv_id"`
ParentSrvType types.String `tfsdk:"parent_srv_type"`
RGID types.Int64 `tfsdk:"rg_id"`
RGName types.String `tfsdk:"rg_name"`
SSHUser types.String `tfsdk:"ssh_user"`
Status types.String `tfsdk:"status"`
TechStatus types.String `tfsdk:"tech_status"`
UpdatedBy types.String `tfsdk:"updated_by"`
UpdatedTime types.Int64 `tfsdk:"updated_time"`
UserManaged types.Bool `tfsdk:"user_managed"`
}

View File

@@ -0,0 +1,23 @@
package models
import (
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type ListInfoSnapshotsModel struct {
//required fields
ServiceID types.Int64 `tfsdk:"service_id"`
//computed fields
Data []ItemSnapshotsModel `tfsdk:"items"`
EntryCount types.Int64 `tfsdk:"entry_count"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
}
type ItemSnapshotsModel struct {
GUID types.String `tfsdk:"guid"`
Label types.String `tfsdk:"label"`
Timestamp types.Int64 `tfsdk:"timestamp"`
Valid types.Bool `tfsdk:"valid"`
}

View File

@@ -0,0 +1,112 @@
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 RecordBasicServiceResourceModel struct {
//required fields
Name types.String `tfsdk:"service_name"`
RGID types.Int64 `tfsdk:"rg_id"`
//optional fields
SSHKey types.String `tfsdk:"ssh_key"`
SSHUser types.String `tfsdk:"ssh_user"`
Permanently types.Bool `tfsdk:"permanently"`
Enable types.Bool `tfsdk:"enable"`
Restore types.Bool `tfsdk:"restore"`
Start types.Bool `tfsdk:"start"`
ServiceId types.Int64 `tfsdk:"service_id"`
Snapshots types.List `tfsdk:"snapshots"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
//computed fields
AccountID types.Int64 `tfsdk:"account_id"`
AccountName types.String `tfsdk:"account_name"`
BaseDomain types.String `tfsdk:"base_domain"`
Computes types.List `tfsdk:"computes"`
CPUTotal types.Int64 `tfsdk:"cpu_total"`
CreatedBy types.String `tfsdk:"created_by"`
CreatedTime types.Int64 `tfsdk:"created_time"`
DeletedBy types.String `tfsdk:"deleted_by"`
DeletedTime types.Int64 `tfsdk:"deleted_time"`
DiskTotal types.Int64 `tfsdk:"disk_total"`
GID types.Int64 `tfsdk:"gid"`
Groups types.List `tfsdk:"groups"`
GUID types.Int64 `tfsdk:"guid"`
Milestones types.Int64 `tfsdk:"milestones"`
ParentSrvID types.Int64 `tfsdk:"parent_srv_id"`
ParentSrvType types.String `tfsdk:"parent_srv_type"`
RAMTotal types.Int64 `tfsdk:"ram_total"`
RGName types.String `tfsdk:"rg_name"`
Status types.String `tfsdk:"status"`
TechStatus types.String `tfsdk:"tech_status"`
UpdatedBy types.String `tfsdk:"updated_by"`
UpdatedTime types.Int64 `tfsdk:"updated_time"`
UserManaged types.Bool `tfsdk:"user_managed"`
ID types.String `tfsdk:"id"`
}
type ItemComputeResourceModel struct {
AccountID types.Int64 `tfsdk:"account_id"`
Architecture types.String `tfsdk:"architecture"`
CompGroupID types.Int64 `tfsdk:"compgroup_id"`
CompGroupName types.String `tfsdk:"compgroup_name"`
CompGroupRole types.String `tfsdk:"compgroup_role"`
ID types.Int64 `tfsdk:"id"`
Name types.String `tfsdk:"name"`
RGID types.Int64 `tfsdk:"rg_id"`
StackID types.Int64 `tfsdk:"stack_id"`
Status types.String `tfsdk:"status"`
TechStatus types.String `tfsdk:"tech_status"`
}
var ItemComputeResource = map[string]attr.Type{
"account_id": types.Int64Type,
"architecture": types.StringType,
"compgroup_id": types.Int64Type,
"compgroup_name": types.StringType,
"compgroup_role": types.StringType,
"id": types.Int64Type,
"name": types.StringType,
"rg_id": types.Int64Type,
"stack_id": types.Int64Type,
"status": types.StringType,
"tech_status": types.StringType,
}
type ItemGroupResourceModel struct {
Computes types.Int64 `tfsdk:"computes"`
Consistency types.Bool `tfsdk:"consistency"`
ID types.Int64 `tfsdk:"id"`
Name types.String `tfsdk:"name"`
Status types.String `tfsdk:"status"`
TechStatus types.String `tfsdk:"tech_status"`
}
var ItemGroupResource = map[string]attr.Type{
"computes": types.Int64Type,
"consistency": types.BoolType,
"id": types.Int64Type,
"name": types.StringType,
"status": types.StringType,
"tech_status": types.StringType,
}
type ItemSnapshotResourceModel struct {
GUID types.String `tfsdk:"guid"`
Label types.String `tfsdk:"label"`
Rollback types.Bool `tfsdk:"rollback"`
Timestamp types.Int64 `tfsdk:"timestamp"`
Valid types.Bool `tfsdk:"valid"`
}
var ItemSnapshotResource = map[string]attr.Type{
"guid": types.StringType,
"label": types.StringType,
"rollback": types.BoolType,
"timestamp": types.Int64Type,
"valid": types.BoolType,
}

View File

@@ -0,0 +1,82 @@
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 ResourceRecordGroupModel struct {
//required fields
ServiceID types.Int64 `tfsdk:"service_id"`
CompCount types.Int64 `tfsdk:"comp_count"`
Name types.String `tfsdk:"compgroup_name"`
CPU types.Int64 `tfsdk:"cpu"`
RAM types.Int64 `tfsdk:"ram"`
Disk types.Int64 `tfsdk:"disk"`
ImageID types.Int64 `tfsdk:"image_id"`
Driver types.String `tfsdk:"driver"`
//optional fields
SEPID types.Int64 `tfsdk:"sep_id"`
SepPool types.String `tfsdk:"sep_pool"`
CloudInit types.String `tfsdk:"cloud_init"`
Role types.String `tfsdk:"role"`
TimeoutStart types.Int64 `tfsdk:"timeout_start"`
VINSes types.List `tfsdk:"vinses"`
ExtNets types.List `tfsdk:"extnets"`
Mode types.String `tfsdk:"mode"`
Start types.Bool `tfsdk:"start"`
ForceStop types.Bool `tfsdk:"force_stop"`
ForceUpdate types.Bool `tfsdk:"force_update"`
Parents types.List `tfsdk:"parents"`
RemoveComputes types.List `tfsdk:"remove_computes"`
CompgroupID types.Int64 `tfsdk:"compgroup_id"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
//compute fields
AccountID types.Int64 `tfsdk:"account_id"`
AccountName types.String `tfsdk:"account_name"`
Computes types.List `tfsdk:"computes"`
Consistency types.Bool `tfsdk:"consistency"`
CreatedBy types.String `tfsdk:"created_by"`
CreatedTime types.Int64 `tfsdk:"created_time"`
DeletedBy types.String `tfsdk:"deleted_by"`
DeletedTime types.Int64 `tfsdk:"deleted_time"`
GID types.Int64 `tfsdk:"gid"`
GUID types.Int64 `tfsdk:"guid"`
Milestones types.Int64 `tfsdk:"milestones"`
RGID types.Int64 `tfsdk:"rg_id"`
RGName types.String `tfsdk:"rg_name"`
SeqNo types.Int64 `tfsdk:"seq_no"`
Status types.String `tfsdk:"status"`
TechStatus types.String `tfsdk:"tech_status"`
UpdatedBy types.String `tfsdk:"updated_by"`
UpdatedTime types.Int64 `tfsdk:"updated_time"`
ID types.String `tfsdk:"id"`
SID types.String `tfsdk:"sid"`
}
type ResourceItemGroupComputeModel struct {
ID types.Int64 `tfsdk:"id"`
IPAddresses types.List `tfsdk:"ip_addresses"`
Name types.String `tfsdk:"name"`
OSUsers types.List `tfsdk:"os_users"`
}
var ResourceItemGroupCompute = map[string]attr.Type{
"id": types.Int64Type,
"ip_addresses": types.ListType{ElemType: types.StringType},
"name": types.StringType,
"os_users": types.ListType{ElemType: types.ObjectType{AttrTypes: ResourceItemOSUser}},
}
type ResourceItemOSUserModel struct {
Login types.String `tfsdk:"login"`
Password types.String `tfsdk:"password"`
}
var ResourceItemOSUser = map[string]attr.Type{
"login": types.StringType,
"password": types.StringType,
}

View File

@@ -0,0 +1,316 @@
package bservice
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/cloudapi/bservice"
"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/cloudapi/bservice/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/bservice/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/bservice/schemas"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/bservice/utilities"
)
// Ensure the implementation satisfies the expected interfaces.
var (
_ resource.Resource = &resourceBService{}
_ resource.ResourceWithImportState = &resourceBService{}
)
// NewresourceBService is a helper function to simplify the provider implementation.
func NewResourceBService() resource.Resource {
return &resourceBService{}
}
// resourceBService is the resource implementation.
type resourceBService struct {
client *decort.DecortClient
}
// Create creates the resource and sets the initial Terraform state.
func (r *resourceBService) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
// Get plan to create resource group
var plan models.RecordBasicServiceResourceModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Create resourceBService: Error receiving the plan")
return
}
contextCreateMap := map[string]any{
"name": plan.Name.ValueString(),
"rg_id": plan.RGID.ValueInt64(),
}
tflog.Info(ctx, "Create resourceBService: got plan successfully", contextCreateMap)
tflog.Info(ctx, "Create resourceBService: start creating", contextCreateMap)
// Set timeouts
createTimeout, diags := plan.Timeouts.Create(ctx, constants.Timeout600s)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Create resourceBService: Error set timeout")
return
}
tflog.Info(ctx, "Create resourceBService: set timeouts successfully", map[string]any{
"name": plan.Name.ValueString(),
"rg_id": plan.RGID.ValueInt64(),
"createTimeout": createTimeout})
ctx, cancel := context.WithTimeout(ctx, createTimeout)
defer cancel()
// Make create request and get response
id, diags := utilities.BServiceResourceCreate(ctx, &plan, r.client)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
plan.ID = types.StringValue(strconv.Itoa(int(*id)))
tflog.Info(ctx, "BServiceResourceCreatee: BService created", map[string]any{"service_id": id})
tflog.Info(ctx, "BServiceResourceCreatee: resource creation is completed", map[string]any{"service_id": id})
currentSnapshots, diags := types.ListValue(plan.Snapshots.Type(ctx), plan.Snapshots.Elements())
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
// Map response body to schema and populate Computed attribute values
resp.Diagnostics.Append(flattens.BServiceResource(ctx, &plan, r.client)...)
if resp.Diagnostics.HasError() {
return
}
if !plan.Snapshots.Equal(currentSnapshots) && !currentSnapshots.IsNull() {
resp.Diagnostics.Append(utilities.SnapshotsBService(ctx, currentSnapshots, plan.Snapshots, uint64(plan.ServiceId.ValueInt64()), r.client)...)
if resp.Diagnostics.HasError() {
tflog.Warn(ctx, "Create resourceBService: Error snapshosts bservice")
return
}
}
// Set state to fully populated data
resp.Diagnostics.Append(resp.State.Set(ctx, plan)...)
if resp.Diagnostics.HasError() {
return
}
}
// Read refreshes the Terraform state with the latest data.
func (r *resourceBService) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
// Get current state
var state models.RecordBasicServiceResourceModel
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read resourceBService: Error get state")
return
}
tflog.Info(ctx, "Read resourceBService: got state successfully", map[string]any{"service_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 resourceBService: Error set timeout")
return
}
tflog.Info(ctx, "Read resourceBService: set timeouts successfully", map[string]any{
"service_id": state.ID.ValueString(),
"readTimeout": readTimeout})
ctx, cancel := context.WithTimeout(ctx, readTimeout)
defer cancel()
// read status
resp.Diagnostics.Append(utilities.BSerivceReadStatus(ctx, &state, r.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read resourceBService: Error reading status")
return
}
// Overwrite items with refreshed state
resp.Diagnostics.Append(flattens.BServiceResource(ctx, &state, r.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read resourceBService: Error flatten")
return
}
// Set refreshed state
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read resourceBService: Error set state")
return
}
tflog.Info(ctx, "End read resourceBService")
}
// Update updates the resource and sets the updated Terraform state on success.
func (r *resourceBService) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
// Retrieve values from plan
var plan models.RecordBasicServiceResourceModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Update resourceBService: Error receiving the plan")
return
}
logMap := map[string]any{"service_id": plan.ID.ValueString()}
tflog.Info(ctx, "Update resourceBService: got plan successfully", logMap)
// Retrieve values from state
var state models.RecordBasicServiceResourceModel
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Update resourceBService: Error receiving the state")
return
}
tflog.Info(ctx, "Update resourceBService: 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 resourceBService: Error set timeout")
return
}
tflog.Info(ctx, "Update resourceBService: set timeouts successfully", map[string]any{
"service_id": state.ID.ValueString(),
"updateTimeout": updateTimeout})
ctx, cancel := context.WithTimeout(ctx, updateTimeout)
defer cancel()
_, err := strconv.Atoi(state.ID.ValueString())
if err != nil {
resp.Diagnostics.AddError("Update resourceBService: Cannot parse ID from state", err.Error())
return
}
// enable/disable bservice
if !plan.Enable.Equal(state.Enable) && !plan.Enable.IsNull() {
resp.Diagnostics.Append(utilities.EnableDisableBService(ctx, &plan, r.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Update resourceBService: Error enabling/disabling bservice")
return
}
}
// start/stop bservice
if !plan.Start.Equal(state.Start) && !plan.Start.IsNull() {
resp.Diagnostics.Append(utilities.StartStopBService(ctx, &plan, r.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Update resourceBService: Error start/stop bservice")
return
}
}
// SnapshotsBService bservice
if !plan.Snapshots.Equal(state.Snapshots) && !plan.Snapshots.IsNull() {
resp.Diagnostics.Append(utilities.SnapshotsBService(ctx, state.Snapshots, plan.Snapshots, uint64(plan.ServiceId.ValueInt64()), r.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Update resourceBService: Error snapshosts bservice")
return
}
}
tflog.Info(ctx, "Update resourceBService: bservice update is completed", logMap)
// Map response body to schema and populate Computed attribute values
resp.Diagnostics.Append(flattens.BServiceResource(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 *resourceBService) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
// Get current state
var state models.RecordBasicServiceResourceModel
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Delete resourceBService: Error get state")
return
}
tflog.Info(ctx, "Delete resourceBService: got state successfully", map[string]any{"serice_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 resourceBService: Error set timeout")
return
}
tflog.Info(ctx, "Delete resourceBService: set timeouts successfully", map[string]any{
"service_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 := bservice.DeleteRequest{
ServiceID: uint64(state.ServiceId.ValueInt64()),
Permanently: permanently,
}
tflog.Info(ctx, "Delete resourceBService: before call CloudAPI().BService().Delete", map[string]any{"req": delReq})
_, err := r.client.CloudAPI().BService().Delete(ctx, delReq)
if err != nil {
resp.Diagnostics.AddError("Delete resourceBService: Error deleting BService with error: ", err.Error())
return
}
tflog.Info(ctx, "End delete resourceBService", map[string]any{"service_id": state.ID.ValueString()})
}
// Schema defines the schema for the resource.
func (r *resourceBService) Schema(ctx context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: schemas.MakeSchemaResourceBService(),
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 *resourceBService) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_bservice"
}
// Configure adds the provider configured client to the resource.
func (r *resourceBService) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
tflog.Info(ctx, "Get Configure resourceBService")
r.client = client.Resource(ctx, &req, resp)
tflog.Info(ctx, "Getting Configure resourceBService successfully")
}
func (r *resourceBService) 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)
}

Some files were not shown because too many files have changed in this diff Show More