Closed iAnomaly closed 8 years ago
Hi @iAnomaly , can you give an example use-case for this addition? Thanks!
Sure thing @jonaf. Should I do that here or in https://github.com/bazaarvoice/cloudformation-ruby-dsl/blob/master/examples/cloudformation-ruby-script.rb?
It would be helpful if you did include a example as well, yes; but actually, I was just curious what you might need something like this for.
We needed this for iteratively creating resources from tabular data. For example, we're managing our Route53 DNS entries as a table and loading multiple columns for use within the DSL. Here is an example:
domains = Table.load 'maps/domains.txt'
# CNAMEs
domains.get_multihash(:purpose, {:product => 'configure', :alias => 'false'}, :prefix, :target).each_pair do |key, value|
resource key+'Cname', :Type => 'AWS::Route53::RecordSet', :Properties => {
:Comment => '',
:HostedZoneName => HOSTED_ZONE,
:Name => value[:prefix]+'.'+HOSTED_ZONE,
:Type => 'CNAME',
:TTL => '900',
:ResourceRecords => [
value[:target]+'.'+HOSTED_ZONE
]
}
maps/domains.txt
purpose product prefix target alias alias_hosted_zone_id has_origin_domain origin_target
CDN demo code dabc123.cloudfront.net true Z2FDTNDATAQYW2 false
Assets demo assets ddef456.cloudfront.net true Z2FDTNDATAQYW2 false
API demo api prod-api false false prod-api-origin.whatever.net.
@jonaf Done! I have incorporated your requests and added an example.
@iAnomaly This looks good to me! Would you mind squashing+rebasing according to https://github.com/bazaarvoice/cloudformation-ruby-dsl/blob/master/docs/Contributing.md#git for a nice, clean merge of this PR?
Done @jonaf! Rebase squashed to a single commit as requested.
Useful for creating multi-column value hash keyed off the primary column key.