问题描述
我有一个用这个 terraform 创建的 DynamoDB 表:
resource "aws_dynamodb_table" "materials_table" {
name = "materials"
hash_key = "MATERIAL"
billing_mode = "PROVISIONED"
read_capacity = 5
write_capacity = 5
attribute {
name = "MATERIAL"
type = "S"
}
}
表格已成功填充(有 4 条记录,如 this post 中所述)但为了解决问题(在该帖子中)我添加了一个字段 PK
并将其设置为 { {1}} 字段,如下:
hash_key
在运行 resource "aws_dynamodb_table" "materials_table" {
name = "materials"
hash_key = "PK"
billing_mode = "PROVISIONED"
read_capacity = 5
write_capacity = 5
attribute {
name = "PK"
type = "S"
}
}
时,这导致了以下错误:
terraform apply
我需要在 Error: error creating DynamoDB Table: ResourceInUseException: Table already exists: materials
中做什么才能让更改被接受?
解决方法
不允许更改 DynamoDB 中的某些属性,例如更改分区键、添加本地二级索引等。
当发生此类更改时,它将需要替换资源,并尝试删除并重新创建资源。在此过程中,如果表已经存在,则失败。
唯一的选择是删除堆栈或手动删除 DynamoDB 表并让模板重新创建它。或重命名表。
Documentation 表示将强制使用新资源
hash_key -(必需,强制新资源)用作 哈希(分区)键。