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

如何获取Terraform模块创建的指定存储账户ID并关联外部资源

解决步骤

步骤1:为模块添加存储账户ID的输出配置

Terraform默认不对外暴露模块内部的资源属性,只有通过output显式声明的属性才可以在模块外部被引用。你需要在模块目录(也就是terraform/modules/路径下)新增outputs.tf文件,或者直接在现有的storage.tf末尾添加如下输出声明:

output "storage_account_id" {
  description = "Azure存储账户的资源ID"
  value       = azurerm_storage_account.storage.id
}

步骤2:在mlws.tf中引用模块输出的存储账户ID

引用模块输出的固定格式为 module.<模块实例名>.<输出项名称>,你这里模块实例名是m2,输出项名是上一步定义的storage_account_id,直接将mlws.tf里storage_account_id的占位符替换为如下内容即可:

storage_account_id = module.m2.storage_account_id

你原有配置中已经添加了depends_on = [module.m2]的依赖声明,不需要额外调整依赖配置。

验证修改

修改完成后执行terraform plan命令,确认没有报错,且输出的变更计划中机器学习工作区的存储账户ID和m2模块创建的m2storage账户ID一致即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.29 18:36:05