This commit is contained in:
2026-06-19 17:43:58 +03:00
parent c734dcfff7
commit c00c608ce9
1307 changed files with 1 additions and 197134 deletions

View File

@@ -1,71 +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>
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"
"fmt"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceResgroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
rg, err := utilityResgroupCheckPresence(ctx, d, m)
if err != nil {
// if empty string is returned from utilityResgroupCheckPresence then there is no
// such resource group and err tells so - just return it to the calling party
d.SetId("") // ensure ID is empty in this case
return diag.FromErr(err)
}
d.SetId(fmt.Sprintf("%d", rg.ID))
flattenResgroup(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

@@ -1,37 +0,0 @@
package rg
import (
"context"
"strconv"
"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 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)
}
d.SetId(strconv.Itoa(d.Get("rg_id").(int)))
d.Set("items", flattenRgAffinityGroupComputes(rgComputes))
return nil
}
func DataSourceRgAffinityGroupComputes() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceRgAffinityGroupComputesRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceRgAffinityGroupComputesSchemaMake(),
}
}

View File

@@ -1,36 +0,0 @@
package rg
import (
"context"
"strconv"
"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 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)))
d.Set("ids", computes)
return nil
}
func DataSourceRgAffinityGroupsGet() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceRgAffinityGroupsGetRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceRgAffinityGroupsGetSchemaMake(),
}
}

View File

@@ -1,38 +0,0 @@
package rg
import (
"context"
"strconv"
"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 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)
}
d.SetId(strconv.Itoa(d.Get("rg_id").(int)))
d.Set("affinity_groups", flattenRgListGroups(list))
d.Set("entry_count", list.EntryCount)
return nil
}
func DataSourceRgAffinityGroupsList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceRgAffinityGroupsListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceRgAffinityGroupsListSchemaMake(),
}
}

View File

@@ -1,37 +0,0 @@
package rg
import (
"context"
"strconv"
"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 dataSourceRgAuditsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
rgAudits, err := utilityRgAuditsCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
diag.FromErr(err)
}
d.SetId(strconv.Itoa(d.Get("rg_id").(int)))
d.Set("items", flattenRgAudits(rgAudits))
return nil
}
func DataSourceRgAudits() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceRgAuditsRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceRgAuditsSchemaMake(),
}
}

View File

@@ -1,70 +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 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 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)
}
id := uuid.New()
d.SetId(id.String())
flattenRGResourceConsumption(d, RGResourceConsumptionRec)
return nil
}
func DataSourceRGResourceConsumptionGet() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceRGResourceConsumptionGetRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceRGResourceConsumptionGetSchemaMake(),
}
}

View File

@@ -1,71 +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>
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 DataSourceRgList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceRgListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceRgListSchemaMake(),
}
}

View File

@@ -1,72 +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 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 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)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenRgListComputes(listComputes))
d.Set("entry_count", listComputes.EntryCount)
return nil
}
func DataSourceRgListComputes() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceRgListComputesRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceRgListComputesSchemaMake(),
}
}

View File

@@ -1,72 +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 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 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)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenRgList(rgList))
d.Set("entry_count", rgList.EntryCount)
return nil
}
func DataSourceRgListDeleted() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceRgListDeletedRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceRgListDeletedSchemaMake(),
}
}

View File

@@ -1,71 +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 rg
import (
"context"
"strconv"
"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 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)
}
d.SetId(strconv.Itoa(d.Get("rg_id").(int)))
d.Set("items", flattenRgListLb(listLb))
d.Set("entry_count", listLb.EntryCount)
return nil
}
func DataSourceRgListLb() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceRgListLbRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceRgListLbSchemaMake(),
}
}

View File

@@ -1,71 +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 rg
import (
"context"
"strconv"
"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 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)
}
d.SetId(strconv.Itoa(d.Get("rg_id").(int)))
d.Set("items", flattenRgListPfw(listPfw))
d.Set("entry_count", listPfw.EntryCount)
return nil
}
func DataSourceRgListPfw() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceRgListPfwRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceRgListPfwSchemaMake(),
}
}

View File

@@ -1,71 +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 rg
import (
"context"
"strconv"
"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 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)
}
d.SetId(strconv.Itoa(d.Get("rg_id").(int)))
d.Set("items", flattenRgListVins(listVins))
d.Set("entry_count", listVins.EntryCount)
return nil
}
func DataSourceRgListVins() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceRgListVinsRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceRgListVinsSchemaMake(),
}
}

View File

@@ -1,71 +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 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 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)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenRGResourceConsumptionList(rgResourceConsumptionList))
d.Set("entry_count", rgResourceConsumptionList.EntryCount)
return nil
}
func DataSourceRGResourceConsumptionList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceRGResourceConsumptionListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceRGResourceConsumptionListSchemaMake(),
}
}

View File

@@ -1,69 +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 rg
import (
"context"
"strconv"
"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 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)
}
d.SetId(strconv.Itoa(d.Get("rg_id").(int)))
flattenRgUsageResource(d, *usage)
return nil
}
func DataSourceRgUsage() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceRgUsageRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceRgUsageSchemaMake(),
}
}

View File

