首页 > 解决方案 > 带有 DynamoDB 后端的 terraform:创建新工作区时出现 400 Bad Request

问题描述

我有 terraform 堆栈,可以在 DynamoDB 中保持锁定:

terraform {
  backend "s3" {
    bucket  = "bucketname"
    key     = "my_key"
    encrypt = "true"
    role_arn = "arn:aws:iam::11111111:role/my_role"
    dynamodb_table = "tf-remote-state-lock"
  }
}

当我运行terraform workspace new test它失败并出现(相当误导)错误:

failed to lock s3 state: 2 errors occurred:
* ResourceNotFoundException: Requested resource not found
* ResourceNotFoundException: Requested resource not found

如果我打开,TF_LOG=DEBUG我会看到400 Bad Request有关 pastebin 的更多详细信息)

我做错了什么以及如何解决?

标签: amazon-dynamodbterraformterraform-provider-aws

解决方案


解决方案:terraform workspace whatsoever应该只在 AFTER 之后朗姆酒terraform init。如果你已经TF_WORKSPACE设置好了,你可能会在tf init说工作空间不存在的时候报错,所以你tf ws new之前可能会有朗姆酒的诱惑tf init。不要这样做,只是在之后设置。TF_WORKSPACEtf init


推荐阅读