You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Terragrunt中依赖模块无输出时如何通过run-all跳过当前模块?

解决方案:动态跳过依赖已销毁的模块

可行,你可以通过Terragrunt的try函数结合skip配置项,实现当依赖模块无输出时自动跳过当前模块,无需重复执行run-all destroy。

具体修改你的terragrunt.hcl如下:

dependency "workspace" {
   config_path = "../workspace"
}

locals {
  # 尝试读取依赖输出,若依赖模块已销毁则返回null
  workspace_resource_id = try(dependency.workspace.outputs.resource_id, null)
  # 当依赖输出为null时,标记当前模块需要跳过
  skip_module = local.workspace_resource_id == null
}

# 动态设置是否跳过当前模块
skip = local.skip_module

inputs = {
  databricks_resource_id = local.workspace_resource_id
}

原理说明

  • try函数会捕获依赖输出不存在的错误,返回预设的null值,避免Terragrunt因依赖报错终止执行;
  • 通过skip配置项,当local.skip_module为true时,Terragrunt在执行run-all命令时会自动跳过当前模块;
  • 执行apply时,依赖模块存在输出,local.skip_module为false,模块正常执行,完全符合你的原有需求。

配合--terragrunt-ignore-dependency-errors参数使用时,首次run-all destroy会销毁依赖模块,后续执行时当前模块会因依赖输出不存在自动跳过,无需重复执行多次。

内容的提问来源于stack exchange,提问作者Chris Snow

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 01:01:11