Compare commits

..

2 Commits
4.0.1 ... 4.1.0

Author SHA1 Message Date
caf7213bca 4.1.0 2023-05-26 17:12:03 +03:00
9cf150437d 4.0.2 2023-05-23 16:48:16 +03:00
142 changed files with 2155 additions and 419 deletions

View File

@@ -1,5 +1,13 @@
## Version 4.0.1
## Version 4.1.0
## Bug Fix
- Fixed incorrect state reading when creating/deleting port_forwarding in decort_kvmvm
- Fixed possible segmentation fault with multiple concurrent resource manipulations
## Features
- Added cloudapi/flipgroup functionality to provider:
- decort_flipgroup data source - read info about created flipgroup
- decort_flipgroup_list data source - read info about all created flipgroups
- decort_flipgroup resource - manage flipgroup instance
## Bug Fixes
- Increased resource_vins timeouts
- Automated compute start/stop when managing networks
- Removed reading of default generated label "workersGroupName=" in resource_k8s, resource_k8s_wg in tfstate
- Updated samples for flipgroups, image, pfw, k8s resources and data sources

View File

@@ -8,7 +8,7 @@ ZIPDIR = ./zip
BINARY=${NAME}.exe
WORKPATH= ./examples/terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAMESPACE}/${VERSION}/${OS_ARCH}
MAINPATH = ./cmd/decort/
VERSION=4.0.1
VERSION=4.1.0
#OS_ARCH=darwin_amd64
OS_ARCH=windows_amd64
#OS_ARCH=linux_amd64

View File

