generated from hashicorp/terraform-provider-scaffolding-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add media_management datasource
- Loading branch information
Showing
5 changed files
with
251 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "radarr_media_management Data Source - terraform-provider-radarr" | ||
subcategory: "Media Management" | ||
description: |- | ||
Media Management ../resources/media_management. | ||
--- | ||
|
||
# radarr_media_management (Data Source) | ||
|
||
[subcategory:Media Management]: # | ||
[Media Management](../resources/media_management). | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "radarr_media_management" "example" { | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Read-Only | ||
|
||
- `auto_rename_folders` (Boolean) Auto rename folders. | ||
- `auto_unmonitor_previously_downloaded_movies` (Boolean) Auto unmonitor previously downloaded movies. | ||
- `chmod_folder` (String) Permission in linux format. | ||
- `chown_group` (String) Group used for permission. | ||
- `copy_using_hardlinks` (Boolean) Use hardlinks instead of copy. | ||
- `create_empty_movie_folders` (Boolean) Create empty movies directories. | ||
- `delete_empty_folders` (Boolean) Delete empty movies directories. | ||
- `download_propers_and_repacks` (String) Download proper and repack policy. valid inputs are: 'preferAndUpgrade', 'doNotUpgrade', and 'doNotPrefer'. | ||
- `enable_media_info` (Boolean) Scan files details. | ||
- `extra_file_extensions` (String) Comma separated list of extra files to import (.nfo will be imported as .nfo-orig). | ||
- `file_date` (String) Define the file date modification. valid inputs are: 'none', 'localAirDate, and 'utcAirDate'. | ||
- `id` (Number) Delay Profile ID. | ||
- `import_extra_files` (Boolean) Import extra files. If enabled it will leverage 'extra_file_extensions'. | ||
- `minimum_free_space_when_importing` (Number) Minimum free space in MB to allow import. | ||
- `paths_default_static` (Boolean) Path default static. | ||
- `recycle_bin` (String) Recycle bin absolute path. | ||
- `recycle_bin_cleanup_days` (Number) Recyle bin days of retention. | ||
- `rescan_after_refresh` (String) Rescan after refresh policy. valid inputs are: 'always', 'afterManual' and 'never'. | ||
- `set_permissions_linux` (Boolean) Set permission for imported files. | ||
- `skip_free_space_check_when_importing` (Boolean) Skip free space check before importing. | ||
|
||
|
This file contains 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,2 @@ | ||
data "radarr_media_management" "example" { | ||
} |
This file contains 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,172 @@ | ||
package provider | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/diag" | ||
"github.com/hashicorp/terraform-plugin-framework/tfsdk" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
"github.com/hashicorp/terraform-plugin-log/tflog" | ||
"golift.io/starr/radarr" | ||
) | ||
|
||
// Ensure provider defined types fully satisfy framework interfaces. | ||
var _ datasource.DataSource = &MediaManagementDataSource{} | ||
|
||
func NewMediaManagementDataSource() datasource.DataSource { | ||
return &MediaManagementDataSource{} | ||
} | ||
|
||
// MediaManagementDataSource defines the media management implementation. | ||
type MediaManagementDataSource struct { | ||
client *radarr.Radarr | ||
} | ||
|
||
func (d *MediaManagementDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { | ||
resp.TypeName = req.ProviderTypeName + "_media_management" | ||
} | ||
|
||
func (d *MediaManagementDataSource) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) { | ||
return tfsdk.Schema{ | ||
// This description is used by the documentation generator and the delay server. | ||
MarkdownDescription: "[subcategory:Media Management]: #\n[Media Management](../resources/media_management).", | ||
Attributes: map[string]tfsdk.Attribute{ | ||
"id": { | ||
MarkdownDescription: "Delay Profile ID.", | ||
Computed: true, | ||
Type: types.Int64Type, | ||
}, | ||
"auto_rename_folders": { | ||
MarkdownDescription: "Auto rename folders.", | ||
Computed: true, | ||
Type: types.BoolType, | ||
}, | ||
"auto_unmonitor_previously_downloaded_movies": { | ||
MarkdownDescription: "Auto unmonitor previously downloaded movies.", | ||
Computed: true, | ||
Type: types.BoolType, | ||
}, | ||
"copy_using_hardlinks": { | ||
MarkdownDescription: "Use hardlinks instead of copy.", | ||
Computed: true, | ||
Type: types.BoolType, | ||
}, | ||
"create_empty_movie_folders": { | ||
MarkdownDescription: "Create empty movies directories.", | ||
Computed: true, | ||
Type: types.BoolType, | ||
}, | ||
"delete_empty_folders": { | ||
MarkdownDescription: "Delete empty movies directories.", | ||
Computed: true, | ||
Type: types.BoolType, | ||
}, | ||
"enable_media_info": { | ||
MarkdownDescription: "Scan files details.", | ||
Computed: true, | ||
Type: types.BoolType, | ||
}, | ||
"import_extra_files": { | ||
MarkdownDescription: "Import extra files. If enabled it will leverage 'extra_file_extensions'.", | ||
Computed: true, | ||
Type: types.BoolType, | ||
}, | ||
"paths_default_static": { | ||
MarkdownDescription: "Path default static.", | ||
Computed: true, | ||
Type: types.BoolType, | ||
}, | ||
"set_permissions_linux": { | ||
MarkdownDescription: "Set permission for imported files.", | ||
Computed: true, | ||
Type: types.BoolType, | ||
}, | ||
"skip_free_space_check_when_importing": { | ||
MarkdownDescription: "Skip free space check before importing.", | ||
Computed: true, | ||
Type: types.BoolType, | ||
}, | ||
"minimum_free_space_when_importing": { | ||
MarkdownDescription: "Minimum free space in MB to allow import.", | ||
Computed: true, | ||
Type: types.Int64Type, | ||
}, | ||
"recycle_bin_cleanup_days": { | ||
MarkdownDescription: "Recyle bin days of retention.", | ||
Computed: true, | ||
Type: types.Int64Type, | ||
}, | ||
"chmod_folder": { | ||
MarkdownDescription: "Permission in linux format.", | ||
Computed: true, | ||
Type: types.StringType, | ||
}, | ||
"chown_group": { | ||
MarkdownDescription: "Group used for permission.", | ||
Computed: true, | ||
Type: types.StringType, | ||
}, | ||
"download_propers_and_repacks": { | ||
MarkdownDescription: "Download proper and repack policy. valid inputs are: 'preferAndUpgrade', 'doNotUpgrade', and 'doNotPrefer'.", | ||
Computed: true, | ||
Type: types.StringType, | ||
}, | ||
"extra_file_extensions": { | ||
MarkdownDescription: "Comma separated list of extra files to import (.nfo will be imported as .nfo-orig).", | ||
Computed: true, | ||
Type: types.StringType, | ||
}, | ||
"file_date": { | ||
MarkdownDescription: "Define the file date modification. valid inputs are: 'none', 'localAirDate, and 'utcAirDate'.", | ||
Computed: true, | ||
Type: types.StringType, | ||
}, | ||
"recycle_bin": { | ||
MarkdownDescription: "Recycle bin absolute path.", | ||
Computed: true, | ||
Type: types.StringType, | ||
}, | ||
"rescan_after_refresh": { | ||
MarkdownDescription: "Rescan after refresh policy. valid inputs are: 'always', 'afterManual' and 'never'.", | ||
Computed: true, | ||
Type: types.StringType, | ||
}, | ||
}, | ||
}, nil | ||
} | ||
|
||
func (d *MediaManagementDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { | ||
// Prevent panic if the provider has not been configured. | ||
if req.ProviderData == nil { | ||
return | ||
} | ||
|
||
client, ok := req.ProviderData.(*radarr.Radarr) | ||
if !ok { | ||
resp.Diagnostics.AddError( | ||
UnexpectedDataSourceConfigureType, | ||
fmt.Sprintf("Expected *radarr.Radarr, got: %T. Please report this issue to the provider developers.", req.ProviderData), | ||
) | ||
|
||
return | ||
} | ||
|
||
d.client = client | ||
} | ||
|
||
func (d *MediaManagementDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
// Get indexer config current value | ||
response, err := d.client.GetMediaManagementContext(ctx) | ||
if err != nil { | ||
resp.Diagnostics.AddError(ClientError, fmt.Sprintf("Unable to read indexer cofig, got error: %s", err)) | ||
|
||
return | ||
} | ||
|
||
tflog.Trace(ctx, "read madia_management") | ||
|
||
result := writeMediaManagement(response) | ||
resp.Diagnostics.Append(resp.State.Set(ctx, &result)...) | ||
} |
This file contains 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,29 @@ | ||
package provider | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccMediaManagementDataSource(t *testing.T) { | ||
t.Parallel() | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
// Read testing | ||
{ | ||
Config: testAccMediaManagementDataSourceConfig, | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttrSet("data.radarr_media_management.test", "id")), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccMediaManagementDataSourceConfig = ` | ||
data "radarr_media_management" "test" { | ||
} | ||
` |
This file contains 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