mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-06-30 02:31:10 +00:00
fix(file): better error message on download failure (#1923)
Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
parent
04a461dffa
commit
d46399024f
@ -76,7 +76,7 @@ resource "proxmox_virtual_environment_download_file" "latest_ubuntu_22_jammy_lxc
|
||||
- `content_type` (String) The file content type. Must be `iso` for VM images or `vztmpl` for LXC images.
|
||||
- `datastore_id` (String) The identifier for the target datastore.
|
||||
- `node_name` (String) The node name.
|
||||
- `url` (String) The URL to download the file from. Format `https?://.*`.
|
||||
- `url` (String) The URL to download the file from. Must match regex: `https?://.*`.
|
||||
|
||||
### Optional
|
||||
|
||||
|
@ -246,10 +246,10 @@ func (r *downloadFileResource) Schema(
|
||||
Default: int64default.StaticInt64(600),
|
||||
},
|
||||
"url": schema.StringAttribute{
|
||||
Description: "The URL to download the file from. Format `https?://.*`.",
|
||||
Description: "The URL to download the file from. Must match regex: `" + httpRegex.String() + "`.",
|
||||
Required: true,
|
||||
Validators: []validator.String{
|
||||
stringvalidator.RegexMatches(httpRegex, "Must match http url regex"),
|
||||
stringvalidator.RegexMatches(httpRegex, "must match HTTP URL regex `"+httpRegex.String()+"`"),
|
||||
},
|
||||
PlanModifiers: []planmodifier.String{
|
||||
stringplanmodifier.RequiresReplace(),
|
||||
@ -460,7 +460,7 @@ func (r *downloadFileResource) getURLMetadata(
|
||||
verify := proxmoxtypes.CustomBool(model.Verify.ValueBool())
|
||||
|
||||
queryURLMetadataReq := nodes.QueryURLMetadataGetRequestBody{
|
||||
URL: model.URL.ValueStringPointer(),
|
||||
URL: model.URL.ValueString(),
|
||||
Verify: &verify,
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@ -47,6 +48,17 @@ func TestAccResourceDownloadFile(t *testing.T) {
|
||||
name string
|
||||
steps []resource.TestStep
|
||||
}{
|
||||
{"missing url", []resource.TestStep{{
|
||||
Config: te.RenderConfig(`
|
||||
resource "proxmox_virtual_environment_download_file" "qcow2_image" {
|
||||
content_type = "iso"
|
||||
node_name = "{{.NodeName}}"
|
||||
datastore_id = "{{.DatastoreID}}"
|
||||
file_name = "fake_qcow2_file.img"
|
||||
url = ""
|
||||
}`),
|
||||
ExpectError: regexp.MustCompile(`Attribute url must match HTTP URL regex`),
|
||||
}}},
|
||||
{"download qcow2 file", []resource.TestStep{{
|
||||
Config: te.RenderConfig(`
|
||||
resource "proxmox_virtual_environment_download_file" "qcow2_image" {
|
||||
|
@ -23,7 +23,7 @@ func (c *Client) GetQueryURLMetadata(
|
||||
|
||||
err := c.DoRequest(ctx, http.MethodGet, c.ExpandPath("query-url-metadata"), d, resBody)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error retrieving URL metadata for %+v: %w", d.URL, err)
|
||||
return nil, fmt.Errorf("error retrieving URL metadata for %q: %w", d.URL, err)
|
||||
}
|
||||
|
||||
if resBody.Data == nil {
|
||||
|
@ -23,5 +23,5 @@ type QueryURLMetadataGetResponseData struct {
|
||||
// QueryURLMetadataGetRequestBody contains the body for a QueryURLMetadata get request.
|
||||
type QueryURLMetadataGetRequestBody struct {
|
||||
Verify *types.CustomBool `json:"verify-certificates,omitempty" url:"verify-certificates,omitempty,int"`
|
||||
URL *string `json:"url,omitempty" url:"url,omitempty"`
|
||||
URL string `json:"url" url:"url"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user