通过 Terraform 部署 AWS WorkSpaces 时出现 ValidationException 错误

ValidationException error when deploying AWS WorkSpaces via terraform

我一直在尝试使用 Terraform 部署 AWS WorkSpaces 基础设施。代码本身通过了验证和计划检查,但未能应用。

来源:

module "networking" {
  source = "../../modules/networking"
  region = var.region
  main_cidr_block = var.main_cidr_block
  cidr_block_1 = var.cidr_block_1
  cidr_block_2 = var.cidr_block_2
  size = var.size
}

resource "aws_directory_service_directory" "main" {
  name     = var.aws_ds_name
  password = var.aws_ds_passwd
  size     = var.size
  type = "SimpleAD"
  vpc_settings {
    vpc_id     = module.networking.main_vpc
    subnet_ids = ["${module.networking.private-0}", "${module.networking.private-1}"]
  }
}

resource "aws_workspaces_directory" "main" {
  directory_id = aws_directory_service_directory.main.id
  subnet_ids   = ["${module.networking.private-0}", "${module.networking.private-1}"]
}

resource "aws_workspaces_ip_group" "main" {
  name        = "Contractors."
  description = "Main IP access control group"


  rules {
    source      = "10.0.0.0/16"
    description = "Contractors"
  }
}

错误代码:

ValidationException: 2 validation errors detected: Value at 'password' failed to satisfy constraint: Member must satisfy regular expression pattern: (?=^.{8,64}$)((?=.*\d)(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[^A-Za-z0-9\s])(?=.*[a-z])|(?=.*[^A-Za-z0-9\s])(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[A-Z])(?=.*[^A-Za-z0-9\s]))^.*; Value '' at 'name' failed to satisfy constraint: Member must satisfy regular expression pattern: ^([a-zA-Z0-9]+[\.-])+([a-zA-Z0-9])+$
        status code: 400, request id: 073f6e61-775e-4ff9-a88e-e1eab97f8519

  on modules/workspaces/workspaces.tf line 10, in resource "aws_directory_service_directory" "main":
  10: resource "aws_directory_service_directory" "main" {

我知道这是 username/passwords 的正则表达式问题,但我现在还没有设置任何用户,出于测试原因我已经重置了安全策略。

以前有人遇到过这个问题吗?

AWS API for the directory service enforces a constraint on the password attribute 并匹配您在 运行 terraform apply:

时在该错误中看到的内容

Password

The password for the directory administrator. The directory creation process creates a directory administrator account with the user name Administrator and this password.

If you need to change the password for the administrator account, you can use the ResetUserPassword API call.

Type: String

Pattern:

(?=^.{8,64}$)((?=.*\d)(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[^A-Za-z0-9\s])(?=.*[a-z])|(?=.*[^A-Za-z0-9\s])(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[A-Z])(?=.*[^A-Za-z0-9\s]))^.*

Required: Yes

通常 Terraform 能够使用计划或验证命令对此进行验证,但不幸的是,AWS 提供商是 currently missing an appropriate ValidateFunc,因此它只会在申请时失败,而不是在几分钟内失败。

如果您希望在计划或验证时捕获它,那么您应该在 provider issue tracker 上提出功能请求。