A Practical Guide to Troubleshooting Git Push Errors in Terraform Projects

Source: Dev.to | Dec 24, 2025 (UTC)

While working on a Terraform project, I ran into several Git push errors that initially felt confusing and frustrating. However, each error turned out to be a valuable learning moment. This article documents those issues step by step, explains why they happen, and shows how to fix them correctly.

If you’re learning Terraform, DevOps, or Infrastructure as Code, chances are you’ll encounter these same problems.

1️⃣GitHub Rejects Large Files (>100 MB)

Error:

File .terraform/...terraform-provider-aws is larger than 100 MB

Enter fullscreen mode

Exit fullscreen mode

Why this happens
The .terraform/ directory was committed. This directory contains Terraform provider binaries, which can be hundreds of megabytes in size and should never be version-controlled.

Correct Fix
Add the following to .gitignore

.terraform/ *.tfstate *.tfstate.backup

Enter fullscreen mode

Exit fullscreen mode

If the file already exists in Git history, the cleanest approach for new projects is to reinitialise the repository:

rm -rf .git git init git add . git commit -m <commit-id>

Enter fullscreen mode

Exit fullscreen mode

2️⃣GitHub Push Protection Blocks Secrets

Error:

Push cannot contain secrets (AWS Access Key detected)

Enter fullscreen mode

Exit fullscreen mode

Why this happens
AWS credentials were hardcoded inside provider.tf. GitHub automatically scans commits for secrets and blocks pushes to prevent credential leaks.

What Not to Do

provider "aws" { access_key = "AKIA..." secret_key = "xxxx" }

Enter fullscreen mode

Exit fullscreen mode

Correct Approach

provider "aws" { region = "us-east-1" } (or add credentials in another file and add that file in .gitignore)

Enter fullscreen mode

Exit fullscreen mode

Provide credentials securely using:

⚠️ If credentials were committed, they should be rotated immediately, even if the push was blocked.

For further actions, you may consider blocking this person and/or reporting abuse

Залишити відповідь

Ваша e-mail адреса не оприлюднюватиметься. Обов’язкові поля позначені *

Читайте також