Hello everyone! How can I create a few slightly di...
# typescript
Hello everyone! How can I create a few slightly different resources re-using an existing code as much as possible? For example, I need to create several Route53 records. However, a few of them are simple CNAMEs but others have failover policy. Is it possible to make the failover block dynamic? Thanks!
Sure thing - you can fo something like
let failover = undefined; if (something) { failover = ...  } new Record(... { failover: failover });
how about something like this?
Copy code
function Record(type: string, record: string, failoverRoutingPolicies?: RecordFailoverRoutingPolicy[]) { return new aws.route53.Record(record, {
    records: [record],
    ttl: 300,
    type: "A",
    zoneId: aws_route53_zone_primary.zoneId,
This then can be used like this:
Copy code
Record('A', '');
Record('CNAME', '<http://foo.com|foo.com>');
Record('CNAME', '<http://blabla.com|blabla.com>', {somepolicy});
obviously my example isn't very useful in itself. but you get the idea: create a function which only accepts as args the 'non-common' things and hardcode the common things inside the function body.
if the failoverpolicy is the same across most entries, you can simply create it as const outside the function via
const policy = {mypolicy}
and then pass it to the function
many thanks! I'm gonna try it