DRY code #293
-
Take this example in Terraform, for example:
How could I make it dynamic, using PKL? Or something like this isn't part of what PKL is trying to solve? Some answers would be very appreciated since I currently have a lot of repetition in my code. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
It's hard to know what you're optimising for. In this case, you're importing two different files. That, by itself, is not going to be much more compact, unless you're just looking for |
Beta Was this translation helpful? Give feedback.
-
I know you got an answer to this a while ago, but have you considered using a for_each block to do this completely in terraform? resource "kubectl_manifest" "deployments" {
for_each = [
"application_one",
"application_two"
]
yaml_body = templatefile("${path.module}/${each.key}/deployment.yaml")
} |
Beta Was this translation helpful? Give feedback.
To use Pkl with Terraform, I recommend using their
.tf.json
format. Still, your example is hard to DRY-up, considering it just consumes one file per app; the only thing that will DRY that up is using glob imports.