Skip to content

Input Validation - Combine two or more variables #25513

@galamiram

Description

@galamiram

Terraform

v0.12.26

Use-cases

When trying to enforce one variable is required not to be empty, if another variable is provided.

Attempted Solutions

variable "alias_record" {
  description = "The record name to associate with the RDS."
  type        = string
  default     = ""
}

variable "hosted_zone_name" {
  description = "The hosted zone name, where to create the alias record. Requieres if alias_record provided"
  type        = string
  default     = ""

  validation {
    condition     = var.alias_record != "" ? var.hosted_zone_name != "" : true
    error_message = "ERROR: hosted_zone_name can not be empty if alias_record provided."
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    configcustom-conditionsFeedback on variable validation, preconditions. postconditions, checks, and test assertionsenhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions