无效表达

问题描述 投票:0回答:1

这是我的代码

formatted_name = var.resource_type == "virtual_machine" ? format("vm-%s-00", substr(local.truncated_base_name, 0, 12)) :
                   var.resource_type == "key_vault" ? lower(format("kv-%s", var.base_name)) :
                   var.resource_type == "storage_account" ? lower(replace(format("sa%s", var.base_name), "-", "")) :
                   var.base_name

出现以下错误

Error: Invalid expression
│ 
│   on ../modules/naming/main.tf line 4, in locals:
│    4:   formatted_name = var.resource_type == "virtual_machine" ? format("vm-%s-00", substr(local.truncated_base_name, 0, 12)) :
│    5:                    var.resource_type == "key_vault" ? lower(format("kv-%s", var.base_name)) :
│ 
│ Expected the start of an expression, but found an invalid expression token.
╵
╷
│ Error: Argument or block definition required
│ 
│   on ../modules/naming/main.tf line 5, in locals:
│    5:                    var.resource_type == "key_vault" ? lower(format("kv-%s", var.base_name)) :
│ 
│ An argument or block definition is required here. To set an argument, use the equals sign "=" to introduce the argument value.

我尝试了不同的方法,但仍然遇到相同的错误,请提供帮助。

terraform
1个回答
0
投票

将表达式括在括号中:

formatted_name = (var.resource_type == "virtual_machine" ? format("vm-%s-00", substr(local.truncated_base_name, 0, 12)) :
                   var.resource_type == "key_vault" ? lower(format("kv-%s", var.base_name)) :
                   var.resource_type == "storage_account" ? lower(replace(format("sa%s", var.base_name), "-", "")) : 
                   var.base_name)
© www.soinside.com 2019 - 2024. All rights reserved.