@@ -1,518 +0,0 @@
package rg
import (
log "github.com/sirupsen/logrus"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg"
)
func flattenResgroup(d *schema.ResourceData, rgData *rg.RecordRG) {
log.Debugf("flattenResgroup: decoded RG name %q / ID %d, account ID %d",
rgData.Name, rgData.ID, rgData.AccountID)
d.Set("account_id", rgData.AccountID)
d.Set("account_name", rgData.AccountName)
d.Set("acl", flattenRgAcl(rgData.ACL))
d.Set("compute_features", rgData.ComputeFeatures)
d.Set("cpu_allocation_parameter", rgData.CPUAllocationParameter)
d.Set("cpu_allocation_ratio", rgData.CPUAllocationRatio)
d.Set("created_by", rgData.CreatedBy)
d.Set("created_time", rgData.CreatedTime)
d.Set("def_net_id", rgData.DefNetID)
d.Set("def_net_type", rgData.DefNetType)
d.Set("deleted_by", rgData.DeletedBy)
d.Set("deleted_time", rgData.DeletedTime)
d.Set("desc", rgData.Description)
d.Set("dirty", rgData.Dirty)
d.Set("gid", rgData.GID)
d.Set("guid", rgData.GUID)
d.Set("rg_id", rgData.ID)
d.Set("lock_status", rgData.LockStatus)
d.Set("milestones", rgData.Milestones)
d.Set("name", rgData.Name)
d.Set("resource_limits", flattenRgResourceLimits(rgData.ResourceLimits))
d.Set("resource_types", rgData.ResTypes)
d.Set("secret", rgData.Secret)
d.Set("status", rgData.Status)
d.Set("uniq_pools", rgData.UniqPools)
d.Set("updated_by", rgData.UpdatedBy)
d.Set("updated_time", rgData.UpdatedTime)
d.Set("vins", rgData.VINS)
d.Set("computes", rgData.VMs)
d.Set("sdn_access_group_id", rgData.SDNAccessGroupID)
d.Set("storage_policy_ids", rgData.StoragePolicyIDs)
}
func flattenRgAcl(rgACLs rg.ListACL) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(rgACLs))
for _, acl := range rgACLs {
temp := map[string]interface{}{
"email": acl.Email,
"explicit": acl.Explicit,
"guid": acl.GUID,
"right": acl.Right,
"status": acl.Status,
"type": acl.Type,
"user_group_id": acl.UserGroupID,
}
res = append(res, temp)
}
return res
}
func flattenRgResourceLimits(rl rg.ResourceLimits) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"cu_c": rl.CUC,
"cu_d": rl.CuD,
"cu_dm": rl.CUDM,
"cu_i": rl.CUI,
"cu_m": rl.CUM,
"gpu_units": rl.GPUUnits,
"storage_policy": flattenRgStoragePolicy(rl.StoragePolicies),
}
res = append(res, temp)
return res
}
func flattenRgAudits(rgAudits rg.ListAudits) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(rgAudits))
for _, rgAudit := range rgAudits {
temp := map[string]interface{}{
"call": rgAudit.Call,
"responsetime": rgAudit.ResponseTime,
"statuscode": rgAudit.StatusCode,
"timestamp": rgAudit.Timestamp,
"user": rgAudit.User,
}
res = append(res, temp)
}
return res
}
func flattenRgListGroups(list *rg.ListAffinityGroup) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(list.Data))
for _, item := range list.Data {
for key, vals := range item {
for _, v := range vals {
temp := map[string]interface{}{
"label": key,
"id": v.ID,
"node_id": v.NodeID,
}
res = append(res, temp)
}
}
}
return res
}
func flattenRgAffinityGroupComputes(list rg.ListAffinityGroupCompute) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(list))
for _, item := range list {
temp := map[string]interface{}{
"compute_id": item.ComputeID,
"other_node": item.OtherNode,
"other_node_indirect": item.OtherNodeIndirect,
"other_node_indirect_soft": item.OtherNodeIndirectSoft,
"other_node_soft": item.OtherNodeSoft,
"same_node": item.SameNode,
"same_node_soft": item.SameNodeSoft,
}
res = append(res, temp)
}
return res
}
func flattenRGResourceConsumption(d *schema.ResourceData, rg *rg.ItemResourceConsumption) {
d.Set("consumed", flattenResource(rg.Consumed))
d.Set("reserved", flattenResource(rg.Reserved))
d.Set("resource_limits", flattenRgResourceLimits(rg.ResourceLimits))
d.Set("rg_id", rg.RGID)
}
func flattenRGResourceConsumptionList(rg *rg.ListResourceConsumption) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(rg.Data))
for _, rc := range rg.Data {
temp := map[string]interface{}{
"consumed": flattenResource(rc.Consumed),
"reserved": flattenResource(rc.Reserved),
"resource_limits": flattenRgResourceLimits(rc.ResourceLimits),
"rg_id": rc.RGID,
}
res = append(res, temp)
}
return res
}
func flattenRgUsageResource(d *schema.ResourceData, usage rg.Reservation) {
d.Set("cpu", usage.CPU)
d.Set("disk_size", usage.DiskSize)
d.Set("disk_size_max", usage.DiskSizeMax)
d.Set("extips", usage.ExtIPs)
d.Set("gpu", usage.GPU)
d.Set("ram", usage.RAM)
d.Set("seps", flattenRGSeps(usage.SEPs))
}
func flattenResource(resource rg.Reservation) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"cpu": resource.CPU,
"disk_size": resource.DiskSize,
"disk_size_max": resource.DiskSizeMax,
"extips": resource.ExtIPs,
"gpu": resource.GPU,
"ram": resource.RAM,
"seps": flattenRGSeps(resource.SEPs),
}
res = append(res, temp)
return res
}
func flattenRGSeps(seps map[string]map[string]rg.DiskUsage) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for sepKey, sepVal := range seps {
for dataKey, dataVal := range sepVal {
temp := map[string]interface{}{
"sep_id": sepKey,
"data_name": dataKey,
"disk_size": dataVal.DiskSize,
"disk_size_max": dataVal.DiskSizeMax,
}
res = append(res, temp)
}
}
return res
}
func flattenRgListComputes(lc *rg.ListComputes) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(lc.Data))
for _, compute := range lc.Data {
temp := map[string]interface{}{
"account_id": compute.AccountID,
"account_name": compute.AccountName,
"affinity_label": compute.AffinityLabel,
"affinity_rules": flattenRules(compute.AffinityRules),
"affinity_weight": compute.AffinityWeight,
"antiaffinity_rules": flattenRules(compute.AntiAffinityRules),
"cpus": compute.CPUs,
"created_by": compute.CreatedBy,
"created_time": compute.CreatedTime,
"deleted_by": compute.DeletedBy,
"deleted_time": compute.DeletedTime,
"id": compute.ID,
"name": compute.Name,
"ram": compute.RAM,
"registered": compute.Registered,
"rg_id": compute.RGID,
"rg_name": compute.RGName,
"status": compute.Status,
"tech_status": compute.TechStatus,
"total_disks_size": compute.TotalDisksSize,
"updated_by": compute.UpdatedBy,
"updated_time": compute.UpdatedTime,
"user_managed": compute.UserManaged,
"vins_connected": compute.VINSConnected,
}
res = append(res, temp)
}
return res
}
func flattenRules(list rg.ListRules) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(list))
for _, rule := range list {
temp := map[string]interface{}{
"guid": rule.GUID,
"key": rule.Key,
"mode": rule.Mode,
"policy": rule.Policy,
"topology": rule.Topology,
"value": rule.Value,
}
res = append(res, temp)
}
return res
}
func flattenRgListLb(listLb *rg.ListLB) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(listLb.Data))
for _, lb := range listLb.Data {
temp := map[string]interface{}{
"ha_mode": lb.HAMode,
"acl": lb.ACL,
"backends": flattenBackends(lb.Backends),
"created_by": lb.CreatedBy,
"created_time": lb.CreatedTime,
"deleted_by": lb.DeletedBy,
"deleted_time": lb.DeletedTime,
"desc": lb.Description,
"dp_api_user": lb.DPAPIUser,
"extnet_id": lb.ExtNetID,
"frontends": flattenFrontends(lb.Frontends),
"gid": lb.GID,
"guid": lb.GUID,
"id": lb.ID,
"image_id": lb.ImageID,
"milestones": lb.Milestones,
"name": lb.Name,
"primary_node": flattenNode(lb.PrimaryNode),
"rg_name": lb.RGName,
"secondary_node": flattenNode(lb.SecondaryNode),
"status": lb.Status,
"tech_status": lb.TechStatus,
"updated_by": lb.UpdatedBy,
"updated_time": lb.UpdatedTime,
"vins_id": lb.VINSID,
}
res = append(res, temp)
}
return res
}
func flattenNode(node rg.RecordNode) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"backend_ip": node.BackendIP,
"compute_id": node.ComputeID,
"frontend_ip": node.FrontendIP,
"guid": node.GUID,
"mgmt_ip": node.MGMTIP,
"network_id": node.NetworkID,
}
res = append(res, temp)
return res
}
func flattenFrontends(list rg.ListFrontends) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(list))
for _, front := range list {
temp := map[string]interface{}{
"backend": front.Backend,
"bindings": flattenBindings(front.Bindings),
"guid": front.GUID,
"name": front.Name,
}
res = append(res, temp)
}
return res
}
func flattenBindings(list rg.ListBindings) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(list))
for _, bind := range list {
temp := map[string]interface{}{
"address": bind.Address,
"guid": bind.GUID,
"name": bind.Name,
"port": bind.Port,
}
res = append(res, temp)
}
return res
}
func flattenBackends(b rg.ListBackends) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(b))
for _, item := range b {
temp := map[string]interface{}{
"algorithm": item.Algorithm,
"guid": item.GUID,
"name": item.Name,
"server_default_settings": flattenServerSettings(item.ServerDefaultSettings),
"servers": flattenListServers(item.Servers),
}
res = append(res, temp)
}
return res
}
func flattenListServers(list rg.ListServers) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(list))
for _, serv := range list {
temp := map[string]interface{}{
"address": serv.Address,
"check": serv.Check,
"guid": serv.GUID,
"name": serv.Name,
"port": serv.Port,
"server_settings": flattenServerSettings(serv.ServerSettings),
}
res = append(res, temp)
}
return res
}
func flattenServerSettings(settings rg.ServerSettings) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"inter": settings.Inter,
"guid": settings.GUID,
"down_inter": settings.DownInter,
"rise": settings.Rise,
"fall": settings.Fall,
"slow_start": settings.SlowStart,
"max_conn": settings.MaxConn,
"max_queue": settings.MaxQueue,
"weight": settings.Weight,
}
res = append(res, temp)
return res
}
func flattenRgList(rgl *rg.ListRG) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(rgl.Data))
for _, rg := range rgl.Data {
temp := map[string]interface{}{
"account_id": rg.AccountID,
"account_name": rg.AccountName,
"acl": flattenRgAcl(rg.ACL),
"compute_features": rg.ComputeFeatures,
"cpu_allocation_parameter": rg.CPUAllocationParameter,
"cpu_allocation_ratio": rg.CPUAllocationRatio,
"created_by": rg.CreatedBy,
"created_time": rg.CreatedTime,
"def_net_id": rg.DefNetID,
"def_net_type": rg.DefNetType,
"deleted_by": rg.DeletedBy,
"deleted_time": rg.DeletedTime,
"desc": rg.Description,
"dirty": rg.Dirty,
"gid": rg.GID,
"guid": rg.GUID,
"rg_id": rg.ID,
"lock_status": rg.LockStatus,
"milestones": rg.Milestones,
"name": rg.Name,
"resource_limits": flattenRgResourceLimits(rg.ResourceLimits),
"secret": rg.Secret,
"status": rg.Status,
"updated_by": rg.UpdatedBy,
"updated_time": rg.UpdatedTime,
"vins": rg.VINS,
"vms": rg.VMs,
"sdn_access_group_id": rg.SDNAccessGroupID,
"storage_policy_ids": rg.StoragePolicyIDs,
}
res = append(res, temp)
}
return res
}
func flattenRgListVins(lv *rg.ListVINS) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(lv.Data))
for _, vins := range lv.Data {
temp := map[string]interface{}{
"account_id": vins.AccountID,
"account_name": vins.AccountName,
"computes": vins.Computes,
"created_by": vins.CreatedBy,
"created_time": vins.CreatedTime,
"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,
"pri_vnf_dev_id": vins.PriVNFDevID,
"rg_id": vins.RGID,
"rg_name": vins.RGName,
"status": vins.Status,
"updated_by": vins.UpdatedBy,
"updated_time": vins.UpdatedTime,
}
res = append(res, temp)
}
return res
}
func flattenRgListPfw(listPfw *rg.ListPFW) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(listPfw.Data))
for _, pfw := range listPfw.Data {
temp := map[string]interface{}{
"public_port_end": pfw.PublicPortEnd,
"public_port_start": pfw.PublicPortStart,
"vm_id": pfw.VMID,
"vm_ip": pfw.VMIP,
"vm_name": pfw.VMName,
"vm_port": pfw.VMPort,
"vins_id": pfw.VINSID,
"vins_name": pfw.VINSName,
}
res = append(res, temp)
}
return res
}
func flattenResourceRG(d *schema.ResourceData, rgData *rg.RecordRG) {
d.Set("account_id", rgData.AccountID)
d.Set("gid", rgData.GID)
d.Set("rg_name", rgData.Name)
d.Set("resource_limits", flattenRgResourceLimits(rgData.ResourceLimits))
d.Set("storage_policy", flattenRgStoragePolicy(rgData.ResourceLimits.StoragePolicies))
d.Set("description", rgData.Description)
d.Set("uniq_pools", rgData.UniqPools)
d.Set("cpu_allocation_parameter", rgData.CPUAllocationParameter)
d.Set("cpu_allocation_ratio", rgData.CPUAllocationRatio)
d.Set("acl", flattenRgAcl(rgData.ACL))
d.Set("account_name", rgData.AccountName)
d.Set("created_by", rgData.CreatedBy)
d.Set("created_time", rgData.CreatedTime)
d.Set("def_net_id", rgData.DefNetID)
d.Set("deleted_by", rgData.DeletedBy)
d.Set("deleted_time", rgData.DeletedTime)
d.Set("guid", rgData.GUID)
d.Set("rg_id", rgData.ID)
d.Set("lock_status", rgData.LockStatus)
d.Set("milestones", rgData.Milestones)
d.Set("resource_types", rgData.ResTypes)
d.Set("secret", rgData.Secret)
d.Set("status", rgData.Status)
d.Set("updated_by", rgData.UpdatedBy)
d.Set("updated_time", rgData.UpdatedTime)
d.Set("vins", rgData.VINS)
d.Set("vms", rgData.VMs)
d.Set("sdn_access_group_id", rgData.SDNAccessGroupID)
d.Set("storage_policy_ids", rgData.StoragePolicyIDs)
}
func flattenRgStoragePolicy(spList []rg.StoragePolicy) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(spList))
for _, sp := range spList {
temp := map[string]interface{}{
"id": sp.ID,
"limit": sp.Limit,
}
res = append(res, temp)
}
return res
}

