This commit is contained in:
2023-12-18 18:55:52 +03:00
parent e2ee45ee14
commit 20050bc169
213 changed files with 37547 additions and 2873 deletions

View File

@@ -0,0 +1,72 @@
/*
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 k8ci
import (
"context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func dataSourceK8CIRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
data, err := utilityK8CICheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
d.SetId(strconv.Itoa(d.Get("k8ci_id").(int)))
flattenK8CIItems(d, data)
return nil
}
func DataSourceK8CI() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceK8CIRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceK8CISchemaMake(),
}
}

View File

@@ -0,0 +1,73 @@
/*
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 k8ci
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 dataSourceK8CIListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
list, err := utilityK8CIListCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
d.SetId(uuid.New().String())
d.Set("items", flattenK8CIListItems(list))
d.Set("entry_count", list.EntryCount)
return nil
}
func DataSourceK8CIList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceK8CIListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceK8CIListSchemaMake(),
}
}

View File

@@ -0,0 +1,73 @@
/*
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 k8ci
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 dataSourceK8CIListDeletedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
list, err := utilityK8CIListDeletedCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
d.SetId(uuid.New().String())
d.Set("items", flattenK8CIListItems(list))
d.Set("entry_count", list.EntryCount)
return nil
}
func DataSourceK8CIListDeleted() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceK8CIListDeletedRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceK8CIListDeletedSchemaMake(),
}
}

View File

@@ -0,0 +1,92 @@
/*
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>
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 k8ci
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8ci"
)
func flattenK8CIListItems(list *k8ci.ListK8CI) []map[string]interface{} {
log.Debug("flattenK8CIListItems")
res := make([]map[string]interface{}, 0, len(list.Data))
for _, item := range list.Data {
temp := map[string]interface{}{
"created_time": item.CreatedTime,
"desc": item.Description,
"gid": item.GID,
"guid": item.GUID,
"k8ci_id": item.ID,
"lb_image_id": item.LBImageID,
"master_driver": item.MasterDriver,
"master_image_id": item.MasterImageID,
"max_master_count": item.MaxMasterCount,
"max_worker_count": item.MaxWorkerCount,
"name": item.Name,
"shared_with": item.SharedWith,
"status": item.Status,
"version": item.Version,
"worker_driver": item.WorkerDriver,
"worker_image_id": item.WorkerImageID,
}
res = append(res, temp)
}
return res
}
func flattenK8CIItems(d *schema.ResourceData, data *k8ci.RecordK8CI) error {
log.Debugf("flattenK8CI: ID %d", data.ID)
d.Set("desc", data.Description)
d.Set("gid", data.GID)
d.Set("guid", data.GUID)
d.Set("k8ci_id", data.ID)
d.Set("lb_image_id", data.LBImageID)
d.Set("master_driver", data.MasterDriver)
d.Set("master_image_id", data.MasterImageID)
d.Set("max_master_count", data.MaxMasterCount)
d.Set("max_worker_count", data.MaxWorkerCount)
d.Set("milestones", data.Milestones)
d.Set("name", data.Name)
d.Set("network_plugins", data.NetworkPlugins)
d.Set("shared_with", data.SharedWith)
d.Set("status", data.Status)
d.Set("version", data.Version)
d.Set("worker_driver", data.WorkerDriver)
d.Set("worker_image_id", data.WorkerImageID)
return nil
}

View File

@@ -0,0 +1,60 @@
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
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 k8ci
import (
"context"
"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"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/ic"
)
func checkParamsExistence(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg) diag.Diagnostics {
var errs []error
masterImageId := uint64(d.Get("master_image_id").(int))
workerImageId := uint64(d.Get("worker_image_id").(int))
if err := ic.ExistImage(ctx, masterImageId, c); err != nil {
errs = append(errs, err)
}
if err := ic.ExistImage(ctx, workerImageId, c); err != nil {
errs = append(errs, err)
}
return dc.ErrorsToDiagnostics(errs)
}

View File

@@ -0,0 +1,360 @@
/*
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>
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 k8ci
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/k8ci"
"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 resourceK8CICreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceK8CICreate: called for k8ci %s", d.Get("name").(string))
c := m.(*controller.ControllerCfg)
if diags := checkParamsExistence(ctx, d, c); diags != nil {
return diags
}
req := k8ci.CreateRequest{
Name: d.Get("name").(string),
Version: d.Get("version").(string),
MasterDriver: d.Get("master_driver").(string),
WorkerDriver: d.Get("worker_driver").(string),
MaxMasterCount: uint64(d.Get("max_master_count").(int)),
MaxWorkerCount: uint64(d.Get("max_worker_count").(int)),
MasterImageID: uint64(d.Get("master_image_id").(int)),
WorkerImageID: uint64(d.Get("worker_image_id").(int)),
}
var networkPlugins []string
for _, item := range d.Get("network_plugins").([]interface{}) {
networkPlugins = append(networkPlugins, item.(string))
}
req.NetworkPlugins = networkPlugins
if desc, ok := d.GetOk("desc"); ok {
req.Description = desc.(string)
}
if sharedWithInterface, ok := d.GetOk("shared_with"); ok {
sharedWithList := sharedWithInterface.(*schema.Set).List()
var sharedWith []uint64
for _, item := range sharedWithList {
sharedWith = append(sharedWith, uint64(item.(int)))
}
req.SharedWith = sharedWith
}
k8ciID, err := c.CloudBroker().K8CI().Create(ctx, req)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
d.SetId(strconv.FormatUint(k8ciID, 10))
warnings := dc.Warnings{}
if enabled, ok := d.GetOk("enabled"); ok {
log.Debugf("resourceK8CICreate: enable=%t k8ci_id %d after completing its resource configuration", enabled, k8ciID)
if enabled.(bool) {
enabledReq := k8ci.EnableRequest{
K8CIID: k8ciID,
}
if _, err := c.CloudBroker().K8CI().Enable(ctx, enabledReq); err != nil {
warnings.Add(err)
}
} else {
disableReq := k8ci.DisableRequest{
K8CIID: k8ciID,
}
if _, err := c.CloudBroker().K8CI().Disable(ctx, disableReq); err != nil {
warnings.Add(err)
}
}
}
return append(warnings.Get(), resourceK8CIRead(ctx, d, m)...)
}
func resourceK8CIRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
// c := m.(*controller.ControllerCfg)
log.Debugf("resourceK8CIRead: called for k8ci id %s, name %s", d.Id(), d.Get("name").(string))
k8ciRec, err := utilityK8CICheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
hasChanged := false
switch k8ciRec.Status {
case status.Deleted:
// restoreReq := k8ci.RestoreRequest{K8CIID: k8ciRec.ID}
// _, err := c.CloudBroker().K8CI().Restore(ctx, restoreReq)
// if err != nil {
// return diag.FromErr(err)
// }
// if enabled, ok := d.GetOk("enabled"); ok {
// if enabled.(bool) {
// enabledReq := k8ci.EnableRequest{K8CIID: k8ciRec.ID}
// _, err := c.CloudBroker().K8CI().Enable(ctx, enabledReq)
// if err != nil {
// return diag.FromErr(err)
// }
// }
// }
// hasChanged = true
case status.Destroyed:
d.SetId("")
// return resourceK8CICreate(ctx, d, m)
return diag.Errorf("The resource cannot be updated because it has been destroyed")
case status.Disabled:
log.Debugf("The k8ci is in status: %s, troubles may occur with update. Please, enable k8ci first.", k8ciRec.Status)
case status.Redeploying:
case status.Deleting:
case status.Destroying:
return diag.Errorf("The k8ci is in progress with status: %s", k8ciRec.Status)
case status.Modeled:
return diag.Errorf("The k8ci is in status: %s, please, contact support for more information", k8ciRec.Status)
}
if hasChanged {
k8ciRec, err = utilityK8CICheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
}
flattenK8CIItems(d, k8ciRec)
return nil
}
func resourceK8CIUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceK8CIUpdate: called for k8ci %s, id: %s", d.Get("name").(string), d.Id())
c := m.(*controller.ControllerCfg)
if diags := checkParamsExistence(ctx, d, c); diags != nil {
return diags
}
k8ciRec, err := utilityK8CICheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
warnings := dc.Warnings{}
hasChanged := false
switch k8ciRec.Status {
case status.Deleted:
restoreReq := k8ci.RestoreRequest{K8CIID: k8ciRec.ID}
_, err := c.CloudBroker().K8CI().Restore(ctx, restoreReq)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
if enabled, ok := d.GetOk("enabled"); ok {
if enabled.(bool) {
enabledReq := k8ci.EnableRequest{K8CIID: k8ciRec.ID}
_, err := c.CloudBroker().K8CI().Enable(ctx, enabledReq)
if err != nil {
warnings.Add(err)
}
} else {
disableReq := k8ci.DisableRequest{K8CIID: k8ciRec.ID}
if _, err := c.CloudBroker().K8CI().Disable(ctx, disableReq); err != nil {
warnings.Add(err)
}
}
}
hasChanged = true
case status.Destroyed:
d.SetId("")
return diag.Errorf("The resource cannot be updated because it has been destroyed")
// return resourceK8CICreate(ctx, d, m)
case status.Disabled:
log.Debugf("The k8ci is in status: %s, troubles may occur with update. Please, enable k8ci first.", k8ciRec.Status)
case status.Redeploying:
case status.Deleting:
case status.Destroying:
return diag.Errorf("The k8ci is in progress with status: %s", k8ciRec.Status)
case status.Modeled:
return diag.Errorf("The k8ci is in status: %s, please, contact support for more information", k8ciRec.Status)
}
if hasChanged {
k8ciRec, err = utilityK8CICheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
}
if d.HasChange("enabled") {
err := resourceK8CIChangeEnable(ctx, d, k8ciRec.ID, m)
if err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("shared_with") {
err := resourceK8CIChangeSharedWith(ctx, d, k8ciRec.ID, m)
if err != nil {
return diag.FromErr(err)
}
}
return append(resourceK8CIRead(ctx, d, m), warnings.Get()...)
}
func resourceK8CIDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceK8CIDelete: called for k8ci %s, id: %s", d.Get("name").(string), d.Id())
c := m.(*controller.ControllerCfg)
k8ciId, _ := strconv.ParseUint(d.Id(), 10, 64)
req := k8ci.DeleteRequest{
K8CIID: k8ciId,
}
if permanently, ok := d.GetOk("permanently"); ok {
req.Permanently = permanently.(bool)
}
if _, err := c.CloudBroker().K8CI().Delete(ctx, req); err != nil {
return diag.FromErr(err)
}
d.SetId("")
return nil
}
func ResourceK8CI() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
CreateContext: resourceK8CICreate,
ReadContext: resourceK8CIRead,
UpdateContext: resourceK8CIUpdate,
DeleteContext: resourceK8CIDelete,
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: resourceK8CISchemaMake(),
}
}
func resourceK8CIChangeEnable(ctx context.Context, d *schema.ResourceData, k8ciId uint64, m interface{}) error {
c := m.(*controller.ControllerCfg)
enabled := d.Get("enabled").(bool)
if enabled {
req := k8ci.EnableRequest{
K8CIID: k8ciId,
}
if _, err := c.CloudBroker().K8CI().Enable(ctx, req); err != nil {
return err
}
} else {
req := k8ci.DisableRequest{
K8CIID: k8ciId,
}
if _, err := c.CloudBroker().K8CI().Disable(ctx, req); err != nil {
return err
}
}
return nil
}
func resourceK8CIChangeSharedWith(ctx context.Context, d *schema.ResourceData, k8ciId uint64, m interface{}) error {
c := m.(*controller.ControllerCfg)
oldSet, newSet := d.GetChange("shared_with")
deletedSharedWith := (oldSet.(*schema.Set).Difference(newSet.(*schema.Set))).List()
if len(deletedSharedWith) > 0 {
for _, userAcessInterface := range deletedSharedWith {
removeReq := k8ci.AccessRemoveRequest{
K8CIID: k8ciId,
AccountId: uint64(userAcessInterface.(int)),
}
if _, err := c.CloudBroker().K8CI().AccessRemove(ctx, removeReq); err != nil {
return err
}
}
}
addedSharedWith := (newSet.(*schema.Set).Difference(oldSet.(*schema.Set))).List()
if len(addedSharedWith) > 0 {
for _, userAcessInterface := range addedSharedWith {
removeReq := k8ci.AccessAddRequest{
K8CIID: k8ciId,
AccountId: uint64(userAcessInterface.(int)),
}
if _, err := c.CloudBroker().K8CI().AccessAdd(ctx, removeReq); err != nil {
return err
}
}
}
return nil
}

View File

@@ -0,0 +1,478 @@
/*
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@dbasistech.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 k8ci
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
func dataSourceK8CISchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"k8ci_id": {
Type: schema.TypeInt,
Required: true,
Description: "K8CI ID",
},
"desc": {
Type: schema.TypeString,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
Description: "gid",
},
"guid": {
Type: schema.TypeInt,
Computed: true,
Description: "guid",
},
"lb_image_id": {
Type: schema.TypeInt,
Computed: true,
Description: "LB Image ID",
},
"master_driver": {
Type: schema.TypeString,
Computed: true,
},
"master_image_id": {
Type: schema.TypeInt,
Computed: true,
},
"max_master_count": {
Type: schema.TypeInt,
Computed: true,
},
"max_worker_count": {
Type: schema.TypeInt,
Computed: true,
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "K8CI name",
},
"network_plugins": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"shared_with": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "K8CI Status",
},
"version": {
Type: schema.TypeString,
Computed: true,
},
"worker_driver": {
Type: schema.TypeString,
Computed: true,
},
"worker_image_id": {
Type: schema.TypeInt,
Computed: true,
},
}
}
func dataSourceK8CIListSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by name",
},
"status": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by status",
},
"worker_driver": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by worker driver",
},
"master_driver": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by master driver",
},
"network_plugin": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by network plugin",
},
"include_disabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Include deleted k8cis in result",
},
"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{
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"desc": {
Type: schema.TypeString,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
Description: "gid",
},
"guid": {
Type: schema.TypeInt,
Computed: true,
Description: "guid",
},
"k8ci_id": {
Type: schema.TypeInt,
Computed: true,
Description: "K8CI ID",
},
"lb_image_id": {
Type: schema.TypeInt,
Computed: true,
Description: "LB Image ID",
},
"master_driver": {
Type: schema.TypeString,
Computed: true,
},
"master_image_id": {
Type: schema.TypeInt,
Computed: true,
},
"max_master_count": {
Type: schema.TypeInt,
Computed: true,
},
"max_worker_count": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "K8CI name",
},
"shared_with": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "K8CI Status",
},
"version": {
Type: schema.TypeString,
Computed: true,
},
"worker_driver": {
Type: schema.TypeString,
Computed: true,
},
"worker_image_id": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
}
func dataSourceK8CIListDeletedSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by name",
},
"worker_driver": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by worker driver",
},
"master_driver": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by master driver",
},
"network_plugin": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by network plugin",
},
"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{
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"desc": {
Type: schema.TypeString,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
Description: "gid",
},
"guid": {
Type: schema.TypeInt,
Computed: true,
Description: "guid",
},
"k8ci_id": {
Type: schema.TypeInt,
Computed: true,
Description: "K8CI ID",
},
"lb_image_id": {
Type: schema.TypeInt,
Computed: true,
Description: "LB Image ID",
},
"master_driver": {
Type: schema.TypeString,
Computed: true,
},
"master_image_id": {
Type: schema.TypeInt,
Computed: true,
},
"max_master_count": {
Type: schema.TypeInt,
Computed: true,
},
"max_worker_count": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "K8CI name",
},
"shared_with": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "K8CI Status",
},
"version": {
Type: schema.TypeString,
Computed: true,
},
"worker_driver": {
Type: schema.TypeString,
Computed: true,
},
"worker_image_id": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
}
func resourceK8CISchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: "K8CI name",
},
"version": {
Type: schema.TypeString,
Required: true,
},
"master_driver": {
Type: schema.TypeString,
Required: true,
},
"master_image_id": {
Type: schema.TypeInt,
Required: true,
},
"max_master_count": {
Type: schema.TypeInt,
Required: true,
},
"max_worker_count": {
Type: schema.TypeInt,
Required: true,
},
"worker_image_id": {
Type: schema.TypeInt,
Required: true,
},
"worker_driver": {
Type: schema.TypeString,
Required: true,
},
"network_plugins": {
Type: schema.TypeList,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"enabled": {
Type: schema.TypeBool,
Optional: true,
},
"permanently": {
Type: schema.TypeBool,
Default: false,
Optional: true,
},
"desc": {
Type: schema.TypeString,
Computed: true,
Optional: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
Description: "gid",
},
"guid": {
Type: schema.TypeInt,
Computed: true,
Description: "guid",
},
"k8ci_id": {
Type: schema.TypeInt,
Computed: true,
Description: "K8CI ID",
},
"lb_image_id": {
Type: schema.TypeInt,
Computed: true,
Description: "LB Image ID",
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
},
"shared_with": {
Type: schema.TypeSet,
Computed: true,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "K8CI Status",
},
}
}

View File

@@ -0,0 +1,63 @@
/*
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 k8ci
import (
"context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8ci"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityK8CICheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*k8ci.RecordK8CI, error) {
c := m.(*controller.ControllerCfg)
req := k8ci.GetRequest{}
if d.Id() != "" {
k8ciId, _ := strconv.ParseUint(d.Id(), 10, 64)
req.K8CIID = k8ciId
} else {
req.K8CIID = uint64(d.Get("k8ci_id").(int))
}
res, err := c.CloudBroker().K8CI().Get(ctx, req)
if err != nil {
return nil, err
}
return res, nil
}

View File

@@ -0,0 +1,84 @@
/*
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 k8ci
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8ci"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityK8CIListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*k8ci.ListK8CI, error) {
c := m.(*controller.ControllerCfg)
req := k8ci.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 status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if worker_driver, ok := d.GetOk("worker_driver"); ok {
req.WorkerDriver = worker_driver.(string)
}
if master_driver, ok := d.GetOk("master_driver"); ok {
req.MasterDriver = master_driver.(string)
}
if network_plugin, ok := d.GetOk("network_plugin"); ok {
req.NetworkPlugins = network_plugin.(string)
}
if include_disabled, ok := d.GetOk("include_disabled"); ok {
req.IncludeDisabled = include_disabled.(bool)
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
resList, err := c.CloudBroker().K8CI().List(ctx, req)
if err != nil {
return nil, err
}
return resList, nil
}

View File

@@ -0,0 +1,78 @@
/*
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 k8ci
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8ci"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityK8CIListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*k8ci.ListK8CI, error) {
c := m.(*controller.ControllerCfg)
req := k8ci.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 worker_driver, ok := d.GetOk("worker_driver"); ok {
req.WorkerDriver = worker_driver.(string)
}
if master_driver, ok := d.GetOk("master_driver"); ok {
req.MasterDriver = master_driver.(string)
}
if network_plugin, ok := d.GetOk("network_plugin"); ok {
req.NetworkPlugins = network_plugin.(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))
}
resList, err := c.CloudBroker().K8CI().ListDeleted(ctx, req)
if err != nil {
return nil, err
}
return resList, nil
}