This commit is contained in:
2024-05-31 14:05:21 +03:00
parent 84b7a80e1b
commit db1760cb72
815 changed files with 58194 additions and 11049 deletions

View File

@@ -68,7 +68,6 @@ func DataSourceResgroup() *schema.Resource {
}
}
// func sepsSchemaMake() map[string]*schema.Schema {
// res := map[string]*schema.Schema{
// "sep_id": {
@@ -300,6 +299,13 @@ func dataSourceRgSchemaMake() map[string]*schema.Schema {
Schema: aclSchemaMake(),
},
},
"compute_features": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"created_by": {
Type: schema.TypeString,
Computed: true,
@@ -418,5 +424,3 @@ func dataSourceRgSchemaMake() map[string]*schema.Schema {
}
return res
}

View File

@@ -83,8 +83,17 @@ func dataSourceRgAffinityGroupsListSchemaMake() map[string]*schema.Schema {
"ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
},
"node_id": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
},

View File

@@ -1,280 +1,292 @@
/*
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 rg
import (
"context"
"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/terraform-provider-decort/internal/constants"
)
func dataSourceRgListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
rgList, err := utilityRgListCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenRgList(rgList))
d.Set("entry_count", rgList.EntryCount)
return nil
}
func dataSourceRgListSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Find by ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Find by name",
},
"account_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Find by account ID",
},
"account_name": {
Type: schema.TypeString,
Optional: true,
Description: "Find by account name",
},
"created_after": {
Type: schema.TypeInt,
Optional: true,
Description: "Find RGs created after specific time (unix timestamp)",
},
"created_before": {
Type: schema.TypeInt,
Optional: true,
Description: "Find RGs created before specific time (unix timestamp)",
},
"status": {
Type: schema.TypeString,
Optional: true,
Description: "Find by status",
},
"lock_status": {
Type: schema.TypeString,
Optional: true,
Description: "Find by lock status",
},
"includedeleted": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "included deleted resource groups",
},
"page": {
Type: schema.TypeInt,
Optional: true,
Description: "Page number",
},
"size": {
Type: schema.TypeInt,
Optional: true,
Description: "Page size",
},
"items": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"account_acl": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: aclSchemaMake(),
},
},
"account_id": {
Type: schema.TypeInt,
Computed: true,
},
"account_name": {
Type: schema.TypeString,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"def_net_id": {
Type: schema.TypeInt,
Computed: true,
},
"def_net_type": {
Type: schema.TypeString,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"desc": {
Type: schema.TypeString,
Computed: true,
},
"dirty": {
Type: schema.TypeBool,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"rg_id": {
Type: schema.TypeInt,
Computed: true,
},
"lock_status": {
Type: schema.TypeString,
Computed: true,
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"register_computes": {
Type: schema.TypeBool,
Computed: true,
},
"resource_limits": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: resourceLimitsSchemaMake(),
},
},
"secret": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
"vins": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"vms": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"resource_types": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"cpu_allocation_parameter": {
Type: schema.TypeString,
Computed: true,
},
"cpu_allocation_ratio": {
Type: schema.TypeFloat,
Computed: true,
},
"uniq_pools": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return res
}
func DataSourceRgList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceRgListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceRgListSchemaMake(),
}
}
/*
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 rg
import (
"context"
"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/terraform-provider-decort/internal/constants"
)
func dataSourceRgListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
rgList, err := utilityRgListCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenRgList(rgList))
d.Set("entry_count", rgList.EntryCount)
return nil
}
func dataSourceRgListSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Find by ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Find by name",
},
"account_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Find by account ID",
},
"account_name": {
Type: schema.TypeString,
Optional: true,
Description: "Find by account name",
},
"created_after": {
Type: schema.TypeInt,
Optional: true,
Description: "Find RGs created after specific time (unix timestamp)",
},
"created_before": {
Type: schema.TypeInt,
Optional: true,
Description: "Find RGs created before specific time (unix timestamp)",
},
"status": {
Type: schema.TypeString,
Optional: true,
Description: "Find by status",
},
"lock_status": {
Type: schema.TypeString,
Optional: true,
Description: "Find by lock status",
},
"includedeleted": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "included deleted resource groups",
},
"sort_by": {
Type: schema.TypeString,
Optional: true,
Description: "sort by one of supported fields, format +|-(field)",
},
"page": {
Type: schema.TypeInt,
Optional: true,
Description: "Page number",
},
"size": {
Type: schema.TypeInt,
Optional: true,
Description: "Page size",
},
"items": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"account_acl": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: aclSchemaMake(),
},
},
"account_id": {
Type: schema.TypeInt,
Computed: true,
},
"account_name": {
Type: schema.TypeString,
Computed: true,
},
"compute_features": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"def_net_id": {
Type: schema.TypeInt,
Computed: true,
},
"def_net_type": {
Type: schema.TypeString,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"desc": {
Type: schema.TypeString,
Computed: true,
},
"dirty": {
Type: schema.TypeBool,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"rg_id": {
Type: schema.TypeInt,
Computed: true,
},
"lock_status": {
Type: schema.TypeString,
Computed: true,
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"register_computes": {
Type: schema.TypeBool,
Computed: true,
},
"resource_limits": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: resourceLimitsSchemaMake(),
},
},
"secret": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
"vins": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"vms": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"resource_types": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"cpu_allocation_parameter": {
Type: schema.TypeString,
Computed: true,
},
"cpu_allocation_ratio": {
Type: schema.TypeFloat,
Computed: true,
},
"uniq_pools": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return res
}
func DataSourceRgList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceRgListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceRgListSchemaMake(),
}
}

View File

@@ -135,6 +135,11 @@ func dataSourceRgListComputesSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "Filter by extnet ID",
},
"sort_by": {
Type: schema.TypeString,
Optional: true,
Description: "sort by one of supported fields, format +|-(field)",
},
"page": {
Type: schema.TypeInt,
Optional: true,

View File

@@ -93,6 +93,11 @@ func dataSourceRgListDeletedSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "Filter by lock status",
},
"sort_by": {
Type: schema.TypeString,
Optional: true,
Description: "sort by one of supported fields, format +|-(field)",
},
"page": {
Type: schema.TypeInt,
Optional: true,
@@ -123,6 +128,13 @@ func dataSourceRgListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"compute_features": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"cpu_allocation_parameter": {
Type: schema.TypeString,
Computed: true,

View File

@@ -257,11 +257,6 @@ func dataSourceRgListLbSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "Filter by name",
},
"account_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by account ID",
},
"tech_status": {
Type: schema.TypeString,
Optional: true,
@@ -282,6 +277,11 @@ func dataSourceRgListLbSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "Filter by backend IP",
},
"sort_by": {
Type: schema.TypeString,
Optional: true,
Description: "sort by one of supported fields, format +|-(field)",
},
"page": {
Type: schema.TypeInt,
Optional: true,

View File

@@ -82,6 +82,11 @@ func dataSourceRgListVinsSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "Filter by ViNS ID",
},
"sort_by": {
Type: schema.TypeString,
Optional: true,
Description: "sort by one of supported fields, format +|-(field)",
},
"page": {
Type: schema.TypeInt,
Optional: true,
@@ -129,6 +134,14 @@ func dataSourceRgListVinsSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"extnet_id": {
Type: schema.TypeInt,
Computed: true,
},
"free_ips": {
Type: schema.TypeInt,
Computed: true,
},
"id": {
Type: schema.TypeInt,
Computed: true,

View File

@@ -91,9 +91,10 @@ func flattenResgroup(d *schema.ResourceData, details rg.RecordResourceGroup) err
d.Set("gid", details.GID)
d.Set("def_net_type", details.DefNetType)
d.Set("name", details.Name)
// d.Set("resources", flattenRgResource(details.Resources))
d.Set("quota", flattenQuota(details.ResourceLimits))
d.Set("account_name", details.AccountName)
d.Set("acl", flattenRgAcl(details.ACL))
d.Set("compute_features", details.ComputeFeatures)
d.Set("vms", details.Computes)
d.Set("created_by", details.CreatedBy)
d.Set("created_time", details.CreatedTime)
@@ -137,6 +138,23 @@ func flattenRgSeps(seps map[string]map[string]rg.DiskUsage) []map[string]interfa
return res
}
func flattenQuota(resource rg.ResourceLimits) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"cpu": resource.CUC,
"ram": resource.CUM,
"disk": resource.CUDM,
"ext_ips": resource.CUI,
"ext_traffic": resource.CUNP,
"gpu_units": resource.GPUUnits,
"cu_d": resource.CUD,
}
res = append(res, temp)
return res
}
func flattenResource(resource rg.Resource) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
@@ -161,6 +179,7 @@ func flattenRg(d *schema.ResourceData, itemRg rg.RecordResourceGroup) {
d.Set("account_name", itemRg.AccountName)
d.Set("acl", flattenRgAcl(itemRg.ACL))
d.Set("computes", itemRg.Computes)
d.Set("compute_features", itemRg.ComputeFeatures)
d.Set("created_by", itemRg.CreatedBy)
d.Set("created_time", itemRg.CreatedTime)
d.Set("def_net_id", itemRg.DefNetID)
@@ -212,6 +231,7 @@ func flattenRgList(rgl *rg.ListResourceGroups) []map[string]interface{} {
"account_acl": flattenRgAcl(rg.ACL),
"account_id": rg.AccountID,
"account_name": rg.AccountName,
"compute_features": rg.ComputeFeatures,
"created_by": rg.CreatedBy,
"created_time": rg.CreatedTime,
"def_net_id": rg.DefNetID,
@@ -242,7 +262,6 @@ func flattenRgList(rgl *rg.ListResourceGroups) []map[string]interface{} {
res = append(res, temp)
}
return res
}
func flattenRgAcl(rgAcls rg.ListACL) []map[string]interface{} {
@@ -491,6 +510,8 @@ func flattenRgListVins(lv *rg.ListVINS) []map[string]interface{} {
"deleted_by": vins.DeletedBy,
"deleted_time": vins.DeletedTime,
"external_ip": vins.ExternalIP,
"extnet_id": vins.ExtnetId,
"free_ips": vins.FreeIPs,
"id": vins.ID,
"name": vins.Name,
"network": vins.Network,
@@ -542,7 +563,7 @@ func flattenRgListGroups(list *rg.ListAffinityGroups) []map[string]interface{} {
for label, ag := range groupVal {
temp := map[string]interface{}{
"label": label,
"ids": ag,
"ids": flattenRgAffinityListGroup(ag),
}
res = append(res, temp)
}
@@ -551,6 +572,19 @@ func flattenRgListGroups(list *rg.ListAffinityGroups) []map[string]interface{} {
return res
}
func flattenRgAffinityListGroup(list rg.ListAffinityGroup) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(list))
for _, ag := range list {
temp := map[string]interface{}{
"id": ag.ID,
"node_id": ag.NodeID,
}
res = append(res, temp)
}
return res
}
func flattenRgUsageResource(d *schema.ResourceData, usage rg.RecordResourceUsage) {
d.Set("cpu", usage.CPU)
d.Set("disk_size", usage.DiskSize)

View File

@@ -92,26 +92,51 @@ func resourceResgroupCreate(ctx context.Context, d *schema.ResourceData, m inter
// Owner: c.GetDecortUsername(),
}
setQuota := false
var quotaRecord QuotaRecord
if argValue, ok := d.GetOk("quota"); ok {
log.Debugf("resourceResgroupCreate: setting Quota on RG requested")
quotaRecord = makeQuotaRecord(argValue.([]interface{}))
setQuota = true
if quota, ok := d.GetOk("quota"); ok {
quotaBlocks := quota.([]interface{})[0]
quotaMap := quotaBlocks.(map[string]interface{})
if quotaMap["ram"] != nil {
maxMemCap := int64(quotaMap["ram"].(int))
if maxMemCap == 0 {
req.MaxMemoryCapacity = -1
} else {
req.MaxMemoryCapacity = maxMemCap
}
}
if quotaMap["disk"] != nil {
maxDiskCap := int64(quotaMap["disk"].(int))
if maxDiskCap == 0 {
req.MaxVDiskCapacity = -1
} else {
req.MaxVDiskCapacity = maxDiskCap
}
}
if quotaMap["cpu"] != nil {
maxCPUCap := int64(quotaMap["cpu"].(int))
if maxCPUCap == 0 {
req.MaxCPUCapacity = -1
} else {
req.MaxCPUCapacity = maxCPUCap
}
}
if quotaMap["ext_ips"] != nil {
maxNumPublicIP := int64(quotaMap["ext_ips"].(int))
if maxNumPublicIP == 0 {
req.MaxNumPublicIP = -1
} else {
req.MaxNumPublicIP = maxNumPublicIP
}
}
if quotaMap["ext_traffic"] != nil {
maxNP := int64(quotaMap["ext_traffic"].(int))
if maxNP == 0 {
req.MaxNetworkPeerTransfer = -1
} else {
req.MaxNetworkPeerTransfer = maxNP
}
}
}
log.Debugf("resourceResgroupCreate: called for RG name %s, account ID %d",
// c.GetDecortUsername(),
rgName.(string), d.Get("account_id").(int))
if setQuota {
req.MaxCPUCapacity = int64(quotaRecord.Cpu)
req.MaxVDiskCapacity = int64(quotaRecord.Disk)
req.MaxMemoryCapacity = int64(quotaRecord.Ram)
req.MaxNetworkPeerTransfer = int64(quotaRecord.ExtTraffic)
req.MaxNumPublicIP = int64(quotaRecord.ExtIPs)
}
if defNetType, ok := d.GetOk("def_net_type"); ok {
req.DefNet = defNetType.(string) // NOTE: in API default network type is set by "def_net" parameter
} else {
@@ -297,6 +322,7 @@ func resourceResgroupRead(ctx context.Context, d *schema.ResourceData, m interfa
return diag.FromErr(err)
}
}
return diag.FromErr(flattenResgroup(d, *rgData))
}
@@ -557,8 +583,8 @@ func ResourceRgSchemaMake() map[string]*schema.Schema {
},
"gid": {
Type: schema.TypeInt,
Required: true,
Type: schema.TypeInt,
Required: true,
// ForceNew: true,
Description: "Unique ID of the grid, where this resource group is deployed.",
},
@@ -603,57 +629,57 @@ func ResourceRgSchemaMake() map[string]*schema.Schema {
},
"owner": {
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
},
"quota": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cpu": {
Type: schema.TypeInt,
Optional: true,
Default: -1,
Computed: true,
Description: "Limit on the total number of CPUs in this resource group.",
},
"ram": {
Type: schema.TypeInt, // NB: API expects and returns this as float in units of MB! This may be changed in the future.
Optional: true,
Default: -1,
Computed: true,
Description: "Limit on the total amount of RAM in this resource group, specified in MB.",
},
"disk": {
Type: schema.TypeInt,
Optional: true,
Default: -1,
Description: "Limit on the total volume of storage resources in this resource group, specified in GB.",
Computed: true,
Description: "Limit on the total volume of virtual storage resources in this resource group, specified in GB.",
},
"ext_traffic": {
Type: schema.TypeInt,
Optional: true,
Default: -1,
Computed: true,
Description: "Limit on the total ingress network traffic for this resource group, specified in GB.",
},
"ext_ips": {
Type: schema.TypeInt,
Optional: true,
Default: -1,
Computed: true,
Description: "Limit on the total number of external IP addresses this resource group can use.",
},
"gpu_units": {
Type: schema.TypeInt,
Optional: true,
Default: -1,
Computed: true,
Description: "Limit on the total number of virtual GPUs this resource group can use.",
},
"cu_d": {
Type: schema.TypeInt,
Computed: true,
Description: "Limit on the total volume of storage resources in this resource group, specified in GB.",
},
},
},
Description: "Quota settings for this resource group.",
@@ -771,6 +797,13 @@ func ResourceRgSchemaMake() map[string]*schema.Schema {
Schema: aclSchemaMake(),
},
},
"compute_features": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,

View File

@@ -8,10 +8,21 @@ import (
func resourceRGStateUpgradeV1(ctx context.Context, rawState map[string]interface{}, meta any) (map[string]interface{}, error) {
log.Debug("resourceRGStateUpgradeV1: upgrading state")
oldQuotaList := rawState["quota"].([]interface{})
if len(oldQuotaList) != 0 {
oldQuota := oldQuotaList[0].(map[string]interface{})
oldQuota["ram"] = int64(oldQuota["ram"].(float64))
quota, ok := rawState["quota"]
if !ok || quota == nil {
rawState["quota"] = QuotaRecord{
Cpu: -1,
Ram: -1,
Disk: -1,
ExtTraffic: -1,
ExtIPs: -1,
GpuUnits: -1,
}
return rawState, nil
}
oldQuotaList := quota.([]interface{})
oldQuota := oldQuotaList[0].(map[string]interface{})
oldQuota["ram"] = int64(oldQuota["ram"].(float64))
return rawState, nil
}

View File

@@ -78,20 +78,52 @@ func utilityUpdateRG(ctx context.Context, d *schema.ResourceData, m interface{},
if d.HasChange("quota") {
log.Debugf("resourceResgroupUpdate: quota specified - looking for deltas from the old quota.")
quotaList := d.Get("quota").([]interface{})
if len(quotaList) != 0 {
quota := quotaList[0].(map[string]interface{})
req.MaxCPUCapacity = int64(quota["cpu"].(int))
req.MaxVDiskCapacity = int64(quota["disk"].(int))
req.MaxMemoryCapacity = int64(quota["ram"].(int))
req.MaxNetworkPeerTransfer = int64(quota["ext_traffic"].(int))
req.MaxNumPublicIP = int64(quota["ext_ips"].(int))
} else {
req.MaxCPUCapacity = -1
req.MaxVDiskCapacity = -1
req.MaxMemoryCapacity = -1
req.MaxNetworkPeerTransfer = -1
req.MaxNumPublicIP = -1
if quota, ok := d.GetOk("quota"); ok {
resLimits := quota.([]interface{})[0]
resLimitsConv := resLimits.(map[string]interface{})
if resLimitsConv["ram"] != nil {
maxMemCap := int64(resLimitsConv["ram"].(int))
if maxMemCap == 0 {
req.MaxMemoryCapacity = -1
} else {
req.MaxMemoryCapacity = maxMemCap
}
}
if resLimitsConv["disk"] != nil {
maxDiskCap := int64(resLimitsConv["disk"].(int))
if maxDiskCap == 0 {
req.MaxVDiskCapacity = -1
} else {
req.MaxVDiskCapacity = maxDiskCap
}
}
if resLimitsConv["cpu"] != nil {
maxCPUCap := int64(resLimitsConv["cpu"].(int))
if maxCPUCap == 0 {
req.MaxCPUCapacity = -1
} else {
req.MaxCPUCapacity = maxCPUCap
}
}
if resLimitsConv["ext_ips"] != nil {
maxNumPublicIP := int64(resLimitsConv["ext_ips"].(int))
if maxNumPublicIP == 0 {
req.MaxNumPublicIP = -1
} else {
req.MaxNumPublicIP = maxNumPublicIP
}
}
if resLimitsConv["ext_traffic"] != nil {
maxNP := int64(resLimitsConv["ext_traffic"].(int))
if maxNP == 0 {
req.MaxNetworkPeerTransfer = -1
} else {
req.MaxNetworkPeerTransfer = maxNP
}
}
}
}

View File

@@ -1,90 +1,93 @@
/*
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 rg
import (
"context"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/rg"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityRgListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListResourceGroups, error) {
c := m.(*controller.ControllerCfg)
req := rg.ListRequest{}
if byId, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(byId.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if accountId, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(accountId.(int))
}
if accountName, ok := d.GetOk("account_name"); ok {
req.AccountName = accountName.(string)
}
if createdAfter, ok := d.GetOk("created_after"); ok {
req.CreatedAfter = uint64(createdAfter.(int))
}
if createdBefore, ok := d.GetOk("created_before"); ok {
req.CreatedBefore = uint64(createdBefore.(int))
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if lockStatus, ok := d.GetOk("lock_status"); ok {
req.LockStatus = lockStatus.(string)
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if includedeleted, ok := d.GetOk("includedeleted"); ok {
req.IncludeDeleted = includedeleted.(bool)
}
log.Debugf("utilityRgListCheckPresence: load rg list")
rgList, err := c.CloudAPI().RG().List(ctx, req)
if err != nil {
return nil, err
}
return rgList, nil
}
/*
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 rg
import (
"context"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/rg"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityRgListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListResourceGroups, error) {
c := m.(*controller.ControllerCfg)
req := rg.ListRequest{}
if byId, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(byId.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if accountId, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(accountId.(int))
}
if accountName, ok := d.GetOk("account_name"); ok {
req.AccountName = accountName.(string)
}
if createdAfter, ok := d.GetOk("created_after"); ok {
req.CreatedAfter = uint64(createdAfter.(int))
}
if createdBefore, ok := d.GetOk("created_before"); ok {
req.CreatedBefore = uint64(createdBefore.(int))
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if lockStatus, ok := d.GetOk("lock_status"); ok {
req.LockStatus = lockStatus.(string)
}
if sortBy, ok := d.GetOk("sort_by"); ok {
req.SortBy = sortBy.(string)
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if includedeleted, ok := d.GetOk("includedeleted"); ok {
req.IncludeDeleted = includedeleted.(bool)
}
log.Debugf("utilityRgListCheckPresence: load rg list")
rgList, err := c.CloudAPI().RG().List(ctx, req)
if err != nil {
return nil, err
}
return rgList, nil
}

View File

@@ -78,6 +78,10 @@ func utilityRgListComputesCheckPresence(ctx context.Context, d *schema.ResourceD
req.ExtNetID = uint64(extnet_id.(int))
}
if sortBy, ok := d.GetOk("sort_by"); ok {
req.SortBy = sortBy.(string)
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}

View File

@@ -72,6 +72,10 @@ func utilityRgListDeletedCheckPresence(ctx context.Context, d *schema.ResourceDa
req.LockStatus = lock_status.(string)
}
if sortBy, ok := d.GetOk("sort_by"); ok {
req.SortBy = sortBy.(string)
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}

View File

@@ -54,10 +54,6 @@ func utilityRgListLbCheckPresence(ctx context.Context, d *schema.ResourceData, m
req.Name = name.(string)
}
if account_id, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(account_id.(int))
}
if tech_status, ok := d.GetOk("tech_status"); ok {
req.TechStatus = tech_status.(string)
}
@@ -74,6 +70,10 @@ func utilityRgListLbCheckPresence(ctx context.Context, d *schema.ResourceData, m
req.BackIP = back_ip.(string)
}
if sortBy, ok := d.GetOk("sort_by"); ok {
req.SortBy = sortBy.(string)
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}

View File

@@ -62,6 +62,10 @@ func utilityRgListVinsCheckPresence(ctx context.Context, d *schema.ResourceData,
req.VINSID = uint64(vins_id.(int))
}
if sortBy, ok := d.GetOk("sort_by"); ok {
req.SortBy = sortBy.(string)
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}