Skip to content

Commit c049964

Browse files
author
Liam Cervante
authored
stacks: include moved and removed in API (#35360)
* stacks: include moved and removed in API * fix race test
1 parent 0f0414d commit c049964

23 files changed

Lines changed: 1272 additions & 653 deletions

File tree

internal/plans/deferring/deferred.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ func (d *Deferred) GetDeferredResourceInstanceValue(addr addrs.AbsResourceInstan
197197
return cty.NilVal, false
198198
}
199199

200+
d.mu.Lock()
201+
defer d.mu.Unlock()
202+
200203
configAddr := addr.ConfigResource()
201204
var instancesMap addrs.Map[addrs.ConfigResource, addrs.Map[addrs.AbsResourceInstance, *plans.DeferredResourceInstanceChange]]
202205

internal/rpcapi/grpc_testing.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package rpcapi
55

66
import (
77
"context"
8+
"encoding/json"
89
"net"
910
"testing"
1011

@@ -13,6 +14,10 @@ import (
1314
"google.golang.org/grpc/test/bufconn"
1415
"google.golang.org/protobuf/proto"
1516
"google.golang.org/protobuf/types/known/anypb"
17+
18+
"github.com/hashicorp/terraform/internal/addrs"
19+
"github.com/hashicorp/terraform/internal/stacks/stackaddrs"
20+
"github.com/hashicorp/terraform/internal/stacks/stackstate"
1621
)
1722

1823
// grpcClientForTesting creates an in-memory-only gRPC server, offers the
@@ -63,6 +68,57 @@ func grpcClientForTesting(ctx context.Context, t *testing.T, registerServices fu
6368
}
6469
}
6570

71+
func appliedChangeToRawState(t *testing.T, changes []stackstate.AppliedChange) map[string]*anypb.Any {
72+
ret := make(map[string]*anypb.Any)
73+
for _, change := range changes {
74+
raw, err := change.AppliedChangeProto()
75+
if err != nil {
76+
t.Fatalf("failed to marshal change to proto: %s", err)
77+
}
78+
for _, raw := range raw.Raw {
79+
ret[raw.Key] = raw.Value
80+
}
81+
}
82+
return ret
83+
}
84+
85+
func mustDefaultRootProvider(provider string) addrs.AbsProviderConfig {
86+
return addrs.AbsProviderConfig{
87+
Module: addrs.RootModule,
88+
Provider: addrs.NewDefaultProvider(provider),
89+
}
90+
}
91+
92+
func mustAbsComponentInstance(t *testing.T, addr string) stackaddrs.AbsComponentInstance {
93+
ret, diags := stackaddrs.ParseAbsComponentInstanceStr(addr)
94+
if len(diags) > 0 {
95+
t.Fatalf("failed to parse component instance address %q: %s", addr, diags)
96+
}
97+
return ret
98+
}
99+
100+
func mustAbsComponent(t *testing.T, addr string) stackaddrs.AbsComponent {
101+
ret, diags := stackaddrs.ParseAbsComponentInstanceStr(addr)
102+
if len(diags) > 0 {
103+
t.Fatalf("failed to parse component instance address %q: %s", addr, diags)
104+
}
105+
if ret.Item.Key != addrs.NoKey {
106+
t.Fatalf("expected component address %q to have no key, but got %q", addr, ret.Item.Key)
107+
}
108+
return stackaddrs.AbsComponent{
109+
Stack: ret.Stack,
110+
Item: ret.Item.Component,
111+
}
112+
}
113+
114+
func mustAbsResourceInstanceObject(t *testing.T, addr string) stackaddrs.AbsResourceInstanceObject {
115+
ret, diags := stackaddrs.ParseAbsResourceInstanceObjectStr(addr)
116+
if len(diags) > 0 {
117+
t.Fatalf("failed to parse resource instance object address %q: %s", addr, diags)
118+
}
119+
return ret
120+
}
121+
66122
func mustMarshalAnyPb(msg proto.Message) *anypb.Any {
67123
var ret anypb.Any
68124
err := anypb.MarshalFrom(&ret, msg, proto.MarshalOptions{})
@@ -71,3 +127,11 @@ func mustMarshalAnyPb(msg proto.Message) *anypb.Any {
71127
}
72128
return &ret
73129
}
130+
131+
func mustMarshalJSONAttrs(attrs map[string]interface{}) []byte {
132+
jsonAttrs, err := json.Marshal(attrs)
133+
if err != nil {
134+
panic(err)
135+
}
136+
return jsonAttrs
137+
}

internal/rpcapi/stacks.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,8 @@ func stackChangeHooks(send func(*terraform1.StackChangeProgress) error, mainStac
856856
Import: int32(cic.Import),
857857
Remove: int32(cic.Remove),
858858
Defer: int32(cic.Defer),
859+
Move: int32(cic.Move),
860+
Forget: int32(cic.Forget),
859861
},
860862
},
861863
})
@@ -881,6 +883,8 @@ func stackChangeHooks(send func(*terraform1.StackChangeProgress) error, mainStac
881883
Import: int32(cic.Import),
882884
Remove: int32(cic.Remove),
883885
Defer: int32(cic.Defer),
886+
Move: int32(cic.Move),
887+
Forget: int32(cic.Forget),
884888
},
885889
},
886890
})

0 commit comments

Comments
 (0)