-
-
Notifications
You must be signed in to change notification settings - Fork 268
feat(backup): add proxmox_backup_job resource and proxmox_backup_jobs data source
#2711
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
768c28b
feat(provider): add `proxmox_backup_job` resource and `proxmox_backup…
bpg-dev d2cd9a5
review feedback
bpg-dev c5d71b6
Merge branch 'main' into feat/2540-backup-job
bpg-dev 86b042a
moar comments
bpg-dev 7e9db5d
Merge branch 'feat/2540-backup-job' of github.com:bpg/terraform-provi…
bpg-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| --- | ||
| layout: page | ||
| title: proxmox_backup_jobs | ||
| parent: Data Sources | ||
| subcategory: Virtual Environment | ||
| description: |- | ||
| Retrieves the list of cluster-wide backup jobs. | ||
| --- | ||
|
|
||
| # Data Source: proxmox_backup_jobs | ||
|
|
||
| Retrieves the list of cluster-wide backup jobs. | ||
|
|
||
| ## Example Usage | ||
|
|
||
| ```terraform | ||
| data "proxmox_backup_jobs" "all" {} | ||
| ``` | ||
|
|
||
| <!-- schema generated by tfplugindocs --> | ||
| ## Schema | ||
|
|
||
| ### Read-Only | ||
|
|
||
| - `id` (String) Unique identifier for this data source. | ||
| - `jobs` (Attributes List) List of backup jobs. (see [below for nested schema](#nestedatt--jobs)) | ||
|
|
||
| <a id="nestedatt--jobs"></a> | ||
| ### Nested Schema for `jobs` | ||
|
|
||
| Read-Only: | ||
|
|
||
| - `all` (Boolean) Indicates whether all VMs and CTs are backed up. | ||
| - `compress` (String) Compression algorithm used for the backup. | ||
| - `enabled` (Boolean) Indicates whether the backup job is enabled. | ||
| - `id` (String) Unique identifier of the backup job. | ||
| - `mailnotification` (String) When to send email notifications (always or failure). | ||
| - `mailto` (String) Comma-separated list of email addresses for notifications. | ||
| - `mode` (String) Backup mode (e.g. snapshot, suspend, stop). | ||
| - `node` (String) Node on which the backup job runs. | ||
| - `notes_template` (String) Template for backup notes. | ||
| - `pool` (String) Pool whose members are backed up. | ||
| - `protected` (Boolean) Indicates whether backups created by this job are protected from pruning. | ||
| - `prune_backups` (String) Prune options in the format `keep-last=N,...`. | ||
| - `schedule` (String) Backup schedule in systemd calendar format. | ||
| - `storage` (String) Target storage for the backup. | ||
| - `vmid` (List of String) List of VM/CT IDs included in the backup job. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| --- | ||
| layout: page | ||
| title: proxmox_backup_job | ||
| parent: Resources | ||
| subcategory: Virtual Environment | ||
| description: |- | ||
| Manages a Proxmox VE cluster backup job. | ||
| --- | ||
|
|
||
| # Resource: proxmox_backup_job | ||
|
|
||
| Manages a Proxmox VE cluster backup job. | ||
|
|
||
| ## Example Usage | ||
|
|
||
| ```terraform | ||
| resource "proxmox_backup_job" "daily_backup" { | ||
| id = "daily-backup" | ||
| schedule = "*-*-* 02:00" | ||
| storage = "local" | ||
| all = true | ||
| mode = "snapshot" | ||
| compress = "zstd" | ||
| } | ||
| ``` | ||
|
|
||
| <!-- schema generated by tfplugindocs --> | ||
| ## Schema | ||
|
|
||
| ### Required | ||
|
|
||
| - `id` (String) The identifier of the backup job. | ||
| - `schedule` (String) Backup schedule in cron format or systemd calendar event. | ||
| - `storage` (String) The storage identifier for the backup. | ||
|
|
||
| ### Optional | ||
|
|
||
| - `all` (Boolean) Whether to back up all known guests on the node. | ||
| - `bwlimit` (Number) I/O bandwidth limit in KiB/s. | ||
| - `compress` (String) The compression algorithm (0, gzip, lzo, or zstd). | ||
bpg-dev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - `enabled` (Boolean) Whether the backup job is enabled. | ||
| - `exclude_path` (List of String) A list of paths to exclude from the backup. | ||
| - `fleecing` (Attributes) Fleecing configuration for the backup job. (see [below for nested schema](#nestedatt--fleecing)) | ||
| - `ionice` (Number) I/O priority (0-8). | ||
| - `lockwait` (Number) Maximum wait time in minutes for the global lock. | ||
| - `mailnotification` (String) Email notification setting (always or failure). | ||
| - `mailto` (String) A comma-separated list of email addresses to send notifications to. | ||
| - `maxfiles` (Number) Deprecated: use prune_backups instead. Maximum number of backup files per guest. | ||
| - `mode` (String) The backup mode (snapshot, suspend, or stop). | ||
| - `node` (String) The cluster node name to limit the backup job to. | ||
| - `notes_template` (String) Template for notes attached to the backup. | ||
| - `pbs_change_detection_mode` (String) PBS change detection mode (legacy, data, or metadata). | ||
| - `performance` (Attributes) Performance-related settings for the backup job. (see [below for nested schema](#nestedatt--performance)) | ||
| - `pigz` (Number) Number of pigz threads (0 disables, 1 uses single-threaded gzip). | ||
| - `pool` (String) Limit backup to guests in the specified pool. | ||
| - `protected` (Boolean) Whether the backup should be marked as protected. | ||
| - `prune_backups` (String) Retention options as a comma-separated list of key=value pairs (e.g. keep-last=3,keep-weekly=2). | ||
| - `remove` (Boolean) Whether to remove old backups if there are more than maxfiles. | ||
| - `repeat_missed` (Boolean) Whether to repeat missed backup jobs as soon as possible. | ||
| - `script` (String) Path to a script to execute before/after the backup job. | ||
| - `starttime` (String) The scheduled start time (HH:MM). | ||
| - `stdexcludes` (Boolean) Whether to exclude common temporary files from the backup. | ||
| - `stopwait` (Number) Maximum wait time in minutes for a guest to stop. | ||
| - `tmpdir` (String) Path to the temporary directory for the backup job. | ||
| - `vmid` (List of String) A list of guest VM/CT IDs to include in the backup job. | ||
| - `zstd` (Number) Number of zstd threads (0 uses half of available cores). | ||
|
|
||
| <a id="nestedatt--fleecing"></a> | ||
| ### Nested Schema for `fleecing` | ||
|
|
||
| Optional: | ||
|
|
||
| - `enabled` (Boolean) Whether fleecing is enabled. | ||
| - `storage` (String) The storage identifier for fleecing. | ||
|
|
||
|
|
||
| <a id="nestedatt--performance"></a> | ||
| ### Nested Schema for `performance` | ||
|
|
||
| Optional: | ||
|
|
||
| - `max_workers` (Number) Maximum number of workers for parallel backup. | ||
| - `pbs_entries_max` (Number) Maximum number of entries for PBS catalog. | ||
|
|
||
| ## Import | ||
|
|
||
| Import is supported using the following syntax: | ||
|
|
||
| ```shell | ||
| terraform import proxmox_backup_job.daily_backup daily-backup | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| data "proxmox_backup_jobs" "all" {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| terraform import proxmox_backup_job.daily_backup daily-backup |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| resource "proxmox_backup_job" "daily_backup" { | ||
| id = "daily-backup" | ||
| schedule = "*-*-* 02:00" | ||
| storage = "local" | ||
| all = true | ||
| mode = "snapshot" | ||
| compress = "zstd" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| /* | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
| */ | ||
|
|
||
| package backup | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-framework/datasource" | ||
| "github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
| "github.com/hashicorp/terraform-plugin-framework/types" | ||
|
|
||
| "github.com/bpg/terraform-provider-proxmox/fwprovider/config" | ||
| "github.com/bpg/terraform-provider-proxmox/proxmox/cluster/backup" | ||
| ) | ||
|
|
||
| // Ensure the implementation satisfies the expected interfaces. | ||
| var ( | ||
| _ datasource.DataSource = &backupJobsDataSource{} | ||
| _ datasource.DataSourceWithConfigure = &backupJobsDataSource{} | ||
| ) | ||
|
|
||
| type backupJobsDataSource struct { | ||
| client *backup.Client | ||
| } | ||
|
|
||
| // backupJobsDataSourceModel is the top-level model for the backup jobs data source. | ||
| type backupJobsDataSourceModel struct { | ||
| ID types.String `tfsdk:"id"` | ||
| Jobs []backupJobDatasourceModel `tfsdk:"jobs"` | ||
| } | ||
|
|
||
| // NewDataSource creates a new backup jobs data source. | ||
| func NewDataSource() datasource.DataSource { | ||
| return &backupJobsDataSource{} | ||
| } | ||
|
|
||
| func (d *backupJobsDataSource) Metadata( | ||
| _ context.Context, | ||
| _ datasource.MetadataRequest, | ||
| resp *datasource.MetadataResponse, | ||
| ) { | ||
| resp.TypeName = "proxmox_backup_jobs" | ||
| } | ||
|
|
||
| func (d *backupJobsDataSource) Configure( | ||
| _ context.Context, | ||
| req datasource.ConfigureRequest, | ||
| resp *datasource.ConfigureResponse, | ||
| ) { | ||
| if req.ProviderData == nil { | ||
| return | ||
| } | ||
|
|
||
| cfg, ok := req.ProviderData.(config.DataSource) | ||
| if !ok { | ||
| resp.Diagnostics.AddError( | ||
| "Unexpected DataSource Configure Type", | ||
| fmt.Sprintf("Expected config.DataSource, got: %T", req.ProviderData), | ||
| ) | ||
|
|
||
| return | ||
| } | ||
|
|
||
| d.client = cfg.Client.Cluster().Backup() | ||
| } | ||
|
|
||
| func (d *backupJobsDataSource) Schema( | ||
| _ context.Context, | ||
| _ datasource.SchemaRequest, | ||
| resp *datasource.SchemaResponse, | ||
| ) { | ||
| resp.Schema = schema.Schema{ | ||
| Description: "Retrieves the list of cluster-wide backup jobs.", | ||
| Attributes: map[string]schema.Attribute{ | ||
| "id": schema.StringAttribute{ | ||
| Description: "Unique identifier for this data source.", | ||
| Computed: true, | ||
| }, | ||
| "jobs": schema.ListNestedAttribute{ | ||
| Description: "List of backup jobs.", | ||
| Computed: true, | ||
| NestedObject: schema.NestedAttributeObject{ | ||
| Attributes: map[string]schema.Attribute{ | ||
| "id": schema.StringAttribute{ | ||
| Description: "Unique identifier of the backup job.", | ||
| Computed: true, | ||
| }, | ||
| "schedule": schema.StringAttribute{ | ||
| Description: "Backup schedule in systemd calendar format.", | ||
| Computed: true, | ||
| }, | ||
| "storage": schema.StringAttribute{ | ||
| Description: "Target storage for the backup.", | ||
| Computed: true, | ||
| }, | ||
| "enabled": schema.BoolAttribute{ | ||
| Description: "Indicates whether the backup job is enabled.", | ||
| Computed: true, | ||
| }, | ||
| "node": schema.StringAttribute{ | ||
| Description: "Node on which the backup job runs.", | ||
| Computed: true, | ||
| }, | ||
| "vmid": schema.ListAttribute{ | ||
| Description: "List of VM/CT IDs included in the backup job.", | ||
| Computed: true, | ||
| ElementType: types.StringType, | ||
| }, | ||
| "all": schema.BoolAttribute{ | ||
| Description: "Indicates whether all VMs and CTs are backed up.", | ||
| Computed: true, | ||
| }, | ||
| "mode": schema.StringAttribute{ | ||
| Description: "Backup mode (e.g. snapshot, suspend, stop).", | ||
| Computed: true, | ||
| }, | ||
| "compress": schema.StringAttribute{ | ||
| Description: "Compression algorithm used for the backup.", | ||
| Computed: true, | ||
| }, | ||
| "mailto": schema.StringAttribute{ | ||
| Description: "Comma-separated list of email addresses for notifications.", | ||
| Computed: true, | ||
| }, | ||
| "mailnotification": schema.StringAttribute{ | ||
| Description: "When to send email notifications (always or failure).", | ||
| Computed: true, | ||
| }, | ||
| "notes_template": schema.StringAttribute{ | ||
| Description: "Template for backup notes.", | ||
| Computed: true, | ||
| }, | ||
| "pool": schema.StringAttribute{ | ||
| Description: "Pool whose members are backed up.", | ||
| Computed: true, | ||
| }, | ||
| "prune_backups": schema.StringAttribute{ | ||
| Description: "Prune options in the format `keep-last=N,...`.", | ||
| Computed: true, | ||
| }, | ||
| "protected": schema.BoolAttribute{ | ||
| Description: "Indicates whether backups created by this job are protected from pruning.", | ||
| Computed: true, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func (d *backupJobsDataSource) Read( | ||
| ctx context.Context, | ||
| _ datasource.ReadRequest, | ||
| resp *datasource.ReadResponse, | ||
| ) { | ||
| jobs, err := d.client.List(ctx) | ||
| if err != nil { | ||
| resp.Diagnostics.AddError("Unable to Read Backup Jobs", err.Error()) | ||
| return | ||
| } | ||
|
|
||
| var state backupJobsDataSourceModel | ||
|
|
||
| state.ID = types.StringValue("backup_jobs") | ||
| state.Jobs = make([]backupJobDatasourceModel, len(jobs)) | ||
|
|
||
| for i, job := range jobs { | ||
| state.Jobs[i].fromAPI(job) | ||
| } | ||
|
|
||
| resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.