4.10.0
This commit is contained in:
@@ -34,6 +34,7 @@ func flattenResourceAccount(d *schema.ResourceData, acc *account.RecordAccount)
|
||||
d.Set("updated_time", acc.UpdatedTime)
|
||||
d.Set("version", acc.Version)
|
||||
d.Set("vins", acc.VINS)
|
||||
d.Set("zone_ids", acc.ZoneIDs)
|
||||
}
|
||||
|
||||
func flattenDataAccount(d *schema.ResourceData, acc *account.RecordAccount) {
|
||||
@@ -54,12 +55,14 @@ func flattenDataAccount(d *schema.ResourceData, acc *account.RecordAccount) {
|
||||
d.Set("displayname", acc.DisplayName)
|
||||
d.Set("guid", acc.GUID)
|
||||
d.Set("account_id", acc.ID)
|
||||
d.Set("default_zone_id", acc.DefaultZoneID)
|
||||
d.Set("account_name", acc.Name)
|
||||
d.Set("resource_limits", flattenRgResourceLimits(acc.ResourceLimits))
|
||||
d.Set("resource_types", acc.ResTypes)
|
||||
d.Set("send_access_emails", acc.SendAccessEmails)
|
||||
d.Set("status", acc.Status)
|
||||
d.Set("uniq_pools", acc.UniqPools)
|
||||
d.Set("zone_ids", flattenZones(acc.ZoneIDs))
|
||||
d.Set("updated_time", acc.UpdatedTime)
|
||||
d.Set("version", acc.Version)
|
||||
d.Set("vins", acc.VINS)
|
||||
@@ -144,10 +147,16 @@ func flattenAccResource(r account.Resource) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenAccAcl(acls []account.ACL) []map[string]interface{} {
|
||||
func flattenAccAcl(acls []account.ACLWithEmails) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(acls))
|
||||
for _, acls := range acls {
|
||||
tempEmails := make([]string, 0, len(acls.Emails))
|
||||
for _, email := range acls.Emails {
|
||||
tempEmails = append(tempEmails, email)
|
||||
}
|
||||
|
||||
temp := map[string]interface{}{
|
||||
"emails": tempEmails,
|
||||
"explicit": acls.Explicit,
|
||||
"guid": acls.GUID,
|
||||
"right": acls.Right,
|
||||
@@ -220,6 +229,8 @@ func flattenListDeleted(al *account.ListAccounts) []map[string]interface{} {
|
||||
"send_access_emails": acc.SendAccessEmails,
|
||||
"status": acc.Status,
|
||||
"uniq_pools": acc.UniqPools,
|
||||
"default_zone_id": acc.DefaultZoneID,
|
||||
"zone_ids": acc.ZoneIDs,
|
||||
"updated_time": acc.UpdatedTime,
|
||||
"version": acc.Version,
|
||||
"vins": acc.VINS,
|
||||
@@ -257,6 +268,8 @@ func flattenAccountList(al *account.ListAccounts) []map[string]interface{} {
|
||||
"send_access_emails": acc.SendAccessEmails,
|
||||
"status": acc.Status,
|
||||
"uniq_pools": acc.UniqPools,
|
||||
"default_zone_id": acc.DefaultZoneID,
|
||||
"zone_ids": acc.ZoneIDs,
|
||||
"updated_time": acc.UpdatedTime,
|
||||
"version": acc.Version,
|
||||
"vins": acc.VINS,
|
||||
@@ -427,3 +440,15 @@ func flattenAccResourceConsumption(lrc *account.ListResources) []map[string]inte
|
||||
func flattenEnabled(status string) bool {
|
||||
return status == "CONFIRMED"
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -33,12 +33,18 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
//"log"
|
||||
"strconv"
|
||||
|
||||
"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/cloudbroker/account"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/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/dc"
|
||||
@@ -59,6 +65,10 @@ func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
req.Description = desc.(string)
|
||||
}
|
||||
|
||||
if zoneID, ok := d.GetOk("default_zone_id"); ok {
|
||||
req.DefaultZoneID = uint64(zoneID.(int))
|
||||
}
|
||||
|
||||
if emailaddress, ok := d.GetOk("emailaddress"); ok {
|
||||
req.EmailAddress = emailaddress.(string)
|
||||
}
|
||||
@@ -74,6 +84,13 @@ func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
}
|
||||
}
|
||||
|
||||
if zones, ok := d.GetOk("zone_ids"); ok {
|
||||
zones := zones.([]interface{})
|
||||
for _, zone := range zones {
|
||||
req.ZoneIDs = append(req.ZoneIDs, uint64(zone.(int)))
|
||||
}
|
||||
}
|
||||
|
||||
if resLimits, ok := d.GetOk("resource_limits"); ok {
|
||||
resLimits := resLimits.([]interface{})[0]
|
||||
resLimitsConv := resLimits.(map[string]interface{})
|
||||
@@ -200,7 +217,6 @@ func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
if !d.Get("enable").(bool) {
|
||||
_, err := c.CloudBroker().Account().Disable(ctx, account.DisableRequest{
|
||||
AccountID: accountId,
|
||||
Reason: d.Get("reason").(string),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
@@ -245,14 +261,34 @@ func resourceAccountDelete(ctx context.Context, d *schema.ResourceData, m interf
|
||||
AccountID: accountData.ID,
|
||||
Permanently: d.Get("permanently").(bool),
|
||||
Name: d.Get("account_name").(string),
|
||||
Reason: d.Get("reason").(string),
|
||||
}
|
||||
|
||||
_, err = c.CloudBroker().Account().Delete(ctx, req)
|
||||
taskID, err := c.CloudBroker().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.CloudBroker().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
|
||||
@@ -282,14 +318,34 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
return diag.Errorf("The account is in progress with status: %s", acc.Status)
|
||||
case status.Deleted:
|
||||
if d.Get("restore").(bool) {
|
||||
_, err := c.CloudBroker().Account().Restore(ctx, account.RestoreRequest{
|
||||
taskID, err := c.CloudBroker().Account().Restore(ctx, account.RestoreRequest{
|
||||
AccountID: accountId,
|
||||
Reason: d.Get("reason").(string),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
taskReq := tasks.GetRequest{
|
||||
AuditID: strings.Trim(taskID, `"`),
|
||||
}
|
||||
|
||||
for {
|
||||
time.Sleep(time.Second * 5)
|
||||
task, err := c.CloudBroker().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
|
||||
}
|
||||
}
|
||||
if _, ok := d.GetOk("enable"); ok {
|
||||
if err := utilityAccountEnableUpdate(ctx, d, m, acc); err != nil {
|
||||
return diag.FromErr(err)
|
||||
@@ -316,7 +372,7 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChanges("account_name", "send_access_emails", "uniq_pools", "resource_limits", "desc") {
|
||||
if d.HasChanges("account_name", "send_access_emails", "uniq_pools", "resource_limits", "desc", "default_zone_id") {
|
||||
if err := utilityAccountUpdate(ctx, d, m); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
@@ -352,6 +408,21 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("zone_ids") {
|
||||
old, new := d.GetChange("zone_ids")
|
||||
|
||||
//toAddSet := old.(*schema.Set).Difference(new.(*schema.Set))
|
||||
toRemoveSet := new.(*schema.Set).Difference(old.(*schema.Set))
|
||||
|
||||
/*if err := utilityZoneIDsUpdate(ctx, d, m, toAddSet); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}*/
|
||||
if err := utilityZoneIDsRemove(ctx, d, m, toRemoveSet); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return resourceAccountRead(ctx, d, m)
|
||||
}
|
||||
|
||||
|
||||
@@ -27,12 +27,25 @@ func resourceAccountSchemaMake() map[string]*schema.Schema {
|
||||
Optional: true,
|
||||
Description: "email",
|
||||
},
|
||||
"default_zone_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "email",
|
||||
},
|
||||
"send_access_emails": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: true,
|
||||
Description: "if true send emails when a user is granted access to resources",
|
||||
},
|
||||
"zone_ids": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"uniq_pools": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
@@ -77,11 +90,6 @@ func resourceAccountSchemaMake() map[string]*schema.Schema {
|
||||
},
|
||||
Description: "Share images with account",
|
||||
},
|
||||
"reason": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "reason for restore or deactivation",
|
||||
},
|
||||
"restore": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
@@ -148,7 +156,7 @@ func resourceAccountSchemaMake() map[string]*schema.Schema {
|
||||
Optional: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
ValidateFunc: validation.StringInSlice([]string{"hugepages", "numa", "cpupin", "vfnic", "dpdk", "changemac"}, true),
|
||||
ValidateFunc: validation.StringInSlice([]string{"hugepages", "numa", "cpupin", "vfnic", "dpdk", "changemac", "trunk"}, true),
|
||||
},
|
||||
},
|
||||
"account_id": {
|
||||
@@ -176,6 +184,13 @@ func resourceAccountSchemaMake() map[string]*schema.Schema {
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"emails": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"explicit": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
@@ -665,6 +680,10 @@ func dataSourceAccountListDeletedSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"default_zone_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"uniq_pools": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
@@ -672,6 +691,13 @@ func dataSourceAccountListDeletedSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"zone_ids": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"updated_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
@@ -1252,6 +1278,10 @@ func dataSourceAccountListSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"default_zone_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"account_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
@@ -1314,6 +1344,13 @@ func dataSourceAccountListSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"zone_ids": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"updated_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
@@ -1928,11 +1965,38 @@ func dataSourceAccountSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"default_zone_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"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,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"acl": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"emails": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"explicit": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
|
||||
@@ -226,6 +226,10 @@ func utilityAccountUpdate(ctx context.Context, d *schema.ResourceData, m interfa
|
||||
req.SendAccessEmails = d.Get("send_access_emails").(bool)
|
||||
}
|
||||
|
||||
if d.HasChange("default_zone_id") {
|
||||
req.DefaultZoneID = uint64(d.Get("default_zone_id").(int))
|
||||
}
|
||||
|
||||
if d.HasChange("uniq_pools") {
|
||||
uniq_pools := d.Get("uniq_pools").([]interface{})
|
||||
|
||||
@@ -401,6 +405,56 @@ func utilityAccountComputeFeaturesUpdate(ctx context.Context, d *schema.Resource
|
||||
return nil
|
||||
}
|
||||
|
||||
func utilityZoneIDsAdd(ctx context.Context, d *schema.ResourceData, m interface{}, toUpdate *schema.Set) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
accountId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
zones := toUpdate.List()
|
||||
|
||||
compZones := make([]uint64, 0, len(zones))
|
||||
for _, item := range zones {
|
||||
compZones = append(compZones, uint64(item.(int)))
|
||||
|
||||
}
|
||||
|
||||
req := account.AddZoneRequest{
|
||||
AccountID: accountId,
|
||||
ZoneIDs: compZones,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().Account().AddZone(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func utilityZoneIDsRemove(ctx context.Context, d *schema.ResourceData, m interface{}, toRemove *schema.Set) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
accountId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
zones := toRemove.List()
|
||||
|
||||
compZones := make([]uint64, 0, len(zones))
|
||||
for _, item := range zones {
|
||||
compZones = append(compZones, uint64(item.(int)))
|
||||
|
||||
}
|
||||
|
||||
req := account.RemoveZoneRequest{
|
||||
AccountID: accountId,
|
||||
ZoneIDs: compZones,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().Account().RemoveZone(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func isContainsUser(els []interface{}, el interface{}) bool {
|
||||
for _, elOld := range els {
|
||||
elOldConv := elOld.(map[string]interface{})
|
||||
|
||||
Reference in New Issue
Block a user