Reputation: 51
We're looking for a suggested design pattern to manage external dependencies in our CDK stack. Specifically, we utilize Atlas (mongodb) with our AWS stack. Our AWS stack is fully deployed using CDK/CF. We would like to use a VPC peering connection between our AWS account and Atlas instance. In a nutshell, the procedure to provision this peering connection is:
Has anyone found a good devops pattern to follow for this scenario? We can't perform step 4 until after the manual actions taken in steps 2 & 3. If we just do steps 2-4 manually after deploying our stack in AWS, what kind of drift issues are we going to experience in CloudFormation?
Upvotes: 5
Views: 1105
Reputation: 2078
Example in Python for VPC Peering:
Install the package:
pip install awscdk-resources-mongodbatlas
from awscdk_resources_mongodbatlas import CfnNetworkPeering
cfn_network_peering = CfnNetworkPeering(
self,
"MongoDbCfnNetworkPeering",
container_id=<container_id>,
project_id=<mongo_project_id>,
vpc_id=vpc.vpc_id,
accepter_region_name="us-east-1",
aws_account_id=<aws_account_id>,
profile=<profile>,
route_table_cidr_block=vpc.vpc_cidr_block,
)
You can get your container_id
using the following CLI command:
atlas config init
atlas networking containers list --projectId <projectId> --output json
For profile
, first create an Access Key via CLI or console (organization > access manager > api keys). Ensure you've given minimum sufficient permissions to your key (believe it's Project Read Only
). Then in the Project Access Manager
tab, click Applications
, and invite your api key to the relevant MongoDB project.
Then create a secret in AWS Secrets Manager according to this spec and more thoroughly this spec:
ProfileName: default
SecretName: cfn/atlas/profile/default
SecretValue: {"PublicKey": "YourPublicKey", "PrivateKey": "YourPrivateKey"}
Note: before you do the above, you will need to enable VPC Peering in Atlas Console or CLI using the following instructions.
There are now native CDK constructs for MongoDB with examples here and construct hub here.
Upvotes: 0
Reputation: 268
With some effort, you should be able to get the whole process automated. the benefit is that the VPC peering's lifecycle will be fully managed by cloudformation.
The key here is to use Cloudformation custom resources and dependencies.
Unfortunately, I can't find a ready-made CDK example for the whole process. I guess you'll have to build it🚀.
Upvotes: 3