View File

@@ -1,144 +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>
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
type ResourceLimits struct {
CUC float64 `json:"CU_C"`
CUD float64 `json:"CU_D"`
CUI float64 `json:"CU_I"`
CUM float64 `json:"CU_M"`
GpuUnits float64 `json:"gpu_units"`
}
type ResgroupRecord struct {
ACLs []AccountAclRecord `json:"acl"`
AccountID int `json:"accountId"`
AccountName string `json:"accountName"`
CreatedBy string `json:"createdBy"`
CreatedTime uint64 `json:"createdTime"`
DefaultNetID int `json:"def_net_id"`
DefaultNetType string `json:"def_net_type"`
DeletedBy string `json:"deletedBy"`
DeletedTime int `json:"deletedTime"`
Decsription string `json:"desc"`
GridID int `json:"gid"`
GUID int `json:"guid"`
ID uint `json:"id"`
LockStatus string `json:"lockStatus"`
Milestones int `json:"milestones"`
Name string `json:"name"`
ResourceLimits ResourceLimits `json:"resourceLimits"`
Secret string `json:"secret"`
Status string `json:"status"`
UpdatedBy string `json:"updatedBy"`
UpdatedTime uint64 `json:"updatedTime"`
Vins []int `json:"vins"`
Computes []int `json:"vms"`
}
type ResgroupListResp []ResgroupRecord
type ResgroupUpdateParam struct {
RgId int `json:"rgId"`
Name string `json:"name"`
Desc string `json:"decs"`
Ram int `json:"maxMemoryCapacity"`
Disk int `json:"maxVDiskCapacity"`
Cpu int `json:"maxCPUCapacity"`
NetTraffic int `json:"maxNetworkPeerTransfer"`
}
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 ResgroupGetResp struct {
ACLs []UserAclRecord `json:"ACLs"`
Usage UsageRecord `json:"Resources"`
AccountID int `json:"accountId"`
AccountName string `json:"accountName"`
GridID int `json:"gid"`
CreatedBy string `json:"createdBy"`
CreatedTime uint64 `json:"createdTime"`
DefaultNetID int `json:"def_net_id"`
DefaultNetType string `json:"def_net_type"`
DeletedBy string `json:"deletedBy"`
DeletedTime uint64 `json:"deletedTime"`
Desc string `json:"desc"`
ID uint `json:"id"`
LockStatus string `json:"lockStatus"`
Name string `json:"name"`
Quota QuotaRecord `json:"resourceLimits"`
Status string `json:"status"`
UpdatedBy string `json:"updatedBy"`
UpdatedTime uint64 `json:"updatedTime"`
Vins []int `json:"vins"`
Computes []int `json:"vms"`
Ignored map[string]interface{} `json:"-"`
}
type UserAclRecord struct {
IsExplicit bool `json:"explicit"`
Rights string `json:"right"`
Status string `json:"status"`
Type string `json:"type"`
UgroupID string `json:"userGroupId"`
// CanBeDeleted bool `json:"canBeDeleted"`
}
type QuotaRecord struct { // this is how quota is reported by /api/.../rg/get
Cpu float64 `json:"CU_C"` // CPU count in pcs
Ram float64 `json:"CU_M"` // RAM volume in MB, it is STILL reported as FLOAT
Disk float64 `json:"CU_D"` // Disk capacity in GB
ExtIPs float64 `json:"CU_I"` // Ext IPs count
GpuUnits float64 `json:"gpu_units"` // GPU count
}
type ResourceRecord struct { // this is how actual usage is reported by /api/.../rg/get
Cpu int `json:"cpu"`
Disk int `json:"disksize"`
ExtIPs int `json:"extips"`
Gpu int `json:"gpu"`
Ram int `json:"ram"`
}
type UsageRecord struct {
Current ResourceRecord `json:"Current"`
Reserved ResourceRecord `json:"Reserved"`
}

