-
-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(storage): add new resource proxmox_virtual_environment_download_file
#837
Conversation
Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl>
Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl>
Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl>
Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl>
Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl>
…ther docs and examples Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl>
Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl>
Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl>
Hi @rafsaf! That's awesome, thanks bunch for the PR! I think having a separate resource to download files make sense, it matches PVE functionality quite nicely. Later on we can rename existing I just skimmed the code and will do a proper review later in the week. One thing I noticed tho is the resource fails when uploading file already exists:
We should probably handle this error more gracefully, and also add a flag to the resource to allow overwrite of the existing file (it should be |
proxmox_virtual_environment_download_file
Sure, this can be handled better, I will look into this |
…esource download file Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl>
…load task on error Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl>
Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl>
I added some validation so As of |
Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl>
Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again @rafsaf for taking on this feature, really good work!
I have a few comments and suggestions, could you please take a look?
|
||
### Optional | ||
|
||
- `allow_unsupported_types` (Boolean) By default `false`. If `true`, content formats `qcow2` and `raw` can be downloaded, though it is not supported by proxmox. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably rework this a bit.
Technically, PVE supports qcow2
and raw
, it is just a matter of renaming the file during upload. For example, I was able to download a debian's raw file without issues:
I see in the code below you're utilizing this "feature" by adding .iso extension, but I think we can replacing this argument with file_name
, that allows to override the original remote file name. This will also match the current behaviour of the *_file
resource, and could save some time for people migrating to *_download_file
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, file_name
is now computed and optional (if not provided by user, we will use default name),
|
||
- `content_type` (String) The file content type. Must be `iso` | `vztmpl`. | ||
- `datastore_id` (String) The identifier for the target datastore. | ||
- `download_url` (String) The URL to download the file from. Format `https?://.*`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably remove the download_
prefix from it, seems redundant in the context of the resource.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
### Read-Only | ||
|
||
- `filename` (String) The file name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be file_name
to match convention in the other resource.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
content_type = "iso" | ||
datastore_id = "local" | ||
node_name = "pve" | ||
download_url = "https://cloud-images.ubuntu.com/noble/20231218/noble-server-cloudimg-amd64.img" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file got disappeared, so make example
throws an error:
│ Error: Error creating Download File interface
│
│ with proxmox_virtual_environment_download_file.ubuntu_noble_image,
│ on resource_virtual_environment_download_file.tf line 19, in resource "proxmox_virtual_environment_download_file" "ubuntu_noble_image":
│ 19: resource "proxmox_virtual_environment_download_file" "ubuntu_noble_image" {
│
│ Could not get GetQueryURLMetadata, unexpected error: error retrieving Query URL metadata configuration: received an HTTP 500 response - Reason: invalid server response: '404 Not Found'
I guess the intention for this resource is to verify the checksum calculation, that means we can't use "current" or "latest" downloads.
You can pick up something else from http://download.proxmox.com/images/system/, or just add checksum to the resource above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
every link from previous work was checked, i either used "latest" / "current" images or release ones, anyway they will not disappear
parent: Resources | ||
subcategory: Virtual Environment | ||
description: |- | ||
Manages files upload using directly proxmox download-url API. It can be a full replacement for ISO files created using proxmox_virtual_environment_file and it does not use SSH. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for picking up on this, but it will be better to use "Proxmox VE", or "PVE", instead of "proxmox" -- there are other products under the Proxmox "umbrella".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
fwprovider/resource_download_file.go
Outdated
Description: "Manages files upload using directly proxmox download-url API. " + | ||
"It can be a full replacement for ISO files created using " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be MarkdownDescription
, and leave the first line for the regular Description
:
Description: "Manages files upload using directly proxmox download-url API. " + | |
"It can be a full replacement for ISO files created using " + | |
Description: "Manages files upload using directly proxmox download-url API.", | |
MarkdownDescription: "Manages files upload using directly proxmox download-url API. " + | |
"It can be a full replacement for ISO files created using " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
fwprovider/resource_download_file.go
Outdated
Attributes: map[string]schema.Attribute{ | ||
"id": structure.IDAttribute(), | ||
"content_type": schema.StringAttribute{ | ||
MarkdownDescription: "The file content type. Must be `iso` | `vztmpl`.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think just Description
for the inner attribute would work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
fwprovider/resource_download_file.go
Outdated
) | ||
if err != nil { | ||
resp.Diagnostics.AddError( | ||
"Error creating Download File interface", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH, I was really confused with the error message when saw it first time 😅
"Error creating Download File interface", | |
"Error initiating file download", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
proxmox/nodes/nodestorage/client.go
Outdated
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package nodestorage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps rename nodestorage
to just storage
? Similar to what we have for node/containers
, node/tasks
, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is already storage
package at proxmox/storage/client.go
for example, for "global" storage api I suppose, this is why i came up with nodestorage
.
But technically it can be named the same I think? so no problem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think /proxmox/nodes/storage
package will be fine. In in some places we need to import both "storages", when we can use nodestorage
import alias.
proxmox/nodes/tasks/client.go
Outdated
@@ -23,13 +23,27 @@ func (c *Client) ExpandPath(_ string) string { | |||
panic("ExpandPath of tasks.Client must not be used. Use BuildPath instead.") | |||
} | |||
|
|||
// BaseTaskPath builds base task path using Task ID. | |||
func (c *Client) BaseTaskPath(taskID string) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function probably doesn't need to be exported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
That may not always be the case, some people may decide to use the "latest" version of their distro. Or copy/paste the file resource in multiple templates. For sure, it's better to have a dedicated resource for each image, but in certain scenarios it is less headache just to overwrite "whatever is cached on PVE" with the "latest and greatest" as part of the current template. |
Thanks for review!!! I will be on it in a few days, I'm not only 100% sure about this The |
Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl>
Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl>
…quiresReplaceModifier Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl>
Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl>
Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl>
Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl>
Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl>
feat(storage): resource download file fixes after review
Happy new year :p Okay, so here we go again. I think now everything should be fine... There is quite big change regarding Second, I spent some hours digging around, checking docs, issues, threads and eventually achieved what I wanted :P My idea is that we if current state size of file doesn't match any of above two (datastore or url), this means that someone manually changed the file (deleted in UI and uploaded something else) or there was change in file size from url (new release in "latest" image url). I want to recreate resource if that happens. Unfortunately, not so quick... I believe even when terraform state is changed on read and computed + not optional attribute has The only fully working solution I tried is to use custom planmodifier and pass there data from Read func using |
Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy New Year @rafsaf!
Thanks for addressing all comments, it looks great!
I just updated the LXC file download resource to use PVE-compatible container image (it requires a proper root filesystem), and fixed few typos.
LGTM! 🚀
Hey, lads! |
👋 Hello, nice catch. I am off till next week, but feel free to submit PR if you are in a position to create a fix. This should be straightforward as only markdown files in the docs folder need to be changed. |
Good catch indeed! :) Fixed in #872 |
Contributor's Note
/docs
for any user-facing features or additions./example
for any new or updated resources / data sources.make example
to verify that the change works as expected.Proof of Work
Hi, I am aware this is big. Sorry about that.
My justification of new resource instead of trying to change
proxmox_virtual_environment_file
is that later is using different approach to upload files (usingupload
API endpoint) and new resource is using only APIdownload-url
ednpoint. This has also the benefit that we will not break existing usage, but rather give another option that should be better suited and scalable in many nodes for vm and lxc images.example
and gave it hard debugging until everything is right (hopefully)..iso
andqcow2
extenstion to save bandwith.storage.go
file into separate module with few files -> ideally this should not cause any issues.allow_unsupported_types
param is somewhat suspicious, but I didn't have any problems when using qcow2 or raw images, they both seem to work when have addediso
postfix.Community Note
Closes #638