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

如何让OS::Heat::ResourceGroup的%index%从1开始计数?

解决OS::Heat::ResourceGroup中%index%从1开始计数的问题

直接在字符串里写%index% + 1会被当成纯字符串处理,导致get_param无法识别为合法的整数索引,因此触发报错。需要用Heat的yaql表达式完成数值运算,具体配置修改如下:

resources:
  server_group:
     type: OS::Heat::ResourceGroup
     properties:
        count: 3
        resource_def:
           type: OS::Nova::Server
           properties:
              name: { get_param: [ server_names, yaql: int($.heat_resource_group.index) + 1 ] }

说明:

  • $.heat_resource_group.index是ResourceGroup为每个实例暴露的内置索引变量(默认从0开始)
  • 通过int()将其转为整数后执行+1运算,得到从1起始的索引值
  • 运算结果直接作为get_param的索引参数,满足整数类型要求

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 07:05:24