View File

@@ -1,132 +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>
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 (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg"
)
func makeQuotaRecord(arg_list []interface{}) QuotaRecord {
quota := QuotaRecord{
Cpu: -1,
Ram: -1., // this is float64, but may change in the future
Disk: -1,
ExtIPs: -1,
GpuUnits: -1,
}
subres_data := arg_list[0].(map[string]interface{})
if subres_data["cpu"].(int) > 0 {
quota.Cpu = subres_data["cpu"].(float64)
}
if subres_data["disk"].(int) > 0 {
quota.Disk = subres_data["disk"].(float64)
}
if subres_data["ram"].(float64) > 0 {
quota.Ram = subres_data["ram"].(float64)
}
if subres_data["ext_ips"].(int) > 0 {
quota.ExtIPs = subres_data["ext_ips"].(float64)
}
if subres_data["gpu_units"].(int) > 0 {
quota.GpuUnits = subres_data["gpu_units"].(float64)
}
return quota
}
func parseQuota(quota rg.ResourceLimits) []interface{} {
quota_map := make(map[string]interface{})
quota_map["cpu"] = quota.CUC
quota_map["ram"] = quota.CUM
quota_map["disk"] = quota.CuD
quota_map["ext_ips"] = quota.CUI
quota_map["gpu_units"] = quota.GPUUnits
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.TypeFloat,
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.TypeFloat,
Optional: true,
Default: -1,
Description: "Limit on the total volume of storage resources in this resource group, specified in GB.",
},
"ext_traffic": {
Type: schema.TypeFloat,
Optional: true,
Default: -1,
Description: "Limit on the total ingress network traffic for this resource group, specified in GB.",
},
"ext_ips": {
Type: schema.TypeFloat,
Optional: true,
Default: -1,
Description: "Limit on the total number of external IP addresses this resource group can use.",
},
"gpu_units": {
Type: schema.TypeFloat,
Optional: true,
Default: -1,
Description: "Limit on the total number of virtual GPUs this resource group can use.",
},
}
return rets
}

View File

@@ -1,32 +0,0 @@
package rg
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/ic"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func checkParamsExistence(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, accountId, gid uint64) diag.Diagnostics {
var errs []error
if err := ic.ExistAccount(ctx, accountId, c); err != nil {
errs = append(errs, err)
}
if err := ic.ExistGID(ctx, gid, c); err != nil {
errs = append(errs, err)
}
extNetId, ok := d.GetOk("ext_net_id")
if ok {
if err := ic.ExistExtNetInRG(ctx, uint64(extNetId.(int)), accountId, c); err != nil {
errs = append(errs, err)
}
}
return dc.ErrorsToDiagnostics(errs)
}

View File

