I am trying to use a variable validation in terraform, i am trying to deny role editor and owner while creating new project, however want to keep excpetions for some project. below is my terraform code.
i am getting errors in the validation block for using another variable
can some one help me with this ?
variable "iam_role_member" {
type = map(list(string))
validation {
condition = length(setintersection(toset(keys(var.iam_role_member)),toset["roles/owner","roles/editor"]))) == 0 || length(var.allowed_project_ids) > 0
error_message = "Project cannot have owner or editor roles."
}
}
variable "allowed_project_ids" {
type = list(string)
default = []
}
data "github_repository_file" "exception_project_list_id" {
repository = "organization/exception-project-list-id"
file_path = "project-ids.txt"
}
locals {
exception_project_ids = length(var.allowed_project_ids) > 0 ? data.github_repository_file.exception_project_list_id.content : []
project_ids = length(local.exception_project_ids) > 0 ? concat(local.exception_project_ids, var.allowed_project_ids) : var.allowed_project_ids
}
variable "project_ids" {
type = list(string)
default = local.project_ids
}