Created
October 21, 2017 12:48
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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