@@ -1,816 +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>
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"
"fmt"
"strconv"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg"
"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/status"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func resourceResgroupCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceResgroupCreate: called for RG name %s, account ID %d",
d.Get("rg_name").(string), d.Get("account_id").(int))
c := m.(*controller.ControllerCfg)
accountId := uint64(d.Get("account_id").(int))
gid := uint64(d.Get("gid").(int))
req := rg.CreateRequest{
AccountID: accountId,
GID: gid,
Name: d.Get("rg_name").(string),
}
if diags := checkParamsExistence(ctx, d, c, accountId, gid); diags != nil {
return diags
}
if resLimits, ok := d.GetOk("resource_limits"); ok {
resLimits := resLimits.([]interface{})[0]
resLimitsConv := resLimits.(map[string]interface{})
if resLimitsConv["cu_m"] != nil {
maxMemCap := int64(resLimitsConv["cu_m"].(float64))
if maxMemCap == 0 {
req.MaxMemoryCapacity = -1
} else {
req.MaxMemoryCapacity = maxMemCap
}
}
if resLimitsConv["cu_dm"] != nil {
maxDiskCap := int64(resLimitsConv["cu_dm"].(float64))
if maxDiskCap == 0 {
req.MaxVDiskCapacity = -1
} else {
req.MaxVDiskCapacity = maxDiskCap
}
}
if resLimitsConv["cu_c"] != nil {
maxCPUCap := int64(resLimitsConv["cu_c"].(float64))
if maxCPUCap == 0 {
req.MaxCPUCapacity = -1
} else {
req.MaxCPUCapacity = maxCPUCap
}
}
if resLimitsConv["cu_i"] != nil {
maxNumPublicIP := int64(resLimitsConv["cu_i"].(float64))
if maxNumPublicIP == 0 {
req.MaxNumPublicIP = -1
} else {
req.MaxNumPublicIP = maxNumPublicIP
}
}
}
if owner, ok := d.GetOk("owner"); ok {
req.Owner = owner.(string)
}
if _, ok := d.GetOk("def_net"); !ok {
if defNetType, ok := d.GetOk("def_net_type"); ok {
if defNetType.(string) == "PRIVATE" {
return diag.Errorf("resourceResgroupCreate: cannot create RG with def_net_type=\"PRIVATE\": no ViNSes exist in a newly created RG. Use def_net_type=\"PRIVATE\" only when updating an existing RG that already contains a ViNS")
}
req.DefNet = defNetType.(string)
}
} else {
req.DefNet = "NONE"
}
if description, ok := d.GetOk("description"); ok {
req.Description = description.(string)
}
if extNetId, ok := d.GetOk("ext_net_id"); ok {
req.ExtNetID = uint64(extNetId.(int))
}
if extIp, ok := d.GetOk("ext_ip"); ok {
req.ExtIP = extIp.(string)
}
if uniqPools, ok := d.GetOk("uniq_pools"); ok {
uniqPools := uniqPools.([]interface{})
for _, pool := range uniqPools {
req.UniqPools = append(req.UniqPools, pool.(string))
}
}
if sdnAccessGroupID, ok := d.GetOk("sdn_access_group_id"); ok {
req.SDNAccessGroupID = sdnAccessGroupID.(string)
}
if storagePolicies, ok := d.GetOk("storage_policy"); ok {
var id uint64
var limit int
if storagePolicies.(*schema.Set).Len() > 0 {
spList := storagePolicies.(*schema.Set).List()
for _, spInterface := range spList {
sps := spInterface.(map[string]interface{})
id = uint64(sps["id"].(int))
limit = sps["limit"].(int)
spModel := rg.StoragePolicy{
ID: id,
Limit: limit,
}
req.StoragePolicies = append(req.StoragePolicies, spModel)
}
}
}
rgID, err := c.CloudBroker().RG().Create(ctx, req)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
d.SetId(strconv.FormatUint(rgID, 10))
d.Set("rg_id", rgID)
w := dc.Warnings{}
// compute_features is not set up during create request and is updated after create on purpose:
// 1. to support configuration as final state in resource group,
// 2. not to support compute_features inheritance from account.
// other implementation may result in inconsistency between user configuration and state after rg creation.
// note that call for compute features updated required even if compute_features is null in configuration, in order not ot inherit from account.
if err := resourceRGChangeComputeFeatures(ctx, d, m); err != nil {
w.Add(err)
}
if _, ok := d.GetOk("access"); ok {
if errs := resourceRGAccessGrant(ctx, d, m); len(errs) != 0 {
for _, err := range errs {
w.Add(err)
}
}
}
if defNet, ok := d.GetOk("def_net"); ok {
if defNet.(*schema.Set).Len() > 0 {
defNetList := defNet.(*schema.Set).List()
defNetItem := defNetList[0].(map[string]interface{})
if defNetItem["net_type"].(string) == "PRIVATE" {
return diag.Errorf("resourceResgroupCreate: cannot create RG with def_net net_type=\"PRIVATE\": no ViNSes exist in a newly created RG. Use net_type=\"PRIVATE\" in def_net block only when updating an existing RG that already contains a ViNS")
}
}
if err := resourceRGSetDefNet(ctx, d, m); err != nil {
w.Add(err)
}
}
if _, ok := d.GetOk("cpu_allocation_parameter"); ok {
if err := resourceRGSetCPUAllocationParameter(ctx, d, m); err != nil {
w.Add(err)
}
}
if _, ok := d.GetOk("cpu_allocation_ratio"); ok {
if err := resourceRGSetCPUAllocationRatio(ctx, d, m); err != nil {
w.Add(err)
}
}
enable, ok := d.GetOk("enable")
if ok && !enable.(bool) {
_, err := c.CloudBroker().RG().Disable(ctx, rg.DisableRequest{RGID: rgID})
if err != nil {
w.Add(err)
}
}
return append(resourceResgroupRead(ctx, d, m), w.Get()...)
}
func resourceResgroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceResgroupRead: called for RG name %s, account ID %d",
d.Get("rg_name").(string), d.Get("account_id").(int))
//c := m.(*controller.ControllerCfg)
rgData, err := utilityResgroupCheckPresence(ctx, d, m)
if err != nil {
d.SetId("") // ensure ID is empty
return diag.FromErr(err)
}
hasChanged := false
switch rgData.Status {
case status.Modeled:
return diag.Errorf("The resource group is in status: %s, please, contact support for more information", rgData.Status)
case status.Created:
case status.Enabled:
case status.Deleted:
//restoreReq := rg.RestoreRequest{
// RGID: rgData.ID,
// Reason: "automatic restore of resource by terraform",
//}
//enableReq := rg.EnableRequest{
// RGID: rgData.ID,
// Reason: "automatic enable of resource by terraform",
//}
//
//log.Debugf("restoring RG")
//_, err := c.CloudBroker().RG().Restore(ctx, restoreReq)
//if err != nil {
// return diag.FromErr(err)
//}
//
//log.Debugf("enabling RG")
//_, err = c.CloudBroker().RG().Enable(context.Background(), enableReq)
//if err != nil {
// return diag.FromErr(err)
//}
//
//hasChanged = true
case status.Deleting:
case status.Destroyed:
d.SetId("")
return diag.Errorf("The resource cannot be read because it has been destroyed")
//return resourceResgroupCreate(ctx, d, m)
case status.Destroying:
case status.Disabled:
case status.Disabling:
case status.Enabled:
case status.Enabling:
}
if hasChanged {
rgData, err = utilityResgroupCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
}
flattenResourceRG(d, rgData)
return nil
}
func resourceResgroupUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceResgroupUpdate: called for RG name %s, account ID %d",
d.Get("rg_name").(string), d.Get("account_id").(int))
c := m.(*controller.ControllerCfg)
accountId := uint64(d.Get("account_id").(int))
gid := uint64(d.Get("gid").(int))
if diags := checkParamsExistence(ctx, d, c, accountId, gid); diags != nil {
return diags
}
rgData, err := utilityResgroupCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
hasChanged := false
switch rgData.Status {
case status.Modeled:
case status.Created:
case status.Enabled:
case status.Deleted:
restore, ok := d.GetOk("restore")
if ok && restore.(bool) {
restoreReq := rg.RestoreRequest{
RGID: rgData.ID,
}
_, err := c.CloudBroker().RG().Restore(ctx, restoreReq)
if err != nil {
return diag.FromErr(err)
}
hasChanged = true
}
enable, ok := d.GetOk("enable")
if ok && enable.(bool) {
enableReq := rg.EnableRequest{
RGID: rgData.ID,
}
_, err = c.CloudBroker().RG().Enable(ctx, enableReq)
if err != nil {
return diag.FromErr(err)
}
hasChanged = true
}
case status.Deleting:
case status.Destroyed:
d.SetId("")
return diag.Errorf("The resource cannot be updated because it has been destroyed")
//return resourceResgroupCreate(ctx, d, m)
case status.Destroying:
case status.Disabled:
case status.Disabling:
case status.Enabled:
case status.Enabling:
}
if hasChanged {
rgData, err = utilityResgroupCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
}
/* NOTE: we do not allow changing the following attributes of an existing RG via terraform:
- def_net_type
- ext_net_id
- ext_ip
The following code fragment checks if any of these have been changed and generates error.
*/
for _, attr := range []string{"def_net_type", "ext_ip"} {
attrNew, attrOld := d.GetChange(attr)
if attrNew.(string) != attrOld.(string) {
return diag.FromErr(fmt.Errorf("resourceResgroupUpdate: RG ID %s: changing %s for existing RG is not allowed", d.Id(), attr))
}
}
attrNew, attrOld := d.GetChange("ext_net_id")
if attrNew.(int) != attrOld.(int) {
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,
}
if d.HasChange("rg_name") {
req.Name = d.Get("rg_name").(string)
doGeneralUpdate = true
}
if d.HasChange("resource_limits") {
if _, ok := d.GetOk("resource_limits"); ok {
resLimits := d.Get("resource_limits").([]interface{})[0]
resLimitsConv := resLimits.(map[string]interface{})
if resLimitsConv["cu_m"] != nil {
maxMemCap := int64(resLimitsConv["cu_m"].(float64))
if maxMemCap == 0 {
req.MaxMemoryCapacity = -1
} else {
req.MaxMemoryCapacity = maxMemCap
}
}
if resLimitsConv["cu_dm"] != nil {
maxDiskCap := int64(resLimitsConv["cu_dm"].(float64))
if maxDiskCap == 0 {
req.MaxVDiskCapacity = -1
} else {
req.MaxVDiskCapacity = maxDiskCap
}
}
if resLimitsConv["cu_c"] != nil {
maxCPUCap := int64(resLimitsConv["cu_c"].(float64))
if maxCPUCap == 0 {
req.MaxCPUCapacity = -1
} else {
req.MaxCPUCapacity = maxCPUCap
}
}
if resLimitsConv["cu_i"] != nil {
maxNumPublicIP := int64(resLimitsConv["cu_i"].(float64))
if maxNumPublicIP == 0 {
req.MaxNumPublicIP = -1
} else {
req.MaxNumPublicIP = maxNumPublicIP
}
}
doGeneralUpdate = true
}
}
if d.HasChange("description") {
req.Description = d.Get("description").(string)
doGeneralUpdate = true
}
if d.HasChange("storage_policy") {
needUpdate, updateEl, err := utilityRGUpdateStPolicy(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
if needUpdate {
// spList := storagePolicies.(*schema.Set).List()
var id uint64
var limit int
for _, spInterface := range updateEl {
// sps := spInterface.(map[string]interface{})
id = uint64(spInterface["id"].(int))
limit = spInterface["limit"].(int)
spModel := rg.StoragePolicy{
ID: id,
Limit: limit,
}
req.StoragePolicies = append(req.StoragePolicies, spModel)
}
doGeneralUpdate = needUpdate
}
}
if d.HasChange("uniq_pools") {
uniqPools := d.Get("uniq_pools").([]interface{})
if len(uniqPools) == 0 {
req.ClearUniqPools = true
}
for _, pool := range uniqPools {
req.UniqPools = append(req.UniqPools, pool.(string))
}
doGeneralUpdate = true
}
if doGeneralUpdate {
log.Debugf("resourceResgroupUpdate: detected delta between new and old RG specs - updating the RG")
_, err := c.CloudBroker().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")
}
if d.HasChange("access") {
if err := resourceRGChangeAccess(ctx, d, m); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("def_net") {
oldDefNet, newDefNet := d.GetChange("def_net")
if newDefNet.(*schema.Set).Len() > 0 {
defNetList := newDefNet.(*schema.Set).List()
defNetItem := defNetList[0].(map[string]interface{})
netType := defNetItem["net_type"].(string)
netID := uint64(defNetItem["net_id"].(int))
if netType == "PRIVATE" {
if netID == 0 {
if len(rgData.VINS) == 0 {
return diag.Errorf("resourceResgroupUpdate: cannot set def_net net_type=\"PRIVATE\" for RG ID %d: no ViNSes exist in this RG", rgData.ID)
}
} else {
found := false
for _, vinsID := range rgData.VINS {
if vinsID == netID {
found = true
break
}
}
if !found {
return diag.Errorf("resourceResgroupUpdate: cannot set def_net net_type=\"PRIVATE\" for RG ID %d: ViNS ID %d is not found in this RG", rgData.ID, netID)
}
}
}
}
if oldDefNet.(*schema.Set).Len() > 0 {
_, err := c.CloudBroker().RG().RemoveDefNet(ctx, rg.RemoveDefNetRequest{RGID: rgData.ID})
if err != nil {
return diag.FromErr(err)
}
}
if err := resourceRGSetDefNet(ctx, d, m); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("cpu_allocation_parameter") {
if err := resourceRGSetCPUAllocationParameter(ctx, d, m); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("cpu_allocation_ratio") {
if err := resourceRGSetCPUAllocationRatio(ctx, d, m); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("enable") {
if err := resourceRGChangeEnable(ctx, d, m); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("compute_features") {
if err := resourceRGChangeComputeFeatures(ctx, d, m); err != nil {
return diag.FromErr(err)
}
}
return resourceResgroupRead(ctx, d, m)
}
func resourceResgroupDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceResgroupDelete: called for RG name %s, account ID %d",
d.Get("rg_name").(string), d.Get("account_id").(int))
rg_facts, err := utilityResgroupCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
req := rg.DeleteRequest{
RGID: rg_facts.ID,
}
if force, ok := d.GetOk("force"); ok {
req.Force = force.(bool)
}
if permanently, ok := d.GetOk("permanently"); ok {
req.Permanently = permanently.(bool)
}
c := m.(*controller.ControllerCfg)
_, err = c.CloudBroker().RG().Delete(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId("")
return nil
}
func resourceRGAccessGrant(ctx context.Context, d *schema.ResourceData, m interface{}) []error {
var errs []error
access := d.Get("access")
rgId := uint64(d.Get("rg_id").(int))
log.Debugf("resourceRGAccessGrant: access %v for rg id %d", access, rgId)
c := m.(*controller.ControllerCfg)
var user, right string
if access.(*schema.Set).Len() > 0 {
accessList := access.(*schema.Set).List()
for _, accessIface := range accessList {
access := accessIface.(map[string]interface{})
user = access["user"].(string)
right = access["right"].(string)
req := rg.AccessGrantRequest{
RGID: rgId,
User: user,
Right: right,
}
if _, err := c.CloudBroker().RG().AccessGrant(ctx, req); err != nil {
errs = append(errs, err)
}
}
}
return errs
}
func resourceRGSetDefNet(ctx context.Context, d *schema.ResourceData, m interface{}) error {
defNet := d.Get("def_net")
rgId := uint64(d.Get("rg_id").(int))
log.Debugf("resourceRGSetDefNet: def_net %v for rg id %d", defNet, rgId)
c := m.(*controller.ControllerCfg)
if defNet.(*schema.Set).Len() > 0 {
defNetList := defNet.(*schema.Set).List()
defNetItem := defNetList[0].(map[string]interface{})
netType := defNetItem["net_type"].(string)
req := rg.SetDefNetRequest{
RGID: rgId,
NetType: netType,
}
if netID, ok := defNetItem["net_id"]; ok {
req.NetID = uint64(netID.(int))
}
_, err := c.CloudBroker().RG().SetDefNet(ctx, req)
return err
}
return nil
}
func resourceRGSetCPUAllocationParameter(ctx context.Context, d *schema.ResourceData, m interface{}) error {
cpuAllocationParameter := d.Get("cpu_allocation_parameter").(string)
log.Debugf("resourceRGSetCPUAllocationParameter: cpuAllocationParameter %s for rg id %d", cpuAllocationParameter, uint64(d.Get("rg_id").(int)))
c := m.(*controller.ControllerCfg)
req := rg.SetCPUAllocationParameterRequest{
RGID: uint64(d.Get("rg_id").(int)),
StrictLoose: cpuAllocationParameter,
}
_, err := c.CloudBroker().RG().SetCPUAllocationParameter(ctx, req)
return err
}
func resourceRGSetCPUAllocationRatio(ctx context.Context, d *schema.ResourceData, m interface{}) error {
cpuAllocationRatio := d.Get("cpu_allocation_ratio").(float64)
log.Debugf("resourceRGSetCPUAllocationRatio: cpuAllocationRatio %s for rg id %d", cpuAllocationRatio, uint64(d.Get("rg_id").(int)))
c := m.(*controller.ControllerCfg)
req := rg.SetCPUAllocationRatioRequest{
RGID: uint64(d.Get("rg_id").(int)),
Ratio: cpuAllocationRatio,
}
_, err := c.CloudBroker().RG().SetCPUAllocationRatio(ctx, req)
return err
}
func resourceRGChangeAccess(ctx context.Context, d *schema.ResourceData, m interface{}) error {
rgId := uint64(d.Get("rg_id").(int))
log.Debugf("resourceRGChangeAccess: for rg id %d", rgId)
c := m.(*controller.ControllerCfg)
oldSet, newSet := d.GetChange("access")
deletedAccess := oldSet.(*schema.Set).Difference(newSet.(*schema.Set)).List()
for _, deletedIface := range deletedAccess {
deleteItem := deletedIface.(map[string]interface{})
user := deleteItem["user"].(string)
reqRevoke := rg.AccessRevokeRequest{
RGID: rgId,
User: user,
}
_, err := c.CloudBroker().RG().AccessRevoke(ctx, reqRevoke)
if err != nil {
return err
}
}
addedAccess := newSet.(*schema.Set).Difference(oldSet.(*schema.Set)).List()
for _, addedIface := range addedAccess {
addedItem := addedIface.(map[string]interface{})
user := addedItem["user"].(string)
right := addedItem["right"].(string)
reqGrant := rg.AccessGrantRequest{
RGID: rgId,
User: user,
Right: right,
}
_, err := c.CloudBroker().RG().AccessGrant(ctx, reqGrant)
if err != nil {
return err
}
}
return nil
}
func resourceRGChangeEnable(ctx context.Context, d *schema.ResourceData, m interface{}) error {
rgId := uint64(d.Get("rg_id").(int))
rgStatus := d.Get("status").(string)
enable := d.Get("enable").(bool)
log.Debugf("resourceRGChangeEnable: enable %t for rg id %d with status %s", enable, rgId, rgStatus)
c := m.(*controller.ControllerCfg)
if enable && rgStatus == status.Disabled {
if _, err := c.CloudBroker().RG().Enable(ctx, rg.EnableRequest{RGID: rgId}); err != nil {
return err
}
} else if !enable && (rgStatus == status.Enabled || rgStatus == status.Created) {
req := rg.DisableRequest{RGID: rgId}
if _, err := c.CloudBroker().RG().Disable(ctx, req); err != nil {
return err
}
}
return nil
}
func resourceRGChangeComputeFeatures(ctx context.Context, d *schema.ResourceData, m interface{}) error {
rgId := uint64(d.Get("rg_id").(int))
compFeaturesInterface := d.Get("compute_features").(*schema.Set).List()
compFeatures := make([]string, 0, len(compFeaturesInterface))
for _, item := range compFeaturesInterface {
compFeatures = append(compFeatures, item.(string))
}
log.Debugf("resourceRGChangeComputeFeatures: compute_features %v for rg id %d", compFeatures, rgId)
c := m.(*controller.ControllerCfg)
req := rg.UpdateComputeFeaturesRequest{
RGID: rgId,
ComputeFeatures: compFeatures,
}
_, err := c.CloudBroker().RG().UpdateComputeFeatures(ctx, req)
if err != nil {
return err
}
return nil
}
func ResourceResgroup() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
CreateContext: resourceResgroupCreate,
ReadContext: resourceResgroupRead,
UpdateContext: resourceResgroupUpdate,
DeleteContext: resourceResgroupDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
CustomizeDiff: func(ctx context.Context, diff *schema.ResourceDiff, i interface{}) error {
if diff.HasChange("def_net") {
diff.SetNewComputed("def_net_id")
}
if diff.HasChange("storage_policy") {
diff.SetNewComputed("storage_policy_ids")
diff.SetNewComputed("resource_limits")
}
if diff.HasChanges() {
diff.SetNewComputed("updated_by")
diff.SetNewComputed("updated_time")
}
return nil
},
Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout600s,
Read: &constants.Timeout300s,
Update: &constants.Timeout600s,
Delete: &constants.Timeout900s,
Default: &constants.Timeout300s,
},
Schema: resourceRgSchemaMake(),
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,150 +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>
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"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityResgroupCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.RecordRG, error) {
c := m.(*controller.ControllerCfg)
req := rg.GetRequest{}
if d.Id() != "" {
rgId, _ := strconv.ParseUint(d.Id(), 10, 64)
req.RGID = rgId
} else {
req.RGID = uint64(d.Get("rg_id").(int))
}
rgData, err := c.CloudBroker().RG().Get(ctx, req)
if err != nil {
return nil, err
}
return rgData, nil
}
func utilityRGUpdateStPolicy(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, []map[string]interface{}, error) {
c := m.(*controller.ControllerCfg)
rgId, _ := strconv.ParseUint(d.Id(), 10, 64)
addSP, delSP, updateSP := utilityGetStoragePolicyUpdate(ctx, d, m)
needUpdate := len(updateSP) > 0
if len(addSP) > 0 {
for _, spMap := range addSP {
req := rg.AddStoragePolicyRequest{
RGID: rgId,
StoragePolicyID: uint64(spMap["id"].(int)),
Limit: spMap["limit"].(int),
}
log.Debugf("utilityRGUpdateStPolicy: starting to add storage policy ID:%d for rg %d", req.StoragePolicyID, req.RGID)
_, err := c.CloudBroker().RG().AddStoragePolicy(ctx, req)
if err != nil {
return needUpdate, updateSP, err
}
}
}
if len(delSP) > 0 {
for _, spMap := range delSP {
req := rg.DelStoragePolicyRequest{
RGID: rgId,
StoragePolicyID: uint64(spMap["id"].(int)),
}
log.Debugf("utilityRGUpdateStPolicy: starting to delete storage policy ID:%d from rg %d", req.StoragePolicyID, req.RGID)
_, err := c.CloudBroker().RG().DelStoragePolicy(ctx, req)
if err != nil {
return needUpdate, updateSP, err
}
}
}
return needUpdate, updateSP, nil
}
func utilityGetStoragePolicyUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) (added, deleted, updated []map[string]interface{}) {
added = make([]map[string]interface{}, 0)
deleted = make([]map[string]interface{}, 0)
updated = make([]map[string]interface{}, 0)
oldSet, newSet := d.GetChange("storage_policy")
oldList := oldSet.(*schema.Set).List()
newList := newSet.(*schema.Set).List()
for _, oldSP := range oldList {
oldMap := oldSP.(map[string]interface{})
found := false
for _, newSP := range newList {
newMap := newSP.(map[string]interface{})
if oldMap["id"] == newMap["id"] {
found = true
if oldMap["limit"] != newMap["limit"] {
updated = append(added, newMap)
}
break
}
if found {
break
}
}
if found {
continue
}
deleted = append(deleted, oldMap)
}
for _, newSP := range newList {
newMap := newSP.(map[string]interface{})
found := false
for _, oldSP := range oldList {
oldMap := oldSP.(map[string]interface{})
if oldMap["id"] == newMap["id"] {
found = true
break
}
}
if found {
continue
}
added = append(added, newMap)
}
return
}

View File

@@ -1,27 +0,0 @@
package rg
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityRgAffinityGroupComputesCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (rg.ListAffinityGroupCompute, error) {
c := m.(*controller.ControllerCfg)
req := rg.AffinityGroupComputesRequest{
RGID: uint64(d.Get("rg_id").(int)),
AffinityGroup: d.Get("affinity_group").(string),
}
log.Debugf("utilityRgAffinityGroupComputesCheckPresence: load affinity group computes")
res, err := c.CloudBroker().RG().AffinityGroupComputes(ctx, req)
if err != nil {
return nil, err
}
return res, nil
}

View File

@@ -1,26 +0,0 @@
package rg
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityRgAffinityGroupsGetCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) ([]uint64, error) {
c := m.(*controller.ControllerCfg)
req := rg.AffinityGroupsGetRequest{
RGID: uint64(d.Get("rg_id").(int)),
AffinityGroup: d.Get("affinity_group").(string),
}
log.Debugf("utilityRgAffinityGroupsGetCheckPresence: load computes in the specified affinity group")
computes, err := c.CloudBroker().RG().AffinityGroupsGet(ctx, req)
if err != nil {
return nil, err
}
return computes, nil
}

