Hi,
I have a local-exec resource running a CLI tool which need a -f (.yaml file) argument . This is the requirement . In future I will need to run this for multiple file, so I ll also build a loop I guess.
In this yaml file, I need to replace one line with a variable $myproject .
apiVersion: opa.k8smgmt.io/v3
kind: OPAConstraint
metadata:
labels:
name: container-limits-custom
project: $myproject
spec:
artifact:
artifact:
paths:
- name: file://artifacts/container-limits-custom/container-limits.yaml
options: {}
type: Yaml
templateName: container-limits-custom
I would like to combine directly the use of the command line and the template rendering in only one block .
Like so:
this is the basic :
resource "null_resource" "run_command" {
provisioner "local-exec" {
command = " my_cli -f ./artifacts/template.yaml"
I thought about using jsonencode() or templatefile() :
resource "null_resource" "run_command" {
provisioner "local-exec" {
command = " my_cli -f $FILE "
environment = { FILE = jsonencode("./artifacts/template.yaml")
}
} }
or :
resource "null_resource" "run_command" {
provisioner "local-exec" {
command = " my_cli -f $FILE "
environment = { FILE = templatefile("./artifacts/template.yaml", { myproject = var.myproject } )
}
} }
Is it even possible to mix jsonencode() or templatefile() as part of a local-exec , and is doing so in an environment argument a good approach ?