This commit is contained in:
asteam
2024-12-04 13:18:58 +03:00
parent 003e4d656e
commit 76ea459b3d
417 changed files with 30051 additions and 975 deletions

View File

@@ -42,6 +42,7 @@ func DataSourceImageList(ctx context.Context, state *models.ListImagesModel, c *
Bootable: state.Bootable,
SortBy: state.SortBy,
Page: state.Page,
Enabled: state.Enabled,
Size: state.Size,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),

View File

@@ -48,7 +48,6 @@ func ResourceImage(ctx context.Context, plan *models.ImageResourceModel, c *deco
SepID: types.Int64Value(int64(image.SepID)),
PoolName: types.StringValue(image.Pool),
Architecture: types.StringValue(image.Architecture),
Permanently: plan.Permanently,
ImageId: types.Int64Value(int64(image.ID)),
Timeouts: plan.Timeouts,
Id: types.StringValue(strconv.Itoa(int(image.ID))),

View File

@@ -33,7 +33,6 @@ func ResourceImageVirtual(ctx context.Context, plan *models.ImageVirtualResource
*plan = models.ImageVirtualResourceModel{
ImageName: types.StringValue(image.Name),
LinkTo: types.Int64Value(int64(image.LinkTo)),
Permanently: plan.Permanently,
Timeouts: plan.Timeouts,
Id: types.StringValue(strconv.Itoa(int(image.ID))),
LastUpdated: plan.LastUpdated,

View File

@@ -22,6 +22,7 @@ type ListImagesModel struct {
SortBy types.String `tfsdk:"sort_by"`
Page types.Int64 `tfsdk:"page"`
Size types.Int64 `tfsdk:"size"`
Enabled types.Bool `tfsdk:"enabled"`
// responce fields
Id types.String `tfsdk:"id"`

View File

@@ -23,7 +23,6 @@ type ImageResourceModel struct {
SepID types.Int64 `tfsdk:"sep_id"`
PoolName types.String `tfsdk:"pool_name"`
Architecture types.String `tfsdk:"architecture"`
Permanently types.Bool `tfsdk:"permanently"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
// responce fields
Id types.String `tfsdk:"id"`

View File

@@ -7,10 +7,9 @@ import (
type ImageVirtualResourceModel struct {
// request fields
ImageName types.String `tfsdk:"image_name"`
LinkTo types.Int64 `tfsdk:"link_to"`
Permanently types.Bool `tfsdk:"permanently"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
ImageName types.String `tfsdk:"image_name"`
LinkTo types.Int64 `tfsdk:"link_to"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
// responce fields
Id types.String `tfsdk:"id"`
LastUpdated types.String `tfsdk:"last_updated"`

View File

@@ -234,15 +234,8 @@ func (r *resourceImage) Delete(ctx context.Context, req resource.DeleteRequest,
ctx, cancel := context.WithTimeout(ctx, deleteTimeout)
defer cancel()
var permanently bool
if state.Permanently.IsNull() {
permanently = true
} else {
permanently = state.Permanently.ValueBool()
}
// Delete image
_, err := r.client.CloudAPI().Image().Delete(ctx, image.DeleteRequest{ImageID: uint64(state.ImageId.ValueInt64()), Permanently: permanently})
_, err := r.client.CloudAPI().Image().Delete(ctx, image.DeleteRequest{ImageID: uint64(state.ImageId.ValueInt64())})
if err != nil {
resp.Diagnostics.AddError("Error deleting image with error: ", err.Error())
return

View File

@@ -229,15 +229,8 @@ func (r *resourceImageVirtual) Delete(ctx context.Context, req resource.DeleteRe
ctx, cancel := context.WithTimeout(ctx, deleteTimeout)
defer cancel()
var permanently bool
if state.Permanently.IsNull() {
permanently = true
} else {
permanently = state.Permanently.ValueBool()
}
// Delete image
_, err := r.client.CloudAPI().Image().Delete(ctx, image.DeleteRequest{ImageID: uint64(state.ImageId.ValueInt64()), Permanently: permanently})
_, err := r.client.CloudAPI().Image().Delete(ctx, image.DeleteRequest{ImageID: uint64(state.ImageId.ValueInt64())})
if err != nil {
resp.Diagnostics.AddError("Error deleting image virtual with error: ", err.Error())
return

View File

@@ -54,6 +54,9 @@ func MakeSchemaDataSourceImageList() map[string]schema.Attribute {
"size": schema.Int64Attribute{
Optional: true,
},
"enabled": schema.BoolAttribute{
Optional: true,
},
// computed attributes
"id": schema.StringAttribute{
Computed: true,

View File

@@ -84,12 +84,9 @@ func MakeSchemaResourceImage() map[string]schema.Attribute {
Computed: true,
Optional: true,
Validators: []validator.String{
stringvalidator.OneOf("X86_64", "PPC64_LE"),
stringvalidator.OneOf("X86_64"),
},
Description: "Binary architecture of this image, one of X86_64 of PPC64_LE",
},
"permanently": schema.BoolAttribute{
Optional: true,
Description: "Binary architecture of this image, one of X86_64",
},
// computed attributes
"id": schema.StringAttribute{

View File

@@ -18,10 +18,6 @@ func MakeSchemaResourceImageVirtual() map[string]schema.Attribute {
Required: true,
Description: "ID of real image to link this virtual image to upon creation",
},
// optional attributes
"permanently": schema.BoolAttribute{
Optional: true,
},
// computed attributes
"id": schema.StringAttribute{
Computed: true,

View File

@@ -56,6 +56,9 @@ func ImageListCheckPresence(ctx context.Context, state *models.ListImagesModel,
if !state.Size.IsNull() {
req.Size = uint64(state.Size.ValueInt64())
}
if !state.Enabled.IsNull() {
req.Enabled = state.Enabled.ValueBool()
}
if !state.Page.IsNull() {
req.Page = uint64(state.Page.ValueInt64())
}