View File

@@ -1,55 +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 rg
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityRgAffinityGroupsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListAffinityGroup, error) {
c := m.(*controller.ControllerCfg)
req := rg.AffinityGroupsListRequest{
RGID: uint64(d.Get("rg_id").(int)),
}
groups, err := c.CloudBroker().RG().AffinityGroupsList(ctx, req)
if err != nil {
return nil, err
}
return groups, nil
}

View File

@@ -1,25 +0,0 @@
package rg
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityRgAuditsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (rg.ListAudits, error) {
c := m.(*controller.ControllerCfg)
req := rg.AuditsRequest{
RGID: uint64(d.Get("rg_id").(int)),
}
log.Debugf("utilityRgAuditsCheckPresence: load rg audits")
rgAudits, err := c.CloudBroker().RG().Audits(ctx, req)
if err != nil {
return nil, err
}
return rgAudits, nil
}

View File

@@ -1,58 +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 rg
import (
"context"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityRGResourceConsumptionGetCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ItemResourceConsumption, error) {
c := m.(*controller.ControllerCfg)
req := rg.GetResourceConsumptionRequest{
RGID: uint64(d.Get("rg_id").(int)),
}
log.Debugf("utilityRGResourceConsumptionGetCheckPresence: load")
accountResourceConsumptionRec, err := c.CloudBroker().RG().GetResourceConsumption(ctx, req)
if err != nil {
return nil, err
}
return accountResourceConsumptionRec, nil
}

