As per the CDK "Best Practices" documentation, we should "model all production stages in code".
In the CDK, you can, and should, build that configuration right into your source code. Create a stack for your production environment, and a separate one for each of your other stages, and put the configuration values for each right there in the code.
I got recently reminded of that best practice and read some more on the non-deterministic results you get if you don't abide by it.
For an environment that includes dev, test and prod (for simplicity) this seems doable and combined with AWS Pipeline sounds like a great idea to run deployments (code driven CI/CD). A commit in the code will automatically result in a re-deploy and changes in the environment as necessary. Great.
However where things seem to be a little more complicated is when prod is really 100s of different tenant environments. So they all "look" the same in terms of the resources they have, but there are differences in, say the network subnets allocations they each use, the vanity name for the access point, etc...
If we want to stick to the deterministic approach referred to above, what is the recommended approach ?
- do we store each tenant deployment in a different code branch ? I.e. each tenant gets their own git branch with a different
cdk.jsonandcdk.context.jsonand we just update those branches if the deployment needs to change (for instance a new ECR image version used by Lambda for a specific set of tenants). - if that's the case, how do we reconcile common changes in the deployment structure (i.e. EC2 instances now need to be "t2.medium" instead of "t2.nano") for all deployments ? Do we just
git rebasefrom a common ancestor ? - or do we need to store each deployment in different
cdk.jsonandcdk.context.json(i.e.tenant1.cdk.json,tenant2.cdk.json, etc.) ? Seems rather ugly... - or create a new stack in the code for each new tenant ? Ugly as well...
Any other suggestions ? Am I missing the point. ?
Or should we somewhat ignore the anti-pattern and introduce more "lookup" and conditional behavior in the code ?