This commit is contained in:
2024-05-31 14:05:21 +03:00
parent 84b7a80e1b
commit db1760cb72
815 changed files with 58194 additions and 11049 deletions

View File

@@ -117,6 +117,11 @@ func dataSourceImageListSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "Find bootable images",
},
"sort_by": {
Type: schema.TypeString,
Optional: true,
Description: "sort by one of supported fields, format +|-(field)",
},
"page": {
Type: schema.TypeInt,
Optional: true,

View File

@@ -1,9 +1,11 @@
package image
import (
"encoding/json"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/image"
"strconv"
)
func flattenHistory(history []image.History) []map[string]interface{} {
@@ -21,6 +23,8 @@ func flattenHistory(history []image.History) []map[string]interface{} {
}
func flattenImage(d *schema.ResourceData, img *image.RecordImage) {
cdPresentedTo, _ := json.Marshal(img.CdPresentedTo)
d.Set("unc_path", img.UNCPath)
d.Set("ckey", img.CKey)
d.Set("account_id", img.AccountID)
@@ -29,6 +33,7 @@ func flattenImage(d *schema.ResourceData, img *image.RecordImage) {
d.Set("boot_type", img.BootType)
d.Set("bootable", img.Bootable)
d.Set("compute_ci_id", img.ComputeCIID)
d.Set("cd_presented_to", string(cdPresentedTo))
d.Set("deleted_time", img.DeletedTime)
d.Set("desc", img.Description)
d.Set("drivers", img.Drivers)
@@ -42,6 +47,7 @@ func flattenImage(d *schema.ResourceData, img *image.RecordImage) {
d.Set("link_to", img.LinkTo)
d.Set("milestones", img.Milestones)
d.Set("image_name", img.Name)
d.Set("network_interface_naming", img.NetworkInterfaceNaming)
d.Set("password", img.Password)
d.Set("pool_name", img.Pool)
d.Set("provider_name", img.ProviderName)
@@ -63,24 +69,25 @@ func flattenImageList(il *image.ListImages) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, img := range il.Data {
temp := map[string]interface{}{
"account_id": img.AccountID,
"architecture": img.Architecture,
"boot_type": img.BootType,
"bootable": img.Bootable,
"cdrom": img.CDROM,
"desc": img.Description,
"drivers": img.Drivers,
"hot_resize": img.HotResize,
"image_id": img.ID,
"link_to": img.LinkTo,
"image_name": img.Name,
"pool_name": img.Pool,
"sep_id": img.SepID,
"size": img.Size,
"status": img.Status,
"type": img.Type,
"username": img.Username,
"virtual": img.Virtual,
"account_id": img.AccountID,
"architecture": img.Architecture,
"boot_type": img.BootType,
"bootable": img.Bootable,
"cdrom": img.CDROM,
"desc": img.Description,
"drivers": img.Drivers,
"hot_resize": img.HotResize,
"image_id": img.ID,
"link_to": img.LinkTo,
"image_name": img.Name,
"network_interface_naming": img.NetworkInterfaceNaming,
"pool_name": img.Pool,
"sep_id": img.SepID,
"size": img.Size,
"status": img.Status,
"type": img.Type,
"username": img.Username,
"virtual": img.Virtual,
}
res = append(res, temp)
}

View File

@@ -1,216 +1,222 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package image
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
func dataSourceImageExtendSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"image_id": {
Type: schema.TypeInt,
Required: true,
},
"show_all": {
Type: schema.TypeBool,
Default: false,
Optional: true,
},
"unc_path": {
Type: schema.TypeString,
Computed: true,
},
"ckey": {
Type: schema.TypeString,
Computed: true,
},
"account_id": {
Type: schema.TypeInt,
Computed: true,
},
"acl": {
Type: schema.TypeString,
Computed: true,
},
"architecture": {
Type: schema.TypeString,
Computed: true,
},
"boot_type": {
Type: schema.TypeString,
Computed: true,
},
"bootable": {
Type: schema.TypeBool,
Computed: true,
},
"compute_ci_id": {
Type: schema.TypeInt,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"desc": {
Type: schema.TypeString,
Computed: true,
},
"drivers": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"enabled": {
Type: schema.TypeBool,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"history": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"guid": {
Type: schema.TypeString,
Computed: true,
},
"id": {
Type: schema.TypeInt,
Computed: true,
},
"timestamp": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"hot_resize": {
Type: schema.TypeBool,
Computed: true,
},
"last_modified": {
Type: schema.TypeInt,
Computed: true,
},
"link_to": {
Type: schema.TypeInt,
Computed: true,
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
},
"image_name": {
Type: schema.TypeString,
Computed: true,
},
"password": {
Type: schema.TypeString,
Computed: true,
},
"pool_name": {
Type: schema.TypeString,
Computed: true,
},
"provider_name": {
Type: schema.TypeString,
Computed: true,
},
"purge_attempts": {
Type: schema.TypeInt,
Computed: true,
},
"present_to": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"res_id": {
Type: schema.TypeString,
Computed: true,
},
"rescuecd": {
Type: schema.TypeBool,
Computed: true,
},
"sep_id": {
Type: schema.TypeInt,
Computed: true,
},
"shared_with": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"size": {
Type: schema.TypeInt,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"username": {
Type: schema.TypeString,
Computed: true,
},
"version": {
Type: schema.TypeString,
Computed: true,
},
}
}
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package image
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
func dataSourceImageExtendSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"image_id": {
Type: schema.TypeInt,
Required: true,
},
"show_all": {
Type: schema.TypeBool,
Default: false,
Optional: true,
},
"unc_path": {
Type: schema.TypeString,
Computed: true,
},
"ckey": {
Type: schema.TypeString,
Computed: true,
},
"account_id": {
Type: schema.TypeInt,
Computed: true,
},
"acl": {
Type: schema.TypeString,
Computed: true,
},
"architecture": {
Type: schema.TypeString,
Computed: true,
},
"boot_type": {
Type: schema.TypeString,
Computed: true,
},
"bootable": {
Type: schema.TypeBool,
Computed: true,
},
"compute_ci_id": {
Type: schema.TypeInt,
Computed: true,
},
"cd_presented_to": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"desc": {
Type: schema.TypeString,
Computed: true,
},
"drivers": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"enabled": {
Type: schema.TypeBool,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"history": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"guid": {
Type: schema.TypeString,
Computed: true,
},
"id": {
Type: schema.TypeInt,
Computed: true,
},
"timestamp": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"hot_resize": {
Type: schema.TypeBool,
Computed: true,
},
"last_modified": {
Type: schema.TypeInt,
Computed: true,
},
"link_to": {
Type: schema.TypeInt,
Computed: true,
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
},
"image_name": {
Type: schema.TypeString,
Computed: true,
},
"network_interface_naming": {
Type: schema.TypeString,
Computed: true,
},
"password": {
Type: schema.TypeString,
Computed: true,
},
"pool_name": {
Type: schema.TypeString,
Computed: true,
},
"provider_name": {
Type: schema.TypeString,
Computed: true,
},
"purge_attempts": {
Type: schema.TypeInt,
Computed: true,
},
"present_to": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"res_id": {
Type: schema.TypeString,
Computed: true,
},
"rescuecd": {
Type: schema.TypeBool,
Computed: true,
},
"sep_id": {
Type: schema.TypeInt,
Computed: true,
},
"shared_with": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"size": {
Type: schema.TypeInt,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"username": {
Type: schema.TypeString,
Computed: true,
},
"version": {
Type: schema.TypeString,
Computed: true,
},
}
}

View File

@@ -94,6 +94,10 @@ func dataSourceImageSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "Image name",
},
"network_interface_naming": {
Type: schema.TypeString,
Computed: true,
},
"pool_name": {
Type: schema.TypeString,
Computed: true,

View File

@@ -1,159 +1,160 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package image
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
func resourceImageSchemaMake(sch map[string]*schema.Schema) map[string]*schema.Schema {
delete(sch, "show_all")
sch["name"] = &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "Name of the rescue disk",
}
sch["url"] = &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "URL where to download media from",
}
sch["gid"] = &schema.Schema{
Type: schema.TypeInt,
Required: true,
Description: "grid (platform) ID where this template should be create in",
}
sch["image_id"] = &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "image id",
}
sch["boot_type"] = &schema.Schema{
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"bios", "uefi"}, true),
Description: "Boot type of image bios or uefi",
}
sch["type"] = &schema.Schema{
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"linux", "windows", "other"}, true),
Description: "Image type linux, windows or other",
}
sch["hot_resize"] = &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "Does this machine supports hot resize",
}
sch["username"] = &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Optional username for the image",
}
sch["password"] = &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Optional password for the image",
}
sch["account_id"] = &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "AccountId to make the image exclusive",
}
sch["username_dl"] = &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "username for upload binary media",
}
sch["password_dl"] = &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "password for upload binary media",
}
sch["pool_name"] = &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "pool for image create",
}
sch["sep_id"] = &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "storage endpoint provider ID",
}
sch["architecture"] = &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{"X86_64", "PPC64_LE"}, true),
Description: "binary architecture of this image, one of X86_64 of PPC64_LE",
}
sch["drivers"] = &schema.Schema{
Type: schema.TypeList,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
}
sch["permanently"] = &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "whether to completely delete the image",
}
return sch
}
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package image
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
func resourceImageSchemaMake(sch map[string]*schema.Schema) map[string]*schema.Schema {
delete(sch, "show_all")
sch["name"] = &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "Name of the rescue disk",
}
sch["url"] = &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "URL where to download media from",
}
sch["image_id"] = &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "image id",
}
sch["boot_type"] = &schema.Schema{
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"bios", "uefi"}, true),
Description: "Boot type of image bios or uefi",
}
sch["type"] = &schema.Schema{
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"linux", "windows", "other"}, true),
Description: "Image type linux, windows or other",
}
sch["hot_resize"] = &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "Does this machine supports hot resize",
}
sch["username"] = &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Optional username for the image",
}
sch["password"] = &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Optional password for the image",
}
sch["account_id"] = &schema.Schema{
Type: schema.TypeInt,
Required: true,
Description: "AccountId to make the image exclusive",
}
sch["username_dl"] = &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "username for upload binary media",
}
sch["password_dl"] = &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "password for upload binary media",
}
sch["pool_name"] = &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "pool for image create",
}
sch["sep_id"] = &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "storage endpoint provider ID",
}
sch["architecture"] = &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{"X86_64", "PPC64_LE"}, true),
Description: "binary architecture of this image, one of X86_64 of PPC64_LE",
}
sch["drivers"] = &schema.Schema{
Type: schema.TypeList,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
}
sch["permanently"] = &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "whether to completely delete the image",
}
sch["network_interface_naming"] = &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{"eth", "ens"}, true),
Description: "select a network interface naming pattern for your Linux machine. eth - onboard, ens - pci slot naming",
}
return sch
}

