向Terraform变量添加约束

问题描述

我在variables.tf中有以下内容

variable "envoy_config" {
  description = "Envoy Docker Image Version"
  type        = object({

    routes = list(object({
      cluster_name = string
      host_rewrite_url = string
      prefix = string

      headers = object({
        name = string
        exact_match = string
      })

    }))

    clusters = list(object({
      name = string
      address = string
    }))

  })
  default = { 
    routes = [] 
    clusters = [] 
    }

  validation {
    condition     = <not quite sure what to add here>
    error_message = "cluster <name> does not exist"
  }  
}

然后在我的variables.tfvars中,我有以下内容:

envoy_config = {
    routes = [{
      host_rewrite_url = "myurl"
      prefix = "myprefix"
      cluster_name = "mycluster"
      headers = {
          name = ":method"
          exact_match = "GET"
      }
    }]

    clusters = [{
        name = "mycluster"
        address = "myurl"
    }]
}

我想确保每个${envoy_config.routes[*].cluster_name${envoy_config.routes[*]. host_rewrite_url分别存在于${envoy_config.clusters[*].name${envoy_config.clusters[*].address中。

在验证步骤中应添加什么条件? 我发现的所有示例都涉及regex

我正在使用Terraform版本v0.12.28

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)