mapbox / cloudfriend

Helper functions for assembling CloudFormation templates in JavaScript
ISC License
69 stars 9 forks source link

Feature: PreCondition / TemplateCondition #30

Open vsmart opened 6 years ago

vsmart commented 6 years ago

Summary We need a feature PreCondition or TemplateCondition that allows for specifying a condition on a resource being included in template building.

Use Case: We currently use Condition: NotInChina for resources that are not applicable to China.

This breaks for resources that are not at all available in China, e.g. KMS. The template is validated before any conditions are applied, which fails if the resource does not exist in AWS-CN. We need a condition that removes these resources before sending it to CFN.

Example:

KmsAccess: {
   Action: ‘Kms:Decrypt’,
   Effect: ‘Allow’, 
   Resource: ‘kms:keys:*’, 
   PreCondition: ‘NotInChina’
}

The resource should be removed from the template object, before being submitted to Cloudformation.

This may require a change in /cfn-config also, since cloudfriend itself is region/deploy-agnostic I think.

cc @mapbox/platform

vsmart commented 6 years ago

Capturing from chat w @rclark :

If you have to get the resources removed from the template, I think you will have to make the “template” a function that sends the json in a callback This will help because cfn-config will pass some options to your function Including the region Basically your .template.js just exports a function that takes 2 arguments: options and callback The function needs to build the template, then pass it to callback(null, template) In cli there is a place in template.js that defines what options will be passed to your function You would do the filtering in your async template function itself cli will invoke your async function when it needs your template json It will expect your function to send it json via callback