GitHub Actions工作流如何正确配置目录路径以引用Terraform模块
问题根因
你的报错是terragrunt.hcl中配置的terraform模块源路径层级错误,导致从工作目录出发找不到对应的infrastructure/test目录,Env段的tf_working_dir配置本身是正确的,不需要调整,只要修正terragrunt.hcl的source路径即可。
你的仓库在GitHub Actions中的默认工作路径为/github/workspace,目录层级如下:
github/workspace/ ├── audit-account/ │ └── prod-env/ # terragrunt执行的工作目录 │ └── terragrunt.hcl └── infrastructure/ └── test/ └── main.tf
你原配置中source = "../../../../..//infrastructure/test"回退了5层目录,远超实际需要的2层,同时路径中多余的双斜杠也会导致解析错误,因此触发路径不存在的报错。
修正方案
修改audit-account/prod-env/terragrunt.hcl的source配置即可,只需要回退2层目录就能到达仓库根目录,再指向infrastructure/test路径,修正后配置如下:
# audit-account/prod-env/terragrunt.hcl terraform { source = "../../infrastructure/test" } include { path = find_in_parent_folders() }
内容的提问来源于stack exchange,提问作者bibi
相关产品推荐
相关产品推荐

