Repository navigation
feat(fwprovider): export the provider implementation for embedding - #434
Conversation
The provider lives in internal/provider, so consumers outside this module cannot obtain a provider.Provider value. That blocks embedding it in-process and forces downstreams to fork this repo just to add the export. Add a public fwprovider package that delegates to the existing constructor, following the terraform-provider-google precedent. No new dependencies, no behaviour change, and the rest of internal/ stays internal. Refs #354
ethanndickson
left a comment
There was a problem hiding this comment.
fwprovider as a name is fine with me, and I don't have any objections with the export.
I'm not able to say if we'll have resources for any maintenance work this introduces, i.e. reviewing fixes for bugs only present downstream, but if this alone is useful I suppose it's fine?
I think that's fair. In the end this is an extension that allows extended usage. If there is something missing or issues, it would be the job of said extensions to handle it or open PRs to mitigate |
|
@ethanndickson could you merge the PR? I don't seem to have permission to do so. Thanks :) |
|
Will make a new release with this |
…anization test (#435) `main` has failed lint since #355 merged (`87f6ed8`): ``` internal/provider/organization_resource_test.go:169:35: undefined: ptr (typecheck) ``` #355 was last tested in July against a base where `organization_resource_test.go` still imported `coderd/util/ptr` and used `ptr.Ref(...)` throughout. In the meantime #422 replaced every `ptr.Ref(...)` in that file with `new(...)` and dropped the import. The squash-merge had no textual conflict, so it landed with one new `ptr.Ref(...)` line and no `ptr` import. #434 then inherited the red `main`. This switches the one remaining `ptr.Ref([]string{...})` to `new([]string{...})`, matching the rest of the file. Also adds a `.github/CODEOWNERS` with `* @ethanndickson`.
* Embed the coderd Terraform provider and run it in-process The coderd Terraform provider now exports its implementation through the fwprovider package (coder/terraform-provider-coderd#434). Link it into the controller and reconcile every resource through upjet's Terraform plugin framework client instead of running terraform and the provider plugin as subprocesses under a workspace per managed resource. Runtime: - config.NewFrameworkProvider hands out provider instances; the version they report is the module version recorded in the build info. - The upjet provider config registers the framework provider and moves all 15 resources to the framework include list, clearing the CLI list. - terraform.Setup carries the provider to configure instead of a Terraform CLI requirement; the --terraform-* flags are gone. - Controllers are regenerated onto the framework async connector and the operation tracker store. CRDs, API types and examples are unchanged. Image: - No terraform binary, no provider plugin, no terraformrc, no build args. - The base moves from alpine to distroless static, pinned by digest. It ships CA certificates and the same UID 65532 the image already ran as. Generation: - Terraform is still used to dump the provider schema the CRDs are generated from, so TERRAFORM_VERSION stays as a generate-time tool. - hack/update-terraform-provider.sh also moves the Go module to the target release so the embedded implementation and the schema cannot drift apart. The module is pinned to a pseudo-version of main until the export ships in a tagged release. Co-Authored-By: Claude Fable 5.1 <[email protected]> * Publish provider packages from CI and repair the breaking-change reports publish-artifacts built the image and the xpkg, uploaded them to the workflow run and stopped there. Nothing this repository built ever reached a registry unless someone dispatched publish-provider-package.yml by hand. Log in to GHCR and run `make publish` on pushes to main and release-*, so merged work lands at ghcr.io/<owner>/provider-coderd. Pull requests keep building and uploading exactly as before, and need no credentials. Neither breaking-change report has ever run: - `make schema-version-diff` was gated on inputs.upjet-based-provider, a leftover from the reusable workflow this job was copied out of. The inputs context is empty for push and pull_request, so the step was always skipped. - `make crddiff` checked out at depth 1, so `git cat-file -e "$GITHUB_BASE_REF:$crd"` could not resolve the base branch and every CRD was skipped with "does not exist in the <branch> branch", and the job had no Go toolchain to run the tool with. Both diff a pull request against its base, so gate the steps -- not the job -- on pull_request: skipping the job would cascade and skip publish-artifacts along with it. Three bugs in the targets themselves kept them from working once reached: - crddiff ran `go run github.com/crossplane/uptest/cmd/crddiff`, but crddiff stayed behind at upbound/uptest when uptest moved to the crossplane org. The module never resolved, and because the target reports a non-zero exit as a breaking change, every CRD came back as "Breaking change detected!" with the resolution error as the body. - schema-version-diff read the previous version out of the base Makefile with a regex matching `TERRAFORM_PROVIDER_VERSION :=`, but the Makefile assigns it with `?=`, so the version was always empty. - scripts/version_diff.py was not executable, so the target died with "Permission denied" the moment it got that far. Also drop the unused $(UPTEST) prerequisite from crddiff, which downloaded a binary the target never invokes. Verified by making an optional CRD field required and confirming crddiff reports it as a new required property. Co-Authored-By: Claude Opus 5 <[email protected]> * Report breaking changes and track the work when bumping the provider The weekly provider bump opened a pull request and left it at that. Whether the new upstream release changed a CRD in an incompatible way, or added a resource that needs wiring up before it is generated at all, was left for whoever happened to read the diff. Run `make crddiff` and `make schema-version-diff` over the regenerated tree and carry their output in the pull request body. The regeneration is still uncommitted at that point, so HEAD is the pre-bump tree and both targets work against it with GITHUB_BASE_REF=HEAD exactly as they do against a pull request's base branch in CI -- no new code, just wiring. The report is a prompt to look rather than a verdict, since crddiff also reports its own failures as breaking changes. File a tracking issue alongside the pull request, carrying the checklist the mechanical bump cannot do: new upstream resources need an entry in config/external_name.go and config/resources/resources.go before `make generate` emits anything for them. The issue is looked up by title first, so a re-run does not file a second one. Add a dry-run mode, and run it on pull requests that touch the automation itself, so a change to the script or the workflow is exercised before it runs for real on a schedule. hack/update-terraform-provider.sh grows a --dry-run flag and an "available" output, letting it report an upstream release without touching the tree. Co-Authored-By: Claude Opus 5 <[email protected]> * File issues for upstream resources that are not generated yet A resource in config/schema.json only becomes a managed resource once it has an entry in config/external_name.go. Nothing noticed the gap: an upstream release could add a resource and it would sit unexposed until somebody happened to compare the schema against config/generated.lst by hand. Subtract the generated list from the schema on a weekly schedule and file one issue per resource left over, each carrying the steps to add it. An issue already mentioning the resource suppresses a duplicate, matching on whole tokens so coderd_agents_model does not match against an issue about coderd_agents_default_model. Pull requests touching the automation run it in dry-run mode. config/generated.lst is regenerated before the comparison, so a stale committed file can never make an implemented resource look missing. That needs a way to write the list without the full generation pipeline: config.GetProvider() is built from the schema and metadata embedded in the config package, so cmd/generatedlist can produce it from a bare checkout, with neither the Terraform CLI nor a docs checkout. Its --check mode gives `make generated-lst-check` for catching a stale file. writeGeneratedList moves out of cmd/generator into internal/generated so both commands share one on-disk representation and the file round-trips byte for byte whichever one writes it. All 15 upstream resources are exposed today, so this starts green and is purely a tripwire for the next release. Co-Authored-By: Claude Opus 5 <[email protected]> * Add a documentation site Everything a user needed to know lived in the README, which is where it stops scaling: the ProviderConfig has two flavours, the provider serves every kind twice, and neither fits in a section of a readme. Build a Hugo site with the Hextra theme, deployed to GitHub Pages on pushes to main that touch docs/, with a preview per pull request under pr-preview/pr-<number>/. Five pages: getting started, ProviderConfig and credentials, the managed resources this provider serves, and how the provider is generated and extended. The resource page is deliberately a map rather than a reference -- package/crds/ is the generated source of truth for field schemas, and duplicating them here would go stale on the next provider bump. The theme is pulled in as a Hugo module, so docs/go.mod and docs/go.sum pin it and the workflows install Go alongside Hugo. Pages is not enabled for this repository yet; the first deploy creates the gh-pages branch it needs to serve from. Co-Authored-By: Claude Opus 5 <[email protected]> * feat: generate from terraform-provider-coderd v0.0.26 The fwprovider export shipped in a tagged release, so the module no longer has to track a pseudo-version of main. Move both pins to v0.0.26: the Makefile, which the schema and the scraped docs are taken from, and go.mod, which the embedded implementation is linked from. The update script moves them together so the two cannot drift apart. v0.0.26 adds default_org_member_roles to coderd_organization, a set of built-in organization role names unioned into every member's effective roles. It needs a Coder deployment running v2.37.0 or later, which is why go mod tidy also moves coder/coder to v2.37.1. No new upstream resources, so config/external_name.go and config/resources/resources.go are unchanged and all 15 resources are still generated. The schema diff is additive and no resource's state schema version changed, so there is nothing to migrate. config/fwprovider.go needs no change: it reads the version out of the build info, and the binary now records v0.0.26 instead of the pseudo-version. Co-Authored-By: Claude Opus 5 <[email protected]> --------- Co-authored-by: Claude Fable 5.1 <[email protected]>
Adds a public
fwproviderpackage that hands out the provider implementation, so Go programs can embed the provider in-process instead of running it as a plugin binary.Motivation
In #354 I asked for a Crossplane provider for Coder. Crossplane's Upjet generates one directly from a Terraform provider's schema, and it can drive that provider two ways:
terraformbinary and the provider binary into its controller image, then runsterraformagainst a workspace per managed resource, which in turn launches the provider plugin. It works against any provider and needs no cooperation from upstream.provider.Providerimplementation directly through its plugin-framework client. Noterraformbinary, no provider binary, no subprocess per reconcile.In-process mode needs an importable
provider.Provider.internal/provideris unimportable outside this module, so today the only route is to fork this repo and add the export in the fork. That is exactly what Upbound does for the providers that keep theirs internal —terraform-provider-aws/xpproviderandterraform-provider-azurerm/xpprovider, both wired in through areplacedirective. Providers that expose theirs upstream need no fork at all:terraform-provider-googlehasgoogle/fwprovider,terraform-provider-keycloakhasprovider.I would rather not maintain a fork of this repo that has to be re-synced on every release, and I doubt you want one circulating either.
What changed
A single public package delegating to the existing constructor:
Returning the factory rather than an instance keeps the signature identical to
provider.New, so it still drops straight intoproviderserver.Serve; embedders call it to get an instance.Kept deliberately small:
terraform-plugin-frameworkis already required.provider.Newbreaks the build here too.internal/stays internal. This exports the provider surface only, not resource implementations,codersdkplumbing, or helpers.main.gois untouched.main.goserves, withTypeName, version, resources and data sources all wired.I named it
fwproviderafter theterraform-provider-googleprecedent rather than Upbound's Crossplane-specificxpprovider, on the grounds that this is an export you own rather than one living in a downstream fork. Happy to rename it, relocate it, or narrow the signature.Context
I have built an Upjet-based Crossplane provider covering all 15 resources, exposing both cluster-scoped and namespaced Crossplane v2 APIs, with a scheduled job that regenerates and opens a PR when a release lands here. It runs in Terraform CLI mode today, because that is the only mode available without forking this repo.
I took the liberty of starting the implementation rather than just filing the request, so there is something concrete to react to. If you would like the Crossplane provider itself to live under the Coder org, I am happy to donate it; equally happy to keep maintaining it out-of-tree if you would rather not adopt another repo. Either way this export stands on its own for anyone embedding the provider.
Refs #354