rpcapi(Stacks): don't send empty moved/import messages

The "progress hooks" mechanism was unconditionally allocating messages
to represent the moved and imported cases and then conditionally populating
the fields inside.

That causes an admittedly-small friction on the client side because they
need to test whether the string fields inside are non-empty instead of
just checking whether the overall message field was populated at all.

To smooth that for clients, we'll instead leave these unset unless there's
actually something to report. For clients written in Go, that means that
the top-level fields will be nil when not relevant, which is easy to
test for and relatively idiomatic.
pull/34738/head
Martin Atkins 3 years ago
parent af0c4764ef
commit dd9c0ab98e

@ -614,17 +614,21 @@ func stackChangeHooks(send func(*terraform1.StackChangeProgress) error, mainStac
attribute.String("resource_instance", ric.Addr.Item.String()),
))
moved := &terraform1.StackChangeProgress_ResourceInstancePlannedChange_Moved{}
var moved *terraform1.StackChangeProgress_ResourceInstancePlannedChange_Moved
if !ric.Change.PrevRunAddr.Equal(ric.Change.Addr) {
moved.PrevAddr = &terraform1.ResourceInstanceInStackAddr{
ComponentInstanceAddr: ric.Addr.Component.String(),
ResourceInstanceAddr: ric.Change.PrevRunAddr.String(),
moved = &terraform1.StackChangeProgress_ResourceInstancePlannedChange_Moved{
PrevAddr: &terraform1.ResourceInstanceInStackAddr{
ComponentInstanceAddr: ric.Addr.Component.String(),
ResourceInstanceAddr: ric.Change.PrevRunAddr.String(),
},
}
}
imported := &terraform1.StackChangeProgress_ResourceInstancePlannedChange_Imported{}
var imported *terraform1.StackChangeProgress_ResourceInstancePlannedChange_Imported
if ric.Change.Importing != nil {
imported.ImportId = ric.Change.Importing.ID
imported = &terraform1.StackChangeProgress_ResourceInstancePlannedChange_Imported{
ImportId: ric.Change.Importing.ID,
}
}
send(&terraform1.StackChangeProgress{

Loading…
Cancel
Save