This commit is contained in:
2023-12-19 16:37:50 +03:00
parent 20050bc169
commit f49d9f8860
150 changed files with 12582 additions and 11709 deletions

View File

@@ -42,146 +42,172 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func sepsSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeString,
Computed: true,
},
"data_name": {
Type: schema.TypeString,
Computed: true,
},
"disk_size": {
Type: schema.TypeFloat,
Computed: true,
},
"disk_size_max": {
Type: schema.TypeInt,
Computed: true,
},
func dataSourceResgroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
rg, err := utilityResgroupCheckPresence(ctx, d, m)
if err != nil {
d.SetId("") // ensure ID is empty in this case
return diag.FromErr(err)
}
return res
d.SetId(strconv.Itoa(d.Get("rg_id").(int)))
flattenRg(d, *rg)
return nil
}
func resourcesSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"current": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cpu": {
Type: schema.TypeInt,
Computed: true,
},
"disk_size": {
Type: schema.TypeFloat,
Computed: true,
},
"disk_size_max": {
Type: schema.TypeFloat,
Computed: true,
},
"extips": {
Type: schema.TypeInt,
Computed: true,
},
"exttraffic": {
Type: schema.TypeInt,
Computed: true,
},
"gpu": {
Type: schema.TypeInt,
Computed: true,
},
"ram": {
Type: schema.TypeInt,
Computed: true,
},
"seps": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeString,
Computed: true,
},
"map": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
},
},
},
"reserved": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cpu": {
Type: schema.TypeInt,
Computed: true,
},
"disk_size": {
Type: schema.TypeFloat,
Computed: true,
},
"disk_size_max": {
Type: schema.TypeInt,
Computed: true,
},
"extips": {
Type: schema.TypeInt,
Computed: true,
},
"exttraffic": {
Type: schema.TypeInt,
Computed: true,
},
"gpu": {
Type: schema.TypeInt,
Computed: true,
},
"ram": {
Type: schema.TypeInt,
Computed: true,
},
"seps": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeString,
Computed: true,
},
"map": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
},
},
},
}
func DataSourceResgroup() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
return res
ReadContext: dataSourceResgroupRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceRgSchemaMake(),
}
}
// func sepsSchemaMake() map[string]*schema.Schema {
// res := map[string]*schema.Schema{
// "sep_id": {
// Type: schema.TypeString,
// Computed: true,
// },
// "data_name": {
// Type: schema.TypeString,
// Computed: true,
// },
// "disk_size": {
// Type: schema.TypeFloat,
// Computed: true,
// },
// "disk_size_max": {
// Type: schema.TypeInt,
// Computed: true,
// },
// }
// return res
// }
// func resourcesSchemaMake() map[string]*schema.Schema {
// res := map[string]*schema.Schema{
// "current": {
// Type: schema.TypeList,
// Computed: true,
// Elem: &schema.Resource{
// Schema: map[string]*schema.Schema{
// "cpu": {
// Type: schema.TypeInt,
// Computed: true,
// },
// "disk_size": {
// Type: schema.TypeFloat,
// Computed: true,
// },
// "disk_size_max": {
// Type: schema.TypeFloat,
// Computed: true,
// },
// "extips": {
// Type: schema.TypeInt,
// Computed: true,
// },
// "exttraffic": {
// Type: schema.TypeInt,
// Computed: true,
// },
// "gpu": {
// Type: schema.TypeInt,
// Computed: true,
// },
// "ram": {
// Type: schema.TypeInt,
// Computed: true,
// },
// "seps": {
// Type: schema.TypeSet,
// Computed: true,
// Elem: &schema.Resource{
// Schema: map[string]*schema.Schema{
// "sep_id": {
// Type: schema.TypeString,
// Computed: true,
// },
// "map": {
// Type: schema.TypeMap,
// Computed: true,
// Elem: &schema.Schema{
// Type: schema.TypeString,
// },
// },
// },
// },
// },
// },
// },
// },
// "reserved": {
// Type: schema.TypeList,
// Computed: true,
// Elem: &schema.Resource{
// Schema: map[string]*schema.Schema{
// "cpu": {
// Type: schema.TypeInt,
// Computed: true,
// },
// "disk_size": {
// Type: schema.TypeFloat,
// Computed: true,
// },
// "disk_size_max": {
// Type: schema.TypeInt,
// Computed: true,
// },
// "extips": {
// Type: schema.TypeInt,
// Computed: true,
// },
// "exttraffic": {
// Type: schema.TypeInt,
// Computed: true,
// },
// "gpu": {
// Type: schema.TypeInt,
// Computed: true,
// },
// "ram": {
// Type: schema.TypeInt,
// Computed: true,
// },
// "seps": {
// Type: schema.TypeSet,
// Computed: true,
// Elem: &schema.Resource{
// Schema: map[string]*schema.Schema{
// "sep_id": {
// Type: schema.TypeString,
// Computed: true,
// },
// "map": {
// Type: schema.TypeMap,
// Computed: true,
// Elem: &schema.Schema{
// Type: schema.TypeString,
// },
// },
// },
// },
// },
// },
// },
// },
// }
// return res
// }
func aclSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"explicit": {
@@ -391,29 +417,3 @@ func dataSourceRgSchemaMake() map[string]*schema.Schema {
}
return res
}
func dataSourceResgroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
rg, err := utilityResgroupCheckPresence(ctx, d, m)
if err != nil {
d.SetId("") // ensure ID is empty in this case
return diag.FromErr(err)
}
d.SetId(strconv.Itoa(d.Get("rg_id").(int)))
flattenRg(d, *rg)
return nil
}
func DataSourceResgroup() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceResgroupRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceRgSchemaMake(),
}
}

