调用Terraform模块获取VMware主机名与UUID时出错
解决Terraform模块引用
name/uuid属性不存在的问题 错误核心原因:你调用的
er模块未通过outputs.tf文件声明name和uuid这两个输出值,Terraform仅允许外部模块引用明确定义的输出属性。具体解决步骤:
补充模块的输出定义
进入你引用的模块仓库(git::https://abc/repo?branch),创建或修改outputs.tf文件,将VM的名称和UUID暴露为输出。假设模块内部通过vsphere_virtual_machine资源创建VM,示例代码如下:output "name" { type = list(string) description = "已部署VM的主机名列表" value = [for vm in vsphere_virtual_machine.vm_resource : vm.name] } output "uuid" { type = list(string) description = "已部署VM的UUID列表" value = [for vm in vsphere_virtual_machine.vm_resource : vm.uuid] }注意:将
vsphere_virtual_machine.vm_resource替换为模块内部实际的VM资源名称。修正local块的引用写法
由于你仅创建了一个er模块实例(未使用count/for_each批量创建),无需使用[*]列表索引,直接引用模块输出即可:locals { rs_hostnames = module.er.name rs_instance_ids = module.er.uuid }匹配实际输出名称
如果模块已有输出但名称不是name/uuid(比如叫vm_names/vm_uuids),需同步修改local块里的引用名称,确保和模块输出名完全一致。
内容的提问来源于stack exchange,提问作者user312307
相关产品推荐
相关产品推荐

