Skip to content

Commit

Permalink
feat: add import list config data source
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuochi committed Jan 26, 2023
1 parent fd4d71f commit 31134a7
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 0 deletions.
29 changes: 29 additions & 0 deletions docs/data-sources/import_list_config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "radarr_import_list_config Data Source - terraform-provider-radarr"
subcategory: "Import Lists"
description: |-
Import List Config ../resources/import_list_config.
---

# radarr_import_list_config (Data Source)

<!-- subcategory:Import Lists -->[Import List Config](../resources/import_list_config).

## Example Usage

```terraform
data "radarr_import_list_config" "example" {
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Read-Only

- `id` (Number) Import List Config ID.
- `sync_interval` (Number) List Update Interval.
- `sync_level` (String) Clean library level.


Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
data "radarr_import_list_config" "example" {
}
72 changes: 72 additions & 0 deletions internal/provider/import_list_config_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package provider

import (
"context"

"github.com/devopsarr/radarr-go/radarr"
"github.com/devopsarr/terraform-provider-radarr/internal/helpers"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-log/tflog"
)

const importListConfigDataSourceName = "import_list_config"

// Ensure provider defined types fully satisfy framework interfaces.
var _ datasource.DataSource = &ImportListConfigDataSource{}

func NewImportListConfigDataSource() datasource.DataSource {
return &ImportListConfigDataSource{}
}

// ImportListConfigDataSource defines the download client config implementation.
type ImportListConfigDataSource struct {
client *radarr.APIClient
}

func (d *ImportListConfigDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_" + importListConfigDataSourceName
}

func (d *ImportListConfigDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
// This description is used by the documentation generator and the delay server.
MarkdownDescription: "<!-- subcategory:Import Lists -->[Import List Config](../resources/import_list_config).",
Attributes: map[string]schema.Attribute{
"id": schema.Int64Attribute{
MarkdownDescription: "Import List Config ID.",
Computed: true,
},
"sync_interval": schema.Int64Attribute{
MarkdownDescription: "List Update Interval.",
Computed: true,
},
"sync_level": schema.StringAttribute{
MarkdownDescription: "Clean library level.",
Computed: true,
},
},
}
}

func (d *ImportListConfigDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
if client := helpers.DataSourceConfigure(ctx, req, resp); client != nil {
d.client = client
}
}

func (d *ImportListConfigDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
// Get indexer config current value
response, _, err := d.client.ImportListConfigApi.GetImportListConfig(ctx).Execute()
if err != nil {
resp.Diagnostics.AddError(helpers.ClientError, helpers.ParseClientError(helpers.Read, importListConfigDataSourceName, err))

return
}

tflog.Trace(ctx, "read "+importListConfigDataSourceName)

config := ImportListConfig{}
config.write(response)
resp.Diagnostics.Append(resp.State.Set(ctx, config)...)
}
29 changes: 29 additions & 0 deletions internal/provider/import_list_config_data_source_test.go
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 TestAccImportListConfigDataSource(t *testing.T) {
t.Parallel()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Read testing
{
Config: testAccImportListConfigDataSourceConfig,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("data.radarr_import_list_config.test", "id")),
},
},
})
}

const testAccImportListConfigDataSourceConfig = `
data "radarr_import_list_config" "test" {
}
`
1 change: 1 addition & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ func (p *RadarrProvider) DataSources(ctx context.Context) []func() datasource.Da
NewRestrictionsDataSource,

// Import Lists
NewImportListConfigDataSource,
NewImportListExclusionDataSource,
NewImportListExclusionsDataSource,

Expand Down

0 comments on commit 31134a7

Please sign in to comment.