From bd784d6a57c2765a257e09d841181eaaa84da079 Mon Sep 17 00:00:00 2001 From: Danny Schofield Date: Tue, 23 Apr 2024 11:04:08 -0400 Subject: [PATCH] lib terraform: preserve file mode when copying over If someone wants to cache providers they will be executable and not match the expected file view pattern. It's best to preserve permissions when possible --- lib/terraform/local.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/terraform/local.go b/lib/terraform/local.go index 4ba44f6..e74f62c 100644 --- a/lib/terraform/local.go +++ b/lib/terraform/local.go @@ -52,6 +52,11 @@ func CopyDir(stack resource.Stack, dst string, resource resource.Resource) error } func replaceVariablesInFile(srcFile, dstFile string, resource resource.Resource, stack resource.Stack) error { + fileInfo, err := os.Stat(srcFile) + if err != nil { + return oops.Wrapf(err, "error accessing file %s", srcFile) + } + content, err := ioutil.ReadFile(srcFile) if err != nil { return err @@ -76,5 +81,5 @@ func replaceVariablesInFile(srcFile, dstFile string, resource resource.Resource, return oops.Errorf("Region needs to be set on stack if performing substitution") } - return ioutil.WriteFile(dstFile, []byte(updatedContent), 0644) + return ioutil.WriteFile(dstFile, []byte(updatedContent), fileInfo.Mode()) }