使用Terragrunt双仓库模式调用本地模块时遇目录读取错误
问题:Terragrunt Live/Remote双仓库模式下模块读取失败
报错信息
Upgrading modules... - common in ╷ │ Error: Unreadable module directory │ │ Unable to evaluate directory symlink: lstat ../common: no such file or │ directory ╵ ╷ │ Error: Failed to read module directory │ │ Module directory does not exist or cannot be read. ╵ ╷ │ Error: Unreadable module directory │ │ Unable to evaluate directory symlink: lstat ../common: no such file or │ directory ╵ ╷ │ Error: Failed to read module directory │ │ Module directory does not exist or cannot be read. ╵
仓库目录结构
Remote仓库(模块仓库)
├project ├──terragrunt.hcl ├──common ├──main.tf ├──my-stack ├── main.tf ├──terragrunt.hcl
Live仓库(配置仓库)
├live ├──terragrunt.hcl ├──my-live-stack ├──terragrunt.hcl
相关代码片段
Remote仓库:project/my-stack/main.tf
module "common" { source = "../common/" } ...
Remote仓库:project/my-stack/terragrunt.hcl
include "root" { path = find_in_parent_folders() }
Remote仓库:project/terragrunt.hcl
remote_state{...}
Live仓库:live/my-live-stack/terragrunt.hcl
terraform { source = "git::git@bitbucket.com:my-company/my-repo.git//my-project?ref=dev" } include "root" { path = find_in_parent_folders() }
问题原因
../common目录未提交到Git仓库,当Live仓库通过Git拉取Remote仓库的代码时,未被Git追踪的common目录不会被同步到本地,导致Terraform尝试读取该模块时找不到对应的目录,从而抛出上述错误。本地执行terragrunt plan正常是因为本地存在该未提交目录。
解决方案
- 将
common目录纳入Git追踪并提交推送:git add common/ git commit -m "Add common module files" git push origin dev - 确保Live仓库引用的Git分支(示例中为
dev)包含该提交,重新运行terragrunt plan即可解决问题。
内容的提问来源于stack exchange,提问作者Hephaestus
相关产品推荐
相关产品推荐