@@ -26,6 +26,7 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/bservice"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/disks"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/extnet"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/flipgroup"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/image"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/k8s"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/kvmvm"
@@ -63,6 +64,7 @@ func newDataSourcesMap() map[string]*schema.Resource {
"decort_k8s_list_deleted": k8s.DataSourceK8sListDeleted(),
"decort_k8s_wg": k8s.DataSourceK8sWg(),
"decort_k8s_wg_list": k8s.DataSourceK8sWgList(),
"decort_k8s_computes": k8s.DataSourceK8sComputes(),
"decort_vins": vins.DataSourceVins(),
"decort_vins_list": vins.DataSourceVinsList(),
"decort_vins_audits": vins.DataSourceVinsAudits(),
@@ -118,6 +120,8 @@ func newDataSourcesMap() map[string]*schema.Resource {
"decort_lb": lb.DataSourceLB(),
"decort_lb_list": lb.DataSourceLBList(),
"decort_lb_list_deleted": lb.DataSourceLBListDeleted(),
"decort_flipgroup": flipgroup.DataSourceFlipgroup(),
"decort_flipgroup_list": flipgroup.DataSourceFlipGroupList(),
"decort_cb_account": cb_account.DataSourceAccount(),
"decort_cb_account_list": cb_account.DataSourceAccountList(),

View File

@@ -25,6 +25,7 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/account"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/bservice"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/disks"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/flipgroup"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/image"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/k8s"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/kvmvm"
@@ -68,22 +69,23 @@ func newResourcesMap() map[string]*schema.Resource {
"decort_lb_backend_server": lb.ResourceLBBackendServer(),
"decort_lb_frontend": lb.ResourceLBFrontend(),
"decort_lb_frontend_bind": lb.ResourceLBFrontendBind(),
"decort_flipgroup": flipgroup.ResourceFlipgroup(),
"decort_cb_account": cb_account.ResourceAccount(),
"decort_cb_disk": cb_disks.ResourceDisk(),
"decort_cb_image": cb_image.ResourceImage(),
"decort_cb_virtual_image":cb_image.ResourceVirtualImage(),
"decort_cb_cdrom_image": cb_image.ResourceCDROMImage(),
"decort_cb_delete_images":cb_image.ResourceDeleteImages(),
"decort_cb_pcidevice": cb_pcidevice.ResourcePcidevice(),
"decort_cb_sep": cb_sep.ResourceSep(),
"decort_cb_sep_config": cb_sep.ResourceSepConfig(),
"decort_cb_resgroup": cb_rg.ResourceResgroup(),
"decort_cb_kvmvm": cb_kvmvm.ResourceCompute(),
"decort_cb_vins": cb_vins.ResourceVins(),
"decort_cb_pfw": cb_pfw.ResourcePfw(),
"decort_cb_k8s": cb_k8s.ResourceK8s(),
"decort_cb_k8s_wg": cb_k8s.ResourceK8sWg(),
"decort_cb_snapshot": cb_snapshot.ResourceSnapshot(),
"decort_cb_account": cb_account.ResourceAccount(),
"decort_cb_disk": cb_disks.ResourceDisk(),
"decort_cb_image": cb_image.ResourceImage(),
"decort_cb_virtual_image": cb_image.ResourceVirtualImage(),
"decort_cb_cdrom_image": cb_image.ResourceCDROMImage(),
"decort_cb_delete_images": cb_image.ResourceDeleteImages(),
"decort_cb_pcidevice": cb_pcidevice.ResourcePcidevice(),
"decort_cb_sep": cb_sep.ResourceSep(),
"decort_cb_sep_config": cb_sep.ResourceSepConfig(),
"decort_cb_resgroup": cb_rg.ResourceResgroup(),
"decort_cb_kvmvm": cb_kvmvm.ResourceCompute(),
"decort_cb_vins": cb_vins.ResourceVins(),
"decort_cb_pfw": cb_pfw.ResourcePfw(),
"decort_cb_k8s": cb_k8s.ResourceK8s(),
"decort_cb_k8s_wg": cb_k8s.ResourceK8sWg(),
"decort_cb_snapshot": cb_snapshot.ResourceSnapshot(),
}
}

View File

@@ -0,0 +1,191 @@
/*
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>
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 flipgroup
import (
"context"
"fmt"
"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 dataSourceFlipgroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
fg, err := utilityFlipgroupCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
flattenFlipgroup(d, fg)
d.SetId(fmt.Sprint(fg.ID))
return nil
}
func dataSourceFlipgroupSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"flipgroup_id": {
Type: schema.TypeInt,
Required: true,
Description: "Flipgroupd ID",
},
"account_id": {
Type: schema.TypeInt,
Computed: true,
},
"account_name": {
Type: schema.TypeString,
Computed: true,
},
"client_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"client_names": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"client_type": {
Type: schema.TypeString,
Computed: true,
},
"conn_id": {
Type: schema.TypeInt,
Computed: true,
},
"conn_type": {
Type: schema.TypeString,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"default_gw": {
Type: schema.TypeString,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"desc": {
Type: schema.TypeString,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"ip": {
Type: schema.TypeString,
Computed: true,
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"net_id": {
Type: schema.TypeInt,
Computed: true,
},
"net_type": {
Type: schema.TypeString,
Computed: true,
},
"network": {
Type: schema.TypeString,
Computed: true,
},
"rg_id": {
Type: schema.TypeInt,
Computed: true,
},
"rg_name": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
}
}
func DataSourceFlipgroup() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceFlipgroupRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout180s,
Default: &constants.Timeout180s,
},
Schema: dataSourceFlipgroupSchemaMake(),
}
}

View File

@@ -0,0 +1,210 @@
/*
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>
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 flipgroup
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 dataSourceFlipgroupList(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
fg_list, err := utilityFlipgroupListCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenFlipgroupList(fg_list))
return nil
}
func dataSourceFlipgroupListSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"page": {
Type: schema.TypeInt,
Optional: true,
Description: "Page number",
},
"size": {
Type: schema.TypeInt,
Optional: true,
Description: "Page size",
},
"items": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"flipgroup_id": {
Type: schema.TypeInt,
Computed: true,
},
"account_id": {
Type: schema.TypeInt,
Computed: true,
},
"account_name": {
Type: schema.TypeString,
Computed: true,
},
"client_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"client_names": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"client_type": {
Type: schema.TypeString,
Computed: true,
},
"conn_id": {
Type: schema.TypeInt,
Computed: true,
},
"conn_type": {
Type: schema.TypeString,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"default_gw": {
Type: schema.TypeString,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"desc": {
Type: schema.TypeString,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"net_id": {
Type: schema.TypeInt,
Computed: true,
},
"net_type": {
Type: schema.TypeString,
Computed: true,
},
"ip": {
Type: schema.TypeString,
Computed: true,
},
"network": {
Type: schema.TypeString,
Computed: true,
},
"rg_id": {
Type: schema.TypeInt,
Computed: true,
},
"rg_name": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
}
}
func DataSourceFlipGroupList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceFlipgroupList,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout180s,
Default: &constants.Timeout180s,
},
Schema: dataSourceFlipgroupListSchemaMake(),
}
}

View File

@@ -0,0 +1,107 @@
/*
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>
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 flipgroup
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/flipgroup"
)
func flattenFlipgroup(d *schema.ResourceData, fg *flipgroup.ItemFLIPGroup) {
d.Set("account_id", fg.AccountID)
d.Set("account_name", fg.AccountName)
d.Set("client_ids", fg.ClientIDs)
d.Set("client_names", fg.ClientNames)
d.Set("client_type", fg.ClientType)
d.Set("conn_id", fg.ConnID)
d.Set("conn_type", fg.ConnType)
d.Set("created_by", fg.CreatedBy)
d.Set("created_time", fg.CreatedTime)
d.Set("default_gw", fg.DefaultGW)
d.Set("deleted_by", fg.DeletedBy)
d.Set("deleted_time", fg.DeletedTime)
d.Set("desc", fg.Description)
d.Set("gid", fg.GID)
d.Set("guid", fg.GUID)
d.Set("flipgroup_id", fg.ID)
d.Set("ip", fg.IP)
d.Set("milestones", fg.Milestones)
d.Set("name", fg.Name)
d.Set("net_id", fg.NetID)
d.Set("net_type", fg.NetType)
d.Set("network", fg.Network)
d.Set("rg_id", fg.RGID)
d.Set("rg_name", fg.RGName)
d.Set("status", fg.Status)
d.Set("updated_by", fg.UpdatedBy)
d.Set("updated_time", fg.UpdatedTime)
}
func flattenFlipgroupList(fg_list flipgroup.ListFLIPGroups) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, fg := range fg_list {
temp := map[string]interface{}{
"account_id": fg.AccountID,
"account_name": fg.AccountName,
"client_ids": fg.ClientIDs,
"client_names": fg.ClientNames,
"client_type": fg.ClientType,
"conn_id": fg.ConnID,
"conn_type": fg.ConnType,
"created_by": fg.CreatedBy,
"created_time": fg.CreatedTime,
"default_gw": fg.DefaultGW,
"deleted_by": fg.DeletedBy,
"deleted_time": fg.DeletedTime,
"desc": fg.Description,
"gid": fg.GID,
"guid": fg.GUID,
"flipgroup_id": fg.ID,
"ip": fg.IP,
"milestones": fg.Milestones,
"name": fg.Name,
"net_id": fg.NetID,
"net_type": fg.NetType,
"network": fg.Network,
"rg_id": fg.RGID,
"rg_name": fg.RGName,
"status": fg.Status,
"updated_by": fg.UpdatedBy,
"updated_time": fg.UpdatedTime,
}
res = append(res, temp)
}
return res
}

View File

@@ -0,0 +1,309 @@
/*
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>
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 flipgroup
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/flipgroup"
"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"
log "github.com/sirupsen/logrus"
)
func resourceFlipgroupCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceFlipgroupCreate called with name: %s, accountID %v", d.Get("name").(string), d.Get("account_id").(int))
c := m.(*controller.ControllerCfg)
req := flipgroup.CreateRequest{
AccountID: uint64(d.Get("account_id").(int)),
Name: d.Get("name").(string),
NetType: d.Get("net_type").(string),
NetID: uint64(d.Get("net_id").(int)),
ClientType: d.Get("client_type").(string),
IP: d.Get("ip").(string),
Description: d.Get("desc").(string),
}
resp, err := c.CloudAPI().FLIPGroup().Create(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId(fmt.Sprint(resp.ID))
var warnings dc.Warnings
if client_ids, ok := d.GetOk("client_ids"); ok {
casted := client_ids.([]interface{})
addComputesAfterCreation(ctx, &warnings, c, casted, resp.ID)
}
defer resourceFlipgroupRead(ctx, d, m)
return warnings.Get()
}
func resourceFlipgroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
fg, err := utilityFlipgroupCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
flattenFlipgroup(d, fg)
return nil
}
func resourceFlipgroupUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceFlipgroupUpdate called with id: %v", d.Get("flipgroup_id").(int))
c := m.(*controller.ControllerCfg)
fg, err := utilityFlipgroupCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
var warnings dc.Warnings
basicUpdate := false
req := flipgroup.EditRequest{FLIPGroupID: fg.ID}
if d.HasChange("desc") {
req.Description = d.Get("desc").(string)
basicUpdate = true
}
if d.HasChange("name") {
req.Name = d.Get("name").(string)
basicUpdate = true
}
if basicUpdate {
_, err := c.CloudAPI().FLIPGroup().Edit(ctx, req)
if err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("client_ids") {
handleClientIDsUpdate(ctx, d, c, fg, &warnings)
}
defer resourceFlipgroupRead(ctx, d, m)
return warnings.Get()
}
func resourceFlipgroupDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceFlipgroupDelete called with id: %v", d.Get("flipgroup_id").(int))
c := m.(*controller.ControllerCfg)
fg, err := utilityFlipgroupCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
req := flipgroup.DeleteRequest{
FLIPGroupID: fg.ID,
}
_, err = c.CloudAPI().FLIPGroup().Delete(ctx, req)
if err != nil {
return diag.FromErr(err)
}
return nil
}
func resourceFlipgroupSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"account_id": {
Type: schema.TypeInt,
Required: true,
Description: "Account ID",
},
"name": {
Type: schema.TypeString,
Required: true,
Description: "Flipgroup name",
},
"net_id": {
Type: schema.TypeInt,
Required: true,
Description: "EXTNET or ViNS ID",
},
"net_type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"EXTNET", "VINS"}, true),
Description: "Network type, EXTNET or VINS",
},
"client_type": {
Type: schema.TypeString,
Required: true,
Description: "Type of client, 'compute' ('vins' will be later)",
ValidateFunc: validation.StringInSlice([]string{"compute"}, true),
},
"ip": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "IP address to associate with this group. If empty, the platform will autoselect IP address",
},
"desc": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Text description of this Flipgroup instance",
},
"client_ids": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
Description: "List of clients attached to this Flipgroup instance",
},
"flipgroup_id": {
Type: schema.TypeInt,
Computed: true,
},
"account_name": {
Type: schema.TypeString,
Computed: true,
},
"client_names": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"conn_id": {
Type: schema.TypeInt,
Computed: true,
},
"conn_type": {
Type: schema.TypeString,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"default_gw": {
Type: schema.TypeString,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
},
"network": {
Type: schema.TypeString,
Computed: true,
},
"rg_id": {
Type: schema.TypeInt,
Computed: true,
},
"rg_name": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
}
}
func ResourceFlipgroup() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
CreateContext: resourceFlipgroupCreate,
ReadContext: resourceFlipgroupRead,
UpdateContext: resourceFlipgroupUpdate,
DeleteContext: resourceFlipgroupDelete,
Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout300s,
Read: &constants.Timeout300s,
Update: &constants.Timeout300s,
Delete: &constants.Timeout300s,
Default: &constants.Timeout300s,
},
Schema: resourceFlipgroupSchemaMake(),
}
}

View File

@@ -0,0 +1,167 @@
/*
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>
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 flipgroup
import (
"context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/flipgroup"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
log "github.com/sirupsen/logrus"
)
func handleClientIDsUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, fg *flipgroup.ItemFLIPGroup, warn *dc.Warnings) {
addedClients := make([]interface{}, 0)
removedClients := make([]interface{}, 0)
old_set, new_set := d.GetChange("client_ids")
oldSlice := old_set.([]interface{})
newSlice := new_set.([]interface{})
for _, oldElem := range oldSlice {
if !containsClient(newSlice, oldElem) {
removedClients = append(removedClients, oldElem)
}
}
for _, newElem := range newSlice {
if !containsClient(oldSlice, newElem) {
addedClients = append(addedClients, newElem)
}
}
log.Debugf("Found client_ids change with %v deletion(s) and %v addition(s) [flipgroupID=%v]", len(removedClients), len(addedClients), fg.ID)
if len(addedClients) > 0 {
for _, id := range addedClients {
req := flipgroup.ComputeAddRequest{
FLIPGroupID: fg.ID,
ComputeID: uint64(id.(int)),
}
if _, err := c.CloudAPI().FLIPGroup().ComputeAdd(ctx, req); err != nil {
warn.Add(err)
}
}
}
if len(removedClients) > 0 {
for _, id := range removedClients {
req := flipgroup.ComputeRemoveRequest{
FLIPGroupID: fg.ID,
ComputeID: uint64(id.(int)),
}
if _, err := c.CloudAPI().FLIPGroup().ComputeRemove(ctx, req); err != nil {
warn.Add(err)
}
}
}
}
func containsClient(set []interface{}, check interface{}) bool {
for _, elem := range set {
elemConv := elem.(int)
checkConv := check.(int)
if elemConv == checkConv {
return true
}
}
return false
}
func addComputesAfterCreation(ctx context.Context, warnings *dc.Warnings, c *controller.ControllerCfg, compute_ids []interface{}, flipgroupID uint64) {
if len(compute_ids) == 0 {
return
}
log.Debugf("Adding %v computes to flipgroup [id=%v]...", len(compute_ids), flipgroupID)
for _, elem := range compute_ids {
compute_id := uint64(elem.(int))
req := flipgroup.ComputeAddRequest{
FLIPGroupID: flipgroupID,
ComputeID: compute_id,
}
_, err := c.CloudAPI().FLIPGroup().ComputeAdd(ctx, req)
if err != nil {
warnings.Add(err)
}
}
}
func utilityFlipgroupCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*flipgroup.ItemFLIPGroup, error) {
c := m.(*controller.ControllerCfg)
req := flipgroup.GetRequest{}
if d.Id() == "" {
req.FLIPGroupID = uint64(d.Get("flipgroup_id").(int))
} else {
id, _ := strconv.ParseUint(d.Id(), 10, 64)
req.FLIPGroupID = id
}
fg, err := c.CloudAPI().FLIPGroup().Get(ctx, req)
if err != nil {
return nil, err
}
return fg, err
}
func utilityFlipgroupListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (flipgroup.ListFLIPGroups, error) {
c := m.(*controller.ControllerCfg)
req := flipgroup.ListRequest{}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
fg_list, err := c.CloudAPI().FLIPGroup().List(ctx, req)
if err != nil {
return nil, err
}
return fg_list, err
}

View File

@@ -0,0 +1,123 @@
/*
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>
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"
"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 dataSourceK8sComputesRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
cluster, err := utilityK8sCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
d.SetId(fmt.Sprint(cluster.ID))
flattenK8sDataComputes(d, cluster)
return nil
}
func computesSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"group_name": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
},
}
}
func workerComputesSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{}
}
func dataSourceK8sComputesSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"k8s_id": {
Type: schema.TypeInt,
Required: true,
},
"masters": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: computesSchemaMake(),
},
},
"workers": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: computesSchemaMake(),
},
},
}
}
func DataSourceK8sComputes() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceK8sComputesRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout60s,
Default: &constants.Timeout60s,
},
Schema: dataSourceK8sComputesSchemaMake(),
}
}

View File

@@ -33,11 +33,53 @@ Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/w
package k8s
import (
"strings"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/k8s"
)
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)
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)
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 flattenAclList(aclList k8s.ListACL) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, acl := range aclList {
@@ -128,6 +170,14 @@ func flattenMasterGroup(mastersGroup k8s.MasterGroup, masters []compute.RecordCo
func flattenK8sGroup(k8SGroupList k8s.ListK8SGroups, workers []compute.RecordCompute) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
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,
@@ -135,7 +185,7 @@ func flattenK8sGroup(k8SGroupList k8s.ListK8SGroups, workers []compute.RecordCom
"disk": k8sGroup.Disk,
"guid": k8sGroup.GUID,
"id": k8sGroup.ID,
"labels": k8sGroup.Labels,
"labels": labels,
"name": k8sGroup.Name,
"num": k8sGroup.Num,
"ram": k8sGroup.RAM,
@@ -283,12 +333,21 @@ func flattenResourceK8s(d *schema.ResourceData, k8s k8s.RecordK8S, masters []com
}
func flattenWg(d *schema.ResourceData, wg k8s.ItemK8SGroup, computes []compute.RecordCompute) {
labels := make([]string, 0)
for _, label := range wg.Labels {
if strings.HasPrefix(label, "workerGroupName") {
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", wg.Labels)
d.Set("labels", labels)
d.Set("name", wg.Name)
d.Set("num", wg.Num)
d.Set("ram", wg.RAM)

View File

@@ -39,12 +39,16 @@ import (
)
type K8sNodeRecord struct {
ID int `json:"id"`
Name string `json:"name"`
Disk int `json:"disk"`
Cpu int `json:"cpu"`
Num int `json:"num"`
Ram int `json:"ram"`
ID int `json:"id"`
Name string `json:"name"`
Disk int `json:"disk"`
Cpu int `json:"cpu"`
Num int `json:"num"`
Ram int `json:"ram"`
// coming in future updates (curr. version 4.0.2)
// Labels []interface{} `json:"labels"`
// Annotations []interface{} `json:"annotations"`
// Taints []interface{} `json:"taints"`
DetailedInfo []struct {
ID int `json:"id"`
Name string `json:"name"`
@@ -53,7 +57,7 @@ type K8sNodeRecord struct {
SepPool string `json:"SepPool"`
}
//K8sRecord represents k8s instance
// K8sRecord represents k8s instance
type K8sRecord struct {
AccountID int `json:"accountId"`
AccountName string `json:"accountName"`
@@ -72,7 +76,7 @@ type K8sRecord struct {
type K8sRecordList []K8sRecord
//LbRecord represents load balancer instance
// LbRecord represents load balancer instance
type LbRecord struct {
ID int `json:"id"`
Name string `json:"name"`
@@ -87,7 +91,7 @@ type LbRecord struct {
} `json:"primaryNode"`
}
//Blasphemous workaround for parsing Result value
// Blasphemous workaround for parsing Result value
type TaskResult int
func (r *TaskResult) UnmarshalJSON(b []byte) error {
@@ -117,7 +121,7 @@ func (r *TaskResult) UnmarshalJSON(b []byte) error {
return nil
}
//AsyncTask represents a long task completion status
// AsyncTask represents a long task completion status
type AsyncTask struct {
AuditID string `json:"auditId"`
Completed bool `json:"completed"`
@@ -136,7 +140,7 @@ type SshKeyConfig struct {
UserShell string
}
//FromSDK
// FromSDK
type K8SGroup struct {
Annotations []string `json:"annotations"`
CPU uint64 `json:"cpu"`

View File

@@ -32,7 +32,9 @@ Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/w
package k8s
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func nodeMasterDefault() K8sNodeRecord {
return K8sNodeRecord{
@@ -52,7 +54,7 @@ func nodeWorkerDefault() K8sNodeRecord {
}
}
func parseNode(nodeList []interface{}) K8sNodeRecord {
func parseDefaultNode(nodeList []interface{}) K8sNodeRecord {
node := nodeList[0].(map[string]interface{})
return K8sNodeRecord{
@@ -65,45 +67,6 @@ func parseNode(nodeList []interface{}) K8sNodeRecord {
}
}
func nodeToResource(node K8sNodeRecord) []interface{} {
mp := make(map[string]interface{})
mp["num"] = node.Num
mp["cpu"] = node.Cpu
mp["ram"] = node.Ram
mp["disk"] = node.Disk
return []interface{}{mp}
}
func nodeK8sSubresourceSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"num": {
Type: schema.TypeInt,
Required: true,
Description: "Number of nodes to create.",
},
"cpu": {
Type: schema.TypeInt,
Required: true,
Description: "Node CPU count.",
},
"ram": {
Type: schema.TypeInt,
Required: true,
Description: "Node RAM in MB.",
},
"disk": {
Type: schema.TypeInt,
Required: true,
Description: "Node boot disk size in GB.",
},
}
}
func mastersSchemaMake() map[string]*schema.Schema {
masters := masterGroupSchemaMake()
masters["num"] = &schema.Schema{
@@ -137,41 +100,78 @@ func mastersSchemaMake() map[string]*schema.Schema {
ForceNew: true,
Description: "Node boot disk size in GB.",
}
return masters
}
func workersSchemaMake() map[string]*schema.Schema {
workers := k8sGroupListSchemaMake()
workers["num"] = &schema.Schema{
Type: schema.TypeInt,
Required: true,
Description: "Number of nodes to create.",
return map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"num": {
Type: schema.TypeInt,
Required: true,
},
"ram": {
Type: schema.TypeInt,
Required: true,
},
"cpu": {
Type: schema.TypeInt,
Required: true,
},
"disk": {
Type: schema.TypeInt,
Required: true,
},
"annotations": {
Type: schema.TypeList,
Computed: true,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"detailed_info": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: detailedInfoSchemaMake(),
},
},
"guid": {
Type: schema.TypeString,
Computed: true,
},
"id": {
Type: schema.TypeInt,
Computed: true,
},
"labels": {
Type: schema.TypeList,
Computed: true,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"taints": {
Type: schema.TypeList,
Computed: true,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"sep_id": {
Type: schema.TypeInt,
Optional: true,
},
"sep_pool": {
Type: schema.TypeString,
Optional: true,
},
}
workers["sep_id"] = &schema.Schema{
Type: schema.TypeInt,
Optional: true,
}
workers["sep_pool"] = &schema.Schema{
Type: schema.TypeString,
Optional: true,
}
workers["cpu"] = &schema.Schema{
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Description: "Node CPU count.",
}
workers["ram"] = &schema.Schema{
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Description: "Node RAM in MB.",
}
workers["disk"] = &schema.Schema{
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Description: "Node boot disk size in GB.",
}
return workers
}

View File

@@ -95,7 +95,7 @@ func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{
var masterNode K8sNodeRecord
if masters, ok := d.GetOk("masters"); ok {
masterNode = parseNode(masters.([]interface{}))
masterNode = parseDefaultNode(masters.([]interface{}))
} else {
masterNode = nodeMasterDefault()
}
@@ -108,7 +108,7 @@ func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{
var workerNode K8sNodeRecord
if workers, ok := d.GetOk("workers"); ok {
workerNode = parseNode(workers.([]interface{}))
workerNode = parseDefaultNode(workers.([]interface{}))
} else {
workerNode = nodeWorkerDefault()
}
@@ -123,7 +123,9 @@ func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{
if labels, ok := d.GetOk("labels"); ok {
labels := labels.([]interface{})
for _, label := range labels {
createReq.Labels = append(createReq.Labels, label.(string))
if !strings.HasPrefix(label.(string), "workersGroupName") {
createReq.Labels = append(createReq.Labels, label.(string))
}
}
}
@@ -421,31 +423,9 @@ func resourceK8sUpdate(ctx context.Context, d *schema.ResourceData, m interface{
}
if d.HasChange("workers") {
wg := cluster.K8SGroups.Workers[0]
newWorkers := parseNode(d.Get("workers").([]interface{}))
if uint64(newWorkers.Num) > wg.Num {
req := k8s.WorkerAddRequest{
K8SID: cluster.ID,
WorkersGroupID: wg.ID,
Num: uint64(newWorkers.Num - int(wg.Num)),
}
if _, err := c.CloudAPI().K8S().WorkerAdd(ctx, req); err != nil {
return diag.FromErr(err)
}
} else {
for i := int(wg.Num) - 1; i >= newWorkers.Num; i-- {
req := k8s.DeleteWorkerFromGroupRequest{
K8SID: cluster.ID,
WorkersGroupID: wg.ID,
WorkerID: wg.DetailedInfo[i].ID,
}
if _, err := c.CloudAPI().K8S().DeleteWorkerFromGroup(ctx, req); err != nil {
return diag.FromErr(err)
}
}
err := handleWorkersChange(ctx, d, c, cluster)
if err != nil {
return diag.FromErr(err)
}
}
@@ -564,7 +544,6 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: workersSchemaMake(),
},
@@ -696,10 +675,10 @@ func ResourceK8s() *schema.Resource {
Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout30m,
Read: &constants.Timeout300s,
Update: &constants.Timeout300s,
Delete: &constants.Timeout300s,
Default: &constants.Timeout300s,
Read: &constants.Timeout600s,
Update: &constants.Timeout600s,
Delete: &constants.Timeout600s,
Default: &constants.Timeout600s,
},
Schema: resourceK8sSchemaMake(),

View File

@@ -55,7 +55,7 @@ func resourceK8sWgCreate(ctx context.Context, d *schema.ResourceData, m interfac
}
if !haveK8sID {
return diag.Errorf("resourceK8sCreate: can't create k8s cluster because K8sID %d is not allowed or does not exist", d.Get("k8s_id").(int))
return diag.Errorf("resourceK8sWgCreate: can't create k8s cluster because K8sID %d is not allowed or does not exist", d.Get("k8s_id").(int))
}
c := m.(*controller.ControllerCfg)
@@ -71,7 +71,9 @@ func resourceK8sWgCreate(ctx context.Context, d *schema.ResourceData, m interfac
labels, _ := d.Get("labels").([]interface{})
for _, label := range labels {
req.Labels = append(req.Labels, label.(string))
if !strings.HasPrefix(label.(string), "workersGroupName") {
req.Labels = append(req.Labels, label.(string))
}
}
annotations, _ := d.Get("annotations").([]interface{})
@@ -317,11 +319,11 @@ func ResourceK8sWg() *schema.Resource {
},
Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout600s,
Read: &constants.Timeout600s,
Update: &constants.Timeout600s,
Delete: &constants.Timeout300s,
Default: &constants.Timeout300s,
Create: &constants.Timeout20m,
Read: &constants.Timeout20m,
Update: &constants.Timeout20m,
Delete: &constants.Timeout20m,
Default: &constants.Timeout20m,
},
Schema: resourceK8sWgSchemaMake(),

View File

@@ -35,6 +35,7 @@ package k8s
import (
"context"
"strconv"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute"
@@ -42,10 +43,145 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func handleWorkersChange(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, cluster *k8s.RecordK8S) error {
o, n := d.GetChange("workers")
old_set, _ := o.([]interface{})
new_set, _ := n.([]interface{})
old_len := len(old_set)
new_len := len(new_set)
if old_len > new_len {
deleted := workersDifference(old_set, new_set)
if err := deleteWGs(ctx, c, cluster, deleted); err != nil {
return err
}
} else if old_len < new_len {
added := workersDifference(old_set, new_set)
if err := addWGs(ctx, c, cluster, added); err != nil {
return err
}
}
if err := updateNum(ctx, c, cluster, old_set, new_set); err != nil {
return err
}
return nil
}
func updateNum(ctx context.Context, c *controller.ControllerCfg, cluster *k8s.RecordK8S, old_set []interface{}, new_set []interface{}) error {
for _, valOld := range old_set {
wgOld, _ := valOld.(map[string]interface{})
for _, valNew := range new_set {
wgNew, _ := valNew.(map[string]interface{})
if wgOld["id"] == wgNew["id"] {
oldNum := wgOld["num"].(int)
newNum := wgNew["num"].(int)
if oldNum < newNum {
req := k8s.WorkerAddRequest{
K8SID: cluster.ID,
WorkersGroupID: uint64(wgNew["id"].(int)),
Num: uint64(newNum - oldNum),
}
_, err := c.CloudAPI().K8S().WorkerAdd(ctx, req)
if err != nil {
return err
}
} else if oldNum > newNum {
for i := oldNum - 1; i >= newNum; i-- {
detailedInfo := wgOld["detailed_info"].([]interface{})
if len(detailedInfo) == 0 {
return nil
}
req := k8s.DeleteWorkerFromGroupRequest{
K8SID: cluster.ID,
WorkersGroupID: uint64(wgNew["id"].(int)),
WorkerID: uint64(detailedInfo[i].(map[string]interface{})["compute_id"].(int)),
}
_, err := c.CloudAPI().K8S().DeleteWorkerFromGroup(ctx, req)
if err != nil {
return err
}
}
}
}
}
}
return nil
}
func deleteWGs(ctx context.Context, c *controller.ControllerCfg, cluster *k8s.RecordK8S, deleted []interface{}) error {
for _, elem := range deleted {
found_wg := elem.(map[string]interface{})
req := k8s.WorkersGroupDeleteRequest{
K8SID: cluster.ID,
WorkersGroupID: uint64(found_wg["id"].(int)),
}
_, err := c.CloudAPI().K8S().WorkersGroupDelete(ctx, req)
if err != nil {
return err
}
}
return nil
}
func addWGs(ctx context.Context, c *controller.ControllerCfg, cluster *k8s.RecordK8S, added []interface{}) error {
for _, elem := range added {
found_wg := elem.(map[string]interface{})
req := k8s.WorkersGroupAddRequest{
K8SID: cluster.ID,
Name: found_wg["name"].(string),
WorkerSEPID: uint64(found_wg["sep_id"].(int)),
WorkerSEPPool: found_wg["sep_pool"].(string),
WorkerNum: uint64(found_wg["num"].(int)),
WorkerCPU: uint64(found_wg["cpu"].(int)),
WorkerRAM: uint64(found_wg["ram"].(int)),
WorkerDisk: uint64(found_wg["disk"].(int)),
}
labels, _ := found_wg["labels"].([]interface{})
for _, label := range labels {
if !strings.HasPrefix(label.(string), "workersGroupName") {
req.Labels = append(req.Labels, label.(string))
}
}
annotations, _ := found_wg["annotations"].([]interface{})
for _, annotation := range annotations {
req.Annotations = append(req.Annotations, annotation.(string))
}
taints, _ := found_wg["taints"].([]interface{})
for _, taint := range taints {
req.Taints = append(req.Taints, taint.(string))
}
_, err := c.CloudAPI().K8S().WorkersGroupAdd(ctx, req)
if err != nil {
return err
}
}
return nil
}
func utilityK8sCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*k8s.RecordK8S, error) {
c := m.(*controller.ControllerCfg)
k8sID, _ := strconv.ParseUint(d.Id(), 10, 64)
var k8sID uint64
if d.Id() != "" {
k8sID, _ = strconv.ParseUint(d.Id(), 10, 64)
} else {
k8sID = uint64(d.Get("k8s_id").(int))
}
req := k8s.GetRequest{
K8SID: k8sID,
}
@@ -112,3 +248,29 @@ func utilityK8sListDeletedCheckPresence(ctx context.Context, d *schema.ResourceD
return k8sList, nil
}
func workersDifference(slice1 []interface{}, slice2 []interface{}) []interface{} {
var diff []interface{}
for i := 0; i < 2; i++ {
for _, s1 := range slice1 {
found := false
for _, s2 := range slice2 {
if s1.(map[string]interface{})["id"] == s2.(map[string]interface{})["id"] {
found = true
break
}
}
if !found {
diff = append(diff, s1)
}
}
if i == 0 {
slice1, slice2 = slice2, slice1
}
}
return diff
}

View File

@@ -215,7 +215,7 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
argVal, ok = d.GetOk("network")
if ok && argVal.(*schema.Set).Len() > 0 {
log.Debugf("resourceComputeCreate: calling utilityComputeNetworksConfigure to attach %d network(s)", argVal.(*schema.Set).Len())
err = utilityComputeNetworksConfigure(ctx, d, m, false, true)
err = utilityComputeNetworksConfigure(ctx, d, m, false, true, computeId)
if err != nil {
log.Errorf("resourceComputeCreate: error when attaching networks to a new Compute ID %d: %s", computeId, err)
cleanup = true
@@ -693,9 +693,11 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
}
}
err = utilityComputeNetworksConfigure(ctx, d, m, true, false) // pass do_delta = true to apply changes, if any
if err != nil {
return diag.FromErr(err)
if d.HasChange("network") {
err = utilityComputeNetworksConfigure(ctx, d, m, true, false, computeRec.ID) // pass do_delta = true to apply changes, if any
if err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("description") || d.HasChange("name") {

View File

@@ -144,11 +144,21 @@ func utilityComputeExtraDisksConfigure(ctx context.Context, d *schema.ResourceDa
return nil
}
func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData, m interface{}, do_delta bool, skip_zero bool) error {
func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData, m interface{}, do_delta bool, skip_zero bool, computeID uint64) error {
c := m.(*controller.ControllerCfg)
old_set, new_set := d.GetChange("network")
req := compute.StopRequest{
ComputeID: computeID,
Force: true,
}
_, err := c.CloudAPI().Compute().Stop(ctx, req)
if err != nil {
return err
}
apiErrCount := 0
var lastSavedError error
@@ -232,6 +242,14 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
}
}
startReq := compute.StartRequest{ComputeID: computeID}
_, err = c.CloudAPI().Compute().Start(ctx, startReq)
if err != nil {
apiErrCount++
lastSavedError = err
}
if apiErrCount > 0 {
log.Errorf("utilityComputeNetworksConfigure: there were %d error(s) when managing networks of Compute ID %s. Last error was: %s",
apiErrCount, d.Id(), lastSavedError)

View File

@@ -847,11 +847,11 @@ func ResourceVins() *schema.Resource {
},
Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout600s,
Read: &constants.Timeout300s,
Update: &constants.Timeout300s,
Delete: &constants.Timeout300s,
Default: &constants.Timeout300s,
Create: &constants.Timeout20m,
Read: &constants.Timeout600s,
Update: &constants.Timeout20m,
Delete: &constants.Timeout600s,
Default: &constants.Timeout600s,
},
Schema: resourceVinsSchemaMake(),

View File

@@ -10,8 +10,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -10,8 +10,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -10,8 +10,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -14,8 +14,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -10,8 +10,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -10,8 +10,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -10,8 +10,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -10,8 +10,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -10,8 +10,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -10,8 +10,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -10,8 +10,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -10,8 +10,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -10,8 +10,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -10,8 +10,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -10,8 +10,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -10,8 +10,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -10,8 +10,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -0,0 +1,32 @@
#Расскомментируйте этот код,
#и внесите необходимые правки в версию и путь,
#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером
/*
terraform {
required_providers {
decort = {
source = "basis/decort/decort"
version = "<VERSION>"
}
}
}
*/
provider "decort" {
authenticator = "oauth2"
oauth2_url = "https://sso.digitalenergy.online"
controller_url = "https://mr4.digitalenergy.online"
app_id = ""
app_secret = ""
}
data "decort_flipgroup" "fg" {
# ID флипгруппы
# Обязательный параметр
# int
flipgroup_id = 999
}
output "fg_out" {
value = data.decort_flipgroup.fg
}

View File

@@ -0,0 +1,37 @@
#Расскомментируйте этот код,
#и внесите необходимые правки в версию и путь,
#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером
/*
terraform {
required_providers {
decort = {
source = "basis/decort/decort"
version = "<VERSION>"
}
}
}
*/
provider "decort" {
authenticator = "oauth2"
oauth2_url = "https://sso.digitalenergy.online"
controller_url = "https://mr4.digitalenergy.online"
app_id = ""
app_secret = ""
}
data "decort_flipgroup_list" "fg" {
# Номер страницы
# Опциональный параметр
# int
page = 0
# Размер страницы
# Опциональный параметр
# int
size = 0
}
output "fg_out" {
value = data.decort_flipgroup_list.fg
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -0,0 +1,31 @@
#Расскомментируйте этот код,
#и внесите необходимые правки в версию и путь,
#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером
/*
terraform {
required_providers {
decort = {
source = "basis/decort/decort"
version = "<VERSION>"
}
}
}
*/
provider "decort" {
authenticator = "oauth2"
oauth2_url = "https://sso.digitalenergy.online"
controller_url = "https://mr4.digitalenergy.online"
app_id = ""
app_secret = ""
}
data "decort_k8s_computes" "computes" {
# ID кластера
# Обязательный параметр
k8s_id = 999
}
output "computes_out" {
value = data.decort_k8s_computes.computes
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -10,8 +10,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -12,8 +12,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -10,8 +10,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
/* terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
} */

View File

@@ -9,8 +9,8 @@
/* terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
} */

View File

@@ -9,8 +9,8 @@
/* terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
} */

View File

@@ -9,8 +9,8 @@
/* terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
} */

View File

@@ -9,8 +9,8 @@
/* terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
} */

View File

@@ -9,8 +9,8 @@
/* terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
} */

View File

@@ -9,8 +9,8 @@
/* terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
} */

View File

@@ -9,8 +9,8 @@
/* terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
} */

View File

@@ -9,8 +9,8 @@
/* terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
} */

View File

@@ -9,8 +9,8 @@
/* terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
} */

View File

@@ -9,8 +9,8 @@
/* terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
} */

View File

@@ -11,8 +11,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -14,8 +14,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -17,8 +17,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -13,8 +13,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -9,8 +9,8 @@
terraform {
required_providers {
decort = {
version = "1.1"
source = "digitalenergy.online/decort/decort"
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}

View File

@@ -0,0 +1,67 @@
#Расскомментируйте этот код,
#и внесите необходимые правки в версию и путь,
#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером
/*
terraform {
required_providers {
decort = {
source = "basis/decort/decort"
version = "<VERSION>"
}
}
}
*/
provider "decort" {
authenticator = "oauth2"
oauth2_url = "https://sso.digitalenergy.online"
controller_url = "https://mr4.digitalenergy.online"
app_id = ""
app_secret = ""
}
resource "decort_flipgroup" "fg" {
# ID аккаунта
# Обязательный параметр
# int
account_id = 999
# Наименование Flipgroup
# Обязательный параметр
# string
name = "flipgroup_name"
# Тип сети (EXTNET, ViNS)
# Обязательный параметр
# string
net_type = "EXTNET"
# ID сети
# Обязательный параметр
# int
net_id = 13
# Тип клиентов (в данный момент поддерживается только тип 'compute')
# Обязательный параметр
# string
client_type = "compute"
# IP-адрес
# Опциональный параметр
# string
ip = "127.0.0.1"
# Список клиентов, прикрепленных к флипгруппе
# Опциональный параметр
# []int
client_ids = [11269]
# Описание флипгруппы
# Опциональный параметр
# string
desc = "CHANGED"
}
output "fg_out" {
value = decort_flipgroup.fg
}

View File

@@ -0,0 +1,102 @@
#Расскомментируйте этот код,
#и внесите необходимые правки в версию и путь,
#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером
/*
terraform {
required_providers {
decort = {
source = "basis/decort/decort"
version = "<VERSION>"
}
}
}
*/
provider "decort" {
authenticator = "oauth2"
oauth2_url = "https://sso.digitalenergy.online"
controller_url = "https://mr4.digitalenergy.online"
app_id = ""
app_secret = ""
}
resource "decort_image" "img" {
# Наименование образа
# Обязательный параметр
# string
name = "image_name"
# grid ID платформы
# Обязательный параметр
# int
gid = 2002
# Драйверы компьютов, подходящие для данного образа
# Обязательный параметр
# []string
drivers = ["KVM_X86"]
# Тип образа (linux, windows и др.)
# Обязательный параметр
# string
type = "linux"
# Прямая ссылка на образ
# Обязательный параметр
# string
url = "https://dl-cdn.alpinelinux.org/alpine/v3.17/releases/x86_64/alpine-virt-3.17.3-x86_64.iso"
# Тип загрузчика (bios/uefi)
# Обязательный параметр
# string
boot_type = "bios"
# ID аккаунта
# Опциональный параметр
# int
account_id = 138
# Поддержка hot resize
# Опциональный параметр
# bool
hot_resize = true
# Юзернейм для образа
# Опциональный параметр
# string
username = "userx"
# Пароль для образа
# Опциональный параметр
# string
password = "passx"
# Юзернейм для загрузки binary media
# Опциональный параметр
# string
username_dl = "userxdl"
# Пароль для загрузки binary media
# Опциональный параметр
# string
password_dl = "passxdl"
# Storage endpoint provider ID
# Опциональный параметр
# int
sep_id = 1
# Pool для образа
# Опциональный параметр
# string
pool_name = "pool"
# Архитектура обраща (X86_64 / PPC64_LE)
# Опциональный параметр
# string
architecture = "PPC64_LE"
}
output "img_out" {
value = decort_image.img
}

View File

@@ -1,15 +1,3 @@
/*
Пример использования
Ресурсов k8s cluster
Ресурсы позволяет:
1. Создавать
2. Редактировать
3. Удалять
*/
#Расскомментируйте этот код,
#и внесите необходимые правки в версию и путь,
#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером
@@ -17,8 +5,8 @@
terraform {
required_providers {
decort = {
source = "terraform.local/local/decort"
version = "1.0.0"
source = "basis/decort/decort"
version = "<VERSION>"
}
}
}
@@ -32,7 +20,6 @@ provider "decort" {
app_secret = ""
}
resource "decort_k8s" "cluster" {
#имя кластера
#обязательный параметр
@@ -50,11 +37,34 @@ resource "decort_k8s" "cluster" {
#тип - число
k8sci_id = 9
#сетевой плагин
#обязательный параметр
#тип - строка
network_plugin = "flannel"
#имя для первой worker group, созданной в кластере
#обязательный параметр
#тип - строка
wg_name = "workers"
# список labels для дефолтной worker группы
# опциональный параметр
# В скором времени параметры labels, annotations, taints будут полностью перенесены в блок workers
# тип - массив строк
labels = ["key1=val1", "key2=val2"]
# список annotations для дефолтной worker группы
# опциональный параметр
# В скором времени параметры labels, annotations, taints будут полностью перенесены в блок workers
# тип - массив строк
annotations = ["key1=val1", "key2=val2"]
# список taints для дефолтной worker группы
# опциональный параметр
# В скором времени параметры labels, annotations, taints будут полностью перенесены в блок workers
# тип - массив строк
taints = ["key1=val1", "key2=val2"]
#настройка мастер node или nodes
#опциональный параметр
#максимальное кол-во элементов - 1
@@ -83,11 +93,16 @@ resource "decort_k8s" "cluster" {
disk = 10
}
#настройка worker node или nodes
#настройка worker группы
#опциональный параметр
#максимальное кол-во элементов - 1
#тип - список нод
#Первая указанная воркер-группа должна соответствовать изначально созданной вместе с кластером.
# labels, annotations, taints для дефолтной worker группы указываются в корне ресурса при создании кластера.
workers {
#наименование worker группы
#обязательный параметр
#тип - строка
name = "workers_wg"
#кол-во node
#обязательный параметр
#тип - число
@@ -107,6 +122,70 @@ resource "decort_k8s" "cluster" {
#обязательный параметр
#тип - число
disk = 10
#Идентификатор SEP
#опциональный параметр
#тип - число
sep_id = 1010
#Имя SEP pool'a
#опциональный параметр
#тип - строка
sep_pool = "data01"
}
#...Далее можно создавать произвольное кол-во дополнительных worker групп
# labels, annotations и taints для последующих групп указываются непосредственно в блоке workers
workers {
#наименование worker группы
#обязательный параметр
#тип - строка
name = "additional_wg"
#кол-во node
#обязательный параметр
#тип - число
num = 2
#кол-во cpu
#обязательный параметр
#тип - число
cpu = 2
#кол-во RAM в Мбайтах
#обязательный параметр
#тип - число
ram = 4096
#размер диска в Гбайтах
#обязательный параметр
#тип - число
disk = 10
#Идентификатор SEP
#опциональный параметр
#тип - число
sep_id = 1010
#Имя SEP pool'a
#опциональный параметр
#тип - строка
sep_pool = "data01"
#Список лейблов
#опциональный параметр
#тип - массив строк
labels = ["label1=value1", "label2=value2"]
#Список аннотаций
#опциональный параметр
#тип - массив строк
annotations = ["key1=value1", "key2=value2"]
#Список taints
#опциональный параметр
#тип - массив строк
taints = ["key1=value1:NoSchedule", "key2=value2:NoExecute"]
}
}

Some files were not shown because too many files have changed in this diff Show More