Skip to content

Instantly share code, notes, and snippets.

@whyvez
Created October 21, 2017 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whyvez/9ba27ca88b69aebdfb78170a8d16ca77 to your computer and use it in GitHub Desktop.
Save whyvez/9ba27ca88b69aebdfb78170a8d16ca77 to your computer and use it in GitHub Desktop.
Simple example of a JavaScript based Terraform pre-processor using tagged template literal
function resource (literals, func) {
console.log(`resource ${literals[0]} ${func()} ${literals[1]}`);
}
function ip_set_descriptors (literals, func) {
return `ip_set_descriptors ${literals[0]} ${func()} ${literals[1]}`;
}
const ips = ['209.171.43.251', '54.55.73.82'];
resource `"aws_waf_ipset" "crc_office" {
name = "dev-crc-office-waf-ipset"
${() => ips.map(ip => (
ip_set_descriptors `{
type = "IPV4"
value = ${() => ip}/32
}`
))}
}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment