0
0

GitHubでHCL(Terraform)をpushしたらHung upエラーになった

Posted at

事象

  • これまでTerraformのHCLファイルをAzure Reposでコード管理していたが、チームの意向でGitHubで管理することになった。
  • ReposのコードをそのままGitHubにpushすると、Hung upのエラーが出てpushできなかった。
$ git push origin main
warning: auto-detection of host provider took too long (>2000ms)
warning: see https://aka.ms/gcm/autodetect for more information.
Enumerating objects: 76, done.
Counting objects: 100% (76/76), done.
Delta compression using up to 8 threads
Compressing objects: 100% (63/63), done.
error: RPC failed; curl 55 Send failure: Connection was reset
send-pack: unexpected disconnect while reading sideband packet
Writing objects: 100% (76/76), 81.75 MiB | 2.82 MiB/s, done.
Total 76 (delta 13), reused 0 (delta 0), pack-reused 0
fatal: the remote end hung up unexpectedly
Everything up-to-date

warning: auto-detection of host provider took too long (>2000ms)の記載からネットワークの問題かと勘違いしトラブルシュートに時間がかかった...

結論

  • .terraform\providers の配下に保存されるプロバイダーのプラグインのサイズが大きすぎることが原因だった。
  • .gitignoreで上記のディレクトリを例外にすることで解決した。

トラブルシュート

bufferサイズの変更

とりあえずエラーメッセージで検索すると、大きいサイズのファイルをclone/pushする場合にバッファーサイズが足りなく場合があるようなので、500MBに変更した。

$ git config http.postBuffer 524288000
$ git push origin master    
    (省略)
remote: error: File envs/dev/.terraform/providers/registry.terraform.io/hashicorp/azurerm/3.75.0/windows_amd64/terraform-provider-azurerm_v3.75.0_x5.exe is 194.77 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: File envs/prod/.terraform/providers/registry.terraform.io/hashicorp/azurerm/3.65.0/windows_amd64/terraform-provider-azurerm_v3.65.0_x5.exe is 187.37 MB; this exceeds GitHub's file size limit of 100.00 MB
    (省略)

まだエラーが出るが、pushしているファイルがGitHubのファイルサイズ上限を超えていると書いてくれている。
公式ドキュメントを確認すると、100MiBを超えるファイルはブロックするらしい!

GitHub には、リポジトリで許可されるファイルのサイズに制限があります。 50 MiBより大きいファイルを追加または更新しようとすると、Gitから警告が表示されます。 変更は引き続きリポジトリに正常にプッシュされますが、パフォーマンスへの影響を最小限に抑えるためにコミットを削除することを検討してもよいでしょう。 詳しくは、「ファイルをリポジトリの履歴から削除する」をご覧ください。

GitHub は 100 MiB を超えるファイルをブロックします。

.gitignoreの編集

Git LFSを使用すると100MiB以上のファイルをGitHubで扱うことができるようだが、サイズ制限に抵触しているファイルはプロバイダーのプラグインでありGit管理する必要がないため、.gitignoreに以下を書き足して解決した。

.gitignore
**/.terraform/*

この制限を超えるファイルを追跡するには、Git Large File Storage (Git LFS) を使う必要があります。 詳しくは、「Git Large File Storageについて」を参照してください。

Azure Repos時代はプロバイダごとPushできていたため、1ファイルのサイズの制限は100MiBではなさそう(無制限ということもないだろうが...)。
Microsoft Learnには、リポジトリのサイズ制限(250 GB)とプッシュサイズ制限(5 GB)との記載があった。(2023/12/6現在)

リポジトリは 250 GB 以下にする必要があります。 リポジトリのサイズを取得するには、コマンド プロンプトで "git count-objects -vH" を実行し、"size-pack" というエントリを探します。

大きなプッシュでは多くのリソースが使用され、サービスの他の部分がブロックまたは遅くなります。 このようなプッシュは、多くの場合、通常のソフトウェア開発アクティビティにはマップされていません。 たとえば、誰かが誤ってビルド出力や VM イメージをチェックインした可能性があります。 このような理由から、プッシュは一度に 5 GB に制限されます。

まとめ

  • Azure ReposからそのままGitHubに移行したらサイズ制限ではまった。

備考

リポジトリを作った際に作れる.gitignore templateでTerraformを選択すると、すでに例外の対象になっているため考慮する必要はない。

.gitignore
# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log
crash.*.log

# Exclude all .tfvars files, which are likely to contain sensitive data, such as
# password, private keys, and other secrets. These should not be part of version 
# control as they are data points which are potentially sensitive and subject 
# to change depending on the environment.
*.tfvars
*.tfvars.json

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Include override files you do wish to add to version control using negated pattern
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

# Ignore CLI configuration files
.terraformrc
terraform.rc

参考

↓ プロバイダーについて詳しく解説してくれています。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0