Runs from TFE Standalone , resource "local_file" not writing to a file

resource "local_file" "command" {
  content  = <<EOT ${local.command}
    EOT
  filename = "/var/result/command.sh"
}

Hi , I am trying to write some content to a file using local_file resource.
Whenever I execute this code from my local PC with terraform opensource installation and the path pointing to a file share the entire module works.

But the same thing when I try to execute from the TFE server its simply not able to write to the file in the specified path. The path specified /var/result/command.sh is a valid path on the linux machine hosting TFE

Hi @shrirammuthuvezhappa,

You didn’t share what error message you got when trying this, but based on the path you gave I’d guess that the problem is that Terraform is running as a user that doesn’t have access to write to /var/result. If you have access to change the permissions then you could perhaps make that directory writable by whatever user Terraform is running as, but writing system-wide files like this with Terraform is an unusual thing to do with Terraform so it might be that there’s a different way to solve your problem that avoids creating files at all, if you’d be willing to share what your underlying goal is.

After giving appropriate permissions to /var/result it works :slight_smile:

Sure, let me explain what I am trying to do.
The content that’s being written to the file is a bash script which does the following

a. makes an api call to our cmdb to get hostname, IP etc, all the return values from the api call are a piece of string.
b. then I am converting this string to a json format
c. returning the json output

then I use data source external to execute this bash script and retrieve the json output

I tried multiple ways this is the only way I could get this to work