4.10.0
This commit is contained in:
@@ -85,6 +85,13 @@ func aclSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"emails": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return res
|
||||
@@ -292,6 +299,26 @@ func dataSourceAccountSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"zone_ids": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"default_zone_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"acl": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
|
||||
@@ -61,7 +61,7 @@ func flattenAccountList(al *account.ListAccounts) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenRgAcl(rgAcls []account.RecordACL) []map[string]interface{} {
|
||||
func flattenRgAcl(rgAcls []account.ListRecordACL) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, rgAcl := range rgAcls {
|
||||
temp := map[string]interface{}{
|
||||
|
||||
@@ -36,6 +36,8 @@ func flattenAccount(d *schema.ResourceData, acc account.RecordAccount) error {
|
||||
d.Set("machines", flattenAccMachines(acc.Machines))
|
||||
d.Set("cpu_allocation_parameter", acc.CPUAllocationParameter)
|
||||
d.Set("cpu_allocation_ratio", acc.CPUAllocationRatio)
|
||||
d.Set("default_zone_id", acc.DefaultZoneID)
|
||||
d.Set("zone_ids", flattenZones(acc.ZoneIDs))
|
||||
|
||||
if username, ok := d.GetOk("username"); ok {
|
||||
d.Set("username", username)
|
||||
@@ -80,6 +82,7 @@ func flattenAccAcl(acls []account.RecordACL) []map[string]interface{} {
|
||||
"right": acls.Rights,
|
||||
"status": acls.Status,
|
||||
"type": acls.Type,
|
||||
"emails": acls.Emails,
|
||||
"user_group_id": acls.UgroupID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
@@ -165,3 +168,15 @@ func flattenAccResourceConsumption(lrc *account.ListResourceConsumption) []map[s
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenZones(zones []account.ZoneID) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, zone := range zones {
|
||||
temp := map[string]interface{}{
|
||||
"id": zone.ID,
|
||||
"name": zone.Name,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -34,13 +34,16 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/tasks"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
|
||||
@@ -116,11 +119,32 @@ func resourceAccountDelete(ctx context.Context, d *schema.ResourceData, m interf
|
||||
Permanently: d.Get("permanently").(bool),
|
||||
}
|
||||
|
||||
_, err = c.CloudAPI().Account().Delete(ctx, req)
|
||||
taskID, err := c.CloudAPI().Account().Delete(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
taskReq := tasks.GetRequest{
|
||||
AuditID: strings.Trim(taskID, `"`),
|
||||
}
|
||||
|
||||
for {
|
||||
time.Sleep(time.Second * 5)
|
||||
task, err := c.CloudAPI().Tasks().Get(ctx, taskReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
log.Debugf("resourceAccountDelete: delete account - %s", task.Stage)
|
||||
|
||||
if task.Completed {
|
||||
if task.Error != "" {
|
||||
return diag.FromErr(fmt.Errorf("cannot delete account: %v", task.Error))
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
@@ -153,11 +177,32 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
AccountID: accountId,
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().Account().Restore(ctx, req)
|
||||
taskID, err := c.CloudAPI().Account().Restore(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
taskReq := tasks.GetRequest{
|
||||
AuditID: strings.Trim(taskID, `"`),
|
||||
}
|
||||
|
||||
for {
|
||||
time.Sleep(time.Second * 5)
|
||||
task, err := c.CloudAPI().Tasks().Get(ctx, taskReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
log.Debugf("resourceAccountUpdate: restore account - %s", task.Stage)
|
||||
|
||||
if task.Completed {
|
||||
if task.Error != "" {
|
||||
return diag.FromErr(fmt.Errorf("cannot restore account: %v", task.Error))
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
hasChanged = true
|
||||
}
|
||||
case status.Disabled:
|
||||
@@ -176,7 +221,6 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
if d.HasChange("enable") {
|
||||
reqSwitch := account.DisableEnableRequest{
|
||||
AccountID: accountId,
|
||||
Reason: d.Get("reason").(string),
|
||||
}
|
||||
enable := d.Get("enable").(bool)
|
||||
|
||||
@@ -285,6 +329,18 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("default_zone_id") {
|
||||
req.DefaultZoneID = uint64(d.Get("default_zone_id").(int))
|
||||
updated = true
|
||||
}
|
||||
|
||||
if updated {
|
||||
_, err := c.CloudAPI().Account().Update(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("users") {
|
||||
deletedUsers := make([]interface{}, 0)
|
||||
addedUsers := make([]interface{}, 0)
|
||||
@@ -431,10 +487,19 @@ func resourceAccountSchemaMake() map[string]*schema.Schema {
|
||||
},
|
||||
},
|
||||
},
|
||||
"reason": {
|
||||
Type: schema.TypeString,
|
||||
"default_zone_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "reason for deactivation",
|
||||
Computed: true,
|
||||
Description: "email",
|
||||
},
|
||||
"zone_ids": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"restore": {
|
||||
Type: schema.TypeBool,
|
||||
|
||||
Reference in New Issue
Block a user