mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-03 03:52:58 +00:00
fix(file): add check for supported content types when uploading file to a storage (#379)
This commit is contained in:
parent
7aa25b8d05
commit
4e1ce30619
@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
"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/schema"
|
||||||
|
"golang.org/x/exp/slices"
|
||||||
|
|
||||||
"github.com/bpg/terraform-provider-proxmox/proxmox/api"
|
"github.com/bpg/terraform-provider-proxmox/proxmox/api"
|
||||||
"github.com/bpg/terraform-provider-proxmox/proxmoxtf"
|
"github.com/bpg/terraform-provider-proxmox/proxmoxtf"
|
||||||
@ -403,6 +404,18 @@ func fileCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag
|
|||||||
return diag.Errorf("failed to determine the datastore path")
|
return diag.Errorf("failed to determine the datastore path")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, found := slices.BinarySearch(datastore.Content, *contentType)
|
||||||
|
if !found {
|
||||||
|
diags = append(diags, diag.Diagnostics{
|
||||||
|
diag.Diagnostic{
|
||||||
|
Severity: diag.Warning,
|
||||||
|
Summary: fmt.Sprintf("the datastore %q does not support content type %q",
|
||||||
|
*datastore.Storage, *contentType,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
}...)
|
||||||
|
}
|
||||||
|
|
||||||
remoteFileDir := *datastore.Path
|
remoteFileDir := *datastore.Path
|
||||||
|
|
||||||
err = capi.SSH().NodeUpload(ctx, nodeName, remoteFileDir, request)
|
err = capi.SSH().NodeUpload(ctx, nodeName, remoteFileDir, request)
|
||||||
@ -412,14 +425,21 @@ func fileCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag
|
|||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
volumeID, diags := fileGetVolumeID(d)
|
volumeID, di := fileGetVolumeID(d)
|
||||||
|
diags = append(diags, di...)
|
||||||
if diags.HasError() {
|
if diags.HasError() {
|
||||||
return diags
|
return diags
|
||||||
}
|
}
|
||||||
|
|
||||||
d.SetId(*volumeID)
|
d.SetId(*volumeID)
|
||||||
|
|
||||||
return fileRead(ctx, d, m)
|
diags = append(diags, fileRead(ctx, d, m)...)
|
||||||
|
|
||||||
|
if d.Id() == "" {
|
||||||
|
diags = append(diags, diag.Errorf("failed to read file from %q", *volumeID)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return diags
|
||||||
}
|
}
|
||||||
|
|
||||||
func fileGetContentType(d *schema.ResourceData) (*string, diag.Diagnostics) {
|
func fileGetContentType(d *schema.ResourceData) (*string, diag.Diagnostics) {
|
||||||
|
Loading…
Reference in New Issue
Block a user