View File

@@ -2,9 +2,12 @@ package image
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/disks"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/locations"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
@@ -34,3 +37,46 @@ func existGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool,
return len(locationList.FilterByGID(gid).Data) != 0, nil
}
func existComputeID(ctx context.Context, computeId uint64, m interface{}) error {
c := m.(*controller.ControllerCfg)
req := compute.GetRequest{ComputeID: computeId}
// check for compute existence
computeRecord, err := c.CloudAPI().Compute().Get(ctx, req)
if err != nil {
return fmt.Errorf("ComputeID %d is not allowed or does not exist", computeId)
}
// check if compute was created as blank
computeImageId := computeRecord.ImageID
bootImageId := -1
for _, d := range computeRecord.Disks {
if d.Type == "B" {
bootImageId = int(d.ImageID)
break
}
}
if computeImageId != 0 && bootImageId != 0 {
return fmt.Errorf("ComputeID %d is not allowed because it is not blank compute (either compute imageId or boot imageId are not zero)", computeId)
}
return nil
}
func existDiskID(ctx context.Context, diskId uint64, m interface{}) error {
c := m.(*controller.ControllerCfg)
req := disks.ListRequest{ByID: diskId}
diskList, err := c.CloudAPI().Disks().List(ctx, req)
if err != nil {
return err
}
if len(diskList.Data) != 1 {
return fmt.Errorf("diskId %d is not allowed or doesn't exist", diskId)
}
return nil
}

