4.10.0
This commit is contained in:
@@ -35,6 +35,7 @@ package image
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/statefuncs"
|
||||
)
|
||||
|
||||
func resourceImageSchemaMake(sch map[string]*schema.Schema) map[string]*schema.Schema {
|
||||
@@ -125,19 +126,13 @@ func resourceImageSchemaMake(sch map[string]*schema.Schema) map[string]*schema.S
|
||||
Description: "storage endpoint provider ID",
|
||||
}
|
||||
|
||||
sch["architecture"] = &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"X86_64"}, true),
|
||||
Description: "binary architecture of this image, one of X86_64",
|
||||
}
|
||||
|
||||
sch["drivers"] = &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Required: true,
|
||||
Type: schema.TypeList,
|
||||
Required: true,
|
||||
StateFunc: statefuncs.StateFuncToUpper,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Type: schema.TypeString,
|
||||
ValidateFunc: validation.StringInSlice([]string{"KVM_X86"}, false),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -149,5 +144,12 @@ func resourceImageSchemaMake(sch map[string]*schema.Schema) map[string]*schema.S
|
||||
Description: "select a network interface naming pattern for your Linux machine. eth - onboard, ens - pci slot naming",
|
||||
}
|
||||
|
||||
sch["sync_mode"] = &schema.Schema{
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
Description: "Create image from a media identified by URL (in synchronous mode)",
|
||||
}
|
||||
|
||||
return sch
|
||||
}
|
||||
|
||||
@@ -34,12 +34,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/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"
|
||||
@@ -94,17 +98,56 @@ func resourceImageCreate(ctx context.Context, d *schema.ResourceData, m interfac
|
||||
if poolName, ok := d.GetOk("pool_name"); ok {
|
||||
req.Pool = poolName.(string)
|
||||
}
|
||||
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 {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
syncMode := d.Get("sync_mode").(bool)
|
||||
var imageId uint64
|
||||
|
||||
if syncMode {
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
imageId, err = c.CloudAPI().Image().Create(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.CloudAPI().Image().AsyncCreate(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.CloudAPI().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))
|
||||
|
||||
@@ -76,12 +76,11 @@ func resourceImageFromPlatformDiskCreate(ctx context.Context, d *schema.Resource
|
||||
|
||||
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
|
||||
DiskID: diskId,
|
||||
Name: name,
|
||||
BootType: d.Get("boot_type").(string),
|
||||
ImageType: d.Get("type").(string),
|
||||
Bootable: d.Get("bootable").(bool), // default value - true
|
||||
}
|
||||
|
||||
if username, ok := d.GetOk("username"); ok {
|
||||
@@ -292,13 +291,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: "binary architecture of this image, one of X86_64",
|
||||
},
|
||||
|
||||
"username": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
@@ -357,6 +349,10 @@ func resourceImageFromPlatformDiskSchemaMake() map[string]*schema.Schema {
|
||||
Description: "create an image in async/sync mode",
|
||||
},
|
||||
|
||||
"architecture": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"image_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
|
||||
@@ -62,10 +62,6 @@ func utilityImageListCheckPresence(ctx context.Context, d *schema.ResourceData,
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user