Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/multi org support #668

Merged
merged 55 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
00fa111
Feat: Adf Multi-Org support
alexevansigg Oct 18, 2023
51ce241
fix: Broken links
alexevansigg Oct 18, 2023
2ad95db
fix: Updated link
alexevansigg Oct 18, 2023
fd4f658
docs: update wording
alexevansigg Oct 18, 2023
0c35eec
fix: codespell fixes
alexevansigg Oct 18, 2023
182d02a
fix: Added propagation of org/stage parameter
alexevansigg Oct 18, 2023
677cddb
fix path part missing for os.path.exists
alexevansigg Oct 18, 2023
7c5f647
feat: extended Multi-Org Docs
falkena1 Oct 31, 2023
1e88aa7
feat: extended Multi-Org Docs
falkena1 Oct 31, 2023
3fcd722
Merge branch 'awslabs:master' into feat/multi-org-support
AndyEfaa Oct 31, 2023
dfb540c
feat: extended Multi-Org Docs - fix typo
falkena1 Oct 31, 2023
24e6ec9
Update README.md
AndyEfaa Nov 11, 2023
ae42efb
Update docs/admin-guide.md
AndyEfaa Nov 11, 2023
5ee01ba
Update docs/multi-organization-guide.md
AndyEfaa Nov 11, 2023
058b393
Update docs/multi-organization-guide.md
AndyEfaa Nov 11, 2023
e0ca137
Update docs/multi-organization-guide.md
AndyEfaa Nov 11, 2023
851bcd3
Update src/lambda_codebase/initial_commit/bootstrap_repository/exampl…
AndyEfaa Nov 11, 2023
d9677a1
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bo…
AndyEfaa Nov 11, 2023
0512cd5
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bo…
AndyEfaa Nov 11, 2023
caa4afb
Update docs/admin-guide.md
AndyEfaa Nov 11, 2023
2569f21
Update docs/multi-organization-guide.md
AndyEfaa Nov 11, 2023
0e382e2
Update docs/multi-organization-guide.md
AndyEfaa Nov 11, 2023
cf42060
Update docs/multi-organization-guide.md
AndyEfaa Nov 11, 2023
3d25aeb
Update docs/multi-organization-guide.md
AndyEfaa Nov 11, 2023
815bc19
Apply suggestions from code review
AndyEfaa Nov 11, 2023
09a8d89
fix: make doc changes based on review
falkena1 Nov 11, 2023
aabc72f
Update docs/multi-organization-guide.md
AndyEfaa Jan 20, 2024
c7d39f9
Update docs/multi-organization-guide.md
AndyEfaa Jan 20, 2024
c50db6c
Update docs/multi-organization-guide.md
AndyEfaa Jan 20, 2024
aa68074
Update docs/multi-organization-guide.md
AndyEfaa Jan 20, 2024
8a25e90
Update docs/multi-organization-guide.md
AndyEfaa Jan 20, 2024
47893ab
Update docs/multi-organization-guide.md
AndyEfaa Jan 20, 2024
3b2e789
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
AndyEfaa Jan 20, 2024
c593135
Update docs/multi-organization-guide.md
AndyEfaa Jan 20, 2024
94bd041
Update docs/multi-organization-guide.md
AndyEfaa Jan 20, 2024
6657729
fix: linter issues
falkena1 Jan 20, 2024
e58d35e
fix: linter issues
falkena1 Jan 20, 2024
24c0b06
Merge branch 'awslabs:master' into feat/multi-org-support
AndyEfaa Jan 20, 2024
0650291
fix: linter issues
falkena1 Jan 20, 2024
41b75bf
fix: linter issues
falkena1 Jan 20, 2024
5c5cccf
Merge branch 'master' into feat/multi-org-support
AndyEfaa Jan 20, 2024
3986e16
Update docs/multi-organization-guide.md
AndyEfaa Jan 22, 2024
6f16517
Update docs/multi-organization-guide.md
AndyEfaa Jan 22, 2024
d7c640c
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bo…
AndyEfaa Jan 22, 2024
13bd9b0
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
AndyEfaa Jan 22, 2024
10161ac
Update docs/multi-organization-guide.md
AndyEfaa Jan 22, 2024
4011722
Update docs/multi-organization-guide.md
AndyEfaa Jan 22, 2024
97493fc
Update docs/multi-organization-guide.md
AndyEfaa Jan 22, 2024
53e8b5d
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bo…
AndyEfaa Jan 22, 2024
f1a5029
Apply suggestions from code review
AndyEfaa Jan 22, 2024
d59b764
Merge branch 'master' into feat/multi-org-support
AndyEfaa Jan 22, 2024
90172b2
Update docs/multi-organization-guide.md
AndyEfaa Jan 22, 2024
71fcfe4
Update docs/multi-organization-guide.md
AndyEfaa Jan 22, 2024
0933119
Update docs/multi-organization-guide.md
AndyEfaa Jan 22, 2024
2911436
Apply suggestions from code review
AndyEfaa Jan 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ template as its baseline.
contribute or build on top of ADF.
- Refer to the [Samples Guide](docs/samples-guide.md) for a detailed walk
through of the provided samples.
- Refer to the [Multi-Organization ADF Setup](docs/multi-organization-guide.md)
to use ADF in an enterprise-grade setup.
7 changes: 6 additions & 1 deletion docs/admin-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ config:
scm: # Source Control Management
auto-create-repositories: enabled # Optional
default-scm-branch: main # Optional
org:
stage: dev # Optional
```

In the above example the properties are categorized into `roles`, `regions`,
Expand Down Expand Up @@ -232,10 +234,13 @@ Config has five components in `main-notification-endpoint`, `scp`, `scm`,
and prod AWS Organization with its own ADF instance per AWS organization.
This approach allows for well-tested and stable prod AWS Organization
deployments. If set, a matching SSM parameter `/adf/org/stage` gets
created that you can reference in your buildspec files to allow for
created in the deployment and all target accounts.
You can reference it within your buildspec files to allow for
org-specific deployments; without hardcoding the AWS Organization stage in
your buildspec. If this variable is not set, the SSM parameter
`/adf/org/stage` defaults to "none".
More information about setting up ADF with multiple AWS Organizations can
be found in the [Multi-Organization Guide](multi-organization-guide.md)

- **default-scm-codecommit-account-id** allows you to configure the default
account id that should be used with all source-code management platforms
Expand Down
Binary file added docs/images/aws-multi-org-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/aws-multi-org-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
339 changes: 339 additions & 0 deletions docs/multi-organization-guide.md

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/lambda_codebase/account_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ def configure_generic_account(sts, event, region, role):
bucket_name = parameter_store_deployment_account.fetch_parameter(
f'/cross_region/s3_regional_bucket/{region}',
)
org_stage = parameter_store_deployment_account.fetch_parameter(
'/adf/org/stage'
)
except (ClientError, ParameterNotFoundError):
raise GenericAccountConfigureError(
f'Account {event["account_id"]} cannot yet be bootstrapped '
Expand All @@ -79,6 +82,7 @@ def configure_generic_account(sts, event, region, role):
'deployment_account_id',
event['deployment_account_id'],
)
parameter_store_target_account.put_parameter('/adf/org/stage', org_stage)


def configure_master_account_parameters(event):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@
AWSTemplateFormatVersion: "2010-09-09"
Description: ADF CloudFormation Template (Global) for IAM in the Deployment Account

# Parameters:
# OrgStage can be set in the respective adfconfig file using the
# path config.org.stage
# OrgStage:
# Type: "AWS::SSM::Parameter::Value<String>"
# Description: A stage used to differentiate Multi-Organization ADF environments
# Default: /adf/org/stage

# Org StageCustom Mappings allows you to dynamically build different IAM
# Conditions / Principals ARN / Resource ARN per Organization applying Least
# Privilege Principals whilst retaining a Single Stack Definition for all
# environments.
# Example usage:
# !FindInMap[OrgStageMap: !Ref OrgStage, ExampleCustomProperty]
# Mappings:
# OrgStageMap:
# Dev:
# ExampleCustomProperty: 1234
# Int:
# ExampleCustomProperty: 5678
# Prod:
# ExampleCustomProperty: 9102

Resources:
CloudFormationDeploymentPolicy:
# This is the policy that will be used to deploy CloudFormation resources from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,28 @@ Parameters:
Description: Deployment Account ID
Default: deployment_account_id

# OrgStage can be set in the respective adfconfig file using the
# path config.org.stage
# OrgStage:
# Type: "AWS::SSM::Parameter::Value<String>"
# Description: A stage used to differentiate Multi-Org ADF environments
# Default: /adf/org/stage

# Org Stage Custom Mappings allows you to dynamically build different IAM
# Conditions / Principals ARN / Resource ARN per Organization applying
# least-privilege principles whilst retaining a Single Stack Definition for all
# environments.
# Example usage:
# !FindInMap[OrgStageMap: !Ref OrgStage, ExampleCustomProperty]
# Mappings:
# OrgStageMap:
# Dev:
# ExampleCustomProperty: 1234
# Int:
# ExampleCustomProperty: 5678
# Prod:
# ExampleCustomProperty: 9102

Resources:
CloudFormationDeploymentPolicy:
# This is the policy that will be used to deploy CloudFormation resources from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,20 @@ def _validate(self):

def _load_config_file(self):
"""
Loads the adfconfig.yml file and executes _parse_config
Checks for an Org Specific adfconfig.yml (adfconfig.{ORG_ID}.yml)
and uses that if it exists. Otherwise it uses the default adfconfig.yml
and executes _parse_config
"""
with open(self.config_path, encoding="utf-8") as config:
self.config_contents = yaml.load(config, Loader=yaml.FullLoader)
self._parse_config()
org_config_path = self.config_path.replace(".yml", f".{self.organization_id}.yml")
if os.path.exists(org_config_path):
with open(org_config_path, encoding="utf-8") as org_config_file:
LOGGER.info("Using organization specific ADF config: %s", org_config_path)
self.config_contents = yaml.load(org_config_file, Loader=yaml.FullLoader)
else:
LOGGER.info("Using default ADF config: %s", self.config_path)
with open(self.config_path, encoding="utf-8") as config:
self.config_contents = yaml.load(config, Loader=yaml.FullLoader)
self._parse_config()

def _parse_config(self):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,15 @@ def worker_thread(
'bucket_name',
updated_kms_bucket_dict[region]['s3_regional_bucket'],
)

# Ensuring the stage parameter on the target account is up-to-date
parameter_store.put_parameter(
'/adf/org/stage',
config.config.get('org', {}).get(
'stage',
ADF_DEFAULT_ORG_STAGE,
)
)
cloudformation = CloudFormation(
region=region,
deployment_account_region=config.deployment_account_region,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ config:
default-scm-branch: master
# ^ The default branch is used when the pipeline does not specify a specific branch.
# If this parameter is not specified, it defaults to the "master" branch.
org:
stage: prod
# ^ This value will be set as an SSM Parameter named /adf/org/stage
# in both the deployment account and and all
# Target member accounts as part of the Bootstrap Statemachine.
# It is useful as a flag to drive Organization specific logic within
# IAM Role definitions/conditions as well as Build spec behavior.

extensions:
terraform:
Expand Down