View File

@@ -48,34 +48,23 @@ import (
func resourceImageCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceImageCreate: called for image %s", d.Get("name").(string))
haveGID, err := existGID(ctx, d, m)
haveAccountID, err := existAccountID(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
if !haveGID {
return diag.Errorf("resourceImageCreate: can't create Image because GID %d is not allowed or does not exist", d.Get("gid").(int))
}
if _, ok := d.GetOk("account_id"); ok {
haveAccountID, err := existAccountID(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
if !haveAccountID {
return diag.Errorf("resourceImageCreate: can't create Image because AccountID %d is not allowed or does not exist", d.Get("account_id").(int))
}
if !haveAccountID {
return diag.Errorf("resourceImageCreate: can't create Image because AccountID %d is not allowed or does not exist", d.Get("account_id").(int))
}
c := m.(*controller.ControllerCfg)
req := image.CreateRequest{}
req.Name = d.Get("name").(string)
req.URL = d.Get("url").(string)
req.GID = uint64(d.Get("gid").(int))
req.BootType = d.Get("boot_type").(string)
req.ImageType = d.Get("type").(string)
req := image.CreateRequest{
AccountID: uint64(d.Get("account_id").(int)),
Name: d.Get("name").(string),
URL: d.Get("url").(string),
BootType: d.Get("boot_type").(string),
ImageType: d.Get("type").(string),
}
drivers := []string{}
for _, driver := range d.Get("drivers").([]interface{}) {
@@ -93,9 +82,6 @@ func resourceImageCreate(ctx context.Context, d *schema.ResourceData, m interfac
if password, ok := d.GetOk("password"); ok {
req.Password = password.(string)
}
if accountId, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(accountId.(int))
}
if usernameDL, ok := d.GetOk("username_dl"); ok {
req.UsernameDL = usernameDL.(string)
}
@@ -111,6 +97,9 @@ func resourceImageCreate(ctx context.Context, d *schema.ResourceData, m interfac
if architecture, ok := d.GetOk("architecture"); ok {
req.Architecture = architecture.(string)
}
if networkInterfaceNaming, ok := d.GetOk("network_interface_naming"); ok {
req.NetworkInterfaceNaming = networkInterfaceNaming.(string)
}
imageId, err := c.CloudAPI().Image().Create(ctx, req)
if err != nil {
@@ -210,15 +199,13 @@ func resourceImageUpdate(ctx context.Context, d *schema.ResourceData, m interfac
return diag.Errorf("resourceImageUpdate: can't update Image because GID %d is not allowed or does not exist", d.Get("gid").(int))
}
if _, ok := d.GetOk("account_id"); ok {
haveAccountID, err := existAccountID(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
haveAccountID, err := existAccountID(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
if !haveAccountID {
return diag.Errorf("resourceImageUpdate: can't update Image because AccountID %d is not allowed or does not exist", d.Get("account_id").(int))
}
if !haveAccountID {
return diag.Errorf("resourceImageUpdate: can't update Image because AccountID %d is not allowed or does not exist", d.Get("account_id").(int))
}
image, err := utilityImageCheckPresence(ctx, d, m)

View File

@@ -0,0 +1,508 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package image
import (
"context"
"fmt"
"strconv"
"strings"
"time"
"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"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/image"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/tasks"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
)
func resourceImageFromBlankComputeCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
computeId := uint64(d.Get("compute_id").(int))
name := d.Get("name").(string)
log.Debugf("resourceImageFromBlankComputeCreate: called for image %s", name)
err := existComputeID(ctx, computeId, m)
if err != nil {
return diag.Errorf("resourceImageFromBlankComputeCreate: can't create Image: %v", err)
}
if _, ok := d.GetOk("account_id"); ok {
haveAccountID, err := existAccountID(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
if !haveAccountID {
return diag.Errorf("resourceImageFromBlankComputeCreate: can't create Image because AccountID %d is not allowed or does not exist", d.Get("account_id").(int))
}
}
c := m.(*controller.ControllerCfg)
req := compute.CreateTemplateFromBlankRequest{
ComputeID: computeId,
Name: name,
BootType: d.Get("boot_type").(string),
ImageType: d.Get("type").(string),
}
if username, ok := d.GetOk("username"); ok {
req.Username = username.(string)
}
if password, ok := d.GetOk("password"); ok {
req.Password = password.(string)
}
if accountId, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(accountId.(int))
}
if sepId, ok := d.GetOk("sep_id"); ok {
req.SepID = uint64(sepId.(int))
}
if poolName, ok := d.GetOk("pool_name"); ok {
req.PoolName = poolName.(string)
}
if hotresize, ok := d.GetOk("hot_resize"); ok {
req.HotResize = hotresize.(bool)
}
var imageId uint64
asyncMode := d.Get("async_mode").(bool)
if !asyncMode {
imageId, err = c.CloudAPI().Compute().CreateTemplateFromBlank(ctx, req)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
} else {
taskId, err := c.CloudAPI().Compute().CreateTemplateFromBlankAsync(ctx, req)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
taskReq := tasks.GetRequest{
AuditID: strings.Trim(taskId, `"`),
}
for {
task, err := c.CloudAPI().Tasks().Get(ctx, taskReq)
if err != nil {
return diag.FromErr(err)
}
log.Debugf("resourceImageFromBlankComputeCreate: instance creating - %s", task.Stage)
if task.Completed {
if task.Error != "" {
return diag.FromErr(fmt.Errorf("cannot create image instance: %v", task.Error))
}
id, err := task.Result.ID()
imageId = uint64(id)
if err != nil {
return diag.FromErr(err)
}
break
}
time.Sleep(time.Second * 20)
}
}
d.SetId(strconv.FormatUint(imageId, 10))
d.Set("image_id", imageId)
_, err = utilityImageCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
return resourceImageFromBlankComputeRead(ctx, d, m)
}
func resourceImageFromBlankComputeRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceImageFromBlankComputeRead: called for %s id: %s", d.Get("name").(string), d.Id())
img, err := utilityImageCheckPresence(ctx, d, m)
if img == nil {
d.SetId("")
return diag.FromErr(err)
}
switch img.Status {
case status.Modeled:
return diag.Errorf("The image is in status: %s, please, contact support for more information", img.Status)
case status.Creating:
case status.Created:
case status.Destroyed, status.Purged:
d.SetId("")
return diag.Errorf("The resource cannot be updated because it has been destroyed")
// return resourceImageCreate(ctx, d, m)
}
flattenImage(d, img)
return nil
}
func resourceImageFromBlankComputeDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceImageFromBlankComputeDelete: called for %s, id: %s", d.Get("name").(string), d.Id())
_, err := utilityImageCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
c := m.(*controller.ControllerCfg)
req := image.DeleteRequest{
ImageID: uint64(d.Get("image_id").(int)),
}
if permanently, ok := d.GetOk("permanently"); ok {
req.Permanently = permanently.(bool)
}
_, err = c.CloudAPI().Image().Delete(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId("")
return nil
}
func resourceImageFromBlankComputeRename(ctx context.Context, d *schema.ResourceData, m interface{}) error {
log.Debugf("resourceImageFromBlankComputeRename: called for %s, id: %s", d.Get("name").(string), d.Id())
c := m.(*controller.ControllerCfg)
req := image.RenameRequest{
ImageID: uint64(d.Get("image_id").(int)),
Name: d.Get("name").(string),
}
_, err := c.CloudAPI().Image().Rename(ctx, req)
if err != nil {
return err
}
return nil
}
func resourceImageFromBlankComputeUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceImageFromBlankComputeUpdate: called for %s, id: %s", d.Get("name").(string), d.Id())
// we do not allow change of compute_id, but allow resource update after import
old, _ := d.GetChange("compute_id")
if old.(int) != 0 && d.HasChange("compute_id") {
return diag.Errorf("resourceImageFromBlankComputeUpdate: can't update Image because compute_id is not allowed to be changed")
}
image, err := utilityImageCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
switch image.Status {
case status.Modeled:
return diag.Errorf("The image is in status: %s, please, contact support for more information", image.Status)
case status.Creating:
case status.Created:
case status.Destroyed, status.Purged:
d.SetId("")
return diag.Errorf("The resource cannot be updated because it has been destroyed")
// return resourceImageCreate(ctx, d, m)
}
if d.HasChange("name") {
err := resourceImageFromBlankComputeRename(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
}
return resourceImageFromBlankComputeRead(ctx, d, m)
}
func ResourceImageFromBlankCompute() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
CreateContext: resourceImageFromBlankComputeCreate,
ReadContext: resourceImageFromBlankComputeRead,
UpdateContext: resourceImageFromBlankComputeUpdate,
DeleteContext: resourceImageFromBlankComputeDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout30m,
Read: &constants.Timeout900s,
Update: &constants.Timeout900s,
Delete: &constants.Timeout900s,
Default: &constants.Timeout900s,
},
Schema: resourceImageFromBlankComputeSchemaMake(),
}
}
func resourceImageFromBlankComputeSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"compute_id": {
Type: schema.TypeInt,
Required: true,
Description: "Compute Id",
},
"name": {
Type: schema.TypeString,
Required: true,
Description: "Name of the rescue disk",
},
"boot_type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"bios", "uefi"}, true),
Description: "Boot type of image BIOS or UEFI",
},
"type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"linux", "windows", "other"}, true),
Description: "Image type linux, windows or other",
},
"username": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Optional username for the image",
},
"password": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Optional password for the image",
},
"account_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "AccountId to make the image exclusive",
},
"sep_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "storage endpoint provider ID",
},
"pool_name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "pool for image create",
},
"hot_resize": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "Does this machine supports hot resize",
},
"async_mode": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "create an image in async/sync mode",
},
"permanently": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "whether to completely delete the image",
},
"image_id": {
Type: schema.TypeInt,
Computed: true,
},
"unc_path": {
Type: schema.TypeString,
Computed: true,
},
"ckey": {
Type: schema.TypeString,
Computed: true,
},
"acl": {
Type: schema.TypeString,
Computed: true,
},
"architecture": {
Type: schema.TypeString,
Computed: true,
},
"bootable": {
Type: schema.TypeBool,
Computed: true,
},
"compute_ci_id": {
Type: schema.TypeInt,
Computed: true,
},
"cd_presented_to": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"desc": {
Type: schema.TypeString,
Computed: true,
},
"drivers": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"enabled": {
Type: schema.TypeBool,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"history": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"guid": {
Type: schema.TypeString,
Computed: true,
},
"id": {
Type: schema.TypeInt,
Computed: true,
},
"timestamp": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"last_modified": {
Type: schema.TypeInt,
Computed: true,
},
"link_to": {
Type: schema.TypeInt,
Computed: true,
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
},
"image_name": {
Type: schema.TypeString,
Computed: true,
},
"network_interface_naming": {
Type: schema.TypeString,
Computed: true,
},
"provider_name": {
Type: schema.TypeString,
Computed: true,
},
"purge_attempts": {
Type: schema.TypeInt,
Computed: true,
},
"present_to": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"res_id": {
Type: schema.TypeString,
Computed: true,
},
"rescuecd": {
Type: schema.TypeBool,
Computed: true,
},
"shared_with": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"size": {
Type: schema.TypeInt,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
},
"version": {
Type: schema.TypeString,
Computed: true,
},
}
}

