1.0.0
This commit is contained in:
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user