_This issue was originally opened by @kojiromike as hashicorp/terraform#14768. It was migrated here as a result of the provider split. The original body of the issue is below._
0.9.5
resource "local_file" "foo" {
content = "contents"
filename = "foo.txt"
}
My umask here is 0022
A file should have been created with mode -rw-r--r--
.
A file was created with mode -rwxr-xr-x
.
While I would prefer the option of providing a specific mode in tf configuration, I think Terraform should fallback to supporting the standard behavior of open
, which would result in the file not being executable.
I think the mode
should be an attribute. For instance, I use a dynamic generated private key for a set of instances but use the loca_file to put it in my local path in case I need to ssh and troubleshoot later. However in my case the .pem
file generated should be with 600
mode in order to be used with the ssh -i <*.pem> <host>
command.
I agree, getting this issue when saving off files that need less permissive modes.
While we don't have a proper solution for that, I'm using the following workaround.
resource "local_file" "foo" {
content = "contents"
filename = "foo.txt"
provisioner "local-exec" {
command = "chmod 644 foo.txt"
}
Not the best solution, but did the trick for me! Hope it helps.
@rodrigocmn Thank you for that work around, that work great for my scenario!
While we don't have a proper solution for that, I'm using the following workaround.
resource "local_file" "foo" { content = "contents" filename = "foo.txt" provisioner "local-exec" { command = "chmod 644 foo.txt" }
Not the best solution, but did the trick for me! Hope it helps.
Very nice trick!
Looks like https://github.com/terraform-providers/terraform-provider-local/pull/5 will close this
Modes are now supported (implemented in pull request #30), use file_permission
argument released in v1.4.0
.
This is not working for me. When I create my local file i set this parameter file_permission = "0600"
. However the file is still created with 755.
Most helpful comment
While we don't have a proper solution for that, I'm using the following workaround.
Not the best solution, but did the trick for me! Hope it helps.