View File

@@ -0,0 +1,506 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package image
import (
"context"
"fmt"
"strconv"
"strings"
"time"
"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"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/disks"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/image"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/tasks"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/statefuncs"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
)
func resourceImageFromPlatformDiskCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
diskId := uint64(d.Get("disk_id").(int))
name := d.Get("name").(string)
log.Debugf("resourceImageFromPlatformDiskCreate: called for image %s", name)
err := existDiskID(ctx, diskId, m)
if err != nil {
return diag.Errorf("resourceImageFromPlatformDiskCreate: can't create Image: %v", err)
}
if _, ok := d.GetOk("account_id"); ok {
haveAccountID, err := existAccountID(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
if !haveAccountID {
return diag.Errorf("resourceImageFromPlatformDiskCreate: can't create Image because AccountID %d is not allowed or does not exist", d.Get("account_id").(int))
}
}
c := m.(*controller.ControllerCfg)
req := disks.FromPlatformDiskRequest{
DiskID: diskId,
Name: name,
BootType: d.Get("boot_type").(string),
ImageType: d.Get("type").(string),
Architecture: d.Get("architecture").(string),
Bootable: d.Get("bootable").(bool), // default value - true
}
if username, ok := d.GetOk("username"); ok {
req.Username = username.(string)
}
if password, ok := d.GetOk("password"); ok {
req.Password = password.(string)
}
if accountId, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(accountId.(int))
}
if sepId, ok := d.GetOk("sep_id"); ok {
req.SepID = uint64(sepId.(int))
}
if poolName, ok := d.GetOk("pool_name"); ok {
req.PoolName = poolName.(string)
}
if driversInterface, ok := d.GetOk("drivers"); ok {
for _, d := range driversInterface.([]interface{}) {
req.Drivers = append(req.Drivers, d.(string))
}
}
if hotresize, ok := d.GetOk("hot_resize"); ok {
req.HotResize = hotresize.(bool)
}
var imageId uint64
asyncMode := d.Get("async_mode").(bool)
if !asyncMode {
imageId, err = c.CloudAPI().Disks().FromPlatformDisk(ctx, req)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
} else {
taskId, err := c.CloudAPI().Disks().FromPlatformDiskAsync(ctx, req)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
taskReq := tasks.GetRequest{
AuditID: strings.Trim(taskId, `"`),
}
for {
task, err := c.CloudAPI().Tasks().Get(ctx, taskReq)
if err != nil {
return diag.FromErr(err)
}
log.Debugf("resourceImageFromPlatformDiskCreate: instance creating - %s", task.Stage)
if task.Completed {
if task.Error != "" {
return diag.FromErr(fmt.Errorf("cannot create image instance: %v", task.Error))
}
id, err := task.Result.ID()
imageId = uint64(id)
if err != nil {
return diag.FromErr(err)
}
break
}
time.Sleep(time.Second * 20)
}
}
d.SetId(strconv.FormatUint(imageId, 10))
d.Set("image_id", imageId)
_, err = utilityImageCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
return resourceImageFromPlatformDiskRead(ctx, d, m)
}
func resourceImageFromPlatformDiskRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceImageFromPlatformDiskRead: called for %s id: %s", d.Get("name").(string), d.Id())
img, err := utilityImageCheckPresence(ctx, d, m)
if img == nil {
d.SetId("")
return diag.FromErr(err)
}
switch img.Status {
case status.Modeled:
return diag.Errorf("The image is in status: %s, please, contact support for more information", img.Status)
case status.Creating:
case status.Created:
case status.Destroyed, status.Purged:
d.SetId("")
return diag.Errorf("The resource cannot be updated because it has been destroyed")
}
flattenImage(d, img)
return nil
}
func resourceImageFromPlatformDiskDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceImageFromPlatformDiskDelete: called for %s, id: %s", d.Get("name").(string), d.Id())
_, err := utilityImageCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
c := m.(*controller.ControllerCfg)
req := image.DeleteRequest{
ImageID: uint64(d.Get("image_id").(int)),
}
if permanently, ok := d.GetOk("permanently"); ok {
req.Permanently = permanently.(bool)
}
_, err = c.CloudAPI().Image().Delete(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId("")
return nil
}
func resourceImageFromPlatformDiskUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceImageFromPlatformDiskUpdate: called for %s, id: %s", d.Get("name").(string), d.Id())
// we do not allow change of disk_id, but allow resource update after import
old, _ := d.GetChange("disk_id")
if old.(int) != 0 && d.HasChange("disk_id") {
return diag.Errorf("resourceImageFromPlatformDiskUpdate: can't update Image because disk_id is not allowed to be changed")
}
image, err := utilityImageCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
switch image.Status {
case status.Modeled:
return diag.Errorf("The image is in status: %s, please, contact support for more information", image.Status)
case status.Creating:
case status.Created:
case status.Destroyed, status.Purged:
d.SetId("")
return diag.Errorf("The resource cannot be updated because it has been destroyed")
}
if d.HasChange("name") {
err := resourceImageRename(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
}
return resourceImageFromPlatformDiskRead(ctx, d, m)
}
func ResourceImageFromPlatformDisk() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
CreateContext: resourceImageFromPlatformDiskCreate,
ReadContext: resourceImageFromPlatformDiskRead,
UpdateContext: resourceImageFromPlatformDiskUpdate,
DeleteContext: resourceImageFromPlatformDiskDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout30m,
Read: &constants.Timeout900s,
Update: &constants.Timeout900s,
Delete: &constants.Timeout900s,
Default: &constants.Timeout900s,
},
Schema: resourceImageFromPlatformDiskSchemaMake(),
}
}
func resourceImageFromPlatformDiskSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"disk_id": {
Type: schema.TypeInt,
Required: true,
Description: "Disk Id",
},
"name": {
Type: schema.TypeString,
Required: true,
Description: "Name of the rescue disk",
},
"boot_type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"bios", "uefi"}, true),
Description: "Boot type of image BIOS or UEFI",
},
"type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"linux", "windows", "other"}, true),
Description: "Image type linux, windows or other",
},
"architecture": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"X86_64", "PPC64_LE"}, true),
Description: "binary architecture of this image, one of X86_64 of PPC64_LE",
},
"username": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Optional username for the image",
},
"password": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Optional password for the image",
},
"account_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "AccountId to make the image exclusive",
},
"sep_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "storage endpoint provider ID",
},
"pool_name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "pool for image create",
},
"drivers": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Schema{
StateFunc: statefuncs.StateFuncToUpper,
ValidateFunc: validation.StringInSlice([]string{"SVA_KVM_X86", "KVM_X86", "KVM_PPC"}, false), // observe case while validating
Type: schema.TypeString,
},
Description: "List of types of compute suitable for image. Example: [ \"KVM_X86\" ]",
},
"bootable": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "bootable image",
},
"hot_resize": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "Does this machine supports hot resize",
},
"async_mode": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "create an image in async/sync mode",
},
"permanently": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "whether to completely delete the image",
},
"image_id": {
Type: schema.TypeInt,
Computed: true,
},
"unc_path": {
Type: schema.TypeString,
Computed: true,
},
"ckey": {
Type: schema.TypeString,
Computed: true,
},
"acl": {
Type: schema.TypeString,
Computed: true,
},
"compute_ci_id": {
Type: schema.TypeInt,
Computed: true,
},
"cd_presented_to": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"desc": {
Type: schema.TypeString,
Computed: true,
},
"enabled": {
Type: schema.TypeBool,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"history": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"guid": {
Type: schema.TypeString,
Computed: true,
},
"id": {
Type: schema.TypeInt,
Computed: true,
},
"timestamp": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"last_modified": {
Type: schema.TypeInt,
Computed: true,
},
"link_to": {
Type: schema.TypeInt,
Computed: true,
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
},
"image_name": {
Type: schema.TypeString,
Computed: true,
},
"network_interface_naming": {
Type: schema.TypeString,
Computed: true,
},
"provider_name": {
Type: schema.TypeString,
Computed: true,
},
"purge_attempts": {
Type: schema.TypeInt,
Computed: true,
},
"present_to": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"res_id": {
Type: schema.TypeString,
Computed: true,
},
"rescuecd": {
Type: schema.TypeBool,
Computed: true,
},
"shared_with": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"size": {
Type: schema.TypeInt,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
},
"version": {
Type: schema.TypeString,
Computed: true,
},
}
}