View File

@@ -1,94 +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>
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/cloudbroker/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.ListRG, 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 includedeleted, ok := d.GetOk("includedeleted"); ok {
req.IncludeDeleted = includedeleted.(bool)
}
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))
}
log.Debugf("utilityRgListCheckPresence: load rg list")
rgList, err := c.CloudBroker().RG().List(ctx, req)
if err != nil {
return nil, err
}
return rgList, nil
}

View File

@@ -1,99 +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 rg
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityRgListComputesCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListComputes, error) {
c := m.(*controller.ControllerCfg)
req := rg.ListComputesRequest{
RGID: uint64(d.Get("rg_id").(int)),
}
if compute_id, ok := d.GetOk("compute_id"); ok {
req.ComputeID = uint64(compute_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if account_id, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(account_id.(int))
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if tech_status, ok := d.GetOk("tech_status"); ok {
req.TechStatus = tech_status.(string)
}
if ip_address, ok := d.GetOk("ip_address"); ok {
req.IPAddress = ip_address.(string)
}
if extnet_name, ok := d.GetOk("extnet_name"); ok {
req.ExtNetName = extnet_name.(string)
}
if extnet_id, ok := d.GetOk("extnet_id"); ok {
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))
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
listComputes, err := c.CloudBroker().RG().ListComputes(ctx, req)
if err != nil {
return nil, err
}
return listComputes, nil
}

View File

@@ -1,92 +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 rg
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityRgListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListRG, error) {
c := m.(*controller.ControllerCfg)
req := rg.ListDeletedRequest{}
if by_id, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(by_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if account_id, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(account_id.(int))
}
if account_name, ok := d.GetOk("account_name"); ok {
req.AccountName = account_name.(string)
}
if created_after, ok := d.GetOk("created_after"); ok {
req.CreatedAfter = uint64(created_after.(int))
}
if created_before, ok := d.GetOk("created_before"); ok {
req.CreatedBefore = uint64(created_before.(int))
}
if lock_status, ok := d.GetOk("lock_status"); ok {
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))
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
rgList, err := c.CloudBroker().RG().ListDeleted(ctx, req)
if err != nil {
return nil, err
}
return rgList, nil
}

