我想创建一个Azure Redis缓存,并希望提供从不同SKU中选择的选项。不支持允许的值参数,因此我无法提及其他SKU。有什么办法可以提吗?
答案 0 :(得分:0)
您已经知道,到目前为止,terraform中不支持allowed values参数。
如果要在输入变量时提及允许的值,可以使用这样的变量描述,
variable "SKU" {
description = "which SKU do you want (options: Basic,Standard,Premium)"
type = "string"
}
或者,作为Github中this issue的一种解决方法。您可以使用本地地图和键查找并添加值检查器。
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 }"
}
希望这可以为您提供帮助。
答案 1 :(得分:0)
这将在Terraform 0.13中提供。对于您的特定用例,如下所示:
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'."
}
}