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,142 +0,0 @@
/*
Copyright (c) 2019-2023 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>
Tim Tkachev, <tvtkachev@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 k8s
import (
"context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8s"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func dataSourceK8sRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("dataSourceK8sRead: called with k8s id %d", d.Get("k8s_id").(int))
cluster, err := utilityK8sCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
d.SetId(strconv.FormatUint(cluster.ID, 10))
k8sList, err := utilityK8sListCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
curK8s := k8s.ItemK8S{}
for _, k8sCluster := range k8sList.Data {
if k8sCluster.ID == cluster.ID {
curK8s = k8sCluster
}
}
if curK8s.ID == 0 {
return diag.Errorf("Cluster with id %d not found in List clusters", cluster.ID)
}
d.Set("desc", curK8s.Description)
d.Set("gid", curK8s.GID)
d.Set("guid", curK8s.GUID)
d.Set("milestones", curK8s.Milestones)
d.Set("service_account", flattenServiceAccount(curK8s.ServiceAccount))
d.Set("ssh_key", curK8s.SSHKey)
d.Set("vins_id", curK8s.VINSID)
masterComputeList := make([]compute.RecordCompute, 0, len(cluster.K8SGroups.Masters.DetailedInfo))
workersComputeList := make([]compute.RecordCompute, 0, len(cluster.K8SGroups.Workers))
for _, masterNode := range cluster.K8SGroups.Masters.DetailedInfo {
compute, err := utilityComputeCheckPresence(ctx, d, m, masterNode.ID)
if err != nil {
return diag.FromErr(err)
}
masterComputeList = append(masterComputeList, *compute)
}
for _, worker := range cluster.K8SGroups.Workers {
for _, info := range worker.DetailedInfo {
compute, err := utilityComputeCheckPresence(ctx, d, m, info.ID)
if err != nil {
return diag.FromErr(err)
}
workersComputeList = append(workersComputeList, *compute)
}
}
c := m.(*controller.ControllerCfg)
getConfigReq := k8s.GetConfigRequest{K8SID: cluster.ID}
kubeconfig, err := c.CloudBroker().K8S().GetConfig(ctx, getConfigReq)
if err != nil {
log.Warnf("could not get kubeconfig: %v", err)
}
d.Set("kubeconfig", kubeconfig)
if cluster.LBID != 0 {
getLbReq := lb.GetRequest{LBID: cluster.LBID}
lb, err := c.CloudBroker().LB().Get(ctx, getLbReq)
if err != nil {
return diag.FromErr(err)
}
d.Set("extnet_id", lb.ExtNetID)
d.Set("lb_ip", lb.PrimaryNode.FrontendIP)
}
flattenK8sData(d, cluster, masterComputeList, workersComputeList)
return nil
}
func DataSourceK8s() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceK8sRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceK8sSchemaMake(),
}
}

View File

@@ -1,73 +0,0 @@
/*
Copyright (c) 2019-2023 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>
Tim Tkachev, <tvtkachev@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 k8s
import (
"context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func dataSourceK8sComputesRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("dataSourceK8sComputesRead: called with k8s id %d", d.Get("k8s_id").(int))
cluster, err := utilityK8sCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
d.SetId(strconv.FormatUint(cluster.ID, 10))
flattenK8sDataComputes(d, cluster)
return nil
}
func DataSourceK8sComputes() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceK8sComputesRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout60s,
Default: &constants.Timeout60s,
},
Schema: dataSourceK8sComputesSchemaMake(),
}
}

View File

@@ -1,75 +0,0 @@
/*
Copyright (c) 2019-2023 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>
Tim Tkachev, <tvtkachev@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 k8s
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func dataSourceK8sListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debug("dataSourceK8sListRead starting")
list, err := utilityK8sListCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenK8sItems(list))
d.Set("entry_count", list.EntryCount)
return nil
}
func DataSourceK8sList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceK8sListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceK8sListSchemaMake(),
}
}

View File

@@ -1,75 +0,0 @@
/*
Copyright (c) 2019-2023 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>
Tim Tkachev, <tvtkachev@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 k8s
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func dataSourceK8sListDeletedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debug("dataSourceK8sListDeletedRead starting")
list, err := utilityK8sListDeletedCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenK8sItems(list))
d.Set("entry_count", list.EntryCount)
return nil
}
func DataSourceK8sListDeleted() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceK8sListDeletedRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceK8sListDeletedSchemaMake(),
}
}

View File

@@ -1,73 +0,0 @@
/*
Copyright (c) 2019-2023 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 k8s
import (
"context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func dataSourceK8sWgRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("dataSourceK8sWgRead: called with k8s id %d", d.Get("k8s_id").(int))
wg, workersComputeList, err := utilityDataK8sWgCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
d.SetId(strconv.FormatUint(wg.ID, 10))
flattenWg(d, wg, workersComputeList)
return nil
}
func DataSourceK8sWg() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceK8sWgRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceK8sWgSchemaMake(),
}
}

View File

@@ -1,74 +0,0 @@
/*
Copyright (c) 2019-2023 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 k8s
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func dataSourceK8sWgCloudInitRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("dataSourceK8sWgCloudInitRead: called with k8s id %d and wg id %d", d.Get("k8s_id").(int), d.Get("wg_id").(int))
metaData, err := utilityK8sWgCloudInitCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("cloud_init", metaData)
return nil
}
func DataSourceK8sWgCloudInit() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceK8sWgCloudInitRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceK8sWgCloudInitSchemaMake(),
}
}

View File

@@ -1,85 +0,0 @@
/*
Copyright (c) 2019-2023 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 k8s
import (
"context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func dataSourceK8sWgListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("dataSourceK8sWgListRead: called with k8s id %d and wg id %d", d.Get("k8s_id").(int), d.Get("wg_id").(int))
wgList, err := utilityK8sWgListCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
d.SetId(strconv.Itoa(d.Get("k8s_id").(int)))
workersComputeList := make(map[uint64][]compute.RecordCompute)
for _, worker := range *wgList {
workersComputeList[worker.ID] = make([]compute.RecordCompute, 0, len(worker.DetailedInfo))
for _, info := range worker.DetailedInfo {
compute, err := utilityComputeCheckPresence(ctx, d, m, info.ID)
if err != nil {
return diag.FromErr(err)
}
workersComputeList[worker.ID] = append(workersComputeList[worker.ID], *compute)
}
}
flattenItemsWg(d, *wgList, workersComputeList)
return nil
}
func DataSourceK8sWgList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceK8sWgListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceK8sWgListSchemaMake(),
}
}

View File

@@ -1,419 +0,0 @@
/*
Copyright (c) 2019-2023 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 k8s
import (
"encoding/json"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8s"
)
func flattenResourceK8sCP(d *schema.ResourceData, k8s k8s.RecordK8S, masters []compute.RecordCompute) {
d.Set("acl", flattenAcl(k8s.ACL))
d.Set("account_id", k8s.AccountID)
d.Set("account_name", k8s.AccountName)
d.Set("k8sci_id", k8s.CIID)
d.Set("bservice_id", k8s.BServiceID)
d.Set("created_by", k8s.CreatedBy)
d.Set("created_time", k8s.CreatedTime)
d.Set("desc", k8s.Description)
d.Set("deleted_by", k8s.DeletedBy)
d.Set("deleted_time", k8s.DeletedTime)
d.Set("k8s_ci_name", k8s.K8CIName)
d.Set("with_lb", k8s.LBID != 0)
d.Set("lb_id", k8s.LBID)
d.Set("k8s_id", k8s.ID)
d.Set("name", k8s.Name)
d.Set("rg_id", k8s.RGID)
d.Set("rg_name", k8s.RGName)
d.Set("status", k8s.Status)
d.Set("tech_status", k8s.TechStatus)
d.Set("updated_by", k8s.UpdatedBy)
d.Set("updated_time", k8s.UpdatedTime)
d.Set("network_plugin", k8s.NetworkPlugin)
d.Set("highly_available_lb", k8s.HighlyAvailableLB)
d.Set("address_vip", flattenAddressVIP(k8s.AddressVIP))
d.Set("extnet_only", k8s.ExtnetOnly)
d.Set("zone_id", k8s.ZoneID)
flattenCPParams(d, k8s.K8SGroups.Masters, masters)
}
func flattenCPParams(d *schema.ResourceData, mastersGroup k8s.MasterGroup, masters []compute.RecordCompute) {
d.Set("cpu", mastersGroup.CPU)
d.Set("detailed_info", flattenDetailedInfo(mastersGroup.DetailedInfo, masters))
d.Set("disk", mastersGroup.Disk)
d.Set("master_id", mastersGroup.ID)
d.Set("master_name", mastersGroup.Name)
d.Set("num", mastersGroup.Num)
d.Set("ram", mastersGroup.RAM)
}
func flattenK8sData(d *schema.ResourceData, cluster *k8s.RecordK8S, masters []compute.RecordCompute, workers []compute.RecordCompute) {
d.Set("acl", flattenAcl(cluster.ACL))
d.Set("account_id", cluster.AccountID)
d.Set("account_name", cluster.AccountName)
d.Set("bservice_id", cluster.BServiceID)
d.Set("k8sci_id", cluster.CIID)
d.Set("created_by", cluster.CreatedBy)
d.Set("created_time", cluster.CreatedTime)
d.Set("deleted_by", cluster.DeletedBy)
d.Set("deleted_time", cluster.DeletedTime)
d.Set("desc", cluster.Description)
d.Set("k8s_id", cluster.ID)
d.Set("k8s_ci_name", cluster.K8CIName)
d.Set("k8s_groups", flattenK8sGroups(cluster.K8SGroups, masters, workers))
d.Set("lb_id", cluster.LBID)
d.Set("network_plugin", cluster.NetworkPlugin)
d.Set("name", cluster.Name)
d.Set("rg_id", cluster.RGID)
d.Set("rg_name", cluster.RGName)
d.Set("status", cluster.Status)
d.Set("tech_status", cluster.TechStatus)
d.Set("updated_by", cluster.UpdatedBy)
d.Set("updated_time", cluster.UpdatedTime)
d.Set("highly_available_lb", cluster.HighlyAvailableLB)
d.Set("address_vip", flattenAddressVIP(cluster.AddressVIP))
d.Set("extnet_only", cluster.ExtnetOnly)
d.Set("with_lb", cluster.WithLB)
d.Set("zone_id", cluster.ZoneID)
}
func flattenAddressVIP(addressVIP k8s.K8SAddressVIP) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"backend_ip": addressVIP.BackendIP,
"frontend_ip": addressVIP.FrontendIP,
}
res = append(res, temp)
return res
}
func flattenAcl(acl k8s.RecordACLGroup) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"account_acl": flattenAclList(acl.AccountACL),
"k8s_acl": flattenAclList(acl.K8SACL),
"rg_acl": flattenAclList(acl.RGACL),
}
res = append(res, temp)
return res
}
func flattenAclList(aclList k8s.ListACL) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(aclList))
for _, acl := range aclList {
temp := map[string]interface{}{
"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 flattenK8sGroups(k8sGroups k8s.RecordK8SGroups, masters []compute.RecordCompute, workers []compute.RecordCompute) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"masters": flattenMasterGroup(k8sGroups.Masters, masters),
"workers": flattenWorkerGroup(k8sGroups.Workers, workers),
}
res = append(res, temp)
return res
}
func flattenMasterGroup(mastersGroup k8s.MasterGroup, masters []compute.RecordCompute) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"cpu": mastersGroup.CPU,
"detailed_info": flattenDetailedInfo(mastersGroup.DetailedInfo, masters),
"disk": mastersGroup.Disk,
"master_id": mastersGroup.ID,
"name": mastersGroup.Name,
"num": mastersGroup.Num,
"ram": mastersGroup.RAM,
}
res = append(res, temp)
return res
}
func flattenDetailedInfo(detailedInfoList k8s.ListDetailedInfo, computes []compute.RecordCompute) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(detailedInfoList))
if computes != nil {
for i, detailedInfo := range detailedInfoList {
temp := map[string]interface{}{
"external_ip": detailedInfo.ExternalIp,
"compute_id": detailedInfo.ID,
"name": detailedInfo.Name,
"status": detailedInfo.Status,
"tech_status": detailedInfo.TechStatus,
"interfaces": flattenInterfaces(computes[i].Interfaces),
}
res = append(res, temp)
}
} else {
for _, detailedInfo := range detailedInfoList {
temp := map[string]interface{}{
"external_ip": detailedInfo.ExternalIp,
"compute_id": detailedInfo.ID,
"name": detailedInfo.Name,
"status": detailedInfo.Status,
"tech_status": detailedInfo.TechStatus,
}
res = append(res, temp)
}
}
return res
}
func flattenInterfaces(interfaces compute.ListInterfaces) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(interfaces))
for _, interfaceCompute := range interfaces {
temp := map[string]interface{}{
"def_gw": interfaceCompute.DefGW,
"ip_address": interfaceCompute.IPAddress,
}
res = append(res, temp)
}
return res
}
func flattenWorkerGroup(k8SGroupList k8s.ListK8SGroup, workers []compute.RecordCompute) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(k8SGroupList))
for _, k8sGroup := range k8SGroupList {
labels := make([]string, 0)
for _, label := range k8sGroup.Labels {
if strings.HasPrefix(label, "workersGroupName") {
continue
}
labels = append(labels, label)
}
temp := map[string]interface{}{
"annotations": k8sGroup.Annotations,
"cpu": k8sGroup.CPU,
"detailed_info": flattenDetailedInfo(k8sGroup.DetailedInfo, workers),
"disk": k8sGroup.Disk,
"guid": k8sGroup.GUID,
"id": k8sGroup.ID,
"labels": labels,
"name": k8sGroup.Name,
"num": k8sGroup.Num,
"ram": k8sGroup.RAM,
"taints": k8sGroup.Taints,
}
res = append(res, temp)
}
return res
}
func flattenServiceAccount(sa k8s.ServiceAccount) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"guid": sa.GUID,
"password": sa.Password,
"username": sa.Username,
}
res = append(res, temp)
return res
}
func flattenK8sItems(k8sList *k8s.ListK8S) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(k8sList.Data))
for _, item := range k8sList.Data {
aclStrArray := make([]string, 0, len(item.ACL))
for _, acl := range item.ACL {
aclStrArray = append(aclStrArray, acl.(string))
}
data, _ := json.Marshal(item.Config)
temp := map[string]interface{}{
"account_id": item.AccountID,
"account_name": item.Name,
"acl": aclStrArray,
"bservice_id": item.BServiceID,
"k8sci_id": item.CIID,
"kubeconfig": string(data),
"created_by": item.CreatedBy,
"created_time": item.CreatedTime,
"deleted_by": item.DeletedBy,
"deleted_time": item.DeletedTime,
"desc": item.Description,
"extnet_id": item.ExtNetID,
"gid": item.GID,
"guid": item.GUID,
"k8s_id": item.ID,
"lb_id": item.LBID,
"milestones": item.Milestones,
"k8s_name": item.Name,
"network_plugin": item.NetworkPlugin,
"rg_id": item.RGID,
"rg_name": item.RGName,
"service_account": flattenServiceAccount(item.ServiceAccount),
"ssh_key": item.SSHKey,
"status": item.Status,
"tech_status": item.TechStatus,
"updated_by": item.UpdatedBy,
"updated_time": item.UpdatedTime,
"vins_id": item.VINSID,
"zone_id": item.ZoneID,
"workers_groups": flattenWorkersGroupList(item.WorkersGroup),
}
res = append(res, temp)
}
return res
}
func flattenWorkersGroupList(k8SGroupList k8s.ListK8SGroup) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(k8SGroupList))
for _, k8sGroup := range k8SGroupList {
labels := make([]string, 0)
for _, label := range k8sGroup.Labels {
if strings.HasPrefix(label, "workersGroupName") {
continue
}
labels = append(labels, label)
}
temp := map[string]interface{}{
"annotations": k8sGroup.Annotations,
"guid": k8sGroup.GUID,
"id": k8sGroup.ID,
"labels": labels,
"taints": k8sGroup.Taints,
}
res = append(res, temp)
}
return res
}
func flattenK8sDataComputes(d *schema.ResourceData, cluster *k8s.RecordK8S) {
d.Set("k8s_id", cluster.ID)
d.Set("masters", flattenMasterComputes(cluster))
d.Set("workers", flattenWorkerComputes(cluster))
}
func flattenMasterComputes(cluster *k8s.RecordK8S) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(cluster.K8SGroups.Masters.DetailedInfo))
for _, comp := range cluster.K8SGroups.Masters.DetailedInfo {
temp := map[string]interface{}{
"id": comp.ID,
"name": comp.Name,
"status": comp.Status,
"tech_status": comp.TechStatus,
"group_name": cluster.K8SGroups.Masters.Name,
}
res = append(res, temp)
}
return res
}
func flattenWorkerComputes(cluster *k8s.RecordK8S) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(cluster.K8SGroups.Workers))
for _, wg := range cluster.K8SGroups.Workers {
for _, comp := range wg.DetailedInfo {
temp := map[string]interface{}{
"id": comp.ID,
"name": comp.Name,
"status": comp.Status,
"tech_status": comp.TechStatus,
"group_name": wg.Name,
}
res = append(res, temp)
}
}
return res
}
func flattenItemsWg(d *schema.ResourceData, wgList k8s.ListK8SGroup, computes map[uint64][]compute.RecordCompute) {
d.Set("items", flattenWgList(wgList, computes))
}
func flattenWgList(wgList k8s.ListK8SGroup, computesMap map[uint64][]compute.RecordCompute) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, wg := range wgList {
computes := computesMap[wg.ID]
temp := map[string]interface{}{
"annotations": wg.Annotations,
"cpu": wg.CPU,
"wg_id": wg.ID,
"detailed_info": flattenDetailedInfo(wg.DetailedInfo, computes),
"disk": wg.Disk,
"guid": wg.GUID,
"labels": wg.Labels,
"name": wg.Name,
"num": wg.Num,
"ram": wg.RAM,
"taints": wg.Taints,
}
res = append(res, temp)
}
return res
}
func flattenWg(d *schema.ResourceData, wg *k8s.RecordK8SGroup, computes []compute.RecordCompute) {
labels := make([]string, 0)
for _, label := range wg.Labels {
if strings.HasPrefix(label, "workersGroupName") {
continue
}
labels = append(labels, label)
}
d.Set("annotations", wg.Annotations)
d.Set("cpu", wg.CPU)
d.Set("detailed_info", flattenDetailedInfo(wg.DetailedInfo, computes))
d.Set("disk", wg.Disk)
d.Set("guid", wg.GUID)
d.Set("labels", labels)
d.Set("name", wg.Name)
d.Set("num", wg.Num)
d.Set("ram", wg.RAM)
d.Set("taints", wg.Taints)
}

View File

@@ -1,76 +0,0 @@
/*
Copyright (c) 2019-2023 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>
Tim Tkachev, <tvtkachev@basistech.ru>
Sergey Kisil, <svkisil@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 k8s
import (
"context"
"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/diag"
"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) diag.Diagnostics {
var errs []error
rgid := uint64(d.Get("rg_id").(int))
k8ciId := uint64(d.Get("k8sci_id").(int))
extNetId := uint64(d.Get("extnet_id").(int))
vinsId := uint64(d.Get("vins_id").(int))
if err := ic.ExistRG(ctx, rgid, c); err != nil {
errs = append(errs, err)
}
if err := ic.ExistK8CI(ctx, k8ciId, c); err != nil {
errs = append(errs, err)
}
if _, ok := d.GetOk("extnet_id"); ok {
if err := ic.ExistExtNetInK8s(ctx, extNetId, c); err != nil {
errs = append(errs, err)
}
}
if _, ok := d.GetOk("vins_id"); ok {
if err := ic.ExistVinsInK8s(ctx, vinsId, c); err != nil {
errs = append(errs, err)
}
}
return dc.ErrorsToDiagnostics(errs)
}

View File

@@ -1,667 +0,0 @@
/*
Copyright (c) 2019-2023 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>
Tim Tkachev, <tvtkachev@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 k8s
import (
"context"
"fmt"
"strconv"
"strings"
"time"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8s"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/tasks"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
)
func resourceK8sCPCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceK8sControlPlaneCreate: called with name %s, rg %d", d.Get("name").(string), d.Get("rg_id").(int))
c := m.(*controller.ControllerCfg)
if diags := checkParamsExistence(ctx, d, c); diags != nil {
return diags
}
createReq := k8s.CreateRequest{
Name: d.Get("name").(string),
RGID: uint64(d.Get("rg_id").(int)),
K8CIID: uint64(d.Get("k8sci_id").(int)),
WorkerGroupName: "temp",
NetworkPlugin: d.Get("network_plugin").(string),
StoragePolicyID: uint64(d.Get("storage_policy_id").(int)),
}
if num, ok := d.GetOk("num"); ok {
createReq.MasterNum = uint64(num.(int))
} else {
createReq.MasterNum = 1
}
if cpu, ok := d.GetOk("cpu"); ok {
createReq.MasterCPU = uint64(cpu.(int))
} else {
createReq.MasterCPU = 2
}
if ram, ok := d.GetOk("ram"); ok {
createReq.MasterRAM = uint64(ram.(int))
} else {
createReq.MasterRAM = 2048
}
if disk, ok := d.GetOk("disk"); ok {
createReq.MasterDisk = uint64(disk.(int))
} else {
createReq.MasterDisk = 0
}
if sepId, ok := d.GetOk("sep_id"); ok {
createReq.MasterSEPID = uint64(sepId.(int))
}
if sepPool, ok := d.GetOk("sep_pool"); ok {
createReq.MasterSEPPool = sepPool.(string)
}
if withLB, ok := d.GetOk("with_lb"); ok {
createReq.WithLB = withLB.(bool)
} else {
createReq.WithLB = true
}
if extNet, ok := d.GetOk("extnet_id"); ok {
createReq.ExtNetID = uint64(extNet.(int))
} else {
createReq.ExtNetID = 0
}
if zoneID, ok := d.GetOk("zone_id"); ok {
createReq.ZoneID = uint64(zoneID.(int))
}
if vins, ok := d.GetOk("vins_id"); ok {
createReq.VinsId = uint64(vins.(int))
} else {
createReq.VinsId = 0
}
if haMode, ok := d.GetOk("ha_mode"); ok {
createReq.HighlyAvailable = haMode.(bool)
}
if additionalSans, ok := d.GetOk("additional_sans"); ok {
addSans := additionalSans.([]interface{})
resSans := make([]string, 0)
for _, san := range addSans {
resSans = append(resSans, san.(string))
}
createReq.AdditionalSANs = resSans
}
if clusterConfig, ok := d.GetOk("cluster_config"); ok {
createReq.ClusterConfiguration = clusterConfig.(string)
}
if kubeletConfig, ok := d.GetOk("kubelet_config"); ok {
createReq.KubeletConfiguration = kubeletConfig.(string)
}
if kubeProxyConfig, ok := d.GetOk("kube_proxy_config"); ok {
createReq.KubeProxyConfiguration = kubeProxyConfig.(string)
}
if joinConfig, ok := d.GetOk("join_config"); ok {
createReq.JoinConfiguration = joinConfig.(string)
}
if initConfig, ok := d.GetOk("init_config"); ok {
createReq.InitConfiguration = initConfig.(string)
}
if oidcCertificate, ok := d.GetOk("oidc_cert"); ok {
createReq.OidcCertificate = oidcCertificate.(string)
}
if chipset, ok := d.GetOk("chipset"); ok {
createReq.Chipset = chipset.(string)
}
if extNetOnly, ok := d.GetOk("extnet_only"); ok {
createReq.ExtNetOnly = extNetOnly.(bool)
}
if desc, ok := d.GetOk("desc"); ok {
createReq.Description = desc.(string)
}
if lbSysctlParams, ok := d.GetOk("lb_sysctl_params"); ok {
syscrlSliceMaps := lbSysctlParams.([]interface{})
res := make([]map[string]interface{}, 0, len(syscrlSliceMaps))
for _, syscrlMap := range syscrlSliceMaps {
tempMap := make(map[string]interface{})
for k, v := range syscrlMap.(map[string]interface{}) {
if intVal, err := strconv.Atoi(v.(string)); err == nil {
tempMap[k] = intVal
continue
}
tempMap[k] = v.(string)
}
res = append(res, tempMap)
}
createReq.LbSysctlParams = res
}
resp, err := c.CloudBroker().K8S().Create(ctx, createReq)
if err != nil {
return diag.FromErr(err)
}
taskReq := tasks.GetRequest{
AuditID: strings.Trim(resp, `"`),
}
for {
task, err := c.CloudBroker().Tasks().Get(ctx, taskReq)
if err != nil {
return diag.FromErr(err)
}
log.Debugf("resourceK8sControlPlaneCreate: instance creating - %s", task.Stage)
if task.Completed {
if task.Error != "" {
return diag.FromErr(fmt.Errorf("cannot create k8s instance: %v", task.Error))
}
id, err := task.Result.ID()
if err != nil {
return diag.FromErr(err)
}
d.SetId(strconv.Itoa(id))
break
}
time.Sleep(time.Second * 20)
}
cluster, err := utilityK8sCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
delWGReq := k8s.WorkersGroupDeleteRequest{
K8SID: cluster.ID,
WorkersGroupID: cluster.K8SGroups.Workers[0].ID,
}
_, err = c.CloudBroker().K8S().WorkersGroupDelete(ctx, delWGReq)
if err != nil {
return diag.FromErr(err)
}
return resourceK8sCPRead(ctx, d, m)
}
func resourceK8sCPRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceK8sCPRead: called with id %s, rg %d", d.Id(), d.Get("rg_id").(int))
k8sData, err := utilityK8sCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
switch k8sData.Status {
case status.Modeled:
return diag.Errorf("The k8s cluster is in status: %s, please, contact support for more information", k8sData.Status)
case status.Destroying:
return diag.Errorf("The k8s cluster is in progress with status: %s", k8sData.Status)
case status.Destroyed:
d.SetId("")
return diag.Errorf("The resource cannot be updated because it has been destroyed")
case status.Disabled:
log.Debugf("The k8s cluster is in status: %s, troubles may occur with update. Please, enable compute first.", k8sData.Status)
}
c := m.(*controller.ControllerCfg)
if d.Get("start").(bool) {
if k8sData.TechStatus == "STOPPED" {
req := k8s.StartRequest{
K8SID: k8sData.ID,
}
_, err := c.CloudBroker().K8S().Start(ctx, req)
if err != nil {
return diag.FromErr(err)
}
}
}
k8sList, err := utilityResourceK8sListCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
curK8s := k8s.ItemK8S{}
for _, k8sCluster := range k8sList.Data {
if k8sCluster.ID == k8sData.ID {
curK8s = k8sCluster
}
}
if curK8s.ID == 0 {
return diag.Errorf("Cluster with id %d not found", k8sData.ID)
}
d.Set("vins_id", curK8s.VINSID)
masterComputeList := make([]compute.RecordCompute, 0, len(k8sData.K8SGroups.Masters.DetailedInfo))
for _, masterNode := range k8sData.K8SGroups.Masters.DetailedInfo {
compute, err := utilityComputeCheckPresence(ctx, d, m, masterNode.ID)
if err != nil {
return diag.FromErr(err)
}
masterComputeList = append(masterComputeList, *compute)
}
var warnings dc.Warnings
if _, ok := d.GetOk("k8s_id"); !ok {
for _, worker := range k8sData.K8SGroups.Workers {
err := fmt.Errorf("found worker-group with ID %d. Make sure to import it to decort_k8s_wg resource if you wish to manage it", worker.ID)
warnings.Add(err)
}
}
flattenResourceK8sCP(d, *k8sData, masterComputeList)
lbGetReq := lb.GetRequest{
LBID: k8sData.LBID,
}
if d.Get("with_lb").(bool) || k8sData.LBID != 0 {
lb, err := c.CloudBroker().LB().Get(ctx, lbGetReq)
if err != nil {
return diag.FromErr(err)
}
d.Set("extnet_id", lb.ExtNetID)
d.Set("lb_ip", lb.PrimaryNode.FrontendIP)
}
kubeconfigReq := k8s.GetConfigRequest{
K8SID: k8sData.ID,
}
kubeconfig, err := c.CloudBroker().K8S().GetConfig(ctx, kubeconfigReq)
if err != nil {
log.Warnf("could not get kubeconfig: %v", err)
}
d.Set("kubeconfig", kubeconfig)
return warnings.Get()
}
func resourceK8sCPUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceK8sControlPlaneUpdate: called with id %s, rg %d", d.Id(), d.Get("rg_id").(int))
c := m.(*controller.ControllerCfg)
if diags := checkParamsExistence(ctx, d, c); diags != nil {
return diags
}
k8sData, err := utilityK8sCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
hasChanged := false
switch k8sData.Status {
case status.Modeled:
return diag.Errorf("The k8s cluster is in status: %s, please, contact support for more information", k8sData.Status)
case status.Deleted:
err := handleRestore(ctx, d, c, k8sData)
if err != nil {
return diag.FromErr(err)
}
hasChanged = true
case status.Destroying:
return diag.Errorf("The k8s cluster is in progress with status: %s", k8sData.Status)
case status.Destroyed:
d.SetId("")
return diag.Errorf("The resource cannot be updated because it has been destroyed")
case status.Disabled:
log.Debugf("The k8s cluster is in status: %s, troubles may occur with update. Please, enable compute first.", k8sData.Status)
}
if hasChanged {
k8sData, err = utilityK8sCheckPresence(ctx, d, m)
if k8sData == nil {
d.SetId("")
if err != nil {
return diag.FromErr(err)
}
return nil
}
}
if d.HasChanges("name", "desc") {
err := handleUpdate(ctx, d, c, k8sData)
if err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("enabled") {
err := handleEnable(ctx, c, d.Get("enabled").(bool), k8sData.ID)
if err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("zone_id") {
start := d.Get("start").(bool)
err := handleZoneID(ctx, c, k8sData.ID, uint64(d.Get("zone_id").(int)), start)
if err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("start") {
err := handleStart(ctx, c, d.Get("start").(bool), k8sData)
if err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("num") {
err := handleUpdateNum(ctx, d, c, k8sData)
if err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("lb_sysctl_params") && d.Get("with_lb").(bool) {
err := handleUpdateLbSysctlParams(ctx, d, c, k8sData)
if err != nil {
return diag.FromErr(err)
}
}
return nil
}
func resourceK8sCPDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceK8sControlPlaneDelete: called with id %s, rg %d", d.Id(), d.Get("rg_id").(int))
k8sData, err := utilityK8sCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
c := m.(*controller.ControllerCfg)
req := k8s.DeleteRequest{
K8SID: k8sData.ID,
}
if val, ok := d.GetOk("permanently"); ok {
req.Permanently = val.(bool)
}
_, err = c.CloudBroker().K8S().Delete(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId("")
return nil
}
func ResourceK8sCP() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
CreateContext: resourceK8sCPCreate,
ReadContext: resourceK8sCPRead,
UpdateContext: resourceK8sCPUpdate,
DeleteContext: resourceK8sCPDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout30m,
Read: &constants.Timeout600s,
Update: &constants.Timeout600s,
Delete: &constants.Timeout600s,
Default: &constants.Timeout600s,
},
Schema: resourceK8sCPSchemaMake(),
}
}
func handleUpdateNum(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, k8sData *k8s.RecordK8S) error {
oldVal, newVal := d.GetChange("num")
if oldVal.(int) > newVal.(int) {
ids := make([]uint64, 0)
for i := oldVal.(int) - 1; i >= newVal.(int); i-- {
id := k8sData.K8SGroups.Masters.DetailedInfo[i].ID
ids = append(ids, id)
}
req := k8s.DeleteMasterFromGroupRequest{
K8SID: k8sData.ID,
MasterGroupID: k8sData.K8SGroups.Masters.ID,
MasterIDs: ids,
}
_, err := c.CloudBroker().K8S().DeleteMasterFromGroup(ctx, req)
if err != nil {
return err
}
}
return nil
}
func handleUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, k8sData *k8s.RecordK8S) error {
updateReq := k8s.UpdateRequest{K8SID: k8sData.ID}
if d.HasChange("name") {
updateReq.Name = d.Get("name").(string)
}
if d.HasChange("desc") {
updateReq.Description = d.Get("desc").(string)
}
_, err := c.CloudBroker().K8S().Update(ctx, updateReq)
if err != nil {
return err
}
return nil
}
func handleRestore(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, k8sData *k8s.RecordK8S) error {
if restore, ok := d.GetOk("restore"); ok && restore.(bool) {
restoreReq := k8s.RestoreRequest{
K8SID: k8sData.ID,
}
_, err := c.CloudBroker().K8S().Restore(ctx, restoreReq)
if err != nil {
return err
}
err = handleEnable(ctx, c, d.Get("enabled").(bool), k8sData.ID)
if err != nil {
return err
}
err = handleStart(ctx, c, d.Get("start").(bool), k8sData)
if err != nil {
return err
}
}
return nil
}
func handleEnable(ctx context.Context, c *controller.ControllerCfg, enable bool, k8sId uint64) error {
if enable {
enableReq := k8s.EnableRequest{K8SID: k8sId}
_, err := c.CloudBroker().K8S().Enable(ctx, enableReq)
if err != nil {
return err
}
} else {
disableReq := k8s.DisableRequest{K8SID: k8sId}
_, err := c.CloudBroker().K8S().Disable(ctx, disableReq)
if err != nil {
return err
}
}
return nil
}
func handleStart(ctx context.Context, c *controller.ControllerCfg, start bool, k8sData *k8s.RecordK8S) error {
if start {
if k8sData.TechStatus == "STOPPED" {
startReq := k8s.StartRequest{K8SID: k8sData.ID}
_, err := c.CloudBroker().K8S().Start(ctx, startReq)
if err != nil {
return err
}
}
} else {
if k8sData.TechStatus == "STARTED" {
stopReq := k8s.StopRequest{K8SID: k8sData.ID}
_, err := c.CloudBroker().K8S().Stop(ctx, stopReq)
if err != nil {
return err
}
}
}
return nil
}
func handleZoneID(ctx context.Context, c *controller.ControllerCfg, k8sId uint64, zoneID uint64, start bool) error {
if start {
stopReq := k8s.StopRequest{
K8SID: k8sId,
}
_, err := c.CloudBroker().K8S().Stop(ctx, stopReq)
if err != nil {
return err
}
}
req := k8s.MigrateToZoneRequest{
K8SID: k8sId,
ZoneID: zoneID,
}
_, err := c.CloudBroker().K8S().MigrateToZone(ctx, req)
if err != nil {
return err
}
if start {
startReq := k8s.StartRequest{
K8SID: k8sId,
}
_, err := c.CloudBroker().K8S().Start(ctx, startReq)
if err != nil {
return err
}
}
return nil
}
func handleUpdateLbSysctlParams(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, k8sData *k8s.RecordK8S) error {
lbSysctlParams := d.Get("lb_sysctl_params").([]interface{})
res := make([]map[string]interface{}, 0, len(lbSysctlParams))
for _, syscrlMap := range lbSysctlParams {
tempMap := make(map[string]interface{})
for k, v := range syscrlMap.(map[string]interface{}) {
if intVal, err := strconv.Atoi(v.(string)); err == nil {
tempMap[k] = intVal
continue
}
tempMap[k] = v.(string)
}
res = append(res, tempMap)
}
if len(res) > 0 {
req := lb.UpdateSysctParamsRequest{
LBID: k8sData.LBID,
SysctlParams: res,
}
_, err := c.CloudBroker().LB().UpdateSysctlParams(ctx, req)
return err
}
return nil
}

View File

@@ -1,278 +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 k8s
import (
"context"
"fmt"
"strconv"
"strings"
"time"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8s"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/tasks"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/ic"
)
func resourceK8sWgCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceK8sWgCreate: called with k8s id %d", d.Get("k8s_id").(int))
c := m.(*controller.ControllerCfg)
if err := ic.ExistK8s(ctx, uint64(d.Get("k8s_id").(int)), c); err != nil {
return diag.FromErr(err)
}
req := k8s.WorkersGroupAddRequest{
K8SID: uint64(d.Get("k8s_id").(int)),
Name: d.Get("name").(string),
WorkerNum: uint64(d.Get("num").(int)),
WorkerCPU: uint64(d.Get("cpu").(int)),
WorkerRAM: uint64(d.Get("ram").(int)),
WorkerSEPID: uint64(d.Get("worker_sep_id").(int)),
WorkerSEPPool: d.Get("worker_sep_pool").(string),
Chipset: d.Get("chipset").(string),
StoragePolicyID: uint64(d.Get("storage_policy_id").(int)),
}
if d.Get("disk") == nil {
req.WorkerDisk = 0
} else {
req.WorkerDisk = uint64(d.Get("disk").(int))
}
labels, _ := d.Get("labels").([]interface{})
for _, label := range labels {
if !strings.HasPrefix(label.(string), "workersGroupName") {
req.Labels = append(req.Labels, label.(string))
}
}
annotations, _ := d.Get("annotations").([]interface{})
for _, annotation := range annotations {
req.Annotations = append(req.Annotations, annotation.(string))
}
taints, _ := d.Get("taints").([]interface{})
for _, taint := range taints {
req.Taints = append(req.Taints, taint.(string))
}
if cloudInit, ok := d.GetOk("cloud_init"); ok {
req.UserData = cloudInit.(string)
}
resp, err := c.CloudBroker().K8S().WorkersGroupAdd(ctx, req)
if err != nil {
return diag.FromErr(err)
}
taskReq := tasks.GetRequest{
AuditID: strings.Trim(resp, `"`),
}
for {
task, err := c.CloudBroker().Tasks().Get(ctx, taskReq)
if err != nil {
return diag.FromErr(err)
}
log.Debugf("resourceK8sWgCreate: instance creating - %s", task.Stage)
if task.Completed {
if task.Error != "" {
return diag.FromErr(fmt.Errorf("cannot create k8sWg instance: %v", task.Error))
}
wgId, err := task.Result.ID()
if err != nil {
return diag.FromErr(err)
}
d.SetId(fmt.Sprintf("%d#%d", d.Get("k8s_id").(int), wgId))
break
}
time.Sleep(time.Second * 20)
}
return resourceK8sWgRead(ctx, d, m)
}
func resourceK8sWgRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceK8sWgRead: called with k8s id %d", d.Get("k8s_id").(int))
wg, err := utilityK8sWgCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
workersComputeList := make([]compute.RecordCompute, 0)
for _, info := range wg.DetailedInfo {
compute, err := utilityComputeCheckPresence(ctx, d, m, info.ID)
if err != nil {
return diag.FromErr(err)
}
workersComputeList = append(workersComputeList, *compute)
}
d.Set("wg_id", wg.ID)
if strings.Contains(d.Id(), "#") {
k8sId, err := strconv.Atoi(strings.Split(d.Id(), "#")[0])
if err != nil {
return diag.FromErr(err)
}
d.Set("k8s_id", k8sId)
} else {
d.Set("k8s_id", d.Get("k8s_id"))
}
d.SetId(fmt.Sprintf("%d#%d", d.Get("k8s_id").(int), wg.ID))
flattenWg(d, wg, workersComputeList)
return nil
}
func resourceK8sWgUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceK8sWgUpdate: called with k8s id %d", d.Get("k8s_id").(int))
c := m.(*controller.ControllerCfg)
if err := ic.ExistK8s(ctx, uint64(d.Get("k8s_id").(int)), c); err != nil {
return diag.FromErr(err)
}
wg, err := utilityK8sWgCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
if d.HasChange("num") {
if newNum := d.Get("num").(int); uint64(newNum) > wg.Num {
req := k8s.WorkerAddRequest{
K8SID: uint64(d.Get("k8s_id").(int)),
WorkersGroupID: wg.ID,
Num: uint64(newNum) - wg.Num,
Chipset: d.Get("chipset").(string),
}
_, err := c.CloudBroker().K8S().WorkerAdd(ctx, req)
if err != nil {
return diag.FromErr(err)
}
} else {
for i := int(wg.Num) - 1; i >= newNum; i-- {
req := k8s.DeleteWorkerFromGroupRequest{
K8SID: uint64(d.Get("k8s_id").(int)),
WorkersGroupID: wg.ID,
WorkerID: wg.DetailedInfo[i].ID,
}
_, err := c.CloudBroker().K8S().DeleteWorkerFromGroup(ctx, req)
if err != nil {
return diag.FromErr(err)
}
}
}
}
if d.HasChange("cloud_init") {
req := k8s.UpdateWorkerNodesMetaDataRequest{
K8SID: uint64(d.Get("k8s_id").(int)),
WorkersGroupID: wg.ID,
UserData: d.Get("cloud_init").(string),
}
_, err := c.CloudBroker().K8S().UpdateWorkerNodesMetaData(ctx, req)
if err != nil {
return diag.FromErr(err)
}
}
return nil
}
func resourceK8sWgDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceK8sWgDelete: called with k8s id %d", d.Get("k8s_id").(int))
wg, err := utilityK8sWgCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
c := m.(*controller.ControllerCfg)
req := k8s.WorkersGroupDeleteRequest{
K8SID: uint64(d.Get("k8s_id").(int)),
WorkersGroupID: wg.ID,
}
_, err = c.CloudBroker().K8S().WorkersGroupDelete(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId("")
return nil
}
func ResourceK8sWg() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
CreateContext: resourceK8sWgCreate,
ReadContext: resourceK8sWgRead,
UpdateContext: resourceK8sWgUpdate,
DeleteContext: resourceK8sWgDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout20m,
Read: &constants.Timeout20m,
Update: &constants.Timeout20m,
Delete: &constants.Timeout20m,
Default: &constants.Timeout20m,
},
Schema: resourceK8sWgSchemaMake(),
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,91 +0,0 @@
/*
Copyright (c) 2019-2023 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 k8s
import (
"context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8s"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityK8sCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*k8s.RecordK8S, error) {
c := m.(*controller.ControllerCfg)
req := k8s.GetRequest{}
if d.Id() != "" {
k8sId, _ := strconv.ParseUint(d.Id(), 10, 64)
req.K8SID = k8sId
} else {
req.K8SID = uint64(d.Get("k8s_id").(int))
}
k8s, err := c.CloudBroker().K8S().Get(ctx, req)
if err != nil {
return nil, err
}
return k8s, nil
}
func utilityComputeCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}, computeID uint64) (*compute.RecordCompute, error) {
c := m.(*controller.ControllerCfg)
req := compute.GetRequest{
ComputeID: computeID,
}
compute, err := c.CloudBroker().Compute().Get(ctx, req)
if err != nil {
return nil, err
}
return compute, nil
}
func utilityResourceK8sListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*k8s.ListK8S, error) {
c := m.(*controller.ControllerCfg)
req := k8s.ListRequest{}
if byID, ok := d.GetOk("k8s_id"); ok {
req.ByID = uint64(byID.(int))
}
k8sList, err := c.CloudBroker().K8S().List(ctx, req)
if err != nil {
return nil, err
}
return k8sList, nil
}

View File

@@ -1,92 +0,0 @@
/*
Copyright (c) 2019-2023 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 k8s
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8s"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityK8sListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*k8s.ListK8S, error) {
c := m.(*controller.ControllerCfg)
req := k8s.ListRequest{}
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 ip_address, ok := d.GetOk("ip_address"); ok {
req.IPAddress = ip_address.(string)
}
if rg_id, ok := d.GetOk("rg_id"); ok {
req.RGID = uint64(rg_id.(int))
}
if lb_id, ok := d.GetOk("lb_id"); ok {
req.LBID = uint64(lb_id.(int))
}
if bservice_id, ok := d.GetOk("bservice_id"); ok {
req.BasicServiceID = uint64(bservice_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 includeDeleted, ok := d.GetOk("include_deleted"); ok {
req.IncludeDeleted = includeDeleted.(bool)
}
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))
}
if zoneID, ok := d.GetOk("zone_id"); ok {
req.ZoneID = uint64(zoneID.(int))
}
k8sList, err := c.CloudBroker().K8S().List(ctx, req)
if err != nil {
return nil, err
}
return k8sList, nil
}

View File

@@ -1,83 +0,0 @@
/*
Copyright (c) 2019-2023 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 k8s
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8s"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityK8sListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*k8s.ListK8S, error) {
c := m.(*controller.ControllerCfg)
req := k8s.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 ip_address, ok := d.GetOk("ip_address"); ok {
req.IPAddress = ip_address.(string)
}
if rg_id, ok := d.GetOk("rg_id"); ok {
req.RGID = uint64(rg_id.(int))
}
if lb_id, ok := d.GetOk("lb_id"); ok {
req.LBID = uint64(lb_id.(int))
}
if bservice_id, ok := d.GetOk("bservice_id"); ok {
req.BasicServiceID = uint64(bservice_id.(int))
}
if tech_status, ok := d.GetOk("tech_status"); ok {
req.TechStatus = tech_status.(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))
}
k8sList, err := c.CloudBroker().K8S().ListDeleted(ctx, req)
if err != nil {
return nil, err
}
return k8sList, nil
}

View File

@@ -1,168 +0,0 @@
/*
Copyright (c) 2019-2023 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 k8s
import (
"context"
"fmt"
"strconv"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8s"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityK8sWgCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*k8s.RecordK8SGroup, error) {
c := m.(*controller.ControllerCfg)
var wgId int
var k8sId int
var err error
if strings.Contains(d.Id(), "#") {
wgId, err = strconv.Atoi(strings.Split(d.Id(), "#")[1])
if err != nil {
return nil, err
}
k8sId, err = strconv.Atoi(strings.Split(d.Id(), "#")[0])
if err != nil {
return nil, err
}
} else {
wgId, err = strconv.Atoi(d.Id())
if err != nil {
return nil, err
}
k8sId = d.Get("k8s_id").(int)
}
req := k8s.GetRequest{
K8SID: uint64(k8sId),
}
cluster, err := c.CloudBroker().K8S().Get(ctx, req)
if err != nil {
return nil, err
}
for _, wg := range cluster.K8SGroups.Workers {
if wg.ID == uint64(wgId) {
return &wg, nil
}
}
return nil, fmt.Errorf("not found wg with id: %v in k8s cluster: %v", wgId, cluster.ID)
}
func utilityDataK8sWgCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*k8s.RecordK8SGroup, []compute.RecordCompute, error) {
c := m.(*controller.ControllerCfg)
k8sId := uint64(d.Get("k8s_id").(int))
wgId := uint64(d.Get("wg_id").(int))
k8sGetReq := k8s.GetRequest{
K8SID: k8sId,
}
cluster, err := c.CloudBroker().K8S().Get(ctx, k8sGetReq)
if err != nil {
return nil, nil, err
}
curWg := k8s.RecordK8SGroup{}
for _, wg := range cluster.K8SGroups.Workers {
if wg.ID == wgId {
curWg = wg
break
}
}
if curWg.ID == 0 {
return nil, nil, fmt.Errorf("WG with id %v in k8s cluster %v not found", wgId, k8sId)
}
workersComputeList := make([]compute.RecordCompute, 0)
for _, info := range curWg.DetailedInfo {
compute, err := utilityComputeCheckPresence(ctx, d, m, info.ID)
if err != nil {
return nil, nil, err
}
workersComputeList = append(workersComputeList, *compute)
}
return &curWg, workersComputeList, nil
}
func utilityK8sWgListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*k8s.ListK8SGroup, error) {
c := m.(*controller.ControllerCfg)
req := k8s.GetRequest{}
if d.Id() != "" {
k8sId, _ := strconv.ParseUint(d.Id(), 10, 64)
req.K8SID = k8sId
} else {
req.K8SID = uint64(d.Get("k8s_id").(int))
}
cluster, err := c.CloudBroker().K8S().Get(ctx, req)
if err != nil {
return nil, err
}
return &cluster.K8SGroups.Workers, nil
}
func utilityK8sWgCloudInitCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
c := m.(*controller.ControllerCfg)
req := k8s.GetWorkerNodesMetaDataRequest{
K8SID: uint64(d.Get("k8s_id").(int)),
WorkersGroupID: uint64(d.Get("wg_id").(int)),
}
cloudInit, err := c.CloudBroker().K8S().GetWorkerNodesMetaData(ctx, req)
if err != nil {
return "", err
}
return cloudInit, nil
}
func cloudInitDiffSupperss(key, oldVal, newVal string, d *schema.ResourceData) bool {
if newVal != "" && newVal != oldVal {
log.Debugf("networkSubresIPAddreDiffSupperss: key=%s, oldVal=%q, newVal=%q -> suppress=FALSE", key, oldVal, newVal)
return false
}
log.Debugf("networkSubresIPAddreDiffSupperss: key=%s, oldVal=%q, newVal=%q -> suppress=TRUE", key, oldVal, newVal)
return true // suppress difference
}