Skip to content

Commit f5e45bc

Browse files
committed
Allow requesting action schema from plan producer
1 parent dc169b8 commit f5e45bc

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

internal/stacks/stackplan/from_plan.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ type PlanProducer interface {
3737

3838
// ResourceSchema returns the schema for a resource type from a provider.
3939
ResourceSchema(ctx context.Context, providerTypeAddr addrs.Provider, mode addrs.ResourceMode, resourceType string) (providers.Schema, error)
40+
41+
// ActionSchema returns the schema for an action type from a provider.
42+
ActionSchema(ctx context.Context, providerTypeAddr addrs.Provider, actionType string) (providers.ActionSchema, error)
4043
}
4144

4245
func FromPlan(ctx context.Context, config *configs.Config, plan *plans.Plan, refreshPlan *plans.Plan, action plans.Action, producer PlanProducer) ([]PlannedChange, tfdiags.Diagnostics) {

internal/stacks/stackruntime/internal/stackeval/component_instance.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ type ComponentInstance struct {
4343
inputVariableValues perEvalPhase[promising.Once[withDiagnostics[cty.Value]]]
4444
}
4545

46-
var _ Applyable = (*ComponentInstance)(nil)
47-
var _ Plannable = (*ComponentInstance)(nil)
48-
var _ ExpressionScope = (*ComponentInstance)(nil)
49-
var _ ConfigComponentExpressionScope[stackaddrs.AbsComponentInstance] = (*ComponentInstance)(nil)
46+
var (
47+
_ Applyable = (*ComponentInstance)(nil)
48+
_ Plannable = (*ComponentInstance)(nil)
49+
_ ExpressionScope = (*ComponentInstance)(nil)
50+
_ ConfigComponentExpressionScope[stackaddrs.AbsComponentInstance] = (*ComponentInstance)(nil)
51+
)
5052

5153
func newComponentInstance(call *Component, addr stackaddrs.AbsComponentInstance, repetition instances.RepetitionData, mode plans.Mode, deferred bool) *ComponentInstance {
5254
component := &ComponentInstance{
@@ -137,7 +139,6 @@ func (c *ComponentInstance) inputValuesForModulesRuntime(ctx context.Context, ph
137139
}
138140
}
139141
return ret
140-
141142
}
142143

143144
func (c *ComponentInstance) PlanOpts(ctx context.Context, mode plans.Mode, skipRefresh bool) (*terraform.PlanOpts, tfdiags.Diagnostics) {
@@ -795,6 +796,25 @@ func (c *ComponentInstance) ResourceSchema(ctx context.Context, providerTypeAddr
795796
return ret, nil
796797
}
797798

799+
// ActionSchema implements stackplan.PlanProducer.
800+
func (c *ComponentInstance) ActionSchema(ctx context.Context, providerTypeAddr addrs.Provider, typ string) (providers.ActionSchema, error) {
801+
// This should not be able to fail with an error because we should
802+
// be retrieving the same schema that was already used to encode
803+
// the object we're working with. The error handling here is for
804+
// robustness but any error here suggests a bug in Terraform.
805+
806+
providerType := c.main.ProviderType(providerTypeAddr)
807+
providerSchema, err := providerType.Schema(ctx)
808+
if err != nil {
809+
return providers.ActionSchema{}, err
810+
}
811+
ret := providerSchema.SchemaForActionType(typ)
812+
if ret.ConfigSchema == nil {
813+
return providers.ActionSchema{}, fmt.Errorf("schema does not include %q", typ)
814+
}
815+
return ret, nil
816+
}
817+
798818
// RequiredComponents implements stackplan.PlanProducer.
799819
func (c *ComponentInstance) RequiredComponents(ctx context.Context) collections.Set[stackaddrs.AbsComponent] {
800820
return c.call.RequiredComponents(ctx)

internal/stacks/stackruntime/internal/stackeval/removed_component_instance.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,3 +366,16 @@ func (r *RemovedComponentInstance) ResourceSchema(ctx context.Context, providerT
366366
func (r *RemovedComponentInstance) tracingName() string {
367367
return r.Addr().String() + " (removed)"
368368
}
369+
370+
func (r *RemovedComponentInstance) ActionSchema(ctx context.Context, providerTypeAddr addrs.Provider, typ string) (providers.ActionSchema, error) {
371+
providerType := r.main.ProviderType(providerTypeAddr)
372+
providerSchema, err := providerType.Schema(ctx)
373+
if err != nil {
374+
return providers.ActionSchema{}, err
375+
}
376+
ret := providerSchema.SchemaForActionType(typ)
377+
if ret.ConfigSchema == nil {
378+
return providers.ActionSchema{}, fmt.Errorf("schema does not include %q", typ)
379+
}
380+
return ret, nil
381+
}

0 commit comments

Comments
 (0)