Merge pull request #35433 from hashicorp/TF-10919

stacks: add new deferred plan status
TF-13968
Daniel Schmidt 2 years ago committed by GitHub
commit 591c3dea36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -757,6 +757,12 @@ func stackChangeHooks(send func(*terraform1.StackChangeProgress) error, mainStac
span.(trace.Span).End()
return nil
},
DeferComponentInstancePlan: func(ctx context.Context, span any, ci stackaddrs.AbsComponentInstance) any {
send(evtComponentInstanceStatus(ci, hooks.ComponentInstanceDeferred))
span.(trace.Span).SetStatus(otelCodes.Error, "planning succeeded, but deferred")
span.(trace.Span).End()
return nil
},
PendingComponentInstanceApply: func(ctx context.Context, ci stackaddrs.AbsComponentInstance) {
send(evtComponentInstanceStatus(ci, hooks.ComponentInstancePending))
},

@ -406,6 +406,17 @@ func TestStackChangeProgress(t *testing.T) {
},
},
},
{
Event: &terraform1.StackChangeProgress_ComponentInstanceStatus_{
ComponentInstanceStatus: &terraform1.StackChangeProgress_ComponentInstanceStatus{
Addr: &terraform1.ComponentInstanceInStackAddr{
ComponentAddr: "component.deferred",
ComponentInstanceAddr: "component.deferred",
},
Status: terraform1.StackChangeProgress_ComponentInstanceStatus_DEFERRED,
},
},
},
},
},
"moved": {

File diff suppressed because it is too large Load Diff

@ -1041,6 +1041,7 @@ message StackChangeProgress {
APPLYING = 4;
APPLIED = 5;
ERRORED = 6;
DEFERRED = 7;
}
}

@ -25,6 +25,7 @@ const (
ComponentInstanceApplying ComponentInstanceStatus = 'a'
ComponentInstanceApplied ComponentInstanceStatus = 'A'
ComponentInstanceErrored ComponentInstanceStatus = 'E'
ComponentInstanceDeferred ComponentInstanceStatus = 'D'
)
// TODO: move this into the rpcapi package somewhere
@ -42,6 +43,8 @@ func (s ComponentInstanceStatus) ForProtobuf() terraform1.StackChangeProgress_Co
return terraform1.StackChangeProgress_ComponentInstanceStatus_APPLIED
case ComponentInstanceErrored:
return terraform1.StackChangeProgress_ComponentInstanceStatus_ERRORED
case ComponentInstanceDeferred:
return terraform1.StackChangeProgress_ComponentInstanceStatus_DEFERRED
default:
return terraform1.StackChangeProgress_ComponentInstanceStatus_INVALID
}

@ -15,18 +15,23 @@ func _() {
_ = x[ComponentInstanceApplying-97]
_ = x[ComponentInstanceApplied-65]
_ = x[ComponentInstanceErrored-69]
_ = x[ComponentInstanceDeferred-68]
}
const (
_ComponentInstanceStatus_name_0 = "ComponentInstanceStatusInvalid"
_ComponentInstanceStatus_name_1 = "ComponentInstancePending"
_ComponentInstanceStatus_name_2 = "ComponentInstanceApplied"
_ComponentInstanceStatus_name_3 = "ComponentInstanceErrored"
_ComponentInstanceStatus_name_3 = "ComponentInstanceDeferredComponentInstanceErrored"
_ComponentInstanceStatus_name_4 = "ComponentInstancePlanned"
_ComponentInstanceStatus_name_5 = "ComponentInstanceApplying"
_ComponentInstanceStatus_name_6 = "ComponentInstancePlanning"
)
var (
_ComponentInstanceStatus_index_3 = [...]uint8{0, 25, 49}
)
func (i ComponentInstanceStatus) String() string {
switch {
case i == 0:
@ -35,8 +40,9 @@ func (i ComponentInstanceStatus) String() string {
return _ComponentInstanceStatus_name_1
case i == 65:
return _ComponentInstanceStatus_name_2
case i == 69:
return _ComponentInstanceStatus_name_3
case 68 <= i && i <= 69:
i -= 68
return _ComponentInstanceStatus_name_3[_ComponentInstanceStatus_index_3[i]:_ComponentInstanceStatus_index_3[i+1]]
case i == 80:
return _ComponentInstanceStatus_name_4
case i == 97:

@ -677,7 +677,13 @@ func (c *ComponentInstance) CheckModuleTreePlan(ctx context.Context) (*plans.Pla
if diags.HasErrors() {
hookMore(ctx, seq, h.ErrorComponentInstancePlan, addr)
} else {
hookMore(ctx, seq, h.EndComponentInstancePlan, addr)
if plan.Complete {
hookMore(ctx, seq, h.EndComponentInstancePlan, addr)
} else {
hookMore(ctx, seq, h.DeferComponentInstancePlan, addr)
}
}
return plan, diags

@ -74,6 +74,10 @@ type Hooks struct {
// is called when the plan operation failed.
ErrorComponentInstancePlan hooks.MoreFunc[stackaddrs.AbsComponentInstance]
// DeferComponentInstancePlan is similar to [Hooks.EndComponentInstancePlan], but
// is called when the plan operation succeeded but signaled a deferral.
DeferComponentInstancePlan hooks.MoreFunc[stackaddrs.AbsComponentInstance]
// PendingComponentInstanceApply is called at the start of the apply
// operation.
PendingComponentInstanceApply hooks.SingleFunc[stackaddrs.AbsComponentInstance]

Loading…
Cancel
Save