@@ -121,10 +121,8 @@ func DeployBackends(cfg *Config) error {
121121
122122 deploymentDeployer := deployer .NewDeploymentDeployer (& gridClient )
123123
124- twinID := uint64 (gridClient .TwinID )
125-
126124 // Load existing deployments
127- existingDeployments , err := loadExistingDeployments (& gridClient , twinID , cfg . DeploymentName )
125+ existingDeployments , err := loadExistingDeployments (& gridClient , cfg )
128126 if err != nil {
129127 return errors .Wrap (err , "failed to load existing deployments" )
130128 }
@@ -168,16 +166,16 @@ func DeployBackends(cfg *Config) error {
168166}
169167
170168// Helper to load existing deployments from the grid
171- func loadExistingDeployments (gridClient * deployer.TFPluginClient , twinID uint64 , deploymentName string ) (map [uint32 ]string , error ) {
169+ func loadExistingDeployments (gridClient * deployer.TFPluginClient , cfg * Config ) (map [uint32 ]string , error ) {
172170 existing := make (map [uint32 ]string )
173- contracts , err := grid .GetContracts (gridClient , twinID )
171+ contracts , err := grid .GetContracts (gridClient , uint64 ( gridClient . TwinID ) )
174172 if err != nil {
175173 return nil , err
176174 }
177175
178176 for _ , contractInfo := range contracts {
179177 name := contractInfo .DeploymentName
180- expectedPrefix := fmt .Sprintf ("%s_%d" , deploymentName , twinID )
178+ expectedPrefix := fmt .Sprintf ("%s_%d" , cfg . DeploymentName , gridClient . TwinID )
181179 if ! strings .HasPrefix (name , expectedPrefix ) {
182180 continue
183181 }
@@ -186,17 +184,19 @@ func loadExistingDeployments(gridClient *deployer.TFPluginClient, twinID uint64,
186184 if len (parts ) != 4 {
187185 continue
188186 }
187+ nodeType := parts [2 ]
189188 nodeID , err := strconv .ParseUint (parts [3 ], 10 , 32 )
190189 if err != nil {
191190 continue
192191 }
193192
193+ gridClient .State .StoreContractIDs (uint32 (nodeID ), uint64 (contractInfo .Contract .ContractID ))
194194 // This loads the deployment into grid.State, which is important for loading ZDB details later
195- if _ , err := gridClient . State . LoadDeploymentFromGrid ( context . Background (), uint32 (nodeID ), name ); err != nil {
195+ if _ , err := loadZDB ( gridClient , cfg , uint32 (nodeID ), nodeType ); err != nil {
196196 fmt .Printf ("warn: could not load deployment '%s' from grid: %v\n " , name , err )
197197 continue
198198 }
199- existing [uint32 (nodeID )] = parts [ 2 ] // Store nodeID -> type ("meta" or "data")
199+ existing [uint32 (nodeID )] = nodeType // Store nodeID -> type ("meta" or "data")
200200 }
201201 return existing , nil
202202}
0 commit comments