View File

@@ -1,111 +1,115 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package image
import (
"context"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/image"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityImageListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*image.ListImages, error) {
c := m.(*controller.ControllerCfg)
req := image.ListRequest{}
if sep_id, ok := d.GetOk("sep_id"); ok {
req.SEPID = uint64(sep_id.(int))
}
if by_id, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(by_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if architecture, ok := d.GetOk("architecture"); ok {
req.Architecture = architecture.(string)
}
if type_image, ok := d.GetOk("type_image"); ok {
req.TypeImage = type_image.(string)
}
if image_size, ok := d.GetOk("image_size"); ok {
req.ImageSize = uint64(image_size.(int))
}
if sep_name, ok := d.GetOk("sep_name"); ok {
req.SEPName = sep_name.(string)
}
if pool, ok := d.GetOk("pool"); ok {
req.Pool = pool.(string)
}
if public, ok := d.GetOk("public"); ok {
req.Public = public.(bool)
}
if hot_resize, ok := d.GetOk("hot_resize"); ok {
req.HotResize = hot_resize.(bool)
}
if bootable, ok := d.GetOk("bootable"); ok {
req.Bootable = bootable.(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))
}
log.Debugf("utilityImageListCheckPresence: load image list")
imageList, err := c.CloudAPI().Image().List(ctx, req)
if err != nil {
return nil, err
}
return imageList, nil
}
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package image
import (
"context"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/image"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityImageListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*image.ListImages, error) {
c := m.(*controller.ControllerCfg)
req := image.ListRequest{}
if sep_id, ok := d.GetOk("sep_id"); ok {
req.SEPID = uint64(sep_id.(int))
}
if by_id, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(by_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if architecture, ok := d.GetOk("architecture"); ok {
req.Architecture = architecture.(string)
}
if type_image, ok := d.GetOk("type_image"); ok {
req.TypeImage = type_image.(string)
}
if image_size, ok := d.GetOk("image_size"); ok {
req.ImageSize = uint64(image_size.(int))
}
if sep_name, ok := d.GetOk("sep_name"); ok {
req.SEPName = sep_name.(string)
}
if pool, ok := d.GetOk("pool"); ok {
req.Pool = pool.(string)
}
if public, ok := d.GetOk("public"); ok {
req.Public = public.(bool)
}
if hot_resize, ok := d.GetOk("hot_resize"); ok {
req.HotResize = hot_resize.(bool)
}
if bootable, ok := d.GetOk("bootable"); ok {
req.Bootable = bootable.(bool)
}
if sortBy, ok := d.GetOk("sort_by"); ok {
req.SortBy = sortBy.(string)
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
log.Debugf("utilityImageListCheckPresence: load image list")
imageList, err := c.CloudAPI().Image().List(ctx, req)
if err != nil {
return nil, err
}
return imageList, nil
}