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

通过API为TFE工作空间添加环境变量的JSON格式纠错求助

错误原因说明
  • 原JSON存在语法错误:同级JSON对象中不能存在重复的data键,且各个同级键值对之间缺少逗号分隔
  • 不符合TFE/TF Cloud批量创建工作空间变量的API规范:批量新增变量时顶层data字段需要定义为数组格式,每个数组元素对应一个变量的配置
修正后可用的JSON代码
{
  "data": [
    {
      "type": "vars",
      "attributes": {
        "key": "ID1",
        "value": "xxxxxx",
        "description": "",
        "category": "terraform",
        "hcl": false,
        "sensitive": false
      }
    },
    {
      "type": "vars",
      "attributes": {
        "key": "ID2",
        "value": "xxxxxx",
        "description": "",
        "category": "terraform",
        "hcl": false,
        "sensitive": false
      }
    },
    {
      "type": "vars",
      "attributes": {
        "key": "ID3",
        "value": "xxxxxx",
        "description": "",
        "category": "terraform",
        "hcl": false,
        "sensitive": true
      }
    },
    {
      "type": "vars",
      "attributes": {
        "key": "ID4",
        "value": "xxxxxx",
        "description": "",
        "category": "terraform",
        "hcl": false,
        "sensitive": true
      }
    }
  ]
}
补充说明

如果是调用单变量创建接口,一次只能传一个变量的配置,不需要用数组,每次请求只保留一个data对象即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.09 22:51:01