跳至主要内容

函数元数据

tofu metadata functions 命令用于打印当前 OpenTofu 版本中可用函数的签名。

用法

用法: tofu metadata functions [选项]

以下标志可用

  • -json - 以机器可读的 JSON 格式显示函数签名。

请注意,目前,-json 标志是必需的选项。在将来的版本中,此命令将扩展以允许使用其他选项。

输出包括一个 format_version 键,其值为 "1.0"。此版本的语义为

  • 我们将为向后兼容的更改或添加增加次要版本,例如 "1.1"。忽略任何具有无法识别的名称的对象属性,以保持与将来次要版本的向前兼容性。
  • 我们将为不向后兼容的更改增加主要版本,例如 "2.0"。拒绝报告不支持的主要版本的任何输入。

我们只会在 OpenTofu 1.0 兼容性承诺 的范围内引入新的主要版本。

格式摘要

以下部分通过示例使用伪 JSON 符号描述 JSON 输出格式。重要的元素用注释描述,注释以 // 为前缀。为了避免过度重复,我们已将完整格式拆分为几个独立的子对象,并在单独的标题下进行了描述。包含在尖括号中的引用(例如 <block-representation>)是占位符,在实际输出中,它们将被指定子对象的实例替换。

JSON 输出格式由以下对象和子对象组成

函数签名表示

代码块
{
"format_version": "1.0",

// "function_signatures" describes the signatures for all
// available functions.
"function_signatures": {
// keys in this map are the function names, such as "abs"
"example_function": {
// "description" is an English-language description of
// the purpose and usage of the function in Markdown.
"description": "string",

// "return_type" is a representation of a type specification
// that the function returns.
"return_type": "string",

// "parameters" is an optional list of the positional parameters
// that the function accepts.
"parameters": [
<parameter-representation>,

],

// "variadic_parameter" is an optional representation of the
// additional arguments that the function accepts after those
// matching with the fixed parameters.
"variadic_parameter": <parameter-representation>
},
"example_function_two": {}
}
}

参数表示

参数表示描述了函数的参数。

代码块
{
// "name" is the internal name of the parameter
"name": "string",

// "description" is an optional English-language description of
// the purpose and usage of the parameter in Markdown.
"description": "string",

// "type" is a representation of a type specification
// that the parameter's value must conform to.
"type": "string"
}