Skip to content

Commit

Permalink
lib terraform: preserve file mode when copying over
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dschofie committed Apr 23, 2024
1 parent 6874efc commit bd784d6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/terraform/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
}

0 comments on commit bd784d6

Please sign in to comment.