Skip to content

Commit

Permalink
Merge pull request #23820 from hashicorp/b/schema-data-sources-cannot…
Browse files Browse the repository at this point in the history
…-support-import

provider: adding a test ensuring that Data Sources do not support import
  • Loading branch information
tombuildsstuff authored Nov 8, 2023
2 parents c78b582 + 8f89d33 commit ac2a612
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
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

0 comments on commit ac2a612

Please sign in to comment.