View File

@@ -1,91 +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 rg
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityRgListLbCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListLB, error) {
c := m.(*controller.ControllerCfg)
req := rg.ListLBRequest{
RGID: uint64(d.Get("rg_id").(int)),
}
if by_id, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(by_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if tech_status, ok := d.GetOk("tech_status"); ok {
req.TechStatus = tech_status.(string)
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if front_ip, ok := d.GetOk("front_ip"); ok {
req.FrontIP = front_ip.(string)
}
if back_ip, ok := d.GetOk("back_ip"); ok {
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))
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
listLb, err := c.CloudBroker().RG().ListLB(ctx, req)
if err != nil {
return nil, err
}
return listLb, nil
}

View File

@@ -1,55 +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 rg
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityRgListPfwCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListPFW, error) {
c := m.(*controller.ControllerCfg)
req := rg.ListPFWRequest{
RGID: uint64(d.Get("rg_id").(int)),
}
listPfw, err := c.CloudBroker().RG().ListPFW(ctx, req)
if err != nil {
return nil, err
}
return listPfw, nil
}

View File

@@ -1,83 +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 rg
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityRgListVinsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListVINS, error) {
c := m.(*controller.ControllerCfg)
req := rg.ListVINSRequest{
RGID: uint64(d.Get("rg_id").(int)),
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if account_id, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(account_id.(int))
}
if ext_ip, ok := d.GetOk("ext_ip"); ok {
req.ExtIP = ext_ip.(string)
}
if vins_id, ok := d.GetOk("vins_id"); ok {
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))
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
listVins, err := c.CloudBroker().RG().ListVINS(ctx, req)
if err != nil {
return nil, err
}
return listVins, nil
}

View File

@@ -1,55 +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 rg
import (
"context"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityRGResourceConsumptionListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListResourceConsumption, error) {
c := m.(*controller.ControllerCfg)
log.Debugf("utilityRGResourceConsumptionListCheckPresence: load")
rgResourceConsumptionList, err := c.CloudBroker().RG().ListResourceConsumption(ctx)
if err != nil {
return nil, err
}
return rgResourceConsumptionList, nil
}

View File

@@ -1,55 +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 rg
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityDataRgUsageCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.Reservation, error) {
c := m.(*controller.ControllerCfg)
req := rg.UsageRequest{
RGID: uint64(d.Get("rg_id").(int)),
}
usage, err := c.CloudBroker().RG().Usage(ctx, req)
if err != nil {
return nil, err
}
return usage, nil
}