Closed necro351 closed 5 months ago
I just ran into this as well. Also with a range key, but hash keys are probably about the same.
The error message I receive when trying to create a mistyped document is as follows:
ValidationException: One or more parameter values were invalid: Type mismatch for key SomeId expected: S actual: N
A workaround is tainting the table:
terraform taint aws_dynamodb_table.MyTable
The plan output then shows the changed attribute as two different blocks:
# aws_dynamodb_table.MyTable is tainted, so must be replaced
-/+ resource "aws_dynamodb_table" "MyTable" {
# (most things hidden)
+ attribute {
+ name = "SomeId"
+ type = "N"
}
- attribute {
- name = "SomeId" -> null
- type = "S" -> null
}
}
I also found a report of this happening with Global Secondary Indexes:
Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.
If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Terraform Version
Terraform Configuration Files
Expected Behavior
When you change the type of a range_key the table will need to be replaced as the application cannot use, e.g., a string-type range key (S) as a number-type (N), and certainly query scans will be in the unexpected/wrong order. I did not check, but I believe DynamoDB would just return errors to the application if it tried to use 'S' type attribute values for, e.g., an 'N' type attribute/range-key.
Given this, terraform should report the table must be replaced if you change the type.
Actual Behavior
Terraform says the infrastructure already matches and there is nothing to do when you change the type.
Steps to Reproduce