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: add multi-org generate_params.py #672

Merged
merged 10 commits into from
Feb 5, 2024
35 changes: 30 additions & 5 deletions docs/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -646,13 +646,16 @@ each account under that OU.
deployment map as a target. If only the account number is in the deployment map
the corresponding OU parameter file will not be referenced.



AndyEfaa marked this conversation as resolved.
Show resolved Hide resolved
```txt
global.yml
└───deployment_account_region.yml (e.g. global_eu-west-1.yml)
└───ou.yml (e.g. ou-1a2b-3c4d5e.yml)
└───ou_region.yml (e.g. ou-1a2b-3c4d5e_eu-west-1.yml)
└───account.yml (e.g. dev-account-1.yml)
└───account_region.yml (e.g. dev-account-1_eu-west-1.yml)
└───deployment_org_stage.yml (e.g. global_dev.yml)
└───deployment_account_region.yml (e.g. global_eu-west-1.yml)
└───ou.yml (e.g. ou-1a2b-3c4d5e.yml)
└───ou_region.yml (e.g. ou-1a2b-3c4d5e_eu-west-1.yml)
└───account.yml (e.g. dev-account-1.yml)
└───account_region.yml (e.g. dev-account-1_eu-west-1.yml)
```

This concept also works for applying **Tags** to the resources within your
Expand Down Expand Up @@ -712,6 +715,28 @@ the root of the repository.
*Note:* Currently only Strings type values are supported as parameters to
CloudFormation templates when deploying via AWS CodePipeline.

**CloudFormation Parameters in a Multi-Organization ADF Setup**
AndyEfaa marked this conversation as resolved.
Show resolved Hide resolved
The CloudFormation Parameter generation feature is fully compatible with
the [Multi-Organization ADF Setup](./multi-organization-guide.md) approach.
Let's assume that we have a three AWS Org setup with a dev, int and prod
AWS Organization. This implies that the SSM param `/adf/org/stage` will have
one of the following three values: `[dev, int, prod]`; depending on the AWS
Organization you are in. Let's further assume that your application in scope
requires AWS Organization specific parameters.In that case, the `params` should
have the following content:
AndyEfaa marked this conversation as resolved.
Show resolved Hide resolved

```txt
params
└───global_dev.yml
└───global_int.yml
└───global_prod.yml
└───global.yml
```

When the application gets deployed, ADF will choose the right parameter file
based on the value of the SSM prameter "/adf/org/stage".

AndyEfaa marked this conversation as resolved.
Show resolved Hide resolved

### Serverless Transforms

If the template that is being deployed contains a transform, such as a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class PipelineDefinition(TypedDict):
DEPLOYMENT_ACCOUNT_REGION = os.environ["AWS_REGION"]
PROJECT_NAME = os.environ["ADF_PROJECT_NAME"]
EMPTY_PARAMS_DICT: ParametersAndTags = {'Parameters': {}, 'Tags': {}}
ADF_ORG_STAGE = os.getenv("ADF_ORG_STAGE", "dev")


class Parameters:
Expand Down Expand Up @@ -229,6 +230,7 @@ def create_parameter_files(self) -> None:
i.e. "/devsecops/security_eu-west-1"
1. f"{organization_unit_path}" i.e. "/devsecops/security"
1. f"{global}_{region}" i.e. "global_eu-west-1"
1. f"{global}_{stage}" i.e. "global_dev"
1. f"{global}" i.e. "global"

It will then generate a JSON file that holds all the parameters per
Expand Down Expand Up @@ -299,6 +301,15 @@ def create_parameter_files(self) -> None:
),
current_params
)
# Compare account_region final to global_stage
adf_org_stage = ADF_ORG_STAGE # Fetch from Environ for Start
current_params = self._merge_params(
Parameters._parse(
params_root_path=self.cwd,
params_filename=f"global_{adf_org_stage}",
),
current_params
)
AndyEfaa marked this conversation as resolved.
Show resolved Hide resolved
# Compare account_region final to global
current_params = self._merge_params(
Parameters._parse(
Expand Down