How to fix Error reading file: permission denied in Terraform
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.
Quick fix
Fixes Error reading file: permission denied
ls -la /path/to/file- Check current file permissions
- Identify the Terraform process owner
- Add read permissions to the file
- Verify file ownership matches the Terraform user
ls -la /path/to/fileError reading file: permission denied
What this error means
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.
Typical symptoms
- Terraform apply or plan fails at the file reading stage
- Error messages containing 'permission denied' with a file path
- Local_file resources fail on subsequent Terraform runs after initial creation
- Issues particularly noticeable on shared systems with multiple users
- Terraform commands abort before plan or apply phase completes
Common causes
- File permissions are too restrictive (e.g., file_permission = '0200' write-only) preventing read access
- Provider binary lacks executable permissions (chmod +x not applied)
- Terraform process runs as a different user than the file owner
- File ownership or permissions changed after initial Terraform run
- Shared systems where multiple users run Terraform with different umask settings
- Remote file systems or mounted drives with permission restrictions
- CI/CD runners or containers with limited file system access
How to fix "Error reading file: permission denied"
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 refreshAdvanced notes
On 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.
Frequently asked questions
- What does "Error reading file: permission denied" mean?
- 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.
- How do I fix "Error reading file: permission denied"?
- 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.
- What causes "Error reading file: permission denied"?
- File permissions are too restrictive (e.g., file_permission = '0200' write-only) preventing read access Provider binary lacks executable permissions (chmod +x not applied) Terraform process runs as a different user than the file owner
- Is the "Error reading file: permission denied" error serious?
- It is a medium-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐Terraform Official Documentation
- ๐
- ๐