Package: aws-organized
AWS OrganizedWhat does this do?This library does two things for you:It allows you to visualise and make changes to your AWS Organization using folders and filesInstead of making changes directly you build up a migration which can then be reviewed before being applied.How does it do thisUsing a read only role with access to your AWS Organization you run an import-organization command.  This generates a
directory that represents your AWS Organization.  It contains directories for OUs and accounts.  It contains files
describing the OUs, accounts and SCP policies.You then make changes to the files and folders - for example, you move account folders to other OU folders to move the
account.Once you are happy with your changes you run a make-migrations command.  This generates some migrations files that
describe what changes you are making.  These changes should be reviewed and then added to git.  You can then use your
fave branching strategy to approve the change in your team.  Once the changes are in your mainline they trigger a
pipeline that will run your migrations using a read/write role.How can I use this?InstallingThis tool has been built in Python 3.7.  We recommend usingpipxto install this
tool:pipxinstallaws-organizedSetting up the IAM RolesThis tool ships with definitions for each IAM role with minimal permissions.You can see and execute the commands as follows:Import OrganizationThe import organization command requires an IAM role in the Organizations management account.  Before you provision the
role you need to decide where this tool will be installed.  We recommend installing the tool into a dedicated prod
shared services foundation account.  Once you have that account which we will call the organized account you are ready
to view or provision the template or stack.You will need to provision this stack into your AWS Organizations management accountTo preview the template you can run:aws-organizedgenerate-import-organization-role-template<organized_account_id>To provision the stack you can run:aws-organizedprovision-import-organization-role-stack<organized_account_id>Make MigrationsThe make-migrations command requires an IAM role in the Organizations management account.You will need to provision this stack into your AWS Organizations management accountTo preview the template you can run:aws-organizedgenerate-make-migrations-role-template<organized_account_id>To provision the stack you can run:aws-organizedprovision-make-migrations-role-stack<organized_account_id>MigrateThe migrate command requires an IAM role in the Organizations management account.You will need to provision this stack into your AWS Organizations management accountTo preview the template you can run:aws-organizedgenerate-migrate-role-template<organized_account_id>To provision the stack you can run:aws-organizedprovision-migrate-role-stack<organized_account_id>Setting up the pipelinesWe recommend running the migrate command in a pipeline so that it is run in a controlled environment where history is
recorded and so audit is possible.You can run this in AWS CodePipeline using our template.When running you have the option of which SCM you would like to useAWS CodeCommitpreview the template:aws-organizedgenerate-codepipeline-template<MIGRATE_ROLE_ARN>provision the template:aws-organizedprovision-codepipeline-stack<MIGRATE_ROLE_ARN>Please note, you can specify --scm-full-repository-id to provide the name of the repo and you can use scm-branch-name to provide a branch.  If you omit either a default value will be used.Finally, you can specify --scm-skip-creation-of-repo and the template will not include the AWS CodeCommit repo - you can bring your own.AWS S3preview the template:aws-organizedgenerate-codepipeline-template--scm-providers3--scm-bucket-namefoo--scm-object-keyenvironment.zip<MIGRATE_ROLE_ARN>provision the template:aws-organizedprovision-codepipeline-stack--scm-providers3--scm-bucket-namefoo--scm-object-keyenvironment.zip<MIGRATE_ROLE_ARN>Please note if you omit --scm-bucket-name we will auto generate a bucket name for you.  If you omit --scm-object-key we will generate a value for you.Finally, you can specify --scm-skip-creation-of-repo and the template will not include the AWS S3 bucket - you can bring your own.Github / Github Enterprise / Bitbucket cloud (via CodeStarSourceConnections)preview the template:aws-organizedgenerate-codepipeline-template--scm-providerCodeStarSourceConnection--scm-connection-arn<CODE_STAR_CONNECTION_ARN>--scm-full-repository-id<GIT_REPO_NAME>--scm-branch-name<GIT_BRANCH_NAME><MIGRATE_ROLE_ARN>provision the template:aws-organizedprovision-codepipeline-stack--scm-providerCodeStarSourceConnection--scm-connection-arn<CODE_STAR_CONNECTION_ARN>--scm-full-repository-id<GIT_REPO_NAME>--scm-branch-name<GIT_BRANCH_NAME><MIGRATE_ROLE_ARN>If you do not provide values for --scm-full-repository-id or --scm-branch-name default values will be provided for you.Making changes to your OrgBefore you can make changes you need to run:aws-organizedimport-organization<import-organization-role>whereimport-organization-roleis the role created by theprovision-import-organization-role-stackcommandOnce you run the import-organization command you have a directory created containing the accounts, OUs and SCPs defined:environment
└──r-japk├──_accounts│└──eamonnf+SCT-demo-hub│├──_meta.yaml│└──_service_control_policies.yaml├──_meta.yaml├──_migrations│├──1613407148.432513_POLICY_CONTENT_UPDATE.yaml│└──1613407148.435472_POLICY_CREATE.yaml├──_organizational_units│├──foo││├──_meta.yaml││├──_organizational_units│││└──bar│││├──_meta.yaml│││├──_organizational_units│││└──_service_control_policies.yaml││└──_service_control_policies.yaml│└──sharedservices│├──_accounts││├──eamonnf+SCT-demo-spoke-1│││├──_meta.yaml│││└──_service_control_policies.yaml││├──eamonnf+SCT-demo-spoke-2│││├──_meta.yaml│││└──_service_control_policies.yaml││├──eamonnf+SCT-demo-spoke-4│││├──_meta.yaml│││└──_service_control_policies.yaml││└──eamonnf+SCT-demo-spoke-5││├──_meta.yaml││└──_service_control_policies.yaml│├──_meta.yaml│├──_organizational_units││└──infra││├──_accounts│││└──eamonnf+SCT-demo-spoke-3│││├──_meta.yaml│││└──_service_control_policies.yaml││├──_meta.yaml││├──_organizational_units││└──_service_control_policies.yaml│└──_service_control_policies.yaml├──_policies│└──service_control_policies│├──FullAWSAccess││├──_meta.yaml││└──policy.json│├──OnlyEc2││└──policy.json│└──OnlyS3│├──_meta.yaml│└──policy.json└──_service_control_policies.yamlYou can currently perform the following operations:Core featuresThe following capabilities are provided:Create an OUTo create an OU you need to create a directory within a new or existing _organizational_units directory.  When creating
a directory you should not add the _meta.yaml file yourself.  You should name the directory with the name of the OU
you want to use.Rename an OUTo rename an OU you need to rename the directory for the OU.  You should not edit the attributes in the _meta.yaml file.Move an accountTo move an account from one OU to another you have to move the directory for the account.  You should move the contents
of the directory with it - including the _meta.yaml and _service_control_policies.yaml files.Service Control Policy featuresThe following capabilities are provided:Create a policyTo create a policy you need to add a directory in the _policies/service_control_policies directory.  The name of the
directory becomes the initial name for the policy.  Within the directory you need to add a file policy.json which
contains the actual SCP policy you want to attach.  When you create a policy do not add a _meta.yaml file for it, the
tool will add it for you.  When you create a policy you cannot set the description, that needs to be another change.Update a policyTo update a policy you either modify the _meta.yaml file or the policy.json file.  If you want to change the
description change the attribute in your _meta.yaml file.  If you want to change the policy content you will need to
edit the policy.json.  At the moment you cannot change the policy name.Attach a policyTo attach a policy to an OU or an account you should add it to the Attached section of the
_service_control_policies.yaml file.  Once you have added it, it should look like this:Attached:-Arn:arn:aws:organizations::aws:policy/service_control_policy/p-FullAWSAccessAwsManaged:trueDescription:Allows access to every operationId:p-FullAWSAccessName:FullAWSAccessType:SERVICE_CONTROL_POLICY-Name:OnlyS3Inherited:-Arn:arn:aws:organizations::aws:policy/service_control_policy/p-FullAWSAccessAwsManaged:trueDescription:Allows access to every operationId:p-FullAWSAccessName:FullAWSAccessSource:sharedservicesType:SERVICE_CONTROL_POLICYIn the above example we appended the name only:Name:OnlyS3AWS-Organized will look up the rest of the details for you.Generating migrationsOnce you have made your changes you can then runaws-organized make-migrations <make-migrations-role-arn>where
make-migrations-role-arn is the Arn of the role created in the steps above.This creates a _migrations directory in your environment/organization direction.  Within the _migrations directory
there should be a file describing the change you want to make.Applying migrationsOnce you have made your migrations you will want to review them - they are human (ish) readable YAML documents that
describe the change you are applying.  Once you are happy with them you will want to run them.Running migrations in a pipeline (recommended)Once you have your migrations you add them to the git repository created in the create pipeline step above.  The default
name for the git repo isAWS-Organized-environmentRunning migrations locally (not recommended)Once you have your migrations you can then runaws-organized migrate <migrate-role-arn>where
migrate-role-arn is the Arn of the role created in the steps above.SecuritySeeCONTRIBUTINGfor more information.LicenseThis project is licensed under the Apache-2.0 License.