mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-08-22 19:38:35 +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.
|
- `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.
|
- `datastore_id` (String) The identifier for the target datastore.
|
||||||
- `node_name` (String) The node name.
|
- `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
|
### Optional
|
||||||
|
|
||||||
|
@ -246,10 +246,10 @@ func (r *downloadFileResource) Schema(
|
|||||||
Default: int64default.StaticInt64(600),
|
Default: int64default.StaticInt64(600),
|
||||||
},
|
},
|
||||||
"url": schema.StringAttribute{
|
"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,
|
Required: true,
|
||||||
Validators: []validator.String{
|
Validators: []validator.String{
|
||||||
stringvalidator.RegexMatches(httpRegex, "Must match http url regex"),
|
stringvalidator.RegexMatches(httpRegex, "must match HTTP URL regex `"+httpRegex.String()+"`"),
|
||||||
},
|
},
|
||||||
PlanModifiers: []planmodifier.String{
|
PlanModifiers: []planmodifier.String{
|
||||||
stringplanmodifier.RequiresReplace(),
|
stringplanmodifier.RequiresReplace(),
|
||||||
@ -460,7 +460,7 @@ func (r *downloadFileResource) getURLMetadata(
|
|||||||
verify := proxmoxtypes.CustomBool(model.Verify.ValueBool())
|
verify := proxmoxtypes.CustomBool(model.Verify.ValueBool())
|
||||||
|
|
||||||
queryURLMetadataReq := nodes.QueryURLMetadataGetRequestBody{
|
queryURLMetadataReq := nodes.QueryURLMetadataGetRequestBody{
|
||||||
URL: model.URL.ValueStringPointer(),
|
URL: model.URL.ValueString(),
|
||||||
Verify: &verify,
|
Verify: &verify,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -47,6 +48,17 @@ func TestAccResourceDownloadFile(t *testing.T) {
|
|||||||
name string
|
name string
|
||||||
steps []resource.TestStep
|
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{{
|
{"download qcow2 file", []resource.TestStep{{
|
||||||
Config: te.RenderConfig(`
|
Config: te.RenderConfig(`
|
||||||
resource "proxmox_virtual_environment_download_file" "qcow2_image" {
|
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)
|
err := c.DoRequest(ctx, http.MethodGet, c.ExpandPath("query-url-metadata"), d, resBody)
|
||||||
if err != nil {
|
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 {
|
if resBody.Data == nil {
|
||||||
|
@ -23,5 +23,5 @@ type QueryURLMetadataGetResponseData struct {
|
|||||||
// QueryURLMetadataGetRequestBody contains the body for a QueryURLMetadata get request.
|
// QueryURLMetadataGetRequestBody contains the body for a QueryURLMetadata get request.
|
||||||
type QueryURLMetadataGetRequestBody struct {
|
type QueryURLMetadataGetRequestBody struct {
|
||||||
Verify *types.CustomBool `json:"verify-certificates,omitempty" url:"verify-certificates,omitempty,int"`
|
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