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

Terraform模块变量调用报错求助:主文件无法获取模块变量

报错原因及解决方法
  • Terraform模块里定义在variables.tf的输入变量属于模块内部入参,默认不会暴露给父模块直接调用。你尝试的module.network.iam_profile和module.network.var.iam_profile两种写法都不符合Terraform的模块引用规则,所以必然报错。
  • 要在主TF文件中获取这个iam_profile的值,必须在modules/network目录下创建outputs.tf文件,将该变量声明为模块输出,示例代码如下:
output "iam_profile" {
  value       = var.iam_profile
  description = "The IAM profile configured in the network module"
}
  • 定义输出后,就能在主TF文件里通过module.network.iam_profile正常引用该值,而module.network.var.iam_profile这种写法本身就是错误的,无论操作多少次terraform init或apply都无法生效。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 01:16:58