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

如何在Terraform的helm_release中传递对象列表类型变量

问题解决:Terraform模板渲染Tolerations为正确YAML格式

直接在模板中插入tolerations变量会输出Terraform内部的对象表示字符串,而非标准YAML结构。要解决这个问题,需要利用Terraform的yamlencode和indent函数将变量转换成合法的YAML格式。

修改模板文件

将metabase-test.tpl内容修改为:

tolerations:
${indent(2, yamlencode(tolerations))}

原理说明

  • yamlencode:将Terraform的list(object)类型变量转换为标准的YAML数组字符串,自动处理每个对象的键值对格式。
  • indent(2, ...):给转换后的YAML字符串每一行添加2个空格缩进,确保符合YAML的层级要求,和tolerations:保持正确的嵌套关系。

验证效果

当你传入包含两个元素的tolerations变量时,渲染后的YAML会和你预期的完全一致:

tolerations:
  - key: metabase1
    operator: Equal
    value: "true"
    effect: NoSchedule
  - key: metabase2
    operator: Equal
    value: "true"
    effect: NoSchedule

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 09:10:11