Skip to content

[Internal] Group SDKv2 resources and data sources by API level#5752

Draft
renaudhartert-db wants to merge 2 commits into
mainfrom
sdkv2-split-by-api-level
Draft

[Internal] Group SDKv2 resources and data sources by API level#5752
renaudhartert-db wants to merge 2 commits into
mainfrom
sdkv2-split-by-api-level

Conversation

@renaudhartert-db

Copy link
Copy Markdown
Contributor

Summary

Moves the SDKv2 resource and data source registration out of sdkv2.go into a new resources.go, split into Workspace*, Account*, and Dual* maps. sdkv2.go now calls DataSources() / Resources(), which flatten the three maps via merge.

Adds two registration-consistency tests in resources_test.go:

  • TestApiField_RegistrationConsistency asserts the dual invariant from the schema; every entry in Dual* must have an api attribute, and every entry in Workspace* / Account* must not. The dual case is mechanically detectable because common.AddApiField is the single source of the api schema attribute.
  • TestNoOverlap asserts that a Terraform name appears in at most one resource map and at most one data source map. Resource and data source namespaces are checked separately (a databricks_table resource and databricks_table data source legitimately coexist).

The workspace-vs-account split is an organizational distinction with no runtime effect today; the merged map is what the provider uses. The split makes intent visible at the registration site and gives a clear home for future account-level additions. There is no mechanical schema signal that distinguishes workspace from account; the TODO in common/resource.go lines 117-122 calls out the proper next step (a resource-level Level annotation), which is out of scope here.

Test plan

  • go build ./... clean
  • make fmt lint ws clean
  • go test ./internal/providers/sdkv2/... passes, including the two new tests
  • CI green

Move the SDKv2 resource and data source registration out of sdkv2.go
into a new resources.go, split into Workspace*, Account*, and Dual*
maps. Add a registration-consistency test that asserts the dual
invariant from the schema (every entry in Dual* has an "api" attribute;
every entry in Workspace* / Account* does not) and a no-overlap test
that catches accidental double-registration across the resource maps
and across the data source maps.

The workspace-vs-account split is an organizational distinction with
no runtime effect today; Resources() and DataSources() flatten all
three maps. The split makes intent visible at the registration site
and gives a clear home for future account-level additions. The TODO
in common/resource.go calls out the proper next step: a resource-level
Level annotation; that is out of scope here.
@github-actions

Copy link
Copy Markdown
Contributor

Please ensure that the NEXT_CHANGELOG.md file is updated with any relevant changes.
If this is not necessary for your PR, please include the following in your PR description:
NO_CHANGELOG=true
and rerun the job.

Extract the duplicate-key check into a testNoDuplicateKeys helper and a
count helper. TestNoDuplicateKeys now invokes the helper twice, once
for the data source maps and once for the resource maps, keeping the
two namespaces separate.
@github-actions

Copy link
Copy Markdown
Contributor

If integration tests don't run automatically, an authorized user can run them manually by following the instructions below:

Trigger:
go/deco-tests-run/terraform

Inputs:

  • PR number: 5752
  • Commit SHA: bac71e1fcc0757fc823295258b541780c694b5cd

Checks will be approved automatically on success.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant