Created
December 17, 2025 15:56
-
-
Save nightspotlight/553913640f4c038dacd811e6291fd293 to your computer and use it in GitHub Desktop.
Sedai script to update group with AWS accounts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| account_id | account_name | |
|---|---|---|
| 012345678901 | testacc1 | |
| 123456789012 | testacc2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import csv | |
| from sedai import account, groups, models | |
| def main(): | |
| csvfile = 'aws_accounts.csv' | |
| group_name = 'XYZ AWS Accounts' | |
| group = groups.get_group(group_name) | |
| if not group: | |
| print(f"Group \"{group_name}\" not found, creating it.") | |
| group_definition = groups.GroupDefinition(group_name) | |
| create_status = groups.create_group(group_definition) | |
| group = groups.get_group(group_name) | |
| print(f"Group {group_name} ({group.groupId}) created with status {create_status}") | |
| else: | |
| group_definition = group.definition | |
| print(f"Group \"{group_name}\" found with id {group.groupId}") | |
| with open(csvfile, newline='') as f: | |
| reader = csv.DictReader(f) | |
| for row in reader: | |
| # Look up Sedai internal account id by AWS account id | |
| accounts = account.search_accounts_by_provider_account_id(row['account_id']) | |
| account_id = models.to_dict(accounts)[0]['id'] | |
| group_definition.add_account_id(account_id) | |
| print(f"Added account {row['account_id']} to group \"{group_name}\"") | |
| groups.update_group(group) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment