fix(wfctl): honor explicit resource adoption#626
Conversation
There was a problem hiding this comment.
Pull request overview
Updates wfctl infra apply adoption behavior so adopt_existing: true is treated as an explicit signal to adopt resources (including for typed IaC resource drivers), while preserving the special built-in adoption reference behavior for DNS resources.
Changes:
- Treat
adopt_existing: trueas an explicit adoption signal when resolving resource drivers and computing adoption refs. - Preserve built-in DNS adoption refs ahead of generic name-based adoption.
- Add regression tests covering config-based adoption, unsupported drivers, and DNS preservation; mark typed drivers as supporting config adoption.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| cmd/wfctl/infra_apply.go | Extends adoption resolution to honor adopt_existing and adds driver capability probing for config-based adoption. |
| cmd/wfctl/infra_apply_test.go | Adds coverage for explicit config adoption, unsupported driver rejection, and DNS built-in ref preservation. |
| cmd/wfctl/iac_typed_adapter.go | Declares typed resource drivers as supporting config-based adoption. |
Comments suppressed due to low confidence (1)
cmd/wfctl/infra_apply.go:652
- When
ResourceDriver()returns(nil, nil)(which is treated elsewhere as “no driver”), the current logic caches the nil driver indrivers[spec.Type]andadoptionRefForSpecwill silently skip adoption even ifadopt_existing: true(or a built-in adoptable type likeinfra.dns) was explicitly requested. This can result in the resource being created instead of adopted, and also prevents later specs of the same type from re-resolving a now-available driver because the nil is cached.
Suggested fix: treat driver == nil as a resolution failure when explicitAdoptable is true (return an error), and avoid caching nil drivers (only write to drivers when non-nil).
explicitAdoptable := hasBuiltInAdoptionRef(spec.Type) || boolFromAny(spec.Config["adopt_existing"])
driver, ok := drivers[spec.Type]
if !ok {
var err error
driver, err = provider.ResourceDriver(spec.Type)
if err != nil {
if !explicitAdoptable {
continue
}
return nil, fmt.Errorf("%s/%s: resolve resource driver: %w", spec.Type, spec.Name, err)
}
drivers[spec.Type] = driver
}
⏱ Benchmark Results✅ No significant performance regressions detected. benchstat comparison (baseline → PR)
|
1b2dbb6 to
b4f3714
Compare
Summary
adopt_existing: trueas an explicit adoption signal when resolving resource driversVerification
Review