向Terraform变量添加约束

时间:2020-10-19 22:54:25

标签: terraform terraform0.12+

我在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

0 个答案:

没有答案
相关问题