This commit is contained in:
2025-08-04 16:11:16 +03:00
parent bae25296bb
commit 4b3f21d9be
239 changed files with 6585 additions and 784 deletions

View File

@@ -73,9 +73,6 @@ func resourceCDROMImageCreate(ctx context.Context, d *schema.ResourceData, m int
if poolName, ok := d.GetOk("pool_name"); ok {
req.PoolName = poolName.(string)
}
if architecture, ok := d.GetOk("architecture"); ok {
req.Architecture = architecture.(string)
}
imageId, err := c.CloudBroker().Image().CreateCDROMImage(ctx, req)
if err != nil {

View File

@@ -33,13 +33,16 @@ 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"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/image"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/tasks"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
@@ -54,26 +57,54 @@ func resourceImageCreate(ctx context.Context, d *schema.ResourceData, m interfac
c := m.(*controller.ControllerCfg)
syncMode := d.Get("sync_mode").(bool)
log.Debugf("resourceImageCreate: sync_mode = %t", d.Get("sync_mode").(bool))
var imageId uint64
req, err := CreateRequest(ctx, d, m, url.(string))
if syncMode {
req, err := SyncCreateRequest(ctx, d, m, url.(string))
if err != nil {
return diag.FromErr(err)
}
imageId, err = c.CloudBroker().Image().SyncCreate(ctx, req)
if err != nil {
return diag.FromErr(err)
}
} else {
req, err := CreateRequest(ctx, d, m, url.(string))
if err != nil {
return diag.FromErr(err)
}
imageId, err = c.CloudBroker().Image().CreateImage(ctx, req)
log.Debugf("resourceImageCreate: imageID = %d", imageId)
if err != nil {
return diag.FromErr(err)
}
} else {
if err != nil {
return diag.FromErr(err)
}
taskID, err := c.CloudBroker().Image().AsyncCreateImage(ctx, req)
if err != nil {
return diag.FromErr(err)
}
taskReq := tasks.GetRequest{
AuditID: strings.Trim(taskID, `"`),
}
for {
time.Sleep(time.Second * 15)
task, err := c.CloudBroker().Tasks().Get(ctx, taskReq)
if err != nil {
return diag.FromErr(err)
}
log.Debugf("resourceAccountDelete: delete account - %s", task.Stage)
if task.Completed {
if task.Error != "" {
return diag.FromErr(fmt.Errorf("cannot delete account: %v", task.Error))
}
id, err := task.Result.ID()
imageId = uint64(id)
if err != nil {
return diag.FromErr(err)
}
break
}
}
}
d.SetId(strconv.FormatUint(imageId, 10))

View File

@@ -59,12 +59,11 @@ func resourceImageFromPlatformDiskCreate(ctx context.Context, d *schema.Resource
}
req := disks.FromPlatformDiskRequest{
DiskID: uint64(d.Get("disk_id").(int)),
Name: d.Get("name").(string),
BootType: d.Get("boot_type").(string),
ImageType: d.Get("image_type").(string),
Architecture: d.Get("architecture").(string),
Bootable: d.Get("bootable").(bool), // default is true
DiskID: uint64(d.Get("disk_id").(int)),
Name: d.Get("name").(string),
BootType: d.Get("boot_type").(string),
ImageType: d.Get("image_type").(string),
Bootable: d.Get("bootable").(bool), // default is true
}
if username, ok := d.GetOk("username"); ok {

View File

@@ -1192,7 +1192,8 @@ func resourceImageSchemaMake() map[string]*schema.Schema {
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{"KVM_X86"}, false),
},
Description: "List of types of compute suitable for image. Example: [ \"KVM_X86\" ]",
},
@@ -1253,7 +1254,6 @@ func resourceImageSchemaMake() map[string]*schema.Schema {
},
"architecture": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "binary architecture of this image, one of X86_64",
},
@@ -1991,13 +1991,6 @@ func resourceImageFromPlatformDiskSchemaMake() map[string]*schema.Schema {
ValidateFunc: validation.StringInSlice([]string{"linux", "windows", "unknown"}, true),
Description: "Image type linux, windows or unknown",
},
"architecture": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"X86_64"}, true),
Description: "Image type linux, windows or other",
},
"username": {
Type: schema.TypeString,
Optional: true,
@@ -2016,6 +2009,10 @@ func resourceImageFromPlatformDiskSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "AccountId to make the image exclusive",
},
"architecture": {
Type: schema.TypeString,
Computed: true,
},
"sep_id": {
Type: schema.TypeInt,
Computed: true,

View File

@@ -57,9 +57,6 @@ func utilityImageListCheckPresence(ctx context.Context, d *schema.ResourceData,
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if architecture, ok := d.GetOk("architecture"); ok {
req.Architecture = architecture.(string)
}
if typeImage, ok := d.GetOk("type_image"); ok {
req.TypeImage = typeImage.(string)
}

View File

@@ -38,58 +38,6 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/image"
)
func SyncCreateRequest(ctx context.Context, d *schema.ResourceData, m interface{}, url string) (image.SyncCreateRequest, error) {
req := image.SyncCreateRequest{
Name: d.Get("name").(string),
URL: url,
BootType: d.Get("boot_type").(string),
ImageType: d.Get("image_type").(string),
}
if _, ok := d.GetOk("drivers"); ok {
drivers := []string{}
for _, driver := range d.Get("drivers").([]interface{}) {
drivers = append(drivers, driver.(string))
}
req.Drivers = drivers
}
if hotresize, ok := d.GetOk("hot_resize"); ok {
req.HotResize = hotresize.(bool)
}
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 usernameDL, ok := d.GetOk("username_dl"); ok {
req.UsernameDL = usernameDL.(string)
}
if passwordDL, ok := d.GetOk("password_dl"); ok {
req.PasswordDL = passwordDL.(string)
}
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 architecture, ok := d.GetOk("architecture"); ok {
req.Architecture = architecture.(string)
}
if bootable, ok := d.GetOk("bootable"); ok {
req.Bootable = bootable.(bool)
}
if networkInterfaceNaming, ok := d.GetOk("network_interface_naming"); ok {
req.NetworkInterfaceNaming = networkInterfaceNaming.(string)
}
return req, nil
}
func CreateRequest(ctx context.Context, d *schema.ResourceData, m interface{}, url string) (image.CreateRequest, error) {
req := image.CreateRequest{
Name: d.Get("name").(string),
@@ -130,9 +78,6 @@ func CreateRequest(ctx context.Context, d *schema.ResourceData, m interface{}, u
if poolName, ok := d.GetOk("pool_name"); ok {
req.PoolName = poolName.(string)
}
if architecture, ok := d.GetOk("architecture"); ok {
req.Architecture = architecture.(string)
}
if bootable, ok := d.GetOk("bootable"); ok {
req.Bootable = bootable.(bool)
}