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 import list config data source
- Loading branch information
Showing
5 changed files
with
133 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,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. | ||
|
||
|
2 changes: 2 additions & 0 deletions
2
examples/data-sources/radarr_import_list_config/data-source.tf
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_import_list_config" "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,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)...) | ||
} |
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 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" { | ||
} | ||
` |
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