# Use templatefile or jsonencode in local-exec command

**URL:** <https://discuss.hashicorp.com/t/use-templatefile-or-jsonencode-in-local-exec-command/44018>\
**Category:** Terraform\
**Created:** [September 6, 2022, 6:34pm UTC](https://discuss.hashicorp.com/t/use-templatefile-or-jsonencode-in-local-exec-command/44018 "2022-09-06T18:34:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nic\_h](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/nic_h/32/30571_2.png) [@Nic\_h](https://discuss.hashicorp.com/u/Nic_h)\
**Post date:** [September 6, 2022, 6:34pm UTC](https://discuss.hashicorp.com/t/use-templatefile-or-jsonencode-in-local-exec-command/44018/1 "2022-09-06T18:34:41Z")

</div>

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**.

```auto
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 :

```auto
resource "null_resource" "run_command" {
  provisioner "local-exec" {
   command = " my_cli -f ./artifacts/template.yaml"

```

I thought about using jsonencode() or templatefile() :

```auto
resource "null_resource" "run_command" {
  provisioner "local-exec" {
   command = " my_cli -f $FILE "
environment = { FILE = jsonencode("./artifacts/template.yaml")
}
} }

```

or :

```auto
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 ?
