terraform type_error ai_generated true

错误:无效的输出值:输出值类型不匹配

Error: Invalid output value: output value type mismatch

ID: terraform/invalid-output-value-type

其他格式: JSON · Markdown 中文 · English
85%修复率
83%置信度
1证据数
2023-04-10首次发现

版本兼容性

版本状态引入弃用备注
Terraform v1.0+ active

根因分析

输出值的声明类型与表达式结果的实际类型不匹配。

English

An output value's declared type does not match the actual type of the expression result.

generic

官方文档

https://developer.hashicorp.com/terraform/language/values/outputs#type-constraints

解决方案

  1. 修正类型声明以匹配表达式:例如,如果输出是列表,将 type = string 改为 type = list(string)
  2. 使用 tostring()、tolist() 等函数将值转换为声明的类型

无效尝试

常见但无效的做法:

  1. 50% 失败

    Without type constraint, output may still fail if used elsewhere expecting a specific type.

  2. 70% 失败

    Hides the type mismatch but may cause downstream failures.