Demonstrate migrating databricks_repo to the Go SDK (follow-up to #5877) - #5883
Draft
GrantIsEaton wants to merge 1 commit into
Draft
Demonstrate migrating databricks_repo to the Go SDK (follow-up to #5877)#5883GrantIsEaton wants to merge 1 commit into
GrantIsEaton wants to merge 1 commit into
Conversation
GrantIsEaton
temporarily deployed
to
test-trigger-is
July 14, 2026 18:42 — with
GitHub Actions
Inactive
Rewire databricks_repo off the hand-rolled ReposAPI/reposCreateRequest HTTP client onto the Go SDK workspace.Repos service and request/response structs. Following review feedback, the schema is generated directly from the Go SDK workspace.RepoInfo struct: the Terraform-specific attribute names (git_provider, commit_hash) are supplied through an Aliases() map on a thin wrapper type rather than a parallel hand-maintained ReposInformation struct. - Remove ReposAPI, NewReposAPI, reposCreateRequest, ReposListResponse and the raw-HTTP Create/Read/Update/Delete/List/ListAll methods. - Add repoInfo wrapper (embeds workspace.RepoInfo + common.Namespace) with Aliases()/CustomizeSchema() to reproduce the existing schema. - CRUD now calls w.Repos.* with the SDK request structs and w.Workspace.MkdirsByPath for parent-directory creation. - Update unit tests: SDK request/response fixtures, the trailing "?" the SDK appends to GET/DELETE URLs, and drop the List/ListAll tests (listing is the SDK's job and is covered by the exporter). - Update exporter tests to use workspace.RepoInfo/ListReposResponse fixtures. - Refresh the unified-host acceptance-test comment now that repo routes through the SDK routing-header path. Co-authored-by: Isaac
GrantIsEaton
force-pushed
the
feature/migrate-repo-to-go-sdk
branch
from
July 14, 2026 19:02
8a9cf47 to
6d3b03d
Compare
GrantIsEaton
temporarily deployed
to
test-trigger-is
July 14, 2026 19:02 — with
GitHub Actions
Inactive
Contributor
Unit testsIf this PR is from a fork, the If this PR changes Actions -> Warm Go Cache -> Run workflow -> pr_number = 5883 Re-run the failed check once the cache warming completes. Integration testsIntegration tests don't run automatically for external contributors; an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
6 tasks
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this is
A demonstration PR responding to review feedback on #5877, where @alexott suggested switching
databricks_repoto the Go SDK structs:This branch does exactly that, using the
Aliases()mechanism Alex pointed at. It's scoped purely to the migration — it does not include thegit_credential_idfield from #5877, so the diff is the migration and nothing else.Approach
Rather than keeping a parallel, hand-maintained schema struct, the schema is generated directly from the Go SDK
workspace.RepoInfovia a thin wrapper:CustomizeSchema()re-applies the force-new/computed/validation attributes that the oldtf:tags carried. CRUD then callsw.Repos.*with the SDK request structs (CreateRepoRequest,UpdateRepoRequest) andw.Workspace.MkdirsByPathfor parent-directory creation.Net: +178 / −301 across 5 files (removes the whole hand-rolled
ReposAPI).What changed
ReposAPI,NewReposAPI,reposCreateRequest,ReposListResponse, and the raw-HTTPCreate/Read/Update/Delete/List/ListAllmethods.repoInfowrapper +Aliases()/CustomizeSchema().Challenges / things to know
The alias mechanism resolves the main obstacle. Generating the schema from an SDK struct normally loses the TF attribute names (
git_provider,commit_hash), becauseworkspace.RepoInfohas notf:alias tags. TheResourceProviderWithAliasinterface (Aliases()) supplies those renames and — verified here — round-trips correctly through schema generation,StructToData, andDataToStruct. This is exactly what Alex referenced.It still requires a wrapper type + boilerplate. As Alex noted, you wrap the SDK struct in a TF-bound struct and re-declare per-field customizations (force_new/computed/validators) in
CustomizeSchema(), since those no longer come from struct tags. It's mechanical, but it's real code, and it has to stay in sync with the SDK struct.Read returns a different SDK type.
w.Repos.GetByRepoIdreturns*GetRepoResponse, not*RepoInfo(the schema struct). They're structurally identical, soReadcopies field-by-field intorepoInfo.SDK URL encoding differs, breaking every fixture. The SDK appends a
?query suffix toGET/DELETEURLs (e.g./api/2.0/repos/123?). The old client did not. Every unit-test and exporter HTTP fixture stubbing a GET/DELETE by id had to be updated, or tests fail with "missing stub". Invisible until you run the tests.Second-order test breakage in the exporter.
ReposInformation/ReposListResponsewere used as fixture bodies inexporter/exporter_test.go; those moved toworkspace.RepoInfo/workspace.ListReposResponseand the now-unusedreposimport was dropped. No production exporter code changed (it already lists repos via the SDK).Dropped provider-local list helpers.
ReposAPI.List/ListAll+ReposListResponsewere provider-only and used solely by unit tests; production listing already goes through the SDK iterator in the exporter. Those two unit tests were removed rather than rewritten.Acceptance-test intent drifted.
internal/acceptance/unified_host_acc_test.gocontrasted a raw-HTTP resource (repo) against a Go SDK resource (jobs) on a unified host. Post-migration that contrast no longer holds, so the comment was rewritten.Risks of rolling this out
databricks_repousers are affected. This rewrites the entire CRUD path, so the risk/reward differs sharply from a small additive field — it deserves its own review and real acceptance-test runs against a workspace.CustomizeSchema()must exactly reproduce the current schema. A missedSetComputed()/SetForceNew()would silently change plan behavior. Unit tests cover the happy paths but not every diff scenario.ForceSendFieldssemantics. The SDK structs useomitempty+ForceSendFieldsto distinguish unset from zero. Not needed here, but any future need to send an explicit zero would require handling it — something the map-based client sidestepped.Recommendation
With the
Aliases()approach this is cleaner than a parallel struct and is clearly the idiomatic direction — but it's still a wrapper + full CRUD rewrite touching all repo users, not a drop-in. Reasonable as a standalone follow-up; bundling it into #5877 would turn a small, low-risk feature into a full-path rewrite.Tests
go build ./...,go vet ./...clean.go test ./repos/... ./exporter/...pass.internal/acceptance) not run here — they require a live workspace / unified host.This pull request and its description were written by Isaac.