You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
direct: new type-safe way of defining resources (#3532)
## Changes
- All resource methods now use concrete types related to this resource,
e.g. for job we define DoCreate(ctx, config *jobs.JobSettings).
- Resources no longer store config on the instance, it will be passed to
methods that need it.
- All resource-related code is now configured via resource methods in
one file (no longer have separate Settings struct). Each
tnresources/_resourcename_.go is self contained with exception of entry
point registration in all.go.
- The resource implementation is now a singleton, it does not have state
related to a particular resource but instead it's a stateless component
used for all resources. One consequence is that we cannot store waiters
there but need to reconstruct it ourselves. That is okay, because we
need to make "ready" part of the persisted state anyway and be able to
wait on the resource that was created by previous process.
- Internal renames: BundleDeployer -> DeploymentBundle, Deployer ->
DeploymentUnit.
- DeploymentUnits are now cached between plan and apply, allowing for
remote state cache to be propagated between these phases (needed in
#3531).
- New package libs/calladapt to facilitate validating and calling such
methods against interface.
## Why
This makes resource implementation type-safe, making it easier to
implement manually today or via LLM or generator in the future.
Especially useful when there are more types / structs involved, as in
remote state support #3531
Also, you get initial feedback quickly, by doing "go test
./bundle/terranova/tnresources'. That type checks all the interfaces and
runs your resource against testserver.
## Tests
There are a new set of unit tests that do a bunch of type checks across
methods, e.g. DoCreate and DoUpdate must accept the same config type.
There are also unit tests that run a few of resource methods against
testserver.
---------
Co-authored-by: Pieter Noordhuis <[email protected]>
0 commit comments