skip to Main Content

I want to create an Azure Redis Cache and want to give options to select from different SKUs. The allowed values argument is not supported and hence i cannot mention different SKUs. Is there any way to mention it?

2

Answers


  1. As you have known, the allowed values argument is not supported in terraform till now.

    If you want to mention allowed values when you input the variable, you could use a variable description like this,

    variable "SKU" {
      description = "which SKU do you want (options: Basic,Standard,Premium)"
      type = "string"
    }
    

    enter image description here

    Or, as a workaround from this issue in Github. You could use a local map and key lookup and add a value checker.

    variable "sku" {
      description = "which SKU do you want (options: Basic,Standard,Premium)"
      type = "string"
    
    }
    
    locals {
      sku_options = ["Basic","Standard","Premium" ]
     # or add this to precisely match the value that case sensitive, validate_sku = "${index(local.sku_options, var.sku)}"
    }
    
    resource "null_resource" "is_sku_name_valid" {
      count = "${contains(local.sku_options, var.sku) == true ? 0 : 1 }"
    
    }
    

    Hope this could help you.

    Login or Signup to reply.
  2. This will be available in Terraform 0.13. For your specific use case, this would look as below:

    variable "sku" {
      description = "which SKU do you want (options: Basic,Standard,Premium)"
      type = "string"
      validation {
        condition     = contains(["Basic", "Standard", "Premium"], var.sku)
        error_message = "Argument 'sku' must one of 'Basic', 'Standard', or 'Premium'."
      }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search