我需要验证 terraform 中的变量。变量的内容只能是0-9、az和AZ。我尝试使用以下代码:
variable "application_name" {
type = string
default = "foo"
validation {
# regex(...) fails if it cannot find a match
condition = can(regex("([0-9A-Za-z])", var.application_name))
error_message = "For the application_name value only a-z, A-Z and 0-9 are allowed."
}
}
Run Code Online (Sandbox Code Playgroud)
这不起作用。当我在变量中设置 abcd- 时,验证返回 true。
我该如何修复正则表达式?
感谢帮助 ;)
@vgersh99 这对我不起作用:
variable "application_name" {
type = string
default = "foo"
validation {
# regex(...) fails if it cannot find a match
condition = can(regex("[^[:alnum:]]", var.application_name))
error_message = "For the application_name …Run Code Online (Sandbox Code Playgroud) terraform 验证后收到以下错误消息:
#################################################### #############
错误:资源“aws_ecs_task_definition”中 .terraform/modules/backend_deployment/task_definition.tf 第 4 行的属性值类型不正确:
需要兼容性=“FARGATE”
属性“requires_compatibility”的值不合适:需要一组字符串。
#################################################### #############
这是我的任务定义:
resource "aws_ecs_task_definition" "task_definition" {
family = join("-", [local.cluster_values.backend_name, local.cluster_values.environment, local.cluster_values.random_id])
network_mode = "awsvpc"
requires_compatibilities = "FARGATE"
cpu = 256
memory = 512
container_definitions = data.template_file.task_definition_template.rendered
task_role_arn = local.cluster_values.task_role
}
Run Code Online (Sandbox Code Playgroud)
Terraform-Doku 说道:
require_compatibility - (可选)任务所需的启动类型集。有效值为 EC2 和 FARGATE。
非常感谢您的帮助!