mirror of
https://github.com/hashicorp/terraform.git
synced 2026-03-27 12:54:12 -04:00
Previously we had the progress messages directly inlined as events of the PlanStackChanges operation, but that means that there's no common interface type for progress events across both the plan and apply phases, making it hard for Go implementations to share marshaling code between the two phases. Now we'll use a new StackChangeProgress message type to contain all of the progress message situations. This makes constructing and using the progress messages a little more verbose -- an extra layer of message -- but means that we can write code that works generically with the StackChangeProgress generated struct and thus share it between the two phases, leading to less code overall. As of this commit we don't yet have the apply phase generating any progress messages, but we'll extend it in a subsequent commit now that it's possible to share more of that event-generating code between the two phases.
65 lines
2.6 KiB
Go
65 lines
2.6 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package hooks
|
|
|
|
import (
|
|
"github.com/hashicorp/terraform/internal/rpcapi/terraform1"
|
|
"github.com/hashicorp/terraform/internal/stacks/stackaddrs"
|
|
)
|
|
|
|
// ComponentInstanceStatus is a UI-focused description of the overall status
|
|
// for a given component instance undergoing a Terraform plan or apply
|
|
// operation. The "pending" and "errored" status are used for both operation
|
|
// types, and the others will be used only for one of plan or apply.
|
|
type ComponentInstanceStatus rune
|
|
|
|
//go:generate go run golang.org/x/tools/cmd/stringer -type=ComponentInstanceStatus component_instance.go
|
|
|
|
const (
|
|
ComponentInstanceStatusInvalid ComponentInstanceStatus = 0
|
|
ComponentInstancePending ComponentInstanceStatus = '.'
|
|
ComponentInstancePlanning ComponentInstanceStatus = 'p'
|
|
ComponentInstancePlanned ComponentInstanceStatus = 'P'
|
|
ComponentInstanceApplying ComponentInstanceStatus = 'a'
|
|
ComponentInstanceApplied ComponentInstanceStatus = 'A'
|
|
ComponentInstanceErrored ComponentInstanceStatus = 'E'
|
|
)
|
|
|
|
// TODO: move this into the rpcapi package somewhere
|
|
func (s ComponentInstanceStatus) ForProtobuf() terraform1.StackChangeProgress_ComponentInstanceStatus_Status {
|
|
switch s {
|
|
case ComponentInstancePending:
|
|
return terraform1.StackChangeProgress_ComponentInstanceStatus_PENDING
|
|
case ComponentInstancePlanning:
|
|
return terraform1.StackChangeProgress_ComponentInstanceStatus_PLANNING
|
|
case ComponentInstancePlanned:
|
|
return terraform1.StackChangeProgress_ComponentInstanceStatus_PLANNED
|
|
case ComponentInstanceApplying:
|
|
return terraform1.StackChangeProgress_ComponentInstanceStatus_APPLYING
|
|
case ComponentInstanceApplied:
|
|
return terraform1.StackChangeProgress_ComponentInstanceStatus_APPLIED
|
|
case ComponentInstanceErrored:
|
|
return terraform1.StackChangeProgress_ComponentInstanceStatus_ERRORED
|
|
default:
|
|
return terraform1.StackChangeProgress_ComponentInstanceStatus_INVALID
|
|
}
|
|
}
|
|
|
|
// ComponentInstanceChange is the argument type for hook callbacks which
|
|
// signal a set of planned or applied changes for a component instance.
|
|
type ComponentInstanceChange struct {
|
|
Addr stackaddrs.AbsComponentInstance
|
|
Add int
|
|
Change int
|
|
Import int
|
|
Remove int
|
|
}
|
|
|
|
// Total sums all of the change counts as a forwards-compatibility measure. If
|
|
// we later add a new change type, older clients will still be able to detect
|
|
// that the component instance has some unknown changes, rather than falsely
|
|
// stating that there are no changes at all.
|
|
func (cic ComponentInstanceChange) Total() int {
|
|
return cic.Add + cic.Change + cic.Import + cic.Remove
|
|
}
|