@@ -245,6 +245,9 @@ func createNetworkACLRules(d *schema.ResourceData, meta interface{}, rules *[]in
245245 log .Printf ("[DEBUG] Creating %d network ACL rules" , len (nrs ))
246246 var errs * multierror.Error
247247
248+ results := make ([]map [string ]interface {}, len (nrs ))
249+ var mu sync.Mutex
250+
248251 var wg sync.WaitGroup
249252 wg .Add (len (nrs ))
250253
@@ -263,10 +266,12 @@ func createNetworkACLRules(d *schema.ResourceData, meta interface{}, rules *[]in
263266 err := createNetworkACLRule (d , meta , rule )
264267 if err != nil {
265268 log .Printf ("[ERROR] Failed to create rule #%d: %v" , index + 1 , err )
269+ mu .Lock ()
266270 errs = multierror .Append (errs , fmt .Errorf ("rule #%d: %v" , index + 1 , err ))
271+ mu .Unlock ()
267272 } else if len (rule ["uuids" ].(map [string ]interface {})) > 0 {
268- log .Printf ("[DEBUG] Successfully created rule #%d, adding to rules list " , index + 1 )
269- * rules = append ( * rules , rule )
273+ log .Printf ("[DEBUG] Successfully created rule #%d, storing at index %d " , index + 1 , index )
274+ results [ index ] = rule
270275 } else {
271276 log .Printf ("[WARN] Rule #%d created but has no UUIDs" , index + 1 )
272277 }
@@ -282,6 +287,13 @@ func createNetworkACLRules(d *schema.ResourceData, meta interface{}, rules *[]in
282287 return err
283288 }
284289
290+ for i , result := range results {
291+ if result != nil {
292+ * rules = append (* rules , result )
293+ log .Printf ("[DEBUG] Added rule #%d to final rules list" , i + 1 )
294+ }
295+ }
296+
285297 log .Printf ("[DEBUG] Successfully created all rules" )
286298 return nil
287299}
@@ -1411,6 +1423,11 @@ func performPortsMigration(d *schema.ResourceData, meta interface{}, oldRules, n
14111423 }
14121424
14131425 log .Printf ("[DEBUG] Successfully created %d new rules during migration" , len (createdRules ))
1426+
1427+ if err := d .Set ("rule" , createdRules ); err != nil {
1428+ return fmt .Errorf ("failed to update state with migrated rules: %v" , err )
1429+ }
1430+ log .Printf ("[DEBUG] Updated Terraform state with %d migrated rules" , len (createdRules ))
14141431 }
14151432
14161433 log .Printf ("[DEBUG] Ports->port migration completed successfully" )
0 commit comments