Skip to content

Instantly share code, notes, and snippets.

@john-auld
Created October 10, 2019 22:41
Show Gist options
  • Save john-auld/0b61279bff12d4341c8f859fb211392a to your computer and use it in GitHub Desktop.
Save john-auld/0b61279bff12d4341c8f859fb211392a to your computer and use it in GitHub Desktop.
Terraform variable validation example

Validate allowed values of a terraform variable

variable "workspace_name_allowed_values" {
  description = "Permitted values of terraform workspace"
  type        = "list"
  default     = ["dev", "sit", "prod"]
}

resource "null_resource" "is_workspace_name_allowed" {
  count = "${contains(var.workspace_name_allowed_values, "${terraform.workspace}") == true ? 0 : 1}"

  "ERROR: Invalid terraform workspace name: ${terraform.workspace}" = true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment