import logging
import re

f_accounts = {'Log archive': [{'AccountId': '884478634998',
                               'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-ab185f05acde5e90',
                               'PrincipalType': 'GROUP',
                               'PrincipalId': '9a672b3314-b858476a-2ef9-4018-90e7-29e5e4bc4388',
                               'GroupName': 'AWSSecurityAuditPowerUsers', 'PermissionSetName': 'AWSPowerUserAccess'},
                              {'AccountId': '884478634998',
                               'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-21058a9d1f62c7e2',
                               'PrincipalType': 'GROUP',
                               'PrincipalId': '9a672b3314-43117aac-887b-48ee-af49-b6b6cd059199',
                               'GroupName': 'AWSControlTowerAdmins', 'PermissionSetName': 'AWSAdministratorAccess'},
                              {'AccountId': '884478634998',
                               'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-21058a9d1f62c7e2',
                               'PrincipalType': 'GROUP',
                               'PrincipalId': '9a672b3314-c481fbee-8062-432a-8b87-eeaa36b763a8',
                               'GroupName': 'AWSLogArchiveAdmins', 'PermissionSetName': 'AWSAdministratorAccess'},
                              {'AccountId': '884478634998',
                               'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-cf27b0efdc941a09',
                               'PrincipalType': 'GROUP',
                               'PrincipalId': '9a672b3314-f46f413e-44d7-4d3d-918b-f86721413097',
                               'GroupName': 'AWSSecurityAuditors', 'PermissionSetName': 'AWSReadOnlyAccess'},
                              {'AccountId': '884478634998',
                               'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-cf27b0efdc941a09',
                               'PrincipalType': 'GROUP',
                               'PrincipalId': '9a672b3314-ff479c57-03cb-440e-8902-be8ea9d7d25b',
                               'GroupName': 'AWSLogArchiveViewers', 'PermissionSetName': 'AWSReadOnlyAccess'}],
              'SecOps': [{'AccountId': '835863553119',
                          'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-ab185f05acde5e90',
                          'PrincipalType': 'GROUP', 'PrincipalId': '9a672b3314-b858476a-2ef9-4018-90e7-29e5e4bc4388',
                          'GroupName': 'AWSSecurityAuditPowerUsers', 'PermissionSetName': 'AWSPowerUserAccess'},
                         {'AccountId': '835863553119',
                          'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-21058a9d1f62c7e2',
                          'PrincipalType': 'USER', 'PrincipalId': 'c1eb9540-e0f1-702f-c53f-405c01d9f991',
                          'UserName': 'w.alejovl+secops-labs@gmail.com', 'PermissionSetName': 'AWSAdministratorAccess'},
                         {'AccountId': '835863553119',
                          'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-cf27b0efdc941a09',
                          'PrincipalType': 'GROUP', 'PrincipalId': '9a672b3314-f46f413e-44d7-4d3d-918b-f86721413097',
                          'GroupName': 'AWSSecurityAuditors', 'PermissionSetName': 'AWSReadOnlyAccess'},
                         {'AccountId': '835863553119',
                          'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-c6046bbbf15aaafc',
                          'PrincipalType': 'GROUP', 'PrincipalId': '9a672b3314-43117aac-887b-48ee-af49-b6b6cd059199',
                          'GroupName': 'AWSControlTowerAdmins', 'PermissionSetName': 'AWSOrganizationsFullAccess'}],
              'Prod': [{'AccountId': '582441254763',
                        'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-ab185f05acde5e90',
                        'PrincipalType': 'GROUP', 'PrincipalId': '9a672b3314-b858476a-2ef9-4018-90e7-29e5e4bc4388',
                        'GroupName': 'AWSSecurityAuditPowerUsers', 'PermissionSetName': 'AWSPowerUserAccess'},
                       {'AccountId': '582441254763',
                        'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-21058a9d1f62c7e2',
                        'PrincipalType': 'GROUP', 'PrincipalId': '318bc590-a071-70f5-63f6-ab21233e4e33',
                        'GroupName': 'DevSecOps_Admins', 'PermissionSetName': 'AWSAdministratorAccess'},
                       {'AccountId': '582441254763',
                        'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-21058a9d1f62c7e2',
                        'PrincipalType': 'USER', 'PrincipalId': '31eb65d0-f051-70a8-3786-9be14e01dc0e',
                        'UserName': 'w.alejovl+prod-labs@gmail.com', 'PermissionSetName': 'AWSAdministratorAccess'},
                       {'AccountId': '582441254763',
                        'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-cf27b0efdc941a09',
                        'PrincipalType': 'GROUP', 'PrincipalId': '9a672b3314-f46f413e-44d7-4d3d-918b-f86721413097',
                        'GroupName': 'AWSSecurityAuditors', 'PermissionSetName': 'AWSReadOnlyAccess'},
                       {'AccountId': '582441254763',
                        'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-c6046bbbf15aaafc',
                        'PrincipalType': 'GROUP', 'PrincipalId': '9a672b3314-43117aac-887b-48ee-af49-b6b6cd059199',
                        'GroupName': 'AWSControlTowerAdmins', 'PermissionSetName': 'AWSOrganizationsFullAccess'}],
              'SecurityTooling': [{'AccountId': '895882538541',
                                   'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-ab185f05acde5e90',
                                   'PrincipalType': 'GROUP',
                                   'PrincipalId': '9a672b3314-b858476a-2ef9-4018-90e7-29e5e4bc4388',
                                   'GroupName': 'AWSSecurityAuditPowerUsers',
                                   'PermissionSetName': 'AWSPowerUserAccess'}, {'AccountId': '895882538541',
                                                                                'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-83071c7372606026',
                                                                                'PrincipalType': 'GROUP',
                                                                                'PrincipalId': '913ba5c0-f071-70e1-05c5-a927586dc132',
                                                                                'GroupName': 'SecOps_Adms',
                                                                                'PermissionSetName': 'LabvelSecOpsAdms'},
                                  {'AccountId': '895882538541',
                                   'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-21058a9d1f62c7e2',
                                   'PrincipalType': 'GROUP',
                                   'PrincipalId': '9a672b3314-43117aac-887b-48ee-af49-b6b6cd059199',
                                   'GroupName': 'AWSControlTowerAdmins', 'PermissionSetName': 'AWSAdministratorAccess'},
                                  {'AccountId': '895882538541',
                                   'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-21058a9d1f62c7e2',
                                   'PrincipalType': 'GROUP',
                                   'PrincipalId': '9a672b3314-faf36c54-a70c-4db6-aefc-e5ac006ad5a1',
                                   'GroupName': 'AWSAuditAccountAdmins', 'PermissionSetName': 'AWSAdministratorAccess'},
                                  {'AccountId': '895882538541',
                                   'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-cf27b0efdc941a09',
                                   'PrincipalType': 'GROUP',
                                   'PrincipalId': '9a672b3314-f46f413e-44d7-4d3d-918b-f86721413097',
                                   'GroupName': 'AWSSecurityAuditors', 'PermissionSetName': 'AWSReadOnlyAccess'}],
              'DevSecOps': [{'AccountId': '105171185823',
                             'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-ab185f05acde5e90',
                             'PrincipalType': 'GROUP', 'PrincipalId': '9a672b3314-b858476a-2ef9-4018-90e7-29e5e4bc4388',
                             'GroupName': 'AWSSecurityAuditPowerUsers', 'PermissionSetName': 'AWSPowerUserAccess'},
                            {'AccountId': '105171185823',
                             'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-002383fcbd1b90d7',
                             'PrincipalType': 'GROUP', 'PrincipalId': '318bc590-a071-70f5-63f6-ab21233e4e33',
                             'GroupName': 'DevSecOps_Admins', 'PermissionSetName': 'LabvelDevSecOpsUsers'},
                            {'AccountId': '105171185823',
                             'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-21058a9d1f62c7e2',
                             'PrincipalType': 'GROUP', 'PrincipalId': '318bc590-a071-70f5-63f6-ab21233e4e33',
                             'GroupName': 'DevSecOps_Admins', 'PermissionSetName': 'AWSAdministratorAccess'},
                            {'AccountId': '105171185823',
                             'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-21058a9d1f62c7e2',
                             'PrincipalType': 'USER', 'PrincipalId': '81bb65b0-40f1-7082-2b16-83138563c37b',
                             'UserName': 'w.alejovl+devsecops-labs@gmail.com',
                             'PermissionSetName': 'AWSAdministratorAccess'}, {'AccountId': '105171185823',
                                                                              'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-e370384c6f6d9b8a',
                                                                              'PrincipalType': 'GROUP',
                                                                              'PrincipalId': '318bc590-a071-70f5-63f6-ab21233e4e33',
                                                                              'GroupName': 'DevSecOps_Admins',
                                                                              'PermissionSetName': 'LabvelDevSecOpsRW'},
                            {'AccountId': '105171185823',
                             'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-cf27b0efdc941a09',
                             'PrincipalType': 'GROUP', 'PrincipalId': '9a672b3314-f46f413e-44d7-4d3d-918b-f86721413097',
                             'GroupName': 'AWSSecurityAuditors', 'PermissionSetName': 'AWSReadOnlyAccess'},
                            {'AccountId': '105171185823',
                             'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-c6046bbbf15aaafc',
                             'PrincipalType': 'GROUP', 'PrincipalId': '9a672b3314-43117aac-887b-48ee-af49-b6b6cd059199',
                             'GroupName': 'AWSControlTowerAdmins', 'PermissionSetName': 'AWSOrganizationsFullAccess'}],
              'Ops': [{'AccountId': '994261317734',
                       'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-ab185f05acde5e90',
                       'PrincipalType': 'GROUP', 'PrincipalId': '9a672b3314-b858476a-2ef9-4018-90e7-29e5e4bc4388',
                       'GroupName': 'AWSSecurityAuditPowerUsers', 'PermissionSetName': 'AWSPowerUserAccess'},
                      {'AccountId': '994261317734',
                       'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-21058a9d1f62c7e2',
                       'PrincipalType': 'USER', 'PrincipalId': '9a672b3314-f7e9ac54-7407-4428-8562-f8e3afebbe76',
                       'UserName': 'w.alejovl+ct-labs@gmail.com', 'PermissionSetName': 'AWSAdministratorAccess'},
                      {'AccountId': '994261317734',
                       'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-cf27b0efdc941a09',
                       'PrincipalType': 'GROUP', 'PrincipalId': '9a672b3314-f46f413e-44d7-4d3d-918b-f86721413097',
                       'GroupName': 'AWSSecurityAuditors', 'PermissionSetName': 'AWSReadOnlyAccess'},
                      {'AccountId': '994261317734',
                       'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-c6046bbbf15aaafc',
                       'PrincipalType': 'GROUP', 'PrincipalId': '9a672b3314-43117aac-887b-48ee-af49-b6b6cd059199',
                       'GroupName': 'AWSControlTowerAdmins', 'PermissionSetName': 'AWSOrganizationsFullAccess'}],
              'SharedServices': [{'AccountId': '155794986228',
                                  'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-ab185f05acde5e90',
                                  'PrincipalType': 'GROUP',
                                  'PrincipalId': '9a672b3314-b858476a-2ef9-4018-90e7-29e5e4bc4388',
                                  'GroupName': 'AWSSecurityAuditPowerUsers', 'PermissionSetName': 'AWSPowerUserAccess'},
                                 {'AccountId': '155794986228',
                                  'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-21058a9d1f62c7e2',
                                  'PrincipalType': 'GROUP', 'PrincipalId': '318bc590-a071-70f5-63f6-ab21233e4e33',
                                  'GroupName': 'DevSecOps_Admins', 'PermissionSetName': 'AWSAdministratorAccess'},
                                 {'AccountId': '155794986228',
                                  'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-21058a9d1f62c7e2',
                                  'PrincipalType': 'USER', 'PrincipalId': '417b65f0-2021-707d-6483-08a1fa4997c6',
                                  'UserName': 'w.alejovl+shared-labs@gmail.com',
                                  'PermissionSetName': 'AWSAdministratorAccess'}, {'AccountId': '155794986228',
                                                                                   'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-cf27b0efdc941a09',
                                                                                   'PrincipalType': 'GROUP',
                                                                                   'PrincipalId': '9a672b3314-f46f413e-44d7-4d3d-918b-f86721413097',
                                                                                   'GroupName': 'AWSSecurityAuditors',
                                                                                   'PermissionSetName': 'AWSReadOnlyAccess'},
                                 {'AccountId': '155794986228',
                                  'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-c6046bbbf15aaafc',
                                  'PrincipalType': 'GROUP',
                                  'PrincipalId': '9a672b3314-43117aac-887b-48ee-af49-b6b6cd059199',
                                  'GroupName': 'AWSControlTowerAdmins',
                                  'PermissionSetName': 'AWSOrganizationsFullAccess'}], 'LabVel': [
        {'AccountId': '029921763173',
         'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-ab185f05acde5e90',
         'PrincipalType': 'GROUP', 'PrincipalId': '9a672b3314-b858476a-2ef9-4018-90e7-29e5e4bc4388',
         'GroupName': 'AWSSecurityAuditPowerUsers', 'PermissionSetName': 'AWSPowerUserAccess'},
        {'AccountId': '029921763173',
         'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-7cc34a5a03379f6f',
         'PrincipalType': 'GROUP', 'PrincipalId': '9a672b3314-f8065505-3174-4d46-a1b4-f134fd0ca2fc',
         'GroupName': 'AWSAccountFactory', 'PermissionSetName': 'AWSServiceCatalogEndUserAccess'},
        {'AccountId': '029921763173',
         'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-21058a9d1f62c7e2',
         'PrincipalType': 'GROUP', 'PrincipalId': '9a672b3314-43117aac-887b-48ee-af49-b6b6cd059199',
         'GroupName': 'AWSControlTowerAdmins', 'PermissionSetName': 'AWSAdministratorAccess'},
        {'AccountId': '029921763173',
         'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-cf27b0efdc941a09',
         'PrincipalType': 'GROUP', 'PrincipalId': '9a672b3314-f46f413e-44d7-4d3d-918b-f86721413097',
         'GroupName': 'AWSSecurityAuditors', 'PermissionSetName': 'AWSReadOnlyAccess'}, {'AccountId': '029921763173',
                                                                                         'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-83e7c23c8b2df8b3',
                                                                                         'PrincipalType': 'GROUP',
                                                                                         'PrincipalId': '9a672b3314-7f743f07-169a-4172-bdbc-561e7908e463',
                                                                                         'GroupName': 'AWSServiceCatalogAdmins',
                                                                                         'PermissionSetName': 'AWSServiceCatalogAdminFullAccess'}],
              'OrganizationManager': [{'AccountId': '837696987585',
                                       'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-ab185f05acde5e90',
                                       'PrincipalType': 'GROUP',
                                       'PrincipalId': '9a672b3314-b858476a-2ef9-4018-90e7-29e5e4bc4388',
                                       'GroupName': 'AWSSecurityAuditPowerUsers',
                                       'PermissionSetName': 'AWSPowerUserAccess'}, {'AccountId': '837696987585',
                                                                                    'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-83071c7372606026',
                                                                                    'PrincipalType': 'GROUP',
                                                                                    'PrincipalId': '913ba5c0-f071-70e1-05c5-a927586dc132',
                                                                                    'GroupName': 'SecOps_Adms',
                                                                                    'PermissionSetName': 'LabvelSecOpsAdms'},
                                      {'AccountId': '837696987585',
                                       'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-21058a9d1f62c7e2',
                                       'PrincipalType': 'USER', 'PrincipalId': 'c19b15f0-4001-7011-b67d-3e211db16680',
                                       'UserName': 'w.alejovl+orgman-labs@gmail.com',
                                       'PermissionSetName': 'AWSAdministratorAccess'}, {'AccountId': '837696987585',
                                                                                        'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-cf27b0efdc941a09',
                                                                                        'PrincipalType': 'GROUP',
                                                                                        'PrincipalId': '9a672b3314-f46f413e-44d7-4d3d-918b-f86721413097',
                                                                                        'GroupName': 'AWSSecurityAuditors',
                                                                                        'PermissionSetName': 'AWSReadOnlyAccess'},
                                      {'AccountId': '837696987585',
                                       'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-c6046bbbf15aaafc',
                                       'PrincipalType': 'GROUP',
                                       'PrincipalId': '9a672b3314-43117aac-887b-48ee-af49-b6b6cd059199',
                                       'GroupName': 'AWSControlTowerAdmins',
                                       'PermissionSetName': 'AWSOrganizationsFullAccess'}], 'Dev': [
        {'AccountId': '571340586587',
         'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-ab185f05acde5e90',
         'PrincipalType': 'GROUP', 'PrincipalId': '9a672b3314-b858476a-2ef9-4018-90e7-29e5e4bc4388',
         'GroupName': 'AWSSecurityAuditPowerUsers', 'PermissionSetName': 'AWSPowerUserAccess'},
        {'AccountId': '571340586587',
         'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-21058a9d1f62c7e2',
         'PrincipalType': 'GROUP', 'PrincipalId': '318bc590-a071-70f5-63f6-ab21233e4e33',
         'GroupName': 'DevSecOps_Admins', 'PermissionSetName': 'AWSAdministratorAccess'}, {'AccountId': '571340586587',
                                                                                           'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-21058a9d1f62c7e2',
                                                                                           'PrincipalType': 'USER',
                                                                                           'PrincipalId': '41fbf590-8001-70d1-334c-2bbb4adb9989',
                                                                                           'UserName': 'w.alejovl+dev-labs@gmail.com',
                                                                                           'PermissionSetName': 'AWSAdministratorAccess'},
        {'AccountId': '571340586587',
         'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-cf27b0efdc941a09',
         'PrincipalType': 'GROUP', 'PrincipalId': '9a672b3314-f46f413e-44d7-4d3d-918b-f86721413097',
         'GroupName': 'AWSSecurityAuditors', 'PermissionSetName': 'AWSReadOnlyAccess'}, {'AccountId': '571340586587',
                                                                                         'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-c6046bbbf15aaafc',
                                                                                         'PrincipalType': 'GROUP',
                                                                                         'PrincipalId': '9a672b3314-43117aac-887b-48ee-af49-b6b6cd059199',
                                                                                         'GroupName': 'AWSControlTowerAdmins',
                                                                                         'PermissionSetName': 'AWSOrganizationsFullAccess'}]}
c_users_and_groups = [
    {'group_id': '9a672b3314-f46f413e-44d7-4d3d-918b-f86721413097', 'group_name': 'AWSSecurityAuditors', 'members': []},
    {'group_id': '9a672b3314-c481fbee-8062-432a-8b87-eeaa36b763a8', 'group_name': 'AWSLogArchiveAdmins', 'members': []},
    {'group_id': '318bc590-a071-70f5-63f6-ab21233e4e33', 'group_name': 'DevSecOps_Admins', 'members': [
        {'IdentityStoreId': 'd-9a672b3314', 'MembershipId': '51bbe5a0-7001-7010-d7c0-46f5044d014e',
         'GroupId': '318bc590-a071-70f5-63f6-ab21233e4e33',
         'MemberId': {'UserId': '010be510-1061-70df-8274-96526bc47eb7', 'UserName': 'DevSecOpsAdm'}}]},
    {'group_id': '9a672b3314-ff479c57-03cb-440e-8902-be8ea9d7d25b', 'group_name': 'AWSLogArchiveViewers',
     'members': []},
    {'group_id': '9a672b3314-b858476a-2ef9-4018-90e7-29e5e4bc4388', 'group_name': 'AWSSecurityAuditPowerUsers',
     'members': []},
    {'group_id': '9a672b3314-faf36c54-a70c-4db6-aefc-e5ac006ad5a1', 'group_name': 'AWSAuditAccountAdmins',
     'members': []},
    {'group_id': '9a672b3314-f8065505-3174-4d46-a1b4-f134fd0ca2fc', 'group_name': 'AWSAccountFactory', 'members': [
        {'IdentityStoreId': 'd-9a672b3314', 'MembershipId': 'e18bb590-9031-70a0-5469-42c9799e8a6b',
         'GroupId': '9a672b3314-f8065505-3174-4d46-a1b4-f134fd0ca2fc',
         'MemberId': {'UserId': '9a672b3314-bd21c8b3-1aa0-4922-9374-92321b4979bf',
                      'UserName': 'velez94@protonmail.com'}}]},
    {'group_id': '9a672b3314-7f743f07-169a-4172-bdbc-561e7908e463', 'group_name': 'AWSServiceCatalogAdmins',
     'members': []},
    {'group_id': '9a672b3314-43117aac-887b-48ee-af49-b6b6cd059199', 'group_name': 'AWSControlTowerAdmins', 'members': [
        {'IdentityStoreId': 'd-9a672b3314', 'MembershipId': 'e14b3500-3051-70b2-25b7-d5729d383061',
         'GroupId': '9a672b3314-43117aac-887b-48ee-af49-b6b6cd059199',
         'MemberId': {'UserId': '9a672b3314-bd21c8b3-1aa0-4922-9374-92321b4979bf',
                      'UserName': 'velez94@protonmail.com'}}]}]


def l_groups_to_d_groups(l_groups: list = None):
    """

    :param l_groups:
    :return:
    """
    names = []
    for a in l_groups:
        names.append(a['group_name'])
    print(names)

    d_user_groups = dict(zip(names, c_users_and_groups))
    print(d_user_groups)

    return d_user_groups


def get_group_members_with_account(accounts: dict = None, g_dict: dict = None):
    for key, value in accounts.items():
        if len(value) > 0:
            for m in value:
                if "GroupName" in m.keys():

                    if m['GroupName'] in g_dict.keys():
                        print(
                            f"FindGroup  {g_dict[m['GroupName']]} with members {g_dict[m['GroupName']]['members']} in {key}")


d_users_group = l_groups_to_d_groups(c_users_and_groups)

get_group_members_with_account(accounts=f_accounts, g_dict=d_users_group)
print(d_users_group[ 'DevSecOps_Admins']['members'])