@@ -1261,6 +1261,8 @@ def __init__(
12611261        self ._official_ami  =  None 
12621262        self .imds  =  imds  or  TopLevelImds (implied = "v1.0" )
12631263        self .deployment_settings  =  deployment_settings 
1264+         self .managed_head_node_security_group  =  None 
1265+         self .managed_compute_security_group  =  None 
12641266
12651267    def  _register_validators (self , context : ValidatorContext  =  None ):  # noqa: D102 #pylint: disable=unused-argument 
12661268        self ._register_validator (RegionValidator , region = self .region )
@@ -1387,15 +1389,15 @@ def _register_storage_validators(self):
13871389                            EfsIdValidator ,
13881390                            efs_id = storage .file_system_id ,
13891391                            avail_zones_mapping = self .availability_zones_subnets_mapping ,
1390-                             are_all_security_groups_customized = self .are_all_security_groups_customized ,
1392+                             security_groups_by_nodes = self .security_groups_by_nodes ,
13911393                        )
13921394                    else :
13931395                        new_storage_count ["efs" ] +=  1 
13941396            self ._register_validator (
13951397                ExistingFsxNetworkingValidator ,
13961398                file_system_ids = list (existing_fsx ),
1397-                 head_node_subnet_id = self .head_node .networking .subnet_id ,
1398-                 are_all_security_groups_customized = self .are_all_security_groups_customized ,
1399+                 subnet_ids = [ self .head_node .networking .subnet_id ]  +   self . compute_subnet_ids ,
1400+                 security_groups_by_nodes = self .security_groups_by_nodes ,
13991401            )
14001402
14011403            self ._validate_max_storage_count (ebs_count , existing_storage_count , new_storage_count )
@@ -1624,17 +1626,29 @@ def is_dcv_enabled(self):
16241626        return  self .head_node .dcv  and  self .head_node .dcv .enabled 
16251627
16261628    @property  
1627-     def  are_all_security_groups_customized (self ):
1629+     def  security_groups_by_nodes (self ):
16281630        """Return True if all head node and queues have (additional) security groups specified.""" 
16291631        head_node_networking  =  self .head_node .networking 
1632+         security_groups_for_head_node  =  set ()
1633+         if  head_node_networking .security_groups :
1634+             security_groups_for_head_node .update (set (head_node_networking .security_groups ))
1635+         if  head_node_networking .additional_security_groups :
1636+             security_groups_for_head_node .update (set (head_node_networking .additional_security_groups ))
16301637        if  not  (head_node_networking .security_groups  or  head_node_networking .additional_security_groups ):
1631-             return  False 
1638+             security_groups_for_head_node .add (self .managed_head_node_security_group )
1639+         security_groups_for_all_nodes  =  {frozenset (security_groups_for_head_node )}
16321640        for  queue  in  self .scheduling .queues :
16331641            queue_networking  =  queue .networking 
16341642            if  isinstance (queue_networking , _QueueNetworking ):
1635-                 if  not  (queue_networking .security_groups  or  queue_networking .additional_security_groups ):
1636-                     return  False 
1637-         return  True 
1643+                 security_groups_for_compute_node  =  set ()
1644+                 if  queue_networking .security_groups :
1645+                     security_groups_for_compute_node .update (set (queue_networking .security_groups ))
1646+                 else :
1647+                     security_groups_for_compute_node .add (self .managed_compute_security_group )
1648+                 if  queue_networking .additional_security_groups :
1649+                     security_groups_for_compute_node .update (set (queue_networking .additional_security_groups ))
1650+                 security_groups_for_all_nodes .add (frozenset (security_groups_for_compute_node ))
1651+         return  security_groups_for_all_nodes 
16381652
16391653    @property  
16401654    def  extra_chef_attributes (self ):
0 commit comments