Terraform 根据其他变量值使变量可为空

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

我正在与 Okta 提供商合作,我想实施

app_oauth
。有一个像
redirect_uris
documentation)这样的属性,除了
service
之外的所有应用程序类型都需要这个属性。我试图在我的
vars.tf
中解决这个问题:

variable "type" {
  description = "Application Type"
  type        = string
  nullable    = false
}

variable "redirect_uris" {
  description = "Application Grant Types"
  type        = list(string)
  nullable    = var.type == "service" ? true : false
}

不幸的是在跑步时

terragrunt plan
我得到:

 Error: Variables not allowed
│ 
│   on vars.tf line 23, in variable "redirect_uris":
│   23:   nullable    = var.type == "service" ? true : false
│ 
│ Variables may not be used here.
╵

╷
│ Error: Unsuitable value type
│ 
│   on vars.tf line 23, in variable "redirect_uris":
│   23:   nullable    = var.type == "service" ? true : false
│ 
│ Unsuitable value: value must be known

有人可以给我任何处理方法的提示吗?

编辑:工作解决方案

resource "okta_app_oauth" "app" {
  label          = var.label
  type           = var.type
  grant_types    = var.grant_types
  redirect_uris  = var.type != "service" ? var.redirect_uris : null
  response_types = var.response_types
}
terraform okta terragrunt
1个回答
2
投票

由于您没有发布可重现的代码块,我认为您可以通过执行以下操作来实现您想要的:

redirect_uris = var.type != "service" ? var.redirect_uris : null
© www.soinside.com 2019 - 2024. All rights reserved.