It seems that modifying a dynamo table is not allowed with terraform.
How would I go about adding a GSI to an existing table with terraform? I was previously doing it in python (with boto3 update_table
), but now trying to do it in Terraform. I don't want to lose data nor to have to do it manually.
This is the error I keep getting:
Error: error creating DynamoDB Table: ResourceInUseException: Table already exists
And my code:
# Create a DynamoDB table with GSIs.
resource "aws_dynamodb_table" "table" {
name = var.function_name
billing_mode = "PAY_PER_REQUEST"
hash_key = "PK" # partition key
range_key = "SK" # sort key
# Partition Key.
attribute {
name = "PK"
type = "S"
}
# Sort Key (datetime in UTC).
attribute {
name = "SK"
type = "S"
}
# Date (no time).
attribute {
name = "date"
type = "S"
}
# Define a GSI.
global_secondary_index {
name = "date-index"
hash_key = "date" # partition key
range_key = "SK"
projection_type = "ALL"
}
}