@@ -70,7 +70,7 @@ def _list_workspace_groups(self) -> list[iam.Group]:
7070
7171 def _list_account_groups (self ) -> list [iam .Group ]:
7272 # TODO: we should avoid using this method, as it's not documented
73- # unfortunately, there's no other way to consistently get the list of account groups
73+ # get account-level groups even if they're not (yet) assigned to a workspace
7474 logger .debug ("Listing account groups..." )
7575 account_groups = [
7676 iam .Group .from_dict (r )
@@ -160,19 +160,25 @@ def prepare_groups_in_environment(self):
160160 "Preparing groups in the current environment. At this step we'll verify that all groups "
161161 "exist and are of the correct type. If some temporary groups are missing, they'll be created"
162162 )
163- if self .config .selected :
163+ group_names = self .config .selected
164+ if group_names :
164165 logger .info ("Using the provided group listing" )
165166
166- for g in self . config . selected :
167+ for g in group_names :
167168 assert g not in self .SYSTEM_GROUPS , f"Cannot migrate system group { g } "
168169 assert self ._get_group (g , "workspace" ), f"Group { g } not found on the workspace level"
169170 assert self ._get_group (g , "account" ), f"Group { g } not found on the account level"
170171
171- self ._set_migration_groups (self .config .selected )
172- else :
173- logger .info ("No group listing provided, all available workspace-level groups will be used" )
174- available_group_names = [g .display_name for g in self ._workspace_groups ]
175- self ._set_migration_groups (groups_names = available_group_names )
172+ if not group_names :
173+ logger .info (
174+ "No group listing provided, all available workspace-level groups that have an account-level "
175+ "group with the same name will be used"
176+ )
177+ ws_group_names = {_ .display_name for _ in self ._workspace_groups }
178+ ac_group_names = {_ .display_name for _ in self ._account_groups }
179+ group_names = list (ws_group_names .intersection (ac_group_names ))
180+
181+ self ._set_migration_groups (group_names )
176182 logger .info ("Environment prepared successfully" )
177183
178184 @property
0 commit comments