This error occurs when Terraform cannot read a file due to insufficient file system permissions. Common causes include restrictive file permissions on local files, provider binary permission issues, or permission changes during Terraform operations.
When Terraform tries to read a file during configuration parsing, state refresh, or data source evaluation, the operating system denies access due to insufficient permissions. This error typically appears when using local_file resources, reading configuration files, or accessing provider binaries without proper read permissions. The error indicates a mismatch between the user running Terraform and the file's permission settings.
First, identify which file Terraform cannot read by examining the error message. Use ls -la to view the file's permissions:
ls -la /path/to/fileLook at the first 10 characters. The first dash indicates it's a file. The next three characters show owner permissions (rwx), followed by group and others permissions. For example, -rw-r--r-- means owner can read and write, group can read, others can read.
Determine which user is running Terraform:
whoamiIf running in a container or CI/CD system, check the effective user:
idThis shows your user ID (uid) and group ID (gid). The Terraform process must have read permissions for the file owner, group, or others based on these IDs.
Use chmod to add read permissions. For the owner to read:
chmod u+r /path/to/fileFor group members:
chmod g+r /path/to/fileFor all users (less secure):
chmod o+r /path/to/fileOr use numeric notation for combined permissions:
chmod 644 /path/to/fileThis sets owner to read-write (6), group to read (4), others to read (4).
Check if the file owner matches the user running Terraform:
ls -l /path/to/file | awk '{print $3}'If the owner differs from the Terraform user, change ownership:
sudo chown $USER /path/to/fileOr if the file should be group-readable:
sudo chown $USER:$GROUP /path/to/file
chmod 640 /path/to/fileIf using local_file resource with write-only permissions (file_permission = '0200'), Terraform cannot read it on subsequent runs. Change to readable permissions:
resource "local_file" "example" {
content = "Hello World"
filename = "./hello.txt"
file_permission = "0644" # Changed from 0200
}Then re-run Terraform:
terraform applyIf Terraform cannot load a provider binary, ensure it has execute permissions:
chmod +x ~/.terraform.d/plugins/provider-binaryAlternatively, reinstall the provider:
rm -rf .terraform
terraform initThis removes the local provider cache and downloads fresh binaries with correct permissions.
After adjusting permissions, run terraform plan to verify the issue is resolved:
terraform planIf the error persists, check the error message again for the specific file path and repeat steps 1-3 for that file. Run terraform refresh if the plan succeeds but the issue still occurs:
terraform refreshOn shared systems, consider using a dedicated Terraform user account with appropriate group memberships rather than running Terraform as root or individual user accounts. This prevents permission issues when multiple team members apply changes. For sensitive files, use umask 077 (owner only) when creating them, then grant group read access only to necessary users: umask 027; touch file.txt; chmod 640 file.txt. In CI/CD environments like GitHub Actions, ensure the runner container has appropriate file permissions by using actions that preserve umask or explicitly set permissions. For remote file systems (NFS, SMB), verify the mount options include appropriate permission handling. Use 'nofsc' for NFS if caching permission changes, and ensure SELinux or AppArmor policies don't restrict Terraform's file access. On Windows systems, NTFS permissions work differently; ensure the Terraform user account has Read & Execute or Modify permissions on the file or parent directory. Use icacls /grant to modify permissions: icacls C:\path\to\file /grant Users:F for full access.
Error: Error rendering template: template not found
How to fix "template not found" error in Terraform
Error: Error generating private key
How to fix 'Error generating private key' in Terraform
Error creating Kubernetes Service: field is immutable
How to fix "field is immutable" errors in Terraform
Error: Error creating local file: open: permission denied
How to fix "Error creating local file: permission denied" in Terraform
Error: line endings have changed from CRLF to LF
Line endings have changed from CRLF to LF in Terraform