View File

@@ -44,6 +44,7 @@ import (
func dataSourceRgAffinityGroupComputesRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
rgComputes, err := utilityRgAffinityGroupComputesCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
@@ -64,7 +65,6 @@ func dataSourceRgAffinityGroupComputesSchemaMake() map[string]*schema.Schema {
Required: true,
Description: "Affinity group label",
},
"items": {
Type: schema.TypeList,
Computed: true,

View File

@@ -44,6 +44,7 @@ import (
func dataSourceRgAffinityGroupsGetRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
computes, err := utilityRgAffinityGroupsGetCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
d.SetId(strconv.Itoa(d.Get("rg_id").(int)))
@@ -63,7 +64,6 @@ func dataSourceRgAffinityGroupsGetSchemaMake() map[string]*schema.Schema {
Required: true,
Description: "Affinity group label",
},
"ids": {
Type: schema.TypeList,
Computed: true,

View File

@@ -44,6 +44,7 @@ import (
func dataSourceRgAffinityGroupsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
list, err := utilityRgAffinityGroupsListCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}

View File

@@ -44,6 +44,7 @@ import (
func dataSourceRgAuditsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
rgAudits, err := utilityRgAuditsCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
@@ -59,7 +60,6 @@ func dataSourceRgAuditsSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Required: true,
},
"items": {
Type: schema.TypeList,
Computed: true,

View File

@@ -44,6 +44,7 @@ import (
func dataSourceRGResourceConsumptionGetRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
RGResourceConsumptionRec, err := utilityRGResourceConsumptionGetCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}

View File

@@ -1,287 +1,280 @@
/*
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 {
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,
},
"acl": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: aclSchemaMake(),
},
},
"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",
},
"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(),
}
}

View File

@@ -44,6 +44,7 @@ import (
func dataSourceRgListComputesRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
listComputes, err := utilityRgListComputesCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}

View File

@@ -44,6 +44,7 @@ import (
func dataSourceRgListDeletedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
rgList, err := utilityRgListDeletedCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
@@ -122,12 +123,13 @@ func dataSourceRgListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"acl": {
Type: schema.TypeList,
"cpu_allocation_parameter": {
Type: schema.TypeString,
Computed: true,
},
"cpu_allocation_ratio": {
Type: schema.TypeFloat,
Computed: true,
Elem: &schema.Resource{
Schema: aclSchemaMake(),
},
},
"created_by": {
Type: schema.TypeString,

View File

@@ -44,6 +44,7 @@ import (
func dataSourceRgListLbRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
listLb, err := utilityRgListLbCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
@@ -307,6 +308,10 @@ func dataSourceRgListLbSchemaMake() map[string]*schema.Schema {
Schema: aclSchemaMake(),
},
},
"backend_haip": {
Type: schema.TypeString,
Computed: true,
},
"backends": {
Type: schema.TypeList,
Computed: true,
@@ -342,6 +347,10 @@ func dataSourceRgListLbSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"frontend_haip": {
Type: schema.TypeString,
Computed: true,
},
"frontends": {
Type: schema.TypeList,
Computed: true,

View File

@@ -44,6 +44,7 @@ import (
func dataSourceRgListPfwRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
listPfw, err := utilityRgListPfwCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}

View File

@@ -44,6 +44,7 @@ import (
func dataSourceRgListVinsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
listVins, err := utilityRgListVinsCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}

View File

@@ -44,6 +44,7 @@ import (
func dataSourceRGResourceConsumptionListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
rgResourceConsumptionList, err := utilityRGResourceConsumptionListCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}

View File

@@ -44,6 +44,7 @@ import (
func dataSourceRgUsageRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
usage, err := utilityDataRgUsageCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}

View File

@@ -91,7 +91,6 @@ 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("account_name", details.AccountName)
d.Set("acl", flattenRgAcl(details.ACL))
@@ -213,7 +212,6 @@ func flattenRgList(rgl *rg.ListResourceGroups) []map[string]interface{} {
"account_acl": flattenRgAcl(rg.ACL),
"account_id": rg.AccountID,
"account_name": rg.AccountName,
"acl": flattenRgAcl(rg.ACL),
"created_by": rg.CreatedBy,
"created_time": rg.CreatedTime,
"def_net_id": rg.DefNetID,
@@ -431,6 +429,7 @@ func flattenRgListLb(listLb *rg.ListLB) []map[string]interface{} {
temp := map[string]interface{}{
"ha_mode": lb.HAMode,
"acl": lb.ACL,
"backend_haip": lb.BackendHAIP,
"backends": flattenBackends(lb.Backends),
"created_by": lb.CreatedBy,
"created_time": lb.CreatedTime,
@@ -439,6 +438,7 @@ func flattenRgListLb(listLb *rg.ListLB) []map[string]interface{} {
"desc": lb.Description,
"dp_api_user": lb.DPAPIUser,
"extnet_id": lb.ExtNetID,
"frontend_haip": lb.FrontendHAIP,
"frontends": flattenFrontends(lb.Frontends),
"gid": lb.GID,
"guid": lb.GUID,

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,292 @@
package rg
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
func resourceRGResourceV1() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"account_id": {
Type: schema.TypeInt,
Required: true,
ValidateFunc: validation.IntAtLeast(1),
Description: "Unique ID of the account, which this resource group belongs to.",
},
"gid": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Description: "Unique ID of the grid, where this resource group is deployed.",
},
"name": {
Type: schema.TypeString,
Required: true,
Description: "Name of this resource group. Names are case sensitive and unique within the context of a account.",
},
"def_net_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{"PRIVATE", "PUBLIC", "NONE"}, false),
Description: "Type of the network, which this resource group will use as default for its computes - PRIVATE or PUBLIC or NONE.",
},
"def_net_id": {
Type: schema.TypeInt,
Computed: true,
Description: "ID of the default network for this resource group (if any).",
},
"ipcidr": {
Type: schema.TypeString,
Optional: true,
Description: "Address of the netowrk inside the private network segment (aka ViNS) if def_net_type=PRIVATE",
},
"ext_net_id": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
Description: "ID of the external network for default ViNS. Pass 0 if def_net_type=PUBLIC or no external connection required for the defult ViNS when def_net_type=PRIVATE",
},
"ext_ip": {
Type: schema.TypeString,
Optional: true,
Description: "IP address on the external netowrk to request when def_net_type=PRIVATE and ext_net_id is not 0",
},
"quota": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cpu": {
Type: schema.TypeInt,
Optional: true,
Default: -1,
Description: "Limit on the total number of CPUs in this resource group.",
},
"ram": {
Type: schema.TypeFloat, // NB: API expects and returns this as float in units of MB! This may be changed in the future.
Optional: true,
Default: -1,
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.",
},
"ext_traffic": {
Type: schema.TypeInt,
Optional: true,
Default: -1,
Description: "Limit on the total ingress network traffic for this resource group, specified in GB.",
},
"ext_ips": {
Type: schema.TypeInt,
Optional: true,
Default: -1,
Description: "Limit on the total number of external IP addresses this resource group can use.",
},
"gpu_units": {
Type: schema.TypeInt,
Optional: true,
Default: -1,
Description: "Limit on the total number of virtual GPUs this resource group can use.",
},
},
},
Description: "Quota settings for this resource group.",
},
"access": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"user": {
Type: schema.TypeString,
Required: true,
Description: "User or group name to grant access",
},
"right": {
Type: schema.TypeString,
Required: true,
Description: "Access rights to set, one of 'R', 'RCX' or 'ARCXDU'",
},
"reason": {
Type: schema.TypeString,
Optional: true,
Description: "Reason for action",
},
},
},
},
"def_net": {
Type: schema.TypeSet,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"net_type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"PRIVATE", "PUBLIC"}, false),
Description: "Network type to set. Must be on of 'PRIVATE' or 'PUBLIC'.",
},
"net_id": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
Description: "Network segment ID. If netType is PUBLIC and netId is 0 then default external network segment will be selected. If netType is PRIVATE and netId=0, the first ViNS defined for this RG will be selected. Otherwise, netId identifies either existing external network segment or ViNS.",
},
"reason": {
Type: schema.TypeString,
Optional: true,
Description: "Reason for action",
},
},
},
},
"description": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "User-defined text description of this resource group.",
},
"force": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Set to True if you want force delete non-empty RG",
},
"permanently": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Set to True if you want force delete non-empty RG",
},
"reason": {
Type: schema.TypeString,
Optional: true,
Description: "Set to True if you want force delete non-empty RG",
},
"register_computes": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Register computes in registration system",
},
"enable": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "flag for enable/disable RG",
},
"account_name": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the account, which this resource group belongs to.",
},
// "resources": {
// Type: schema.TypeList,
// Computed: true,
// Elem: &schema.Resource{
// Schema: resourcesSchemaMake(),
// },
// },
"acl": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: aclSchemaMake(),
},
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"dirty": {
Type: schema.TypeBool,
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,
},
"secret": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "Current status of this resource group.",
},
"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,
},
Description: "List of VINs deployed in this resource group.",
},
"vms": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
Description: "List of computes deployed in this resource group.",
},
"res_types": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"uniq_pools": {
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,
},
},
}
}

View File

@@ -32,10 +32,6 @@ Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/w
package rg
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func makeQuotaRecord(arg_list []interface{}) QuotaRecord {
quota := QuotaRecord{
Cpu: -1,
@@ -56,8 +52,8 @@ func makeQuotaRecord(arg_list []interface{}) QuotaRecord {
quota.Disk = subres_data["disk"].(int) // Disk capacity ib GB
}
if subres_data["ram"].(float64) > 0 {
quota.Ram = subres_data["ram"].(float64) // RAM volume in MB, as float64!
if subres_data["ram"].(int) > 0 {
quota.Ram = subres_data["ram"].(int) // RAM volume in MB
}
if subres_data["ext_traffic"].(int) > 0 {
@@ -75,65 +71,18 @@ func makeQuotaRecord(arg_list []interface{}) QuotaRecord {
return quota
}
func parseQuota(quota QuotaRecord) []interface{} {
quota_map := make(map[string]interface{})
// func parseQuota(quota QuotaRecord) []interface{} {
// quota_map := make(map[string]interface{})
quota_map["cpu"] = quota.Cpu
quota_map["ram"] = quota.Ram // NB: this is float64, unlike the rest of values
quota_map["disk"] = quota.Disk
quota_map["ext_traffic"] = quota.ExtTraffic
quota_map["ext_ips"] = quota.ExtIPs
quota_map["gpu_units"] = quota.GpuUnits
// quota_map["cpu"] = quota.Cpu
// quota_map["ram"] = quota.Ram // NB: this is float64, unlike the rest of values
// quota_map["disk"] = quota.Disk
// quota_map["ext_traffic"] = quota.ExtTraffic
// quota_map["ext_ips"] = quota.ExtIPs
// quota_map["gpu_units"] = quota.GpuUnits
result := make([]interface{}, 1)
result[0] = quota_map
// result := make([]interface{}, 1)
// result[0] = quota_map
return result // this result will be used to d.Set("quota,") of dataSourceResgroup schema
}
func quotaRgSubresourceSchemaMake() map[string]*schema.Schema {
rets := map[string]*schema.Schema{
"cpu": {
Type: schema.TypeInt,
Optional: true,
Default: -1,
Description: "Limit on the total number of CPUs in this resource group.",
},
"ram": {
Type: schema.TypeFloat, // NB: API expects and returns this as float in units of MB! This may be changed in the future.
Optional: true,
Default: -1.,
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.",
},
"ext_traffic": {
Type: schema.TypeInt,
Optional: true,
Default: -1,
Description: "Limit on the total ingress network traffic for this resource group, specified in GB.",
},
"ext_ips": {
Type: schema.TypeInt,
Optional: true,
Default: -1,
Description: "Limit on the total number of external IP addresses this resource group can use.",
},
"gpu_units": {
Type: schema.TypeInt,
Optional: true,
Default: -1,
Description: "Limit on the total number of virtual GPUs this resource group can use.",
},
}
return rets
}
// return result // this result will be used to d.Set("quota,") of dataSourceResgroup schema
// }

View File

@@ -42,7 +42,6 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/location"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
@@ -54,7 +53,7 @@ import (
func resourceResgroupCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
rgName, ok := d.GetOk("name")
if !ok {
return diag.FromErr(fmt.Errorf("Cannot create new RG: missing name."))
return diag.FromErr(fmt.Errorf("cannot create new RG: missing name"))
}
log.Debugf("resourceResgroupCreate: called for RG name %s, account ID %d",
@@ -86,26 +85,25 @@ func resourceResgroupCreate(ctx context.Context, d *schema.ResourceData, m inter
}
}
c := m.(*controller.ControllerCfg)
req := rg.CreateRequest{}
req := rg.CreateRequest{
Name: rgName.(string),
AccountID: uint64(d.Get("account_id").(int)),
GID: uint64(d.Get("gid").(int)),
// Owner: c.GetDecortUsername(),
}
setQuota := false
var quotaRecord QuotaRecord
argValue, ok := d.GetOk("quota")
if ok {
if argValue, ok := d.GetOk("quota"); ok {
log.Debugf("resourceResgroupCreate: setting Quota on RG requested")
quotaRecord = makeQuotaRecord(argValue.([]interface{}))
setQuota = true
}
log.Debugf("resourceResgroupCreate: called by user %q for RG name %s, account ID %d",
c.GetDecortUsername(),
log.Debugf("resourceResgroupCreate: called for RG name %s, account ID %d",
// c.GetDecortUsername(),
rgName.(string), d.Get("account_id").(int))
req.AccountID = uint64(d.Get("account_id").(int))
req.Name = rgName.(string)
req.GID = uint64(location.DefaultGridID)
req.Owner = c.GetDecortUsername()
if setQuota {
req.MaxCPUCapacity = int64(quotaRecord.Cpu)
req.MaxVDiskCapacity = int64(quotaRecord.Disk)
@@ -114,40 +112,37 @@ func resourceResgroupCreate(ctx context.Context, d *schema.ResourceData, m inter
req.MaxNumPublicIP = int64(quotaRecord.ExtIPs)
}
defNetType, ok := d.GetOk("def_net_type")
if ok {
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 {
d.Set("def_net_type", "PRIVATE")
}
ipcidr, ok := d.GetOk("ipcidr")
if ok {
if owner, ok := d.GetOk("owner"); ok {
req.Owner = owner.(string)
}
if ipcidr, ok := d.GetOk("ipcidr"); ok {
req.IPCIDR = ipcidr.(string)
}
description, ok := d.GetOk("description")
if ok {
if description, ok := d.GetOk("description"); ok {
req.Description = description.(string)
}
reason, ok := d.GetOk("reason")
if ok {
if reason, ok := d.GetOk("reason"); ok {
req.Reason = reason.(string)
}
extNetId, ok := d.GetOk("ext_net_id")
if ok {
if extNetId, ok := d.GetOk("ext_net_id"); ok {
req.ExtNetID = uint64(extNetId.(int))
}
extIp, ok := d.GetOk("ext_ip")
if ok {
if extIp, ok := d.GetOk("ext_ip"); ok {
req.ExtIP = extIp.(string)
}
regComputes, ok := d.GetOk("register_computes")
if ok {
if regComputes, ok := d.GetOk("register_computes"); ok {
req.RegisterComputes = regComputes.(bool)
}
@@ -217,8 +212,7 @@ func resourceResgroupCreate(ctx context.Context, d *schema.ResourceData, m inter
}
if enable, ok := d.GetOk("enable"); ok {
enable := enable.(bool)
if enable {
if enable.(bool) {
req := rg.EnableRequest{
RGID: apiResp,
}
@@ -247,8 +241,7 @@ func resourceResgroupCreate(ctx context.Context, d *schema.ResourceData, m inter
}
}
defer resourceResgroupRead(ctx, d, m)
return w.Get()
return append(w.Get(), resourceResgroupRead(ctx, d, m)...)
}
func resourceResgroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
@@ -352,19 +345,30 @@ func resourceResgroupUpdate(ctx context.Context, d *schema.ResourceData, m inter
case status.Created:
case status.Enabled:
case status.Deleted:
restoreReq := rg.RestoreRequest{RGID: rgData.ID}
enableReq := rg.EnableRequest{RGID: rgData.ID}
if restore, ok := d.GetOk("restore"); ok && restore.(bool) {
restoreReq := rg.RestoreRequest{RGID: rgData.ID}
_, err := c.CloudAPI().RG().Restore(ctx, restoreReq)
if err != nil {
return diag.FromErr(err)
if reason, ok := d.GetOk("reason"); ok {
restoreReq.Reason = reason.(string)
}
_, err := c.CloudAPI().RG().Restore(ctx, restoreReq)
if err != nil {
return diag.FromErr(err)
}
if enable, ok := d.GetOk("enable"); ok && enable.(bool) {
enableReq := rg.EnableRequest{RGID: rgData.ID}
if reason, ok := d.GetOk("reason"); ok {
enableReq.Reason = reason.(string)
}
_, err = c.CloudAPI().RG().Enable(ctx, enableReq)
if err != nil {
return diag.FromErr(err)
}
}
}
_, err = c.CloudAPI().RG().Enable(ctx, enableReq)
if err != nil {
return diag.FromErr(err)
}
hasChanged = true
case status.Deleting:
case status.Destroyed:
@@ -393,7 +397,7 @@ func resourceResgroupUpdate(ctx context.Context, d *schema.ResourceData, m inter
The following code fragment checks if any of these have been changed and generates error.
*/
if ok := d.HasChange("def_net"); ok {
if d.HasChange("def_net") {
_, newDefNet := d.GetChange("def_net")
if newDefNet.(*schema.Set).Len() == 0 {
return diag.Errorf("resourceResgroupUpdate: block def_net must not be empty")
@@ -412,171 +416,99 @@ func resourceResgroupUpdate(ctx context.Context, d *schema.ResourceData, m inter
return diag.FromErr(fmt.Errorf("resourceResgroupUpdate: RG ID %s: changing ext_net_id for existing RG is not allowed", d.Id()))
}
doGeneralUpdate := false
req := rg.UpdateRequest{
RGID: rgData.ID,
}
nameNew, nameSet := d.GetOk("name")
if nameSet {
log.Debugf("resourceResgroupUpdate: name specified - looking for deltas from the old settings.")
nameOld, _ := d.GetChange("name")
if nameOld.(string) != nameNew.(string) {
req.Name = nameNew.(string)
doGeneralUpdate = true
}
}
quotaValue, quotaSet := d.GetOk("quota")
if quotaSet {
log.Debugf("resourceResgroupUpdate: quota specified - looking for deltas from the old quota.")
quotarecordNew := makeQuotaRecord(quotaValue.([]interface{}))
quotaValueOld, _ := d.GetChange("quota")
quotarecordOld := makeQuotaRecord(quotaValueOld.([]interface{}))
log.Debug(quotaValueOld, quotarecordNew)
if quotarecordNew.Cpu != quotarecordOld.Cpu {
doGeneralUpdate = true
log.Debugf("resourceResgroupUpdate: Cpu diff %d <- %d", quotarecordNew.Cpu, quotarecordOld.Cpu)
req.MaxCPUCapacity = int64(quotarecordNew.Cpu)
}
if quotarecordNew.Disk != quotarecordOld.Disk {
doGeneralUpdate = true
log.Debugf("resourceResgroupUpdate: Disk diff %d <- %d", quotarecordNew.Disk, quotarecordOld.Disk)
req.MaxVDiskCapacity = int64(quotarecordNew.Disk)
}
if quotarecordNew.Ram != quotarecordOld.Ram {
doGeneralUpdate = true
log.Debugf("resourceResgroupUpdate: Ram diff %f <- %f", quotarecordNew.Ram, quotarecordOld.Ram)
req.MaxMemoryCapacity = int64(quotarecordNew.Ram)
}
if quotarecordNew.ExtTraffic != quotarecordOld.ExtTraffic {
doGeneralUpdate = true
log.Debugf("resourceResgroupUpdate: ExtTraffic diff %d <- %d", quotarecordNew.ExtTraffic, quotarecordOld.ExtTraffic)
req.MaxNetworkPeerTransfer = int64(quotarecordNew.ExtTraffic)
}
if quotarecordNew.ExtIPs != quotarecordOld.ExtIPs {
doGeneralUpdate = true
log.Debugf("resourceResgroupUpdate: ExtIPs diff %d <- %d", quotarecordNew.ExtIPs, quotarecordOld.ExtIPs)
req.MaxNumPublicIP = int64(quotarecordNew.ExtIPs)
}
} else {
doGeneralUpdate = true
req.MaxCPUCapacity = -1
req.MaxVDiskCapacity = -1
req.MaxMemoryCapacity = -1
req.MaxNetworkPeerTransfer = -1
req.MaxNumPublicIP = -1
}
descNew, descSet := d.GetOk("description")
if descSet {
log.Debugf("resourceResgroupUpdate: description specified - looking for deltas from the old settings.")
descOld, _ := d.GetChange("description")
if descOld.(string) != descNew.(string) {
doGeneralUpdate = true
req.Description = descNew.(string)
}
}
if doGeneralUpdate {
log.Debugf("resourceResgroupUpdate: detected delta between new and old RG specs - updating the RG")
_, err := c.CloudAPI().RG().Update(ctx, req)
if err != nil {
return diag.FromErr(err)
}
} else {
log.Debugf("resourceResgroupUpdate: no difference between old and new state - no update on the RG will be done")
}
enableOld, enableNew := d.GetChange("enable")
if enableOld.(bool) && !enableNew.(bool) {
req := rg.DisableRequest{RGID: rgData.ID}
_, err := c.CloudAPI().RG().Disable(ctx, req)
if err != nil {
return diag.FromErr(err)
}
} else if !enableOld.(bool) && enableNew.(bool) {
req := rg.EnableRequest{RGID: rgData.ID}
_, err := c.CloudAPI().RG().Enable(ctx, req)
if err != nil {
if d.HasChanges("name", "quota", "description", "register_computes") {
if err := utilityUpdateRG(ctx, d, m, rgData.ID); err != nil {
return diag.FromErr(err)
}
}
oldSet, newSet := d.GetChange("access")
if d.HasChange("enable") {
enableOld, enableNew := d.GetChange("enable")
if enableOld.(bool) && !enableNew.(bool) {
req := rg.DisableRequest{RGID: rgData.ID}
deletedAccess := (oldSet.(*schema.Set).Difference(newSet.(*schema.Set))).List()
for _, deletedInterface := range deletedAccess {
deletedItem := deletedInterface.(map[string]interface{})
user := deletedItem["user"].(string)
req := rg.AccessRevokeRequest{
RGID: rgData.ID,
User: user,
}
if reason, ok := d.GetOk("reason"); ok {
req.Reason = reason.(string)
}
_, err := c.CloudAPI().RG().Disable(ctx, req)
if err != nil {
return diag.FromErr(err)
}
} else if !enableOld.(bool) && enableNew.(bool) {
req := rg.EnableRequest{RGID: rgData.ID}
_, err := c.CloudAPI().RG().AccessRevoke(ctx, req)
if err != nil {
return diag.FromErr(err)
_, err := c.CloudAPI().RG().Enable(ctx, req)
if err != nil {
return diag.FromErr(err)
}
}
}
addedAccess := (newSet.(*schema.Set).Difference(oldSet.(*schema.Set))).List()
for _, addedInterface := range addedAccess {
addedItem := addedInterface.(map[string]interface{})
user := addedItem["user"].(string)
right := addedItem["right"].(string)
if d.HasChange("access") {
oldSet, newSet := d.GetChange("access")
deletedAccess := (oldSet.(*schema.Set).Difference(newSet.(*schema.Set))).List()
for _, deletedInterface := range deletedAccess {
deletedItem := deletedInterface.(map[string]interface{})
user := deletedItem["user"].(string)
req := rg.AccessRevokeRequest{
RGID: rgData.ID,
User: user,
}
if reason, ok := d.GetOk("reason"); ok {
req.Reason = reason.(string)
}
req := rg.AccessGrantRequest{
RGID: rgData.ID,
User: user,
Right: right,
_, err := c.CloudAPI().RG().AccessRevoke(ctx, req)
if err != nil {
return diag.FromErr(err)
}
}
if reason, ok := d.GetOk("reason"); ok {
req.Reason = reason.(string)
}
addedAccess := (newSet.(*schema.Set).Difference(oldSet.(*schema.Set))).List()
for _, addedInterface := range addedAccess {
addedItem := addedInterface.(map[string]interface{})
user := addedItem["user"].(string)
right := addedItem["right"].(string)
_, err := c.CloudAPI().RG().AccessGrant(ctx, req)
if err != nil {
return diag.FromErr(err)
req := rg.AccessGrantRequest{
RGID: rgData.ID,
User: user,
Right: right,
}
if reason, ok := d.GetOk("reason"); ok {
req.Reason = reason.(string)
}
_, err := c.CloudAPI().RG().AccessGrant(ctx, req)
if err != nil {
return diag.FromErr(err)
}
}
}
if ok := d.HasChange("def_net"); ok {
oldDefNet, newDefNet := d.GetChange("def_net")
if newDefNet.(*schema.Set).Len() > 0 {
changedDefNet := (newDefNet.(*schema.Set).Difference(oldDefNet.(*schema.Set))).List()
for _, changedDefNetInterface := range changedDefNet {
defNetItem := changedDefNetInterface.(map[string]interface{})
netType := defNetItem["net_type"].(string)
if d.HasChange("def_net") {
if ok := d.HasChange("def_net"); ok {
oldDefNet, newDefNet := d.GetChange("def_net")
if newDefNet.(*schema.Set).Len() > 0 {
changedDefNet := (newDefNet.(*schema.Set).Difference(oldDefNet.(*schema.Set))).List()
for _, changedDefNetInterface := range changedDefNet {
defNetItem := changedDefNetInterface.(map[string]interface{})
netType := defNetItem["net_type"].(string)
req := rg.SetDefNetRequest{
RGID: rgData.ID,
NetType: netType,
}
req := rg.SetDefNetRequest{
RGID: rgData.ID,
NetType: netType,
}
if netID, ok := defNetItem["net_id"]; ok {
req.NetID = uint64(netID.(int))
}
if reason, ok := defNetItem["reason"]; ok {
req.Reason = reason.(string)
}
if netID, ok := defNetItem["net_id"]; ok {
req.NetID = uint64(netID.(int))
}
if reason, ok := defNetItem["reason"]; ok {
req.Reason = reason.(string)
}
_, err := c.CloudAPI().RG().SetDefNet(ctx, req)
if err != nil {
return diag.FromErr(err)
_, err := c.CloudAPI().RG().SetDefNet(ctx, req)
if err != nil {
return diag.FromErr(err)
}
}
}
}
@@ -625,9 +557,9 @@ func ResourceRgSchemaMake() map[string]*schema.Schema {
},
"gid": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Type: schema.TypeInt,
Required: true,
// ForceNew: true,
Description: "Unique ID of the grid, where this resource group is deployed.",
},
@@ -670,12 +602,59 @@ func ResourceRgSchemaMake() map[string]*schema.Schema {
Description: "IP address on the external netowrk to request when def_net_type=PRIVATE and ext_net_id is not 0",
},
"owner": {
Type: schema.TypeString,
Optional: true,
},
"quota": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: quotaRgSubresourceSchemaMake(),
Schema: map[string]*schema.Schema{
"cpu": {
Type: schema.TypeInt,
Optional: true,
Default: -1,
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,
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.",
},
"ext_traffic": {
Type: schema.TypeInt,
Optional: true,
Default: -1,
Description: "Limit on the total ingress network traffic for this resource group, specified in GB.",
},
"ext_ips": {
Type: schema.TypeInt,
Optional: true,
Default: -1,
Description: "Limit on the total number of external IP addresses this resource group can use.",
},
"gpu_units": {
Type: schema.TypeInt,
Optional: true,
Default: -1,
Description: "Limit on the total number of virtual GPUs this resource group can use.",
},
},
},
Description: "Quota settings for this resource group.",
},
@@ -760,7 +739,11 @@ func ResourceRgSchemaMake() map[string]*schema.Schema {
Default: false,
Description: "Register computes in registration system",
},
"restore": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"enable": {
Type: schema.TypeBool,
Optional: true,
@@ -878,7 +861,7 @@ func ResourceRgSchemaMake() map[string]*schema.Schema {
func ResourceResgroup() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
SchemaVersion: 2,
CreateContext: resourceResgroupCreate,
ReadContext: resourceResgroupRead,
@@ -916,5 +899,12 @@ func ResourceResgroup() *schema.Resource {
},
),
),
StateUpgraders: []schema.StateUpgrader{
{
Type: resourceRGResourceV1().CoreConfigSchema().ImpliedType(),
Upgrade: resourceRGStateUpgradeV1,
Version: 1,
},
},
}
}

View File

@@ -0,0 +1,28 @@
package rg
import (
"context"
log "github.com/sirupsen/logrus"
)
func resourceRGStateUpgradeV1(ctx context.Context, rawState map[string]interface{}, meta any) (map[string]interface{}, error) {
log.Debug("resourceRGStateUpgradeV1: upgrading state")
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

@@ -36,10 +36,10 @@ import (
"context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
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 utilityResgroupCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.RecordResourceGroup, error) {
@@ -63,3 +63,47 @@ func utilityResgroupCheckPresence(ctx context.Context, d *schema.ResourceData, m
return rgData, nil
}
func utilityUpdateRG(ctx context.Context, d *schema.ResourceData, m interface{}, rgId uint64) error {
c := m.(*controller.ControllerCfg)
req := rg.UpdateRequest{
RGID: rgId,
}
if d.HasChange("name") {
log.Debugf("resourceResgroupUpdate: name specified - looking for deltas from the old settings")
req.Name = d.Get("name").(string)
}
if d.HasChange("quota") {
log.Debugf("resourceResgroupUpdate: quota specified - looking for deltas from the old quota.")
quotaList := d.Get("quota").([]interface{})
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))
}
if d.HasChange("description") {
log.Debugf("resourceResgroupUpdate: description specified - looking for deltas from the old settings.")
req.Description = d.Get("description").(string)
}
if d.HasChange("register_computes") {
log.Debugf("resourceResgroupUpdate: register_computes specified - looking for deltas from the old settings.")
req.RegisterComputes = d.Get("register_computes").(bool)
}
if reason, ok := d.GetOk("reason"); ok {
req.Reason = reason.(string)
}
_, err := c.CloudAPI().RG().Update(ctx, req)
if err != nil {
return err
}
return nil
}