Skip to content
This repository has been archived by the owner on Feb 7, 2018. It is now read-only.

Commit

Permalink
Resolve some uses of {Ref} and {Fn::FindInMap} inside Boxen decls.
Browse files Browse the repository at this point in the history
This is required if you want to e.g. use a different base AMI depending
on the target region.  It's nice to use the same syntax as CloudFormation
runtime.
  • Loading branch information
rfk committed Jun 28, 2013
1 parent 2cb59e8 commit cfc00c2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ PENDING
will write those files at startup.
* Rename "lib/projinfo.js" to "lib/loadTemplate.js", since that's really
the only thing that it does.
* Resolve uses of {'Ref'} and {'Fn::FindInMap'} in Boxen declarations.
This is helpful if you need to use a different AMI in different regions.
* Allow specifying --aws-id, --aws-secret and --aws-region on the command line.
* Tweak how .awsbox.json declarations are upgraded into a Boxen, making it
possible to disable this feature by setting Boxen.AWSBox = null;
* Allow specifying --aws-id, --aws-secret and --aws-region on the command line.


0.3.0 - 2013-06-25
Expand Down
34 changes: 34 additions & 0 deletions lib/loadTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,40 @@ function loadTemplate(projDir, opts, cb) {
cb(null);
},

// Resolve any CloudFormation function calls inside Boxen declarations.
// It's kinda yuck that we have to do this, but the Boxen need to be
// build before CloudFormation ever sees the template.
function resolveFunctionCallsInBoxenDefinitions(cb) {
// Do one pass to resolve "AWS::Region" and "AWS::StackName" refs.
traverse(cfg).forEach(function(obj) {
if (typeof obj === 'object') {
var keys = Object.keys(obj);
if (keys.length === 1 && keys[0] === 'Ref') {
if (obj['Ref'] === 'AWS::Region') {
this.update(opts.aws_region);
} else if (obj['Ref'] === 'AWS::StackName' && opts.name) {
this.update(opts.name);
}
}
}
});
// Now we can resolve any occurrances of Fn::FindInMap.
traverse(cfg).forEach(function(obj) {
if (typeof obj === 'object') {
var keys = Object.keys(obj);
if (keys.length === 1 && keys[0] === 'Fn::FindInMap') {
try {
var mapped = cfg.Mappings[obj['Fn::FindInMap'][0]];
mapped = mapped[obj['Fn::FindInMap'][1]];
mapped = mapped[obj['Fn::FindInMap'][2]];
this.update(mapped);
} catch (e) { };
}
}
});
return cb(null);
},

// Apply any custom helper functions.
// We traverse the entire document looking for single-key objects
// whose key matches "Fn::AWSBoxen::<funcname>", then call the named
Expand Down

0 comments on commit cfc00c2

Please sign in to comment.