diff --git a/docs/resources/import_list_tmdb_list.md b/docs/resources/import_list_tmdb_list.md new file mode 100644 index 00000000..70df176a --- /dev/null +++ b/docs/resources/import_list_tmdb_list.md @@ -0,0 +1,62 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "radarr_import_list_tmdb_list Resource - terraform-provider-radarr" +subcategory: "Import Lists" +description: |- + Import List TMDB List resource. + For more information refer to Import List https://wiki.servarr.com/radarr/settings#import-lists and TMDB List https://wiki.servarr.com/radarr/supported#tmdblistimport. +--- + +# radarr_import_list_tmdb_list (Resource) + +Import List TMDB List resource. +For more information refer to [Import List](https://wiki.servarr.com/radarr/settings#import-lists) and [TMDB List](https://wiki.servarr.com/radarr/supported#tmdblistimport). + +## Example Usage + +```terraform +resource "radarr_import_list_tmdb_list" "example" { + enabled = true + enable_auto = false + search_on_add = false + root_folder_path = "/config" + monitor = "none" + minimum_availability = "tba" + quality_profile_id = 1 + name = "Example" + list_id = "11842" +} +``` + + +## Schema + +### Required + +- `list_id` (String) List ID. +- `minimum_availability` (String) Minimum availability. +- `monitor` (String) Should monitor. +- `name` (String) Import List name. +- `quality_profile_id` (Number) Quality profile ID. +- `root_folder_path` (String) Root folder path. + +### Optional + +- `enable_auto` (Boolean) Enable automatic add flag. +- `enabled` (Boolean) Enabled flag. +- `list_order` (Number) List order. +- `search_on_add` (Boolean) Search on add flag. +- `tags` (Set of Number) List of associated tags. + +### Read-Only + +- `id` (Number) Import List ID. + +## Import + +Import is supported using the following syntax: + +```shell +# import using the API/UI ID +terraform import radarr_import_list_tmdb_list.example 1 +``` diff --git a/examples/resources/radarr_import_list_tmdb_list/import.sh b/examples/resources/radarr_import_list_tmdb_list/import.sh new file mode 100644 index 00000000..0c3557d9 --- /dev/null +++ b/examples/resources/radarr_import_list_tmdb_list/import.sh @@ -0,0 +1,2 @@ +# import using the API/UI ID +terraform import radarr_import_list_tmdb_list.example 1 \ No newline at end of file diff --git a/examples/resources/radarr_import_list_tmdb_list/resource.tf b/examples/resources/radarr_import_list_tmdb_list/resource.tf new file mode 100644 index 00000000..9f2625db --- /dev/null +++ b/examples/resources/radarr_import_list_tmdb_list/resource.tf @@ -0,0 +1,11 @@ +resource "radarr_import_list_tmdb_list" "example" { + enabled = true + enable_auto = false + search_on_add = false + root_folder_path = "/config" + monitor = "none" + minimum_availability = "tba" + quality_profile_id = 1 + name = "Example" + list_id = "11842" +} \ No newline at end of file diff --git a/internal/provider/import_list_tmdb_company_resource.go b/internal/provider/import_list_tmdb_company_resource.go index 3b42d7f8..0f669ecf 100644 --- a/internal/provider/import_list_tmdb_company_resource.go +++ b/internal/provider/import_list_tmdb_company_resource.go @@ -19,29 +19,29 @@ import ( ) const ( - importListTMDCompanyBResourceName = "import_list_tmdb_company" - importListTMDCompanyBImplementation = "TMDbCompanyImport" - importListTMDCompanyBConfigContract = "TMDbCompanySettings" - importListTMDCompanyBType = "advanced" + importListTMDBCompanyResourceName = "import_list_tmdb_company" + importListTMDBCompanyImplementation = "TMDbCompanyImport" + importListTMDBCompanyConfigContract = "TMDbCompanySettings" + importListTMDBCompanyType = "advanced" ) // Ensure provider defined types fully satisfy framework interfaces. var ( - _ resource.Resource = &ImportListTMDCompanyBResource{} - _ resource.ResourceWithImportState = &ImportListTMDCompanyBResource{} + _ resource.Resource = &ImportListTMDBCompanyResource{} + _ resource.ResourceWithImportState = &ImportListTMDBCompanyResource{} ) -func NewImportListTMDCompanyBResource() resource.Resource { - return &ImportListTMDCompanyBResource{} +func NewImportListTMDBCompanyResource() resource.Resource { + return &ImportListTMDBCompanyResource{} } -// ImportListTMDCompanyBResource defines the import list implementation. -type ImportListTMDCompanyBResource struct { +// ImportListTMDBCompanyResource defines the import list implementation. +type ImportListTMDBCompanyResource struct { client *radarr.APIClient } -// ImportListTMDCompanyB describes the import list data model. -type ImportListTMDCompanyB struct { +// ImportListTMDBCompany describes the import list data model. +type ImportListTMDBCompany struct { Tags types.Set `tfsdk:"tags"` Name types.String `tfsdk:"name"` Monitor types.String `tfsdk:"monitor"` @@ -56,7 +56,7 @@ type ImportListTMDCompanyB struct { SearchOnAdd types.Bool `tfsdk:"search_on_add"` } -func (i ImportListTMDCompanyB) toImportList() *ImportList { +func (i ImportListTMDBCompany) toImportList() *ImportList { return &ImportList{ Tags: i.Tags, Name: i.Name, @@ -73,7 +73,7 @@ func (i ImportListTMDCompanyB) toImportList() *ImportList { } } -func (i *ImportListTMDCompanyB) fromImportList(importList *ImportList) { +func (i *ImportListTMDBCompany) fromImportList(importList *ImportList) { i.Tags = importList.Tags i.Name = importList.Name i.Monitor = importList.Monitor @@ -88,11 +88,11 @@ func (i *ImportListTMDCompanyB) fromImportList(importList *ImportList) { i.SearchOnAdd = importList.SearchOnAdd } -func (r *ImportListTMDCompanyBResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_" + importListTMDCompanyBResourceName +func (r *ImportListTMDBCompanyResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_" + importListTMDBCompanyResourceName } -func (r *ImportListTMDCompanyBResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { +func (r *ImportListTMDBCompanyResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = schema.Schema{ MarkdownDescription: "Import List TMDB Company resource.\nFor more information refer to [Import List](https://wiki.servarr.com/radarr/settings#import-lists) and [TMDB Company](https://wiki.servarr.com/radarr/supported#tmdbcompanyimport).", Attributes: map[string]schema.Attribute{ @@ -164,15 +164,15 @@ func (r *ImportListTMDCompanyBResource) Schema(ctx context.Context, req resource } } -func (r *ImportListTMDCompanyBResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { +func (r *ImportListTMDBCompanyResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { if client := helpers.ResourceConfigure(ctx, req, resp); client != nil { r.client = client } } -func (r *ImportListTMDCompanyBResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { +func (r *ImportListTMDBCompanyResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { // Retrieve values from plan - var importList *ImportListTMDCompanyB + var importList *ImportListTMDBCompany resp.Diagnostics.Append(req.Plan.Get(ctx, &importList)...) @@ -180,25 +180,25 @@ func (r *ImportListTMDCompanyBResource) Create(ctx context.Context, req resource return } - // Create new ImportListTMDCompanyB + // Create new ImportListTMDBCompany request := importList.read(ctx) response, _, err := r.client.ImportListApi.CreateImportList(ctx).ImportListResource(*request).Execute() if err != nil { - resp.Diagnostics.AddError(helpers.ClientError, helpers.ParseClientError(helpers.Create, importListTMDCompanyBResourceName, err)) + resp.Diagnostics.AddError(helpers.ClientError, helpers.ParseClientError(helpers.Create, importListTMDBCompanyResourceName, err)) return } - tflog.Trace(ctx, "created "+importListTMDCompanyBResourceName+": "+strconv.Itoa(int(response.GetId()))) + tflog.Trace(ctx, "created "+importListTMDBCompanyResourceName+": "+strconv.Itoa(int(response.GetId()))) // Generate resource state struct importList.write(ctx, response) resp.Diagnostics.Append(resp.State.Set(ctx, &importList)...) } -func (r *ImportListTMDCompanyBResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { +func (r *ImportListTMDBCompanyResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { // Get current state - var importList *ImportListTMDCompanyB + var importList *ImportListTMDBCompany resp.Diagnostics.Append(req.State.Get(ctx, &importList)...) @@ -206,23 +206,23 @@ func (r *ImportListTMDCompanyBResource) Read(ctx context.Context, req resource.R return } - // Get ImportListTMDCompanyB current value + // Get ImportListTMDBCompany current value response, _, err := r.client.ImportListApi.GetImportListById(ctx, int32(importList.ID.ValueInt64())).Execute() if err != nil { - resp.Diagnostics.AddError(helpers.ClientError, helpers.ParseClientError(helpers.Read, importListTMDCompanyBResourceName, err)) + resp.Diagnostics.AddError(helpers.ClientError, helpers.ParseClientError(helpers.Read, importListTMDBCompanyResourceName, err)) return } - tflog.Trace(ctx, "read "+importListTMDCompanyBResourceName+": "+strconv.Itoa(int(response.GetId()))) + tflog.Trace(ctx, "read "+importListTMDBCompanyResourceName+": "+strconv.Itoa(int(response.GetId()))) // Map response body to resource schema attribute importList.write(ctx, response) resp.Diagnostics.Append(resp.State.Set(ctx, &importList)...) } -func (r *ImportListTMDCompanyBResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { +func (r *ImportListTMDBCompanyResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { // Get plan values - var importList *ImportListTMDCompanyB + var importList *ImportListTMDBCompany resp.Diagnostics.Append(req.Plan.Get(ctx, &importList)...) @@ -230,24 +230,24 @@ func (r *ImportListTMDCompanyBResource) Update(ctx context.Context, req resource return } - // Update ImportListTMDCompanyB + // Update ImportListTMDBCompany request := importList.read(ctx) response, _, err := r.client.ImportListApi.UpdateImportList(ctx, strconv.Itoa(int(request.GetId()))).ImportListResource(*request).Execute() if err != nil { - resp.Diagnostics.AddError(helpers.ClientError, helpers.ParseClientError(helpers.Update, importListTMDCompanyBResourceName, err)) + resp.Diagnostics.AddError(helpers.ClientError, helpers.ParseClientError(helpers.Update, importListTMDBCompanyResourceName, err)) return } - tflog.Trace(ctx, "updated "+importListTMDCompanyBResourceName+": "+strconv.Itoa(int(response.GetId()))) + tflog.Trace(ctx, "updated "+importListTMDBCompanyResourceName+": "+strconv.Itoa(int(response.GetId()))) // Generate resource state struct importList.write(ctx, response) resp.Diagnostics.Append(resp.State.Set(ctx, &importList)...) } -func (r *ImportListTMDCompanyBResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { - var importList *ImportListTMDCompanyB +func (r *ImportListTMDBCompanyResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var importList *ImportListTMDBCompany resp.Diagnostics.Append(req.State.Get(ctx, &importList)...) @@ -255,24 +255,24 @@ func (r *ImportListTMDCompanyBResource) Delete(ctx context.Context, req resource return } - // Delete ImportListTMDCompanyB current value + // Delete ImportListTMDBCompany current value _, err := r.client.ImportListApi.DeleteImportList(ctx, int32(importList.ID.ValueInt64())).Execute() if err != nil { - resp.Diagnostics.AddError(helpers.ClientError, helpers.ParseClientError(helpers.Read, importListTMDCompanyBResourceName, err)) + resp.Diagnostics.AddError(helpers.ClientError, helpers.ParseClientError(helpers.Read, importListTMDBCompanyResourceName, err)) return } - tflog.Trace(ctx, "deleted "+importListTMDCompanyBResourceName+": "+strconv.Itoa(int(importList.ID.ValueInt64()))) + tflog.Trace(ctx, "deleted "+importListTMDBCompanyResourceName+": "+strconv.Itoa(int(importList.ID.ValueInt64()))) resp.State.RemoveResource(ctx) } -func (r *ImportListTMDCompanyBResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { +func (r *ImportListTMDBCompanyResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { helpers.ImportStatePassthroughIntID(ctx, path.Root("id"), req, resp) - tflog.Trace(ctx, "imported "+importListTMDCompanyBResourceName+": "+req.ID) + tflog.Trace(ctx, "imported "+importListTMDBCompanyResourceName+": "+req.ID) } -func (i *ImportListTMDCompanyB) write(ctx context.Context, importList *radarr.ImportListResource) { +func (i *ImportListTMDBCompany) write(ctx context.Context, importList *radarr.ImportListResource) { genericImportList := ImportList{ Name: types.StringValue(importList.GetName()), Monitor: types.StringValue(string(importList.GetMonitor())), @@ -290,7 +290,7 @@ func (i *ImportListTMDCompanyB) write(ctx context.Context, importList *radarr.Im i.fromImportList(&genericImportList) } -func (i *ImportListTMDCompanyB) read(ctx context.Context) *radarr.ImportListResource { +func (i *ImportListTMDBCompany) read(ctx context.Context) *radarr.ImportListResource { tags := make([]*int32, len(i.Tags.Elements())) tfsdk.ValueAs(ctx, i.Tags, &tags) @@ -303,9 +303,9 @@ func (i *ImportListTMDCompanyB) read(ctx context.Context) *radarr.ImportListReso list.SetEnableAuto(i.EnableAuto.ValueBool()) list.SetEnabled(i.Enabled.ValueBool()) list.SetSearchOnAdd(i.SearchOnAdd.ValueBool()) - list.SetListType(importListTMDCompanyBType) - list.SetConfigContract(importListTMDCompanyBConfigContract) - list.SetImplementation(importListTMDCompanyBImplementation) + list.SetListType(importListTMDBCompanyType) + list.SetConfigContract(importListTMDBCompanyConfigContract) + list.SetImplementation(importListTMDBCompanyImplementation) list.SetId(int32(i.ID.ValueInt64())) list.SetName(i.Name.ValueString()) list.SetTags(tags) diff --git a/internal/provider/import_list_tmdb_company_resource_test.go b/internal/provider/import_list_tmdb_company_resource_test.go index 1bbeff34..7db8c004 100644 --- a/internal/provider/import_list_tmdb_company_resource_test.go +++ b/internal/provider/import_list_tmdb_company_resource_test.go @@ -17,7 +17,7 @@ func TestAccImportListTMDBCompanyResource(t *testing.T) { // Create and Read testing { PreConfig: rootFolderDSInit, - Config: testAccImportListTMDBCompanyResourceConfig("resourceTMDBCompanyTest", "none"), + Config: testAccImportListTMDBCompanyResourceConfig("resourceTMDCompanyTest", "none"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("radarr_import_list_tmdb_company.test", "monitor", "none"), resource.TestCheckResourceAttrSet("radarr_import_list_tmdb_company.test", "id"), @@ -25,7 +25,7 @@ func TestAccImportListTMDBCompanyResource(t *testing.T) { }, // Update and Read testing { - Config: testAccImportListTMDBCompanyResourceConfig("resourceTMDBCompanyTest", "movieOnly"), + Config: testAccImportListTMDBCompanyResourceConfig("resourceTMDCompanyTest", "movieOnly"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("radarr_import_list_tmdb_company.test", "monitor", "movieOnly"), ), diff --git a/internal/provider/import_list_tmdb_keyword_resource.go b/internal/provider/import_list_tmdb_keyword_resource.go index 2ea3febd..afd4c1bc 100644 --- a/internal/provider/import_list_tmdb_keyword_resource.go +++ b/internal/provider/import_list_tmdb_keyword_resource.go @@ -19,29 +19,29 @@ import ( ) const ( - importListTMDKeywordBResourceName = "import_list_tmdb_keyword" - importListTMDKeywordBImplementation = "TMDbKeywordImport" - importListTMDKeywordBConfigContract = "TMDbKeywordSettings" - importListTMDKeywordBType = "advanced" + importListTMDBKeywordResourceName = "import_list_tmdb_keyword" + importListTMDBKeywordImplementation = "TMDbKeywordImport" + importListTMDBKeywordConfigContract = "TMDbKeywordSettings" + importListTMDBKeywordType = "advanced" ) // Ensure provider defined types fully satisfy framework interfaces. var ( - _ resource.Resource = &ImportListTMDKeywordBResource{} - _ resource.ResourceWithImportState = &ImportListTMDKeywordBResource{} + _ resource.Resource = &ImportListTMDBKeywordResource{} + _ resource.ResourceWithImportState = &ImportListTMDBKeywordResource{} ) -func NewImportListTMDKeywordBResource() resource.Resource { - return &ImportListTMDKeywordBResource{} +func NewImportListTMDBKeywordResource() resource.Resource { + return &ImportListTMDBKeywordResource{} } -// ImportListTMDKeywordBResource defines the import list implementation. -type ImportListTMDKeywordBResource struct { +// ImportListTMDBKeywordResource defines the import list implementation. +type ImportListTMDBKeywordResource struct { client *radarr.APIClient } -// ImportListTMDKeywordB describes the import list data model. -type ImportListTMDKeywordB struct { +// ImportListTMDBKeyword describes the import list data model. +type ImportListTMDBKeyword struct { Tags types.Set `tfsdk:"tags"` Name types.String `tfsdk:"name"` Monitor types.String `tfsdk:"monitor"` @@ -56,7 +56,7 @@ type ImportListTMDKeywordB struct { SearchOnAdd types.Bool `tfsdk:"search_on_add"` } -func (i ImportListTMDKeywordB) toImportList() *ImportList { +func (i ImportListTMDBKeyword) toImportList() *ImportList { return &ImportList{ Tags: i.Tags, Name: i.Name, @@ -73,7 +73,7 @@ func (i ImportListTMDKeywordB) toImportList() *ImportList { } } -func (i *ImportListTMDKeywordB) fromImportList(importList *ImportList) { +func (i *ImportListTMDBKeyword) fromImportList(importList *ImportList) { i.Tags = importList.Tags i.Name = importList.Name i.Monitor = importList.Monitor @@ -88,11 +88,11 @@ func (i *ImportListTMDKeywordB) fromImportList(importList *ImportList) { i.SearchOnAdd = importList.SearchOnAdd } -func (r *ImportListTMDKeywordBResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_" + importListTMDKeywordBResourceName +func (r *ImportListTMDBKeywordResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_" + importListTMDBKeywordResourceName } -func (r *ImportListTMDKeywordBResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { +func (r *ImportListTMDBKeywordResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = schema.Schema{ MarkdownDescription: "Import List TMDB Keyword resource.\nFor more information refer to [Import List](https://wiki.servarr.com/radarr/settings#import-lists) and [TMDB Keyword](https://wiki.servarr.com/radarr/supported#tmdbkeywordimport).", Attributes: map[string]schema.Attribute{ @@ -164,15 +164,15 @@ func (r *ImportListTMDKeywordBResource) Schema(ctx context.Context, req resource } } -func (r *ImportListTMDKeywordBResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { +func (r *ImportListTMDBKeywordResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { if client := helpers.ResourceConfigure(ctx, req, resp); client != nil { r.client = client } } -func (r *ImportListTMDKeywordBResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { +func (r *ImportListTMDBKeywordResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { // Retrieve values from plan - var importList *ImportListTMDKeywordB + var importList *ImportListTMDBKeyword resp.Diagnostics.Append(req.Plan.Get(ctx, &importList)...) @@ -180,25 +180,25 @@ func (r *ImportListTMDKeywordBResource) Create(ctx context.Context, req resource return } - // Create new ImportListTMDKeywordB + // Create new ImportListTMDBKeyword request := importList.read(ctx) response, _, err := r.client.ImportListApi.CreateImportList(ctx).ImportListResource(*request).Execute() if err != nil { - resp.Diagnostics.AddError(helpers.ClientError, helpers.ParseClientError(helpers.Create, importListTMDKeywordBResourceName, err)) + resp.Diagnostics.AddError(helpers.ClientError, helpers.ParseClientError(helpers.Create, importListTMDBKeywordResourceName, err)) return } - tflog.Trace(ctx, "created "+importListTMDKeywordBResourceName+": "+strconv.Itoa(int(response.GetId()))) + tflog.Trace(ctx, "created "+importListTMDBKeywordResourceName+": "+strconv.Itoa(int(response.GetId()))) // Generate resource state struct importList.write(ctx, response) resp.Diagnostics.Append(resp.State.Set(ctx, &importList)...) } -func (r *ImportListTMDKeywordBResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { +func (r *ImportListTMDBKeywordResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { // Get current state - var importList *ImportListTMDKeywordB + var importList *ImportListTMDBKeyword resp.Diagnostics.Append(req.State.Get(ctx, &importList)...) @@ -206,23 +206,23 @@ func (r *ImportListTMDKeywordBResource) Read(ctx context.Context, req resource.R return } - // Get ImportListTMDKeywordB current value + // Get ImportListTMDBKeyword current value response, _, err := r.client.ImportListApi.GetImportListById(ctx, int32(importList.ID.ValueInt64())).Execute() if err != nil { - resp.Diagnostics.AddError(helpers.ClientError, helpers.ParseClientError(helpers.Read, importListTMDKeywordBResourceName, err)) + resp.Diagnostics.AddError(helpers.ClientError, helpers.ParseClientError(helpers.Read, importListTMDBKeywordResourceName, err)) return } - tflog.Trace(ctx, "read "+importListTMDKeywordBResourceName+": "+strconv.Itoa(int(response.GetId()))) + tflog.Trace(ctx, "read "+importListTMDBKeywordResourceName+": "+strconv.Itoa(int(response.GetId()))) // Map response body to resource schema attribute importList.write(ctx, response) resp.Diagnostics.Append(resp.State.Set(ctx, &importList)...) } -func (r *ImportListTMDKeywordBResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { +func (r *ImportListTMDBKeywordResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { // Get plan values - var importList *ImportListTMDKeywordB + var importList *ImportListTMDBKeyword resp.Diagnostics.Append(req.Plan.Get(ctx, &importList)...) @@ -230,24 +230,24 @@ func (r *ImportListTMDKeywordBResource) Update(ctx context.Context, req resource return } - // Update ImportListTMDKeywordB + // Update ImportListTMDBKeyword request := importList.read(ctx) response, _, err := r.client.ImportListApi.UpdateImportList(ctx, strconv.Itoa(int(request.GetId()))).ImportListResource(*request).Execute() if err != nil { - resp.Diagnostics.AddError(helpers.ClientError, helpers.ParseClientError(helpers.Update, importListTMDKeywordBResourceName, err)) + resp.Diagnostics.AddError(helpers.ClientError, helpers.ParseClientError(helpers.Update, importListTMDBKeywordResourceName, err)) return } - tflog.Trace(ctx, "updated "+importListTMDKeywordBResourceName+": "+strconv.Itoa(int(response.GetId()))) + tflog.Trace(ctx, "updated "+importListTMDBKeywordResourceName+": "+strconv.Itoa(int(response.GetId()))) // Generate resource state struct importList.write(ctx, response) resp.Diagnostics.Append(resp.State.Set(ctx, &importList)...) } -func (r *ImportListTMDKeywordBResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { - var importList *ImportListTMDKeywordB +func (r *ImportListTMDBKeywordResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var importList *ImportListTMDBKeyword resp.Diagnostics.Append(req.State.Get(ctx, &importList)...) @@ -255,24 +255,24 @@ func (r *ImportListTMDKeywordBResource) Delete(ctx context.Context, req resource return } - // Delete ImportListTMDKeywordB current value + // Delete ImportListTMDBKeyword current value _, err := r.client.ImportListApi.DeleteImportList(ctx, int32(importList.ID.ValueInt64())).Execute() if err != nil { - resp.Diagnostics.AddError(helpers.ClientError, helpers.ParseClientError(helpers.Read, importListTMDKeywordBResourceName, err)) + resp.Diagnostics.AddError(helpers.ClientError, helpers.ParseClientError(helpers.Read, importListTMDBKeywordResourceName, err)) return } - tflog.Trace(ctx, "deleted "+importListTMDKeywordBResourceName+": "+strconv.Itoa(int(importList.ID.ValueInt64()))) + tflog.Trace(ctx, "deleted "+importListTMDBKeywordResourceName+": "+strconv.Itoa(int(importList.ID.ValueInt64()))) resp.State.RemoveResource(ctx) } -func (r *ImportListTMDKeywordBResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { +func (r *ImportListTMDBKeywordResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { helpers.ImportStatePassthroughIntID(ctx, path.Root("id"), req, resp) - tflog.Trace(ctx, "imported "+importListTMDKeywordBResourceName+": "+req.ID) + tflog.Trace(ctx, "imported "+importListTMDBKeywordResourceName+": "+req.ID) } -func (i *ImportListTMDKeywordB) write(ctx context.Context, importList *radarr.ImportListResource) { +func (i *ImportListTMDBKeyword) write(ctx context.Context, importList *radarr.ImportListResource) { genericImportList := ImportList{ Name: types.StringValue(importList.GetName()), Monitor: types.StringValue(string(importList.GetMonitor())), @@ -290,7 +290,7 @@ func (i *ImportListTMDKeywordB) write(ctx context.Context, importList *radarr.Im i.fromImportList(&genericImportList) } -func (i *ImportListTMDKeywordB) read(ctx context.Context) *radarr.ImportListResource { +func (i *ImportListTMDBKeyword) read(ctx context.Context) *radarr.ImportListResource { tags := make([]*int32, len(i.Tags.Elements())) tfsdk.ValueAs(ctx, i.Tags, &tags) @@ -303,9 +303,9 @@ func (i *ImportListTMDKeywordB) read(ctx context.Context) *radarr.ImportListReso list.SetEnableAuto(i.EnableAuto.ValueBool()) list.SetEnabled(i.Enabled.ValueBool()) list.SetSearchOnAdd(i.SearchOnAdd.ValueBool()) - list.SetListType(importListTMDKeywordBType) - list.SetConfigContract(importListTMDKeywordBConfigContract) - list.SetImplementation(importListTMDKeywordBImplementation) + list.SetListType(importListTMDBKeywordType) + list.SetConfigContract(importListTMDBKeywordConfigContract) + list.SetImplementation(importListTMDBKeywordImplementation) list.SetId(int32(i.ID.ValueInt64())) list.SetName(i.Name.ValueString()) list.SetTags(tags) diff --git a/internal/provider/import_list_tmdb_keyword_resource_test.go b/internal/provider/import_list_tmdb_keyword_resource_test.go index 5a216b1a..ea12a48b 100644 --- a/internal/provider/import_list_tmdb_keyword_resource_test.go +++ b/internal/provider/import_list_tmdb_keyword_resource_test.go @@ -17,7 +17,7 @@ func TestAccImportListTMDBKeywordResource(t *testing.T) { // Create and Read testing { PreConfig: rootFolderDSInit, - Config: testAccImportListTMDBKeywordResourceConfig("resourceTMDBKeywordTest", "none"), + Config: testAccImportListTMDBKeywordResourceConfig("resourceTMDKeywordTest", "none"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("radarr_import_list_tmdb_keyword.test", "monitor", "none"), resource.TestCheckResourceAttrSet("radarr_import_list_tmdb_keyword.test", "id"), @@ -25,7 +25,7 @@ func TestAccImportListTMDBKeywordResource(t *testing.T) { }, // Update and Read testing { - Config: testAccImportListTMDBKeywordResourceConfig("resourceTMDBTest", "movieOnly"), + Config: testAccImportListTMDBKeywordResourceConfig("resourceTMDTest", "movieOnly"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("radarr_import_list_tmdb_keyword.test", "monitor", "movieOnly"), ), diff --git a/internal/provider/import_list_tmdb_list_resource.go b/internal/provider/import_list_tmdb_list_resource.go new file mode 100644 index 00000000..7135a9e2 --- /dev/null +++ b/internal/provider/import_list_tmdb_list_resource.go @@ -0,0 +1,315 @@ +package provider + +import ( + "context" + "strconv" + + "github.com/devopsarr/radarr-go/radarr" + "github.com/devopsarr/terraform-provider-radarr/internal/helpers" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +const ( + importListTMDBListResourceName = "import_list_tmdb_list" + importListTMDBListImplementation = "TMDbListImport" + importListTMDBListConfigContract = "TMDbListSettings" + importListTMDBListType = "advanced" +) + +// Ensure provider defined types fully satisfy framework interfaces. +var ( + _ resource.Resource = &ImportListTMDBListResource{} + _ resource.ResourceWithImportState = &ImportListTMDBListResource{} +) + +func NewImportListTMDBListResource() resource.Resource { + return &ImportListTMDBListResource{} +} + +// ImportListTMDBListResource defines the import list implementation. +type ImportListTMDBListResource struct { + client *radarr.APIClient +} + +// ImportListTMDBList describes the import list data model. +type ImportListTMDBList struct { + Tags types.Set `tfsdk:"tags"` + Name types.String `tfsdk:"name"` + Monitor types.String `tfsdk:"monitor"` + MinimumAvailability types.String `tfsdk:"minimum_availability"` + RootFolderPath types.String `tfsdk:"root_folder_path"` + ListID types.String `tfsdk:"list_id"` + ListOrder types.Int64 `tfsdk:"list_order"` + ID types.Int64 `tfsdk:"id"` + QualityProfileID types.Int64 `tfsdk:"quality_profile_id"` + Enabled types.Bool `tfsdk:"enabled"` + EnableAuto types.Bool `tfsdk:"enable_auto"` + SearchOnAdd types.Bool `tfsdk:"search_on_add"` +} + +func (i ImportListTMDBList) toImportList() *ImportList { + return &ImportList{ + Tags: i.Tags, + Name: i.Name, + Monitor: i.Monitor, + MinimumAvailability: i.MinimumAvailability, + RootFolderPath: i.RootFolderPath, + ListID: i.ListID, + ListOrder: i.ListOrder, + ID: i.ID, + QualityProfileID: i.QualityProfileID, + Enabled: i.Enabled, + EnableAuto: i.EnableAuto, + SearchOnAdd: i.SearchOnAdd, + } +} + +func (i *ImportListTMDBList) fromImportList(importList *ImportList) { + i.Tags = importList.Tags + i.Name = importList.Name + i.Monitor = importList.Monitor + i.MinimumAvailability = importList.MinimumAvailability + i.RootFolderPath = importList.RootFolderPath + i.ListID = importList.ListID + i.ListOrder = importList.ListOrder + i.ID = importList.ID + i.QualityProfileID = importList.QualityProfileID + i.Enabled = importList.Enabled + i.EnableAuto = importList.EnableAuto + i.SearchOnAdd = importList.SearchOnAdd +} + +func (r *ImportListTMDBListResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_" + importListTMDBListResourceName +} + +func (r *ImportListTMDBListResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + MarkdownDescription: "Import List TMDB List resource.\nFor more information refer to [Import List](https://wiki.servarr.com/radarr/settings#import-lists) and [TMDB List](https://wiki.servarr.com/radarr/supported#tmdblistimport).", + Attributes: map[string]schema.Attribute{ + "enable_auto": schema.BoolAttribute{ + MarkdownDescription: "Enable automatic add flag.", + Optional: true, + Computed: true, + }, + "enabled": schema.BoolAttribute{ + MarkdownDescription: "Enabled flag.", + Optional: true, + Computed: true, + }, + "search_on_add": schema.BoolAttribute{ + MarkdownDescription: "Search on add flag.", + Optional: true, + Computed: true, + }, + "quality_profile_id": schema.Int64Attribute{ + MarkdownDescription: "Quality profile ID.", + Required: true, + }, + "list_order": schema.Int64Attribute{ + MarkdownDescription: "List order.", + Optional: true, + Computed: true, + }, + "root_folder_path": schema.StringAttribute{ + MarkdownDescription: "Root folder path.", + Required: true, + }, + "monitor": schema.StringAttribute{ + MarkdownDescription: "Should monitor.", + Required: true, + Validators: []validator.String{ + stringvalidator.OneOf("movieOnly", "movieAndCollection", "none"), + }, + }, + "minimum_availability": schema.StringAttribute{ + MarkdownDescription: "Minimum availability.", + Required: true, + Validators: []validator.String{ + stringvalidator.OneOf("tba", "announced", "inCinemas", "released", "deleted"), + }, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "Import List name.", + Required: true, + }, + "tags": schema.SetAttribute{ + MarkdownDescription: "List of associated tags.", + Optional: true, + Computed: true, + ElementType: types.Int64Type, + }, + "id": schema.Int64Attribute{ + MarkdownDescription: "Import List ID.", + Computed: true, + PlanModifiers: []planmodifier.Int64{ + int64planmodifier.UseStateForUnknown(), + }, + }, + // Field values + "list_id": schema.StringAttribute{ + MarkdownDescription: "List ID.", + Required: true, + }, + }, + } +} + +func (r *ImportListTMDBListResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + if client := helpers.ResourceConfigure(ctx, req, resp); client != nil { + r.client = client + } +} + +func (r *ImportListTMDBListResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + // Retrieve values from plan + var importList *ImportListTMDBList + + resp.Diagnostics.Append(req.Plan.Get(ctx, &importList)...) + + if resp.Diagnostics.HasError() { + return + } + + // Create new ImportListTMDBList + request := importList.read(ctx) + + response, _, err := r.client.ImportListApi.CreateImportList(ctx).ImportListResource(*request).Execute() + if err != nil { + resp.Diagnostics.AddError(helpers.ClientError, helpers.ParseClientError(helpers.Create, importListTMDBListResourceName, err)) + + return + } + + tflog.Trace(ctx, "created "+importListTMDBListResourceName+": "+strconv.Itoa(int(response.GetId()))) + // Generate resource state struct + importList.write(ctx, response) + resp.Diagnostics.Append(resp.State.Set(ctx, &importList)...) +} + +func (r *ImportListTMDBListResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + // Get current state + var importList *ImportListTMDBList + + resp.Diagnostics.Append(req.State.Get(ctx, &importList)...) + + if resp.Diagnostics.HasError() { + return + } + + // Get ImportListTMDBList current value + response, _, err := r.client.ImportListApi.GetImportListById(ctx, int32(importList.ID.ValueInt64())).Execute() + if err != nil { + resp.Diagnostics.AddError(helpers.ClientError, helpers.ParseClientError(helpers.Read, importListTMDBListResourceName, err)) + + return + } + + tflog.Trace(ctx, "read "+importListTMDBListResourceName+": "+strconv.Itoa(int(response.GetId()))) + // Map response body to resource schema attribute + importList.write(ctx, response) + resp.Diagnostics.Append(resp.State.Set(ctx, &importList)...) +} + +func (r *ImportListTMDBListResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + // Get plan values + var importList *ImportListTMDBList + + resp.Diagnostics.Append(req.Plan.Get(ctx, &importList)...) + + if resp.Diagnostics.HasError() { + return + } + + // Update ImportListTMDBList + request := importList.read(ctx) + + response, _, err := r.client.ImportListApi.UpdateImportList(ctx, strconv.Itoa(int(request.GetId()))).ImportListResource(*request).Execute() + if err != nil { + resp.Diagnostics.AddError(helpers.ClientError, helpers.ParseClientError(helpers.Update, importListTMDBListResourceName, err)) + + return + } + + tflog.Trace(ctx, "updated "+importListTMDBListResourceName+": "+strconv.Itoa(int(response.GetId()))) + // Generate resource state struct + importList.write(ctx, response) + resp.Diagnostics.Append(resp.State.Set(ctx, &importList)...) +} + +func (r *ImportListTMDBListResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var importList *ImportListTMDBList + + resp.Diagnostics.Append(req.State.Get(ctx, &importList)...) + + if resp.Diagnostics.HasError() { + return + } + + // Delete ImportListTMDBList current value + _, err := r.client.ImportListApi.DeleteImportList(ctx, int32(importList.ID.ValueInt64())).Execute() + if err != nil { + resp.Diagnostics.AddError(helpers.ClientError, helpers.ParseClientError(helpers.Read, importListTMDBListResourceName, err)) + + return + } + + tflog.Trace(ctx, "deleted "+importListTMDBListResourceName+": "+strconv.Itoa(int(importList.ID.ValueInt64()))) + resp.State.RemoveResource(ctx) +} + +func (r *ImportListTMDBListResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + helpers.ImportStatePassthroughIntID(ctx, path.Root("id"), req, resp) + tflog.Trace(ctx, "imported "+importListTMDBListResourceName+": "+req.ID) +} + +func (i *ImportListTMDBList) write(ctx context.Context, importList *radarr.ImportListResource) { + genericImportList := ImportList{ + Name: types.StringValue(importList.GetName()), + Monitor: types.StringValue(string(importList.GetMonitor())), + MinimumAvailability: types.StringValue(string(importList.GetMinimumAvailability())), + RootFolderPath: types.StringValue(importList.GetRootFolderPath()), + ListOrder: types.Int64Value(int64(importList.GetListOrder())), + ID: types.Int64Value(int64(importList.GetId())), + QualityProfileID: types.Int64Value(int64(importList.GetQualityProfileId())), + Enabled: types.BoolValue(importList.GetEnabled()), + EnableAuto: types.BoolValue(importList.GetEnableAuto()), + SearchOnAdd: types.BoolValue(importList.GetSearchOnAdd()), + } + genericImportList.Tags, _ = types.SetValueFrom(ctx, types.Int64Type, importList.Tags) + genericImportList.writeFields(ctx, importList.Fields) + i.fromImportList(&genericImportList) +} + +func (i *ImportListTMDBList) read(ctx context.Context) *radarr.ImportListResource { + tags := make([]*int32, len(i.Tags.Elements())) + tfsdk.ValueAs(ctx, i.Tags, &tags) + + list := radarr.NewImportListResource() + list.SetMonitor(radarr.MonitorTypes(i.Monitor.ValueString())) + list.SetMinimumAvailability(radarr.MovieStatusType(i.MinimumAvailability.ValueString())) + list.SetRootFolderPath(i.RootFolderPath.ValueString()) + list.SetQualityProfileId(int32(i.QualityProfileID.ValueInt64())) + list.SetListOrder(int32(i.ListOrder.ValueInt64())) + list.SetEnableAuto(i.EnableAuto.ValueBool()) + list.SetEnabled(i.Enabled.ValueBool()) + list.SetSearchOnAdd(i.SearchOnAdd.ValueBool()) + list.SetListType(importListTMDBListType) + list.SetConfigContract(importListTMDBListConfigContract) + list.SetImplementation(importListTMDBListImplementation) + list.SetId(int32(i.ID.ValueInt64())) + list.SetName(i.Name.ValueString()) + list.SetTags(tags) + list.SetFields(i.toImportList().readFields(ctx)) + + return list +} diff --git a/internal/provider/import_list_tmdb_list_resource_test.go b/internal/provider/import_list_tmdb_list_resource_test.go new file mode 100644 index 00000000..db84886d --- /dev/null +++ b/internal/provider/import_list_tmdb_list_resource_test.go @@ -0,0 +1,57 @@ +package provider + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccImportListTMDBListResource(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create and Read testing + { + PreConfig: rootFolderDSInit, + Config: testAccImportListTMDBListResourceConfig("resourceTMDListTest", "none"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("radarr_import_list_tmdb_list.test", "monitor", "none"), + resource.TestCheckResourceAttrSet("radarr_import_list_tmdb_list.test", "id"), + ), + }, + // Update and Read testing + { + Config: testAccImportListTMDBListResourceConfig("resourceTMDListTest", "movieOnly"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("radarr_import_list_tmdb_list.test", "monitor", "movieOnly"), + ), + }, + // ImportState testing + { + ResourceName: "radarr_import_list_tmdb_list.test", + ImportState: true, + ImportStateVerify: true, + }, + // Delete testing automatically occurs in TestCase + }, + }) +} + +func testAccImportListTMDBListResourceConfig(name, monitor string) string { + return fmt.Sprintf(` + resource "radarr_import_list_tmdb_list" "test" { + enabled = false + enable_auto = false + search_on_add = false + root_folder_path = "/config" + monitor = "%s" + minimum_availability = "tba" + quality_profile_id = 1 + name = "%s" + list_id = "11842" + }`, monitor, name) +} diff --git a/internal/provider/provider.go b/internal/provider/provider.go index e94f2817..72a4b056 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -179,8 +179,9 @@ func (p *RadarrProvider) Resources(ctx context.Context) []func() resource.Resour NewImportListRadarrResource, NewImportListRSSResource, NewImportListStevenluResource, - NewImportListTMDCompanyBResource, - NewImportListTMDKeywordBResource, + NewImportListTMDBCompanyResource, + NewImportListTMDBKeywordResource, + NewImportListTMDBListResource, NewImportListConfigResource, NewImportListExclusionResource,