Skip to content

Instantly share code, notes, and snippets.

@jsamuel1
Created March 1, 2021 05:14
Show Gist options
  • Save jsamuel1/6af7b26ae1567cf845959fadc655e27a to your computer and use it in GitHub Desktop.
Save jsamuel1/6af7b26ae1567cf845959fadc655e27a to your computer and use it in GitHub Desktop.

Revisions

  1. jsamuel1 created this gist Mar 1, 2021.
    40 changes: 40 additions & 0 deletions move_account_ou
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    #!/usr/bin/env python

    from __future__ import print_function
    import boto3
    import botocore
    import time
    import sys
    import argparse

    def move_account_ou(
    organization_unit_id,
    new_org_id,
    account_id
    ):

    client = boto3.client('organizations')
    try:
    move_account_response = client.move_account(AccountId=account_id, SourceParentId=organization_unit_id, DestinationParentId=new_org_id)
    except botocore.exceptions.ClientError as e:
    print(e)
    sys.exit(1)



    def main(arguments):

    organization_unit_id = 'ou-xxxx-xxxxxxxx'
    new_org_id = 'r-xxxx'

    client = boto3.client('organizations')
    accounts = client.list_accounts_for_parent(ParentId=organization_unit_id, MaxResults=10)

    print(accounts)
    for account in accounts['Accounts']:
    print(account)
    move_account_ou(organization_unit_id, new_org_id, account['Id'])


    if __name__ == '__main__':
    sys.exit(main(sys.argv[1:]))