4.0.0
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package account
|
||||
|
||||
const accountAddUserAPI = "/restmachine/cloudapi/account/addUser"
|
||||
const accountAuditsAPI = "/restmachine/cloudapi/account/audits"
|
||||
const accountCreateAPI = "/restmachine/cloudapi/account/create"
|
||||
const accountDeleteAPI = "/restmachine/cloudapi/account/delete"
|
||||
const accountDeleteUserAPI = "/restmachine/cloudapi/account/deleteUser"
|
||||
const accountDisableAPI = "/restmachine/cloudapi/account/disable"
|
||||
const accountEnableAPI = "/restmachine/cloudapi/account/enable"
|
||||
const accountGetAPI = "/restmachine/cloudapi/account/get"
|
||||
const accountGetConsumedUnitsAPI = "/restmachine/cloudapi/account/getConsumedAccountUnits"
|
||||
const accountGetConsumedUnitsByTypeAPI = "/restmachine/cloudapi/account/getConsumedCloudUnitsByType"
|
||||
const accountGetReservedUnitsAPI = "/restmachine/cloudapi/account/getReservedAccountUnits"
|
||||
const accountListAPI = "/restmachine/cloudapi/account/list"
|
||||
const accountListComputesAPI = "/restmachine/cloudapi/account/listComputes"
|
||||
const accountListDeletedAPI = "/restmachine/cloudapi/account/listDeleted"
|
||||
const accountListDisksAPI = "/restmachine/cloudapi/account/listDisks"
|
||||
const accountListFlipGroupsAPI = "/restmachine/cloudapi/account/listFlipGroups"
|
||||
const accountListRGAPI = "/restmachine/cloudapi/account/listRG"
|
||||
const accountListTemplatesAPI = "/restmachine/cloudapi/account/listTemplates"
|
||||
const accountListVinsAPI = "/restmachine/cloudapi/account/listVins"
|
||||
const accountRestoreAPI = "/restmachine/cloudapi/account/restore"
|
||||
const accountUpdateAPI = "/restmachine/cloudapi/account/update"
|
||||
const accountUpdateUserAPI = "/restmachine/cloudapi/account/updateUser"
|
||||
@@ -48,7 +48,7 @@ func dataSourceAccountRead(ctx context.Context, d *schema.ResourceData, m interf
|
||||
}
|
||||
|
||||
flattenAccount(d, *acc)
|
||||
d.SetId(strconv.Itoa(acc.ID))
|
||||
d.SetId(strconv.Itoa(int(acc.ID)))
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -385,6 +385,14 @@ func dataSourceAccountSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"cpu_allocation_parameter": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"cpu_allocation_ratio": {
|
||||
Type: schema.TypeFloat,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -38,10 +38,11 @@ import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func flattenAccountAuditsList(aal AccountAuditsList) []map[string]interface{} {
|
||||
func flattenAccountAuditsList(aal account.ListAudits) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, aa := range aal {
|
||||
temp := map[string]interface{}{
|
||||
|
||||
@@ -38,33 +38,34 @@ import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func flattenAccountComputesList(acl AccountComputesList) []map[string]interface{} {
|
||||
func flattenAccountComputesList(acl account.ListComputes) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, acc := range acl {
|
||||
temp := map[string]interface{}{
|
||||
"account_id": acc.AccountId,
|
||||
"account_id": acc.AccountID,
|
||||
"account_name": acc.AccountName,
|
||||
"cpus": acc.CPUs,
|
||||
"created_by": acc.CreatedBy,
|
||||
"created_time": acc.CreatedTime,
|
||||
"deleted_by": acc.DeletedBy,
|
||||
"deleted_time": acc.DeletedTime,
|
||||
"compute_id": acc.ComputeId,
|
||||
"compute_id": acc.ComputeID,
|
||||
"compute_name": acc.ComputeName,
|
||||
"ram": acc.RAM,
|
||||
"registered": acc.Registered,
|
||||
"rg_id": acc.RgId,
|
||||
"rg_name": acc.RgName,
|
||||
"rg_id": acc.RGID,
|
||||
"rg_name": acc.RGName,
|
||||
"status": acc.Status,
|
||||
"tech_status": acc.TechStatus,
|
||||
"total_disks_size": acc.TotalDisksSize,
|
||||
"updated_by": acc.UpdatedBy,
|
||||
"updated_time": acc.UpdatedTime,
|
||||
"user_managed": acc.UserManaged,
|
||||
"vins_connected": acc.VinsConnected,
|
||||
"vins_connected": acc.VINSConnected,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ func dataSourceAccountConsumedUnitsRead(ctx context.Context, d *schema.ResourceD
|
||||
d.Set("cu_i", accountConsumedUnits.CUI)
|
||||
d.Set("cu_m", accountConsumedUnits.CUM)
|
||||
d.Set("cu_np", accountConsumedUnits.CUNP)
|
||||
d.Set("gpu_units", accountConsumedUnits.GpuUnits)
|
||||
d.Set("gpu_units", accountConsumedUnits.GPUUnits)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -37,17 +37,18 @@ import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func flattenAccountDisksList(adl AccountDisksList) []map[string]interface{} {
|
||||
func flattenAccountDisksList(adl account.ListDisks) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, ad := range adl {
|
||||
temp := map[string]interface{}{
|
||||
"disk_id": ad.ID,
|
||||
"disk_name": ad.Name,
|
||||
"pool": ad.Pool,
|
||||
"sep_id": ad.SepId,
|
||||
"sep_id": ad.SEPID,
|
||||
"shareable": ad.Shareable,
|
||||
"size_max": ad.SizeMax,
|
||||
"type": ad.Type,
|
||||
|
||||
@@ -38,14 +38,15 @@ import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func flattenAccountFlipGroupsList(afgl AccountFlipGroupsList) []map[string]interface{} {
|
||||
func flattenAccountFlipGroupsList(afgl account.ListFLIPGroups) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, afg := range afgl {
|
||||
temp := map[string]interface{}{
|
||||
"account_id": afg.AccountId,
|
||||
"account_id": afg.AccountID,
|
||||
"client_type": afg.ClientType,
|
||||
"conn_type": afg.ConnType,
|
||||
"created_by": afg.CreatedBy,
|
||||
@@ -53,7 +54,7 @@ func flattenAccountFlipGroupsList(afgl AccountFlipGroupsList) []map[string]inter
|
||||
"default_gw": afg.DefaultGW,
|
||||
"deleted_by": afg.DeletedBy,
|
||||
"deleted_time": afg.DeletedTime,
|
||||
"desc": afg.Desc,
|
||||
"desc": afg.Description,
|
||||
"gid": afg.GID,
|
||||
"guid": afg.GUID,
|
||||
"fg_id": afg.ID,
|
||||
|
||||
@@ -38,14 +38,15 @@ import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func flattenAccountList(al AccountCloudApiList) []map[string]interface{} {
|
||||
func flattenAccountList(al account.ListAccounts) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, acc := range al {
|
||||
temp := map[string]interface{}{
|
||||
"acl": flattenRgAcl(acc.Acl),
|
||||
"acl": flattenRgAcl(acc.ACL),
|
||||
"created_time": acc.CreatedTime,
|
||||
"deleted_time": acc.DeletedTime,
|
||||
"account_id": acc.ID,
|
||||
@@ -58,12 +59,12 @@ func flattenAccountList(al AccountCloudApiList) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenRgAcl(rgAcls []AccountAclRecord) []map[string]interface{} {
|
||||
func flattenRgAcl(rgAcls []account.RecordACL) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, rgAcl := range rgAcls {
|
||||
temp := map[string]interface{}{
|
||||
"explicit": rgAcl.IsExplicit,
|
||||
"guid": rgAcl.Guid,
|
||||
"guid": rgAcl.GUID,
|
||||
"right": rgAcl.Rights,
|
||||
"status": rgAcl.Status,
|
||||
"type": rgAcl.Type,
|
||||
|
||||
@@ -54,7 +54,7 @@ func dataSourceAccountReservedUnitsRead(ctx context.Context, d *schema.ResourceD
|
||||
d.Set("cu_i", accountReservedUnits.CUI)
|
||||
d.Set("cu_m", accountReservedUnits.CUM)
|
||||
d.Set("cu_np", accountReservedUnits.CUNP)
|
||||
d.Set("gpu_units", accountReservedUnits.GpuUnits)
|
||||
d.Set("gpu_units", accountReservedUnits.GPUUnits)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -38,10 +38,11 @@ import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func flattenAccountRGList(argl AccountRGList) []map[string]interface{} {
|
||||
func flattenAccountRGList(argl account.ListRG) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, arg := range argl {
|
||||
temp := map[string]interface{}{
|
||||
@@ -57,7 +58,7 @@ func flattenAccountRGList(argl AccountRGList) []map[string]interface{} {
|
||||
"status": arg.Status,
|
||||
"updated_by": arg.UpdatedBy,
|
||||
"updated_time": arg.UpdatedTime,
|
||||
"vinses": arg.Vinses,
|
||||
"vinses": arg.VINSes,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
@@ -65,7 +66,7 @@ func flattenAccountRGList(argl AccountRGList) []map[string]interface{} {
|
||||
|
||||
}
|
||||
|
||||
func flattenAccRGComputes(argc AccountRGComputes) []map[string]interface{} {
|
||||
func flattenAccRGComputes(argc account.RGComputes) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"started": argc.Started,
|
||||
@@ -75,13 +76,13 @@ func flattenAccRGComputes(argc AccountRGComputes) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenAccResourceHack(r ResourceHack) []map[string]interface{} {
|
||||
func flattenAccResourceHack(r account.LimitsRG) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"cpu": r.CPU,
|
||||
"disksize": r.Disksize,
|
||||
"extips": r.Extips,
|
||||
"exttraffic": r.Exttraffic,
|
||||
"disksize": r.DiskSize,
|
||||
"extips": r.ExtIPs,
|
||||
"exttraffic": r.ExtTraffic,
|
||||
"gpu": r.GPU,
|
||||
"ram": r.RAM,
|
||||
//"seps": flattenAccountSeps(r.SEPs),
|
||||
@@ -90,13 +91,13 @@ func flattenAccResourceHack(r ResourceHack) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenAccResourceRg(r Resource) []map[string]interface{} {
|
||||
func flattenAccResourceRg(r account.Resource) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"cpu": r.CPU,
|
||||
"disksize": r.Disksize,
|
||||
"extips": r.Extips,
|
||||
"exttraffic": r.Exttraffic,
|
||||
"disksize": r.DiskSize,
|
||||
"extips": r.ExtIPs,
|
||||
"exttraffic": r.ExtTraffic,
|
||||
"gpu": r.GPU,
|
||||
"ram": r.RAM,
|
||||
}
|
||||
@@ -104,7 +105,7 @@ func flattenAccResourceRg(r Resource) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenAccRGResources(argr AccountRGResources) []map[string]interface{} {
|
||||
func flattenAccRGResources(argr account.RGResources) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"consumed": flattenAccResourceRg(argr.Consumed),
|
||||
|
||||
@@ -38,16 +38,17 @@ import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func flattenAccountTemplatesList(atl AccountTemplatesList) []map[string]interface{} {
|
||||
func flattenAccountTemplatesList(atl account.ListTemplates) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, at := range atl {
|
||||
temp := map[string]interface{}{
|
||||
"unc_path": at.UNCPath,
|
||||
"account_id": at.AccountId,
|
||||
"desc": at.Desc,
|
||||
"account_id": at.AccountID,
|
||||
"desc": at.Description,
|
||||
"template_id": at.ID,
|
||||
"template_name": at.Name,
|
||||
"public": at.Public,
|
||||
|
||||
@@ -38,14 +38,15 @@ import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func flattenAccountVinsList(avl AccountVinsList) []map[string]interface{} {
|
||||
func flattenAccountVinsList(avl account.ListVINS) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, av := range avl {
|
||||
temp := map[string]interface{}{
|
||||
"account_id": av.AccountId,
|
||||
"account_id": av.AccountID,
|
||||
"account_name": av.AccountName,
|
||||
"computes": av.Computes,
|
||||
"created_by": av.CreatedBy,
|
||||
@@ -56,9 +57,9 @@ func flattenAccountVinsList(avl AccountVinsList) []map[string]interface{} {
|
||||
"vin_id": av.ID,
|
||||
"vin_name": av.Name,
|
||||
"network": av.Network,
|
||||
"pri_vnf_dev_id": av.PriVnfDevId,
|
||||
"rg_id": av.RgId,
|
||||
"rg_name": av.RgName,
|
||||
"pri_vnf_dev_id": av.PriVNFDevID,
|
||||
"rg_id": av.RGID,
|
||||
"rg_name": av.RGName,
|
||||
"status": av.Status,
|
||||
"updated_by": av.UpdatedBy,
|
||||
"updated_time": av.UpdatedTime,
|
||||
|
||||
@@ -2,20 +2,19 @@ package account
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||
)
|
||||
|
||||
func flattenAccount(d *schema.ResourceData, acc AccountWithResources) error {
|
||||
func flattenAccount(d *schema.ResourceData, acc account.RecordAccount) error {
|
||||
d.Set("dc_location", acc.DCLocation)
|
||||
d.Set("resources", flattenAccResources(acc.Resources))
|
||||
d.Set("ckey", acc.CKey)
|
||||
d.Set("meta", flattens.FlattenMeta(acc.Meta))
|
||||
d.Set("acl", flattenAccAcl(acc.Acl))
|
||||
d.Set("acl", flattenAccAcl(acc.ACL))
|
||||
d.Set("company", acc.Company)
|
||||
d.Set("companyurl", acc.CompanyUrl)
|
||||
d.Set("companyurl", acc.CompanyURL)
|
||||
d.Set("created_by", acc.CreatedBy)
|
||||
d.Set("created_time", acc.CreatedTime)
|
||||
d.Set("deactivation_time", acc.DeactiovationTime)
|
||||
d.Set("deactivation_time", acc.DeactivationTime)
|
||||
d.Set("deleted_by", acc.DeletedBy)
|
||||
d.Set("deleted_time", acc.DeletedTime)
|
||||
d.Set("displayname", acc.DisplayName)
|
||||
@@ -24,25 +23,26 @@ func flattenAccount(d *schema.ResourceData, acc AccountWithResources) error {
|
||||
d.Set("account_name", acc.Name)
|
||||
d.Set("resource_limits", flattenRgResourceLimits(acc.ResourceLimits))
|
||||
d.Set("send_access_emails", acc.SendAccessEmails)
|
||||
d.Set("service_account", acc.ServiceAccount)
|
||||
d.Set("status", acc.Status)
|
||||
d.Set("updated_time", acc.UpdatedTime)
|
||||
d.Set("version", acc.Version)
|
||||
d.Set("vins", acc.Vins)
|
||||
d.Set("vinses", acc.Vinses)
|
||||
d.Set("vins", acc.VINS)
|
||||
d.Set("vinses", acc.VINSes)
|
||||
d.Set("computes", flattenAccComputes(acc.Computes))
|
||||
d.Set("machines", flattenAccMachines(acc.Machines))
|
||||
d.Set("cpu_allocation_parameter", acc.CPUAllocationParameter)
|
||||
d.Set("cpu_allocation_ratio", acc.CPUAllocationRatio)
|
||||
|
||||
if username, ok := d.GetOk("username"); ok {
|
||||
d.Set("username", username)
|
||||
} else {
|
||||
d.Set("username", acc.Acl[0].UgroupID)
|
||||
d.Set("username", acc.ACL[0].UgroupID)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func flattenAccComputes(acs Computes) []map[string]interface{} {
|
||||
func flattenAccComputes(acs account.Computes) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"started": acs.Started,
|
||||
@@ -52,7 +52,7 @@ func flattenAccComputes(acs Computes) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenAccMachines(ams Machines) []map[string]interface{} {
|
||||
func flattenAccMachines(ams account.Machines) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"running": ams.Running,
|
||||
@@ -62,13 +62,13 @@ func flattenAccMachines(ams Machines) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenAccAcl(acls []AccountAclRecord) []map[string]interface{} {
|
||||
func flattenAccAcl(acls []account.RecordACL) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, acls := range acls {
|
||||
temp := map[string]interface{}{
|
||||
"can_be_deleted": acls.CanBeDeleted,
|
||||
"explicit": acls.IsExplicit,
|
||||
"guid": acls.Guid,
|
||||
"guid": acls.GUID,
|
||||
"right": acls.Rights,
|
||||
"status": acls.Status,
|
||||
"type": acls.Type,
|
||||
@@ -79,7 +79,7 @@ func flattenAccAcl(acls []AccountAclRecord) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenRgResourceLimits(rl ResourceLimits) []map[string]interface{} {
|
||||
func flattenRgResourceLimits(rl account.ResourceLimits) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"cu_c": rl.CUC,
|
||||
@@ -87,7 +87,7 @@ func flattenRgResourceLimits(rl ResourceLimits) []map[string]interface{} {
|
||||
"cu_i": rl.CUI,
|
||||
"cu_m": rl.CUM,
|
||||
"cu_np": rl.CUNP,
|
||||
"gpu_units": rl.GpuUnits,
|
||||
"gpu_units": rl.GPUUnits,
|
||||
}
|
||||
res = append(res, temp)
|
||||
|
||||
@@ -95,7 +95,7 @@ func flattenRgResourceLimits(rl ResourceLimits) []map[string]interface{} {
|
||||
|
||||
}
|
||||
|
||||
func flattenAccResources(r Resources) []map[string]interface{} {
|
||||
func flattenAccResources(r account.Resources) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"current": flattenAccResource(r.Current),
|
||||
@@ -105,7 +105,7 @@ func flattenAccResources(r Resources) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenAccountSeps(seps map[string]map[string]ResourceSep) []map[string]interface{} {
|
||||
func flattenAccountSeps(seps map[string]map[string]account.DiskUsage) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for sepKey, sepVal := range seps {
|
||||
for dataKey, dataVal := range sepVal {
|
||||
@@ -121,13 +121,13 @@ func flattenAccountSeps(seps map[string]map[string]ResourceSep) []map[string]int
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenAccResource(r Resource) []map[string]interface{} {
|
||||
func flattenAccResource(r account.Resource) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"cpu": r.CPU,
|
||||
"disksize": r.Disksize,
|
||||
"extips": r.Extips,
|
||||
"exttraffic": r.Exttraffic,
|
||||
"disksize": r.DiskSize,
|
||||
"extips": r.ExtIPs,
|
||||
"exttraffic": r.ExtTraffic,
|
||||
"gpu": r.GPU,
|
||||
"ram": r.RAM,
|
||||
"seps": flattenAccountSeps(r.SEPs),
|
||||
|
||||
@@ -1,277 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package account
|
||||
|
||||
type AccountAclRecord struct {
|
||||
IsExplicit bool `json:"explicit"`
|
||||
Guid string `json:"guid"`
|
||||
Rights string `json:"right"`
|
||||
Status string `json:"status"`
|
||||
Type string `json:"type"`
|
||||
UgroupID string `json:"userGroupId"`
|
||||
CanBeDeleted bool `json:"canBeDeleted"`
|
||||
}
|
||||
|
||||
type ResourceLimits struct {
|
||||
CUC float64 `json:"CU_C"`
|
||||
CUD float64 `json:"CU_D"`
|
||||
CUI float64 `json:"CU_I"`
|
||||
CUM float64 `json:"CU_M"`
|
||||
CUNP float64 `json:"CU_NP"`
|
||||
GpuUnits float64 `json:"gpu_units"`
|
||||
}
|
||||
|
||||
type Account struct {
|
||||
DCLocation string `json:"DCLocation"`
|
||||
CKey string `jspn:"_ckey"`
|
||||
Meta []interface{} `json:"_meta"`
|
||||
Acl []AccountAclRecord `json:"acl"`
|
||||
Company string `json:"company"`
|
||||
CompanyUrl string `json:"companyurl"`
|
||||
CreatedBy string `jspn:"createdBy"`
|
||||
CreatedTime int `json:"createdTime"`
|
||||
DeactiovationTime float64 `json:"deactivationTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime int `json:"deletedTime"`
|
||||
DisplayName string `json:"displayname"`
|
||||
GUID int `json:"guid"`
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
ResourceLimits ResourceLimits `json:"resourceLimits"`
|
||||
SendAccessEmails bool `json:"sendAccessEmails"`
|
||||
ServiceAccount bool `json:"serviceAccount"`
|
||||
Status string `json:"status"`
|
||||
UpdatedTime int `json:"updatedTime"`
|
||||
Version int `json:"version"`
|
||||
Vins []int `json:"vins"`
|
||||
}
|
||||
|
||||
type AccountList []Account
|
||||
|
||||
type AccountCloudApi struct {
|
||||
Acl []AccountAclRecord `json:"acl"`
|
||||
CreatedTime int `json:"createdTime"`
|
||||
DeletedTime int `json:"deletedTime"`
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
UpdatedTime int `json:"updatedTime"`
|
||||
}
|
||||
|
||||
type AccountCloudApiList []AccountCloudApi
|
||||
|
||||
type ResourceSep struct {
|
||||
DiskSize float64 `json:"disksize"`
|
||||
DiskSizeMax int `json:"disksizemax"`
|
||||
}
|
||||
|
||||
type Resource struct {
|
||||
CPU int `json:"cpu"`
|
||||
Disksize float64 `json:"disksize"`
|
||||
Extips int `json:"extips"`
|
||||
Exttraffic int `json:"exttraffic"`
|
||||
GPU int `json:"gpu"`
|
||||
RAM int `json:"ram"`
|
||||
SEPs map[string]map[string]ResourceSep `json:"seps"`
|
||||
}
|
||||
|
||||
type Resources struct {
|
||||
Current Resource `json:"Current"`
|
||||
Reserved Resource `json:"Reserved"`
|
||||
}
|
||||
|
||||
type Computes struct {
|
||||
Started int `json:"started"`
|
||||
Stopped int `json:"stopped"`
|
||||
}
|
||||
|
||||
type Machines struct {
|
||||
Running int `json:"running"`
|
||||
Halted int `json:"halted"`
|
||||
}
|
||||
|
||||
type AccountWithResources struct {
|
||||
Account
|
||||
Resources Resources `json:"Resources"`
|
||||
Computes Computes `json:"computes"`
|
||||
Machines Machines `json:"machines"`
|
||||
Vinses int `json:"vinses"`
|
||||
}
|
||||
|
||||
type AccountCompute struct {
|
||||
AccountId int `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
CPUs int `json:"cpus"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime int `json:"createdTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime int `json:"deletedTime"`
|
||||
ComputeId int `json:"id"`
|
||||
ComputeName string `json:"name"`
|
||||
RAM int `json:"ram"`
|
||||
Registered bool `json:"registered"`
|
||||
RgId int `json:"rgId"`
|
||||
RgName string `json:"rgName"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
TotalDisksSize int `json:"totalDisksSize"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime int `json:"updatedTime"`
|
||||
UserManaged bool `json:"userManaged"`
|
||||
VinsConnected int `json:"vinsConnected"`
|
||||
}
|
||||
|
||||
type AccountComputesList []AccountCompute
|
||||
|
||||
type AccountDisk struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Pool string `json:"pool"`
|
||||
SepId int `json:"sepId"`
|
||||
Shareable bool `json:"shareable"`
|
||||
SizeMax int `json:"sizeMax"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type AccountDisksList []AccountDisk
|
||||
|
||||
type AccountVin struct {
|
||||
AccountId int `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
Computes int `json:"computes"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime int `json:"createdTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime int `json:"deletedTime"`
|
||||
ExternalIP string `json:"externalIP"`
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Network string `json:"network"`
|
||||
PriVnfDevId int `json:"priVnfDevId"`
|
||||
RgId int `json:"rgId"`
|
||||
RgName string `json:"rgName"`
|
||||
Status string `json:"status"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime int `json:"updatedTime"`
|
||||
}
|
||||
|
||||
type AccountVinsList []AccountVin
|
||||
|
||||
type AccountAudit struct {
|
||||
Call string `json:"call"`
|
||||
ResponseTime float64 `json:"responsetime"`
|
||||
StatusCode int `json:"statuscode"`
|
||||
Timestamp float64 `json:"timestamp"`
|
||||
User string `json:"user"`
|
||||
}
|
||||
|
||||
type AccountAuditsList []AccountAudit
|
||||
|
||||
type AccountRGComputes struct {
|
||||
Started int `json:"Started"`
|
||||
Stopped int `json:"Stopped"`
|
||||
}
|
||||
|
||||
type ResourceHack struct {
|
||||
CPU int `json:"cpu"`
|
||||
Disksize float64 `json:"disksize"`
|
||||
Extips int `json:"extips"`
|
||||
Exttraffic int `json:"exttraffic"`
|
||||
GPU int `json:"gpu"`
|
||||
RAM int `json:"ram"`
|
||||
}
|
||||
|
||||
type AccountRGResources struct {
|
||||
Consumed Resource `json:"Consumed"`
|
||||
Limits ResourceHack `json:"Limits"`
|
||||
Reserved Resource `json:"Reserved"`
|
||||
}
|
||||
|
||||
type AccountRG struct {
|
||||
Computes AccountRGComputes `json:"Computes"`
|
||||
Resources AccountRGResources `json:"Resources"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime int `json:"createdTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime int `json:"deletedTime"`
|
||||
RGID int `json:"id"`
|
||||
Milestones int `json:"milestones"`
|
||||
RGName string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime int `json:"updatedTime"`
|
||||
Vinses int `json:"vinses"`
|
||||
}
|
||||
|
||||
type AccountRGList []AccountRG
|
||||
|
||||
type AccountTemplate struct {
|
||||
UNCPath string `json:"UNCPath"`
|
||||
AccountId int `json:"accountId"`
|
||||
Desc string `json:"desc"`
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Public bool `json:"public"`
|
||||
Size int `json:"size"`
|
||||
Status string `json:"status"`
|
||||
Type string `json:"type"`
|
||||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
type AccountTemplatesList []AccountTemplate
|
||||
|
||||
type AccountFlipGroup struct {
|
||||
AccountId int `json:"accountId"`
|
||||
ClientType string `json:"clientType"`
|
||||
ConnType string `json:"connType"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime int `json:"createdTime"`
|
||||
DefaultGW string `json:"defaultGW"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime int `json:"deletedTime"`
|
||||
Desc string `json:"desc"`
|
||||
GID int `json:"gid"`
|
||||
GUID int `json:"guid"`
|
||||
ID int `json:"id"`
|
||||
IP string `json:"ip"`
|
||||
Milestones int `json:"milestones"`
|
||||
Name string `json:"name"`
|
||||
NetID int `json:"netId"`
|
||||
NetType string `json:"netType"`
|
||||
NetMask int `json:"netmask"`
|
||||
Status string `json:"status"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime int `json:"updatedTime"`
|
||||
}
|
||||
|
||||
type AccountFlipGroupsList []AccountFlipGroup
|
||||
@@ -34,13 +34,13 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"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/terraform-provider-decort/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
|
||||
@@ -50,99 +50,103 @@ func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
log.Debugf("resourceAccountCreate")
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
req := account.CreateRequest{}
|
||||
|
||||
urlValues.Add("name", d.Get("account_name").(string))
|
||||
urlValues.Add("username", d.Get("username").(string))
|
||||
req.Name = d.Get("account_name").(string)
|
||||
req.Username = d.Get("username").(string)
|
||||
|
||||
if emailaddress, ok := d.GetOk("emailaddress"); ok {
|
||||
urlValues.Add("emailaddress", emailaddress.(string))
|
||||
req.EmailAddress = emailaddress.(string)
|
||||
}
|
||||
if sendAccessEmails, ok := d.GetOk("send_access_emails"); ok {
|
||||
urlValues.Add("sendAccessEmails", strconv.FormatBool(sendAccessEmails.(bool)))
|
||||
req.SendAccessEmails = sendAccessEmails.(bool)
|
||||
}
|
||||
|
||||
if resLimits, ok := d.GetOk("resource_limits"); ok {
|
||||
resLimit := resLimits.([]interface{})[0]
|
||||
resLimitConv := resLimit.(map[string]interface{})
|
||||
if resLimitConv["cu_m"] != nil {
|
||||
maxMemCap := int(resLimitConv["cu_m"].(float64))
|
||||
if maxMemCap == 0 {
|
||||
urlValues.Add("maxMemoryCapacity", strconv.Itoa(-1))
|
||||
req.MaxMemoryCapacity = -1
|
||||
} else {
|
||||
urlValues.Add("maxMemoryCapacity", strconv.Itoa(maxMemCap))
|
||||
req.MaxMemoryCapacity = int64(maxMemCap)
|
||||
}
|
||||
}
|
||||
if resLimitConv["cu_d"] != nil {
|
||||
maxDiskCap := int(resLimitConv["cu_d"].(float64))
|
||||
if maxDiskCap == 0 {
|
||||
urlValues.Add("maxVDiskCapacity", strconv.Itoa(-1))
|
||||
req.MaxVDiskCapacity = -1
|
||||
} else {
|
||||
urlValues.Add("maxVDiskCapacity", strconv.Itoa(maxDiskCap))
|
||||
req.MaxVDiskCapacity = int64(maxDiskCap)
|
||||
}
|
||||
}
|
||||
if resLimitConv["cu_c"] != nil {
|
||||
maxCPUCap := int(resLimitConv["cu_c"].(float64))
|
||||
if maxCPUCap == 0 {
|
||||
urlValues.Add("maxCPUCapacity", strconv.Itoa(-1))
|
||||
req.MaxCPUCapacity = -1
|
||||
} else {
|
||||
urlValues.Add("maxCPUCapacity", strconv.Itoa(maxCPUCap))
|
||||
req.MaxCPUCapacity = int64(maxCPUCap)
|
||||
}
|
||||
|
||||
}
|
||||
if resLimitConv["cu_i"] != nil {
|
||||
maxNumPublicIP := int(resLimitConv["cu_i"].(float64))
|
||||
if maxNumPublicIP == 0 {
|
||||
urlValues.Add("maxNumPublicIP", strconv.Itoa(-1))
|
||||
req.MaxNumPublicIP = -1
|
||||
} else {
|
||||
urlValues.Add("maxNumPublicIP", strconv.Itoa(maxNumPublicIP))
|
||||
req.MaxNumPublicIP = int64(maxNumPublicIP)
|
||||
}
|
||||
|
||||
}
|
||||
if resLimitConv["cu_np"] != nil {
|
||||
maxNP := int(resLimitConv["cu_np"].(float64))
|
||||
if maxNP == 0 {
|
||||
urlValues.Add("maxNetworkPeerTransfer", strconv.Itoa(-1))
|
||||
req.MaxNetworkPeerTransfer = -1
|
||||
} else {
|
||||
urlValues.Add("maxNetworkPeerTransfer", strconv.Itoa(maxNP))
|
||||
req.MaxNetworkPeerTransfer = int64(maxNP)
|
||||
}
|
||||
|
||||
}
|
||||
if resLimitConv["gpu_units"] != nil {
|
||||
gpuUnits := int(resLimitConv["gpu_units"].(float64))
|
||||
if gpuUnits == 0 {
|
||||
urlValues.Add("gpu_units", strconv.Itoa(-1))
|
||||
req.GPUUnits = -1
|
||||
} else {
|
||||
urlValues.Add("gpu_units", strconv.Itoa(gpuUnits))
|
||||
req.GPUUnits = int64(gpuUnits)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
accountId, err := c.DecortAPICall(ctx, "POST", accountCreateAPI, urlValues)
|
||||
accountId, err := c.CloudAPI().Account().Create(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
accIdParsed, _ := strconv.Atoi(accountId)
|
||||
|
||||
d.SetId(accountId)
|
||||
d.Set("account_id", accIdParsed)
|
||||
|
||||
urlValues = &url.Values{}
|
||||
d.SetId(strconv.FormatUint(accountId, 10))
|
||||
d.Set("account_id", accountId)
|
||||
|
||||
if enable, ok := d.GetOk("enable"); ok {
|
||||
api := accountDisableAPI
|
||||
reqSwitch := account.DisableEnableRequest{
|
||||
AccountID: accountId,
|
||||
}
|
||||
enable := enable.(bool)
|
||||
|
||||
if enable {
|
||||
api = accountEnableAPI
|
||||
}
|
||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||
|
||||
_, err := c.DecortAPICall(ctx, "POST", api, urlValues)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
_, err := c.CloudAPI().Account().Enable(ctx, reqSwitch)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
|
||||
urlValues = &url.Values{}
|
||||
} else {
|
||||
|
||||
_, err := c.CloudAPI().Account().Disable(ctx, reqSwitch)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if users, ok := d.GetOk("users"); ok {
|
||||
@@ -151,15 +155,16 @@ func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
if len(addedUsers) > 0 {
|
||||
for _, user := range addedUsers {
|
||||
userConv := user.(map[string]interface{})
|
||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||
urlValues.Add("userId", userConv["user_id"].(string))
|
||||
urlValues.Add("accesstype", strings.ToUpper(userConv["access_type"].(string)))
|
||||
_, err := c.DecortAPICall(ctx, "POST", accountAddUserAPI, urlValues)
|
||||
|
||||
req := account.AddUserRequest{
|
||||
AccountID: accountId,
|
||||
UserID: userConv["user_id"].(string),
|
||||
AccessType: strings.ToUpper(userConv["access_type"].(string)),
|
||||
}
|
||||
_, err := c.CloudAPI().Account().AddUser(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
urlValues = &url.Values{}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -187,10 +192,13 @@ func resourceAccountRead(ctx context.Context, d *schema.ResourceData, m interfac
|
||||
case status.Destroying:
|
||||
return diag.Errorf("The account is in progress with status: %s", acc.Status)
|
||||
case status.Deleted:
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("accountId", d.Id())
|
||||
id, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
|
||||
_, err := c.DecortAPICall(ctx, "POST", accountRestoreAPI, urlValues)
|
||||
req := account.RestoreRequest{
|
||||
AccountID: id,
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().Account().Restore(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
@@ -216,41 +224,40 @@ func resourceAccountRead(ctx context.Context, d *schema.ResourceData, m interfac
|
||||
|
||||
func resourceAccountDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceAccountDelete")
|
||||
|
||||
account, err := utilityAccountCheckPresence(ctx, d, m)
|
||||
if account == nil {
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||
urlValues.Add("permanently", strconv.FormatBool(d.Get("permanently").(bool)))
|
||||
|
||||
_, err = c.DecortAPICall(ctx, "POST", accountDeleteAPI, urlValues)
|
||||
_, err := utilityAccountCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
req := account.DeleteRequest{
|
||||
AccountID: uint64(d.Get("account_id").(int)),
|
||||
Permanently: d.Get("permanently").(bool),
|
||||
}
|
||||
|
||||
_, err = c.CloudAPI().Account().Delete(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceAccountEdit")
|
||||
log.Debugf("resourceAccountUpdate")
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
urlValues := &url.Values{}
|
||||
|
||||
acc, err := utilityAccountCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
accountId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
|
||||
hasChanged := false
|
||||
|
||||
switch acc.Status {
|
||||
@@ -260,10 +267,12 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
case status.Destroying:
|
||||
return diag.Errorf("The account is in progress with status: %s", acc.Status)
|
||||
case status.Deleted:
|
||||
urlVal := &url.Values{}
|
||||
urlVal.Add("accountId", d.Id())
|
||||
|
||||
_, err := c.DecortAPICall(ctx, "POST", accountRestoreAPI, urlVal)
|
||||
req := account.RestoreRequest{
|
||||
AccountID: accountId,
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().Account().Restore(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
@@ -283,31 +292,39 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
}
|
||||
|
||||
if d.HasChange("enable") {
|
||||
api := accountDisableAPI
|
||||
reqSwitch := account.DisableEnableRequest{
|
||||
AccountID: accountId,
|
||||
}
|
||||
enable := d.Get("enable").(bool)
|
||||
|
||||
if enable {
|
||||
api = accountEnableAPI
|
||||
}
|
||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||
|
||||
_, err := c.DecortAPICall(ctx, "POST", api, urlValues)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
_, err := c.CloudAPI().Account().Enable(ctx, reqSwitch)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
|
||||
urlValues = &url.Values{}
|
||||
} else {
|
||||
|
||||
_, err := c.CloudAPI().Account().Disable(ctx, reqSwitch)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
req := account.UpdateRequest{
|
||||
AccountID: accountId,
|
||||
}
|
||||
|
||||
updated := false
|
||||
|
||||
if d.HasChange("account_name") {
|
||||
urlValues.Add("name", d.Get("account_name").(string))
|
||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||
_, err := c.DecortAPICall(ctx, "POST", accountUpdateAPI, urlValues)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
urlValues = &url.Values{}
|
||||
req.Name = d.Get("account_name").(string)
|
||||
updated = true
|
||||
}
|
||||
|
||||
if d.HasChange("resource_limits") {
|
||||
resLimit := d.Get("resource_limits").([]interface{})[0]
|
||||
resLimitConv := resLimit.(map[string]interface{})
|
||||
@@ -315,85 +332,83 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
if resLimitConv["cu_m"] != nil {
|
||||
maxMemCap := int(resLimitConv["cu_m"].(float64))
|
||||
if maxMemCap == 0 {
|
||||
urlValues.Add("maxMemoryCapacity", strconv.Itoa(-1))
|
||||
req.MaxMemoryCapacity = -1
|
||||
} else {
|
||||
urlValues.Add("maxMemoryCapacity", strconv.Itoa(maxMemCap))
|
||||
req.MaxMemoryCapacity = int64(maxMemCap)
|
||||
}
|
||||
updated = true
|
||||
}
|
||||
if resLimitConv["cu_d"] != nil {
|
||||
maxDiskCap := int(resLimitConv["cu_d"].(float64))
|
||||
if maxDiskCap == 0 {
|
||||
urlValues.Add("maxVDiskCapacity", strconv.Itoa(-1))
|
||||
req.MaxVDiskCapacity = -1
|
||||
} else {
|
||||
urlValues.Add("maxVDiskCapacity", strconv.Itoa(maxDiskCap))
|
||||
req.MaxVDiskCapacity = int64(maxDiskCap)
|
||||
}
|
||||
updated = true
|
||||
}
|
||||
if resLimitConv["cu_c"] != nil {
|
||||
maxCPUCap := int(resLimitConv["cu_c"].(float64))
|
||||
if maxCPUCap == 0 {
|
||||
urlValues.Add("maxCPUCapacity", strconv.Itoa(-1))
|
||||
req.MaxCPUCapacity = -1
|
||||
} else {
|
||||
urlValues.Add("maxCPUCapacity", strconv.Itoa(maxCPUCap))
|
||||
req.MaxCPUCapacity = int64(maxCPUCap)
|
||||
}
|
||||
|
||||
updated = true
|
||||
}
|
||||
if resLimitConv["cu_i"] != nil {
|
||||
maxNumPublicIP := int(resLimitConv["cu_i"].(float64))
|
||||
if maxNumPublicIP == 0 {
|
||||
urlValues.Add("maxNumPublicIP", strconv.Itoa(-1))
|
||||
req.MaxNumPublicIP = -1
|
||||
} else {
|
||||
urlValues.Add("maxNumPublicIP", strconv.Itoa(maxNumPublicIP))
|
||||
req.MaxNumPublicIP = int64(maxNumPublicIP)
|
||||
}
|
||||
|
||||
updated = true
|
||||
}
|
||||
if resLimitConv["cu_np"] != nil {
|
||||
maxNP := int(resLimitConv["cu_np"].(float64))
|
||||
if maxNP == 0 {
|
||||
urlValues.Add("maxNetworkPeerTransfer", strconv.Itoa(-1))
|
||||
req.MaxNetworkPeerTransfer = -1
|
||||
} else {
|
||||
urlValues.Add("maxNetworkPeerTransfer", strconv.Itoa(maxNP))
|
||||
req.MaxNetworkPeerTransfer = int64(maxNP)
|
||||
}
|
||||
|
||||
updated = true
|
||||
}
|
||||
if resLimitConv["gpu_units"] != nil {
|
||||
gpuUnits := int(resLimitConv["gpu_units"].(float64))
|
||||
if gpuUnits == 0 {
|
||||
urlValues.Add("gpu_units", strconv.Itoa(-1))
|
||||
req.GPUUnits = -1
|
||||
} else {
|
||||
urlValues.Add("gpu_units", strconv.Itoa(gpuUnits))
|
||||
req.GPUUnits = int64(gpuUnits)
|
||||
}
|
||||
updated = true
|
||||
}
|
||||
|
||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||
_, err := c.DecortAPICall(ctx, "POST", accountUpdateAPI, urlValues)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
urlValues = &url.Values{}
|
||||
}
|
||||
|
||||
if d.HasChange("send_access_emails") {
|
||||
urlValues.Add("sendAccessEmails", strconv.FormatBool(d.Get("send_access_emails").(bool)))
|
||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||
_, err := c.DecortAPICall(ctx, "POST", accountUpdateAPI, urlValues)
|
||||
req.SendAccessEmails = d.Get("send_access_emails").(bool)
|
||||
updated = true
|
||||
}
|
||||
|
||||
if updated {
|
||||
_, err := c.CloudAPI().Account().Update(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
urlValues = &url.Values{}
|
||||
}
|
||||
|
||||
if d.HasChange("restore") {
|
||||
restore := d.Get("restore").(bool)
|
||||
if restore {
|
||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||
_, err := c.DecortAPICall(ctx, "POST", accountRestoreAPI, urlValues)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
if acc.Status == "DELETED" {
|
||||
req := account.RestoreRequest{
|
||||
AccountID: accountId,
|
||||
}
|
||||
_, err := c.CloudAPI().Account().Restore(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
urlValues = &url.Values{}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -402,9 +417,9 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
addedUsers := make([]interface{}, 0)
|
||||
updatedUsers := make([]interface{}, 0)
|
||||
|
||||
old, new := d.GetChange("users")
|
||||
old, new_ := d.GetChange("users")
|
||||
oldConv := old.([]interface{})
|
||||
newConv := new.([]interface{})
|
||||
newConv := new_.([]interface{})
|
||||
for _, el := range oldConv {
|
||||
if !isContainsUser(newConv, el) {
|
||||
deletedUsers = append(deletedUsers, el)
|
||||
@@ -412,7 +427,15 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
}
|
||||
for _, el := range newConv {
|
||||
if !isContainsUser(oldConv, el) {
|
||||
addedUsers = append(addedUsers, el)
|
||||
duplicate := false
|
||||
for _, user := range acc.ACL {
|
||||
if user.UgroupID == el.(map[string]interface{})["user_id"].(string) {
|
||||
duplicate = true
|
||||
}
|
||||
}
|
||||
if !duplicate {
|
||||
addedUsers = append(addedUsers, el)
|
||||
}
|
||||
} else {
|
||||
if isChangedUser(oldConv, el) {
|
||||
updatedUsers = append(updatedUsers, el)
|
||||
@@ -423,45 +446,50 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
if len(deletedUsers) > 0 {
|
||||
for _, user := range deletedUsers {
|
||||
userConv := user.(map[string]interface{})
|
||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||
urlValues.Add("userId", userConv["user_id"].(string))
|
||||
urlValues.Add("recursivedelete", strconv.FormatBool(userConv["recursive_delete"].(bool)))
|
||||
_, err := c.DecortAPICall(ctx, "POST", accountDeleteUserAPI, urlValues)
|
||||
|
||||
req := account.DeleteUserRequest{
|
||||
AccountID: accountId,
|
||||
UserID: userConv["user_id"].(string),
|
||||
RecursiveDelete: userConv["recursive_delete"].(bool),
|
||||
}
|
||||
_, err := c.CloudAPI().Account().DeleteUser(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
urlValues = &url.Values{}
|
||||
}
|
||||
}
|
||||
|
||||
if len(addedUsers) > 0 {
|
||||
for _, user := range addedUsers {
|
||||
userConv := user.(map[string]interface{})
|
||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||
urlValues.Add("userId", userConv["user_id"].(string))
|
||||
urlValues.Add("accesstype", strings.ToUpper(userConv["access_type"].(string)))
|
||||
_, err := c.DecortAPICall(ctx, "POST", accountAddUserAPI, urlValues)
|
||||
|
||||
req := account.AddUserRequest{
|
||||
AccountID: accountId,
|
||||
UserID: userConv["user_id"].(string),
|
||||
AccessType: strings.ToUpper(userConv["access_type"].(string)),
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().Account().AddUser(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
urlValues = &url.Values{}
|
||||
}
|
||||
}
|
||||
|
||||
if len(updatedUsers) > 0 {
|
||||
for _, user := range updatedUsers {
|
||||
userConv := user.(map[string]interface{})
|
||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||
urlValues.Add("userId", userConv["user_id"].(string))
|
||||
urlValues.Add("accesstype", strings.ToUpper(userConv["access_type"].(string)))
|
||||
_, err := c.DecortAPICall(ctx, "POST", accountUpdateUserAPI, urlValues)
|
||||
|
||||
req := account.UpdateUserRequest{
|
||||
AccountID: accountId,
|
||||
UserID: userConv["user_id"].(string),
|
||||
AccessType: strings.ToUpper(userConv["access_type"].(string)),
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().Account().UpdateUser(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
urlValues = &url.Values{}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -514,7 +542,6 @@ func resourceAccountSchemaMake() map[string]*schema.Schema {
|
||||
"send_access_emails": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: true,
|
||||
Description: "if true send emails when a user is granted access to resources",
|
||||
},
|
||||
"users": {
|
||||
@@ -613,13 +640,13 @@ func resourceAccountSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"meta": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
// "meta": {
|
||||
// Type: schema.TypeList,
|
||||
// Computed: true,
|
||||
// Elem: &schema.Schema{
|
||||
// Type: schema.TypeString,
|
||||
// },
|
||||
// },
|
||||
"acl": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
@@ -704,6 +731,14 @@ func resourceAccountSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"cpu_allocation_parameter": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"cpu_allocation_ratio": {
|
||||
Type: schema.TypeFloat,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,34 +34,32 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityAccountCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*AccountWithResources, error) {
|
||||
account := &AccountWithResources{}
|
||||
func utilityAccountCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.RecordAccount, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
var id uint64
|
||||
|
||||
if (strconv.Itoa(d.Get("account_id").(int))) != "0" {
|
||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||
id = uint64(d.Get("account_id").(int))
|
||||
} else {
|
||||
urlValues.Add("accountId", d.Id())
|
||||
idParsed, _ := strconv.Atoi(d.Id())
|
||||
id = uint64(idParsed)
|
||||
}
|
||||
|
||||
req := account.GetRequest{
|
||||
AccountID: id,
|
||||
}
|
||||
|
||||
log.Debugf("utilityAccountCheckPresence: load account")
|
||||
accountRaw, err := c.DecortAPICall(ctx, "POST", accountGetAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(accountRaw), &account)
|
||||
account, err := c.CloudAPI().Account().Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -34,30 +34,26 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityAccountAuditsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (AccountAuditsList, error) {
|
||||
accountAuditsList := AccountAuditsList{}
|
||||
func utilityAccountAuditsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListAudits, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
var id uint64
|
||||
|
||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||
id = uint64(d.Get("account_id").(int))
|
||||
|
||||
log.Debugf("utilityAccountAuditsListCheckPresence: load account list")
|
||||
accountAuditsListRaw, err := c.DecortAPICall(ctx, "POST", accountAuditsAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
req := account.AuditsRequest{
|
||||
AccountID: id,
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(accountAuditsListRaw), &accountAuditsList)
|
||||
log.Debugf("utilityAccountAuditsListCheckPresence: load account list")
|
||||
accountAuditsList, err := c.CloudAPI().Account().Audits(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -34,30 +34,26 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityAccountComputesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (AccountComputesList, error) {
|
||||
accountComputesList := AccountComputesList{}
|
||||
func utilityAccountComputesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListComputes, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
var id uint64
|
||||
|
||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||
id = uint64(d.Get("account_id").(int))
|
||||
|
||||
log.Debugf("utilityAccountComputesListCheckPresence: load account list")
|
||||
accountComputesListRaw, err := c.DecortAPICall(ctx, "POST", accountListComputesAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
req := account.ListComputesRequest{
|
||||
AccountID: id,
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(accountComputesListRaw), &accountComputesList)
|
||||
log.Debugf("utilityAccountComputesListCheckPresence: load account list")
|
||||
accountComputesList, err := c.CloudAPI().Account().ListComputes(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -34,30 +34,26 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityAccountConsumedUnitsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*ResourceLimits, error) {
|
||||
accountConsumedUnits := &ResourceLimits{}
|
||||
func utilityAccountConsumedUnitsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ResourceLimits, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
var id uint64
|
||||
|
||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||
id = uint64(d.Get("account_id").(int))
|
||||
|
||||
log.Debugf("utilityAccountConsumedUnitsCheckPresence: load account list")
|
||||
accountConsumedUnitsRaw, err := c.DecortAPICall(ctx, "POST", accountGetConsumedUnitsAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
req := account.GetConsumedAccountUnitsRequest{
|
||||
AccountID: id,
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(accountConsumedUnitsRaw), accountConsumedUnits)
|
||||
log.Debugf("utilityAccountConsumedUnitsCheckPresence: load account list")
|
||||
accountConsumedUnits, err := c.CloudAPI().Account().GetConsumedAccountUnits(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -34,11 +34,10 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
@@ -46,17 +45,19 @@ import (
|
||||
|
||||
func utilityAccountConsumedUnitsByTypeCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (float64, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
var id uint64
|
||||
var cuType string
|
||||
|
||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||
urlValues.Add("cutype", strings.ToUpper(d.Get("cu_type").(string)))
|
||||
id = uint64(d.Get("account_id").(int))
|
||||
cuType = strings.ToUpper(d.Get("cu_type").(string))
|
||||
|
||||
req := account.GetConsumedCloudUnitsByTypeRequest{
|
||||
AccountID: id,
|
||||
CUType: cuType,
|
||||
}
|
||||
|
||||
log.Debugf("utilityAccountConsumedUnitsByTypeCheckPresence")
|
||||
resultRaw, err := c.DecortAPICall(ctx, "POST", accountGetConsumedUnitsByTypeAPI, urlValues)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
result, err := strconv.ParseFloat(resultRaw, 64)
|
||||
result, err := c.CloudAPI().Account().GetConsumedCloudUnitsByType(ctx, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -34,38 +34,37 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityAccountDeletedListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (AccountCloudApiList, error) {
|
||||
accountDeletedList := AccountCloudApiList{}
|
||||
func utilityAccountDeletedListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListAccounts, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
var (
|
||||
pageVal uint64 = 0
|
||||
sizeVal uint64 = 0
|
||||
)
|
||||
|
||||
if page, ok := d.GetOk("page"); ok {
|
||||
urlValues.Add("page", strconv.Itoa(page.(int)))
|
||||
pageVal = uint64(page.(int))
|
||||
}
|
||||
if size, ok := d.GetOk("size"); ok {
|
||||
urlValues.Add("size", strconv.Itoa(size.(int)))
|
||||
sizeVal = uint64(size.(int))
|
||||
}
|
||||
|
||||
req := account.ListDeletedRequest{
|
||||
Page: pageVal,
|
||||
Size: sizeVal,
|
||||
}
|
||||
|
||||
log.Debugf("utilityAccountDeletedListCheckPresence: load")
|
||||
accountDeletedListRaw, err := c.DecortAPICall(ctx, "POST", accountListDeletedAPI, urlValues)
|
||||
accountDeletedList, err := c.CloudAPI().Account().ListDeleted(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(accountDeletedListRaw), &accountDeletedList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return accountDeletedList, nil
|
||||
}
|
||||
|
||||
@@ -34,30 +34,24 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityAccountDisksListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (AccountDisksList, error) {
|
||||
accountDisksList := AccountDisksList{}
|
||||
func utilityAccountDisksListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListDisks, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
var id uint64
|
||||
|
||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||
id = uint64(d.Get("account_id").(int))
|
||||
|
||||
log.Debugf("utilityAccountDisksListCheckPresence: load account list")
|
||||
accountDisksListRaw, err := c.DecortAPICall(ctx, "POST", accountListDisksAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
req := account.ListDisksRequest{
|
||||
AccountID: id,
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(accountDisksListRaw), &accountDisksList)
|
||||
accountDisksList, err := c.CloudAPI().Account().ListDisks(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -34,30 +34,26 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityAccountFlipGroupsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (AccountFlipGroupsList, error) {
|
||||
accountFlipGroupsList := AccountFlipGroupsList{}
|
||||
func utilityAccountFlipGroupsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListFLIPGroups, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
var id uint64
|
||||
|
||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||
id = uint64(d.Get("account_id").(int))
|
||||
|
||||
log.Debugf("utilityAccountFlipGroupsListCheckPresence")
|
||||
accountFlipGroupsListRaw, err := c.DecortAPICall(ctx, "POST", accountListFlipGroupsAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
req := account.ListFLIPGroupsRequest{
|
||||
AccountID: id,
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(accountFlipGroupsListRaw), &accountFlipGroupsList)
|
||||
log.Debugf("utilityAccountFlipGroupsListCheckPresence")
|
||||
accountFlipGroupsList, err := c.CloudAPI().Account().ListFLIPGroups(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -34,66 +34,38 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityAccountListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (AccountCloudApiList, error) {
|
||||
accountList := AccountCloudApiList{}
|
||||
func utilityAccountListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListAccounts, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
var (
|
||||
pageVal uint64 = 0
|
||||
sizeVal uint64 = 0
|
||||
)
|
||||
|
||||
if page, ok := d.GetOk("page"); ok {
|
||||
urlValues.Add("page", strconv.Itoa(page.(int)))
|
||||
pageVal = uint64(page.(int))
|
||||
}
|
||||
if size, ok := d.GetOk("size"); ok {
|
||||
urlValues.Add("size", strconv.Itoa(size.(int)))
|
||||
sizeVal = uint64(size.(int))
|
||||
}
|
||||
|
||||
req := account.ListRequest{
|
||||
Page: pageVal,
|
||||
Size: sizeVal,
|
||||
}
|
||||
|
||||
log.Debugf("utilityAccountListCheckPresence: load account list")
|
||||
accountListRaw, err := c.DecortAPICall(ctx, "POST", accountListAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(accountListRaw), &accountList)
|
||||
accountList, err := c.CloudAPI().Account().List(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return accountList, nil
|
||||
}
|
||||
|
||||
/*uncomment for cloudbroker
|
||||
func utilityAccountListCheckPresence(d *schema.ResourceData, m interface{}) (AccountList, error) {
|
||||
accountList := AccountList{}
|
||||
controller := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
|
||||
if page, ok := d.GetOk("page"); ok {
|
||||
urlValues.Add("page", strconv.Itoa(page.(int)))
|
||||
}
|
||||
if size, ok := d.GetOk("size"); ok {
|
||||
urlValues.Add("size", strconv.Itoa(size.(int)))
|
||||
}
|
||||
|
||||
log.Debugf("utilityAccountListCheckPresence: load account list")
|
||||
accountListRaw, err := controller.decortAPICall("POST", accountListAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(accountListRaw), &accountList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return accountList, nil
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -34,30 +34,26 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityAccountReservedUnitsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*ResourceLimits, error) {
|
||||
accountReservedUnits := &ResourceLimits{}
|
||||
func utilityAccountReservedUnitsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ResourceLimits, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
var id uint64
|
||||
|
||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||
id = uint64(d.Get("account_id").(int))
|
||||
|
||||
log.Debugf("utilityAccountReservedUnitsCheckPresence: load units")
|
||||
accountReservedUnitsRaw, err := c.DecortAPICall(ctx, "POST", accountGetReservedUnitsAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
req := account.GetReservedAccountUnitsRequest{
|
||||
AccountID: id,
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(accountReservedUnitsRaw), accountReservedUnits)
|
||||
log.Debugf("utilityAccountReservedUnitsCheckPresence: load units")
|
||||
accountReservedUnits, err := c.CloudAPI().Account().GetReservedAccountUnits(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -34,30 +34,26 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityAccountRGListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (AccountRGList, error) {
|
||||
accountRGList := AccountRGList{}
|
||||
func utilityAccountRGListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListRG, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
var id uint64
|
||||
|
||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||
id = uint64(d.Get("account_id").(int))
|
||||
|
||||
log.Debugf("utilityAccountRGListCheckPresence: load account list")
|
||||
accountRGListRaw, err := c.DecortAPICall(ctx, "POST", accountListRGAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
req := account.ListRGRequest{
|
||||
AccountID: id,
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(accountRGListRaw), &accountRGList)
|
||||
log.Debugf("utilityAccountRGListCheckPresence: load account list")
|
||||
accountRGList, err := c.CloudAPI().Account().ListRG(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -34,30 +34,26 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityAccountTemplatesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (AccountTemplatesList, error) {
|
||||
accountTemplatesList := AccountTemplatesList{}
|
||||
func utilityAccountTemplatesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListTemplates, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
var id uint64
|
||||
|
||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||
id = uint64(d.Get("account_id").(int))
|
||||
|
||||
log.Debugf("utilityAccountTemplatesListCheckPresence: load")
|
||||
accountTemplatesListRaw, err := c.DecortAPICall(ctx, "POST", accountListTemplatesAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
req := account.ListTemplatesRequest{
|
||||
AccountID: id,
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(accountTemplatesListRaw), &accountTemplatesList)
|
||||
log.Debugf("utilityAccountTemplatesListCheckPresence: load")
|
||||
accountTemplatesList, err := c.CloudAPI().Account().ListTemplates(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -34,30 +34,26 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityAccountVinsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (AccountVinsList, error) {
|
||||
accountVinsList := AccountVinsList{}
|
||||
func utilityAccountVinsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListVINS, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
var id uint64
|
||||
|
||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||
id = uint64(d.Get("account_id").(int))
|
||||
|
||||
log.Debugf("utilityAccountVinsListCheckPresence: load account list")
|
||||
accountVinsListRaw, err := c.DecortAPICall(ctx, "POST", accountListVinsAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
req := account.ListVINSRequest{
|
||||
AccountID: id,
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(accountVinsListRaw), &accountVinsList)
|
||||
log.Debugf("utilityAccountVinsListCheckPresence: load account list")
|
||||
accountVinsList, err := c.CloudAPI().Account().ListVINS(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user