Skip to content
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

provider: adding a test ensuring that Data Sources do not support import #23820

Merged
merged 4 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions internal/provider/provider_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,24 @@ func schemaContainsSensitiveFieldsNotMarkedAsSensitive(input map[string]*plugins
return nil
}

func TestDataSourcesShouldNotSupportImport(t *testing.T) {
provider := TestAzureProvider()

// intentionally sorting these so the output is consistent
dataSourceNames := make([]string, 0)
for dataSourceName := range provider.DataSourcesMap {
dataSourceNames = append(dataSourceNames, dataSourceName)
}
sort.Strings(dataSourceNames)

for _, dataSourceName := range dataSourceNames {
dataSource := provider.DataSourcesMap[dataSourceName]
if dataSource.Importer != nil {
t.Fatalf("the Data Source %q supports Import but Terraform does not support this - please remove the `Importer` from this Data Source", dataSourceName)
}
}
}

func TestDataSourcesHaveEnabledFieldsMarkedAsBooleans(t *testing.T) {
// This test validates that Data Sources do not contain a field suffixed with `_enabled` that isn't a Boolean.
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ func dataSourceDataProtectionBackupVault() *pluginsdk.Resource {
Read: pluginsdk.DefaultTimeout(5 * time.Minute),
},

Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error {
_, err := backupvaults.ParseBackupVaultID(id)
return err
}),

Schema: map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Expand Down
6 changes: 0 additions & 6 deletions internal/services/kusto/kusto_database_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2023-08-15/databases"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/kusto/parse"
kustoValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/kusto/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
Expand All @@ -22,11 +21,6 @@ func dataSourceKustoDatabase() *pluginsdk.Resource {
return &pluginsdk.Resource{
Read: dataSourceKustoDatabaseRead,

Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error {
_, err := parse.DatabaseID(id)
return err
}),

Timeouts: &pluginsdk.ResourceTimeout{
Read: pluginsdk.DefaultTimeout(5 * time.Minute),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ func dataSourceVirtualHubRouteTable() *pluginsdk.Resource {
Read: pluginsdk.DefaultTimeout(5 * time.Minute),
},

Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error {
_, err := parse.HubRouteTableID(id)
return err
}),

Schema: map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Expand Down
Loading