Adding constraints to terraform variable

829 views Asked by At

I have the following in 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"
  }  
}

and then in my variables.tfvars, I have the following:

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

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

I want to make sure that every ${envoy_config.routes[*].cluster_name and ${envoy_config.routes[*]. host_rewrite_url exists in ${envoy_config.clusters[*].name and ${envoy_config.clusters[*].address respectively.

What condition should I be adding the in the validation step? The examples I found all deal with regex

I am using terraform version v0.12.28

0

There are 0 answers