Removes AI task support from the provisioner protocol: the task-related proto fields, terraform scanning for `coder_ai_task` resources, echo provisioner support, the regenerated `.pb.go` and `provisionerGenerated.ts`, and the terraform testdata that exercised them. The provisioner API version change lives in `provisionerd/proto/version.go`. **Stack context:** Coder Tasks removal stack (CODAGT-642): #28743 frontend → #28788 CLI → #28789 API → #28790 provisioner → #29084 notifications and usage → #29085 build reasons → #29086 tables → #28750 permissions. The last four PRs replace the single data-drop migration that used to live in #28750; each carries one concern and a focused migration test. **Why:** the proto fields lost their last consumer in #28789; this deletes the producer side and the wire format. **What to scrutinize:** the proto/version handling, and that `coder_ai_task` resources in existing templates are now ignored rather than errors (template imports simply no longer scan for them). **Validation:** `go build ./...`, `go test ./provisionersdk/... ./provisionerd/...`, `go test ./provisioner/terraform -run TestConvertResources`, provisioner list golden regenerated, site tsc, pre-commit hooks. **Size:** +580/-1,286 over 76 files; most files are mechanical testdata and generated-code updates. > Created by Xum (AI agent) on behalf of @ibetitsmike.
75 lines
2.0 KiB
Go
75 lines
2.0 KiB
Go
package terraform
|
|
|
|
import (
|
|
tfjson "github.com/hashicorp/terraform-json"
|
|
"github.com/mitchellh/mapstructure"
|
|
"golang.org/x/xerrors"
|
|
)
|
|
|
|
type PlanState struct {
|
|
DailyCost int32
|
|
}
|
|
|
|
func planModules(plan *tfjson.Plan) []*tfjson.StateModule {
|
|
modules := []*tfjson.StateModule{}
|
|
if plan.PriorState != nil {
|
|
// We need the data resources for rich parameters. For some reason, they
|
|
// only show up in the PriorState.
|
|
//
|
|
// We don't want all prior resources, because Quotas (and
|
|
// future features) would never know which resources are getting
|
|
// deleted by a stop.
|
|
|
|
filtered := onlyDataResources(*plan.PriorState.Values.RootModule)
|
|
modules = append(modules, &filtered)
|
|
}
|
|
modules = append(modules, plan.PlannedValues.RootModule)
|
|
return modules
|
|
}
|
|
|
|
// ConvertPlanState consumes a terraform plan json output and produces a thinner
|
|
// version of `State` to be used before `terraform apply`. `ConvertState`
|
|
// requires `terraform graph`, this does not.
|
|
func ConvertPlanState(plan *tfjson.Plan) (*PlanState, error) {
|
|
modules := planModules(plan)
|
|
|
|
var dailyCost int32
|
|
for _, mod := range modules {
|
|
err := forEachResource(mod, func(res *tfjson.StateResource) error {
|
|
if res.Type == "coder_metadata" {
|
|
var attrs resourceMetadataAttributes
|
|
err := mapstructure.Decode(res.AttributeValues, &attrs)
|
|
if err != nil {
|
|
return xerrors.Errorf("decode metadata attributes: %w", err)
|
|
}
|
|
dailyCost += attrs.DailyCost
|
|
}
|
|
return nil
|
|
})
|
|
if err != nil {
|
|
return nil, xerrors.Errorf("parse plan: %w", err)
|
|
}
|
|
}
|
|
|
|
return &PlanState{
|
|
DailyCost: dailyCost,
|
|
}, nil
|
|
}
|
|
|
|
func forEachResource(input *tfjson.StateModule, do func(res *tfjson.StateResource) error) error {
|
|
for _, res := range input.Resources {
|
|
err := do(res)
|
|
if err != nil {
|
|
return xerrors.Errorf("in module %s: %w", input.Address, err)
|
|
}
|
|
}
|
|
|
|
for _, mod := range input.ChildModules {
|
|
err := forEachResource(mod, do)
|
|
if err != nil {
|
|
return xerrors.Errorf("in module %s: %w", mod.Address, err)
|
|
}
|
|
}
|
|
return nil
|
|
}
|