resource "aws_dynamodb_table" "tasks_dynamodb_table_promotionblobcleanup" {
name = "promotionblobcleanup"
billing_mode = "PAY_PER_REQUEST"
hash_key = "keyspace"
range_key = "blob_id"
attribute {
name = "keyspace"
type = "S"
}
attribute {
name = "blob_id"
type = "S"
}
attribute {
name = "created"
type = "S"
}
local_secondary_index {
name = "lsi-created"
range_key = "created"
projection_type = "ALL"
}
tags = {
Project = var.project
Environment = var.environment
}
}
The DynamoDB table should be replaced.
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LSI.html
Local secondary indexes on a table are created when the table is created.
https://www.terraform.io/docs/providers/aws/r/dynamodb_table.html#local_secondary_index
these can only be allocated at creation so you cannot change this definition after you have created the resource
Since a local secondary index can't be changed after a table is created, the table should be recreated when there is a change in one of the local secondary indexes.
This is the expected terraform output:
# aws_dynamodb_table.tasks_dynamodb_table_promotionblobcleanup must be replaced
-/+ resource "aws_dynamodb_table" "tasks_dynamodb_table_promotionblobcleanup" {
~ arn = "arn:aws:dynamodb:eu-west-1:067346078311:table/promotionblobcleanup" -> (known after apply)
billing_mode = "PAY_PER_REQUEST"
hash_key = "keyspace"
~ id = "promotionblobcleanup" -> (known after apply)
name = "promotionblobcleanup"
range_key = "blob_id"
- read_capacity = 0 -> null
+ stream_arn = (known after apply)
- stream_enabled = false -> null
+ stream_label = (known after apply)
+ stream_view_type = (known after apply)
tags = {
"Environment" = "development"
"Project" = "secp"
}
- write_capacity = 0 -> null
attribute {
name = "blob_id"
type = "S"
}
attribute {
name = "created"
type = "S"
}
attribute {
name = "keyspace"
type = "S"
}
- local_secondary_index { # forces replacement
- name = "lsi-created" -> null
- non_key_attributes = [] -> null
- projection_type = "ALL" -> null
- range_key = "created" -> null
}
+ local_secondary_index { # forces replacement
+ name = "si-created"
+ non_key_attributes = []
+ projection_type = "ALL"
+ range_key = "created"
}
~ point_in_time_recovery {
~ enabled = false -> (known after apply)
}
+ server_side_encryption {
+ enabled = (known after apply)
+ kms_key_arn = (known after apply)
}
- ttl {
- enabled = false -> null
}
}
The DynamoDB table is updated in-place.
But the local secondary index's name remains the same after the terraform apply
, because you can't make changes to a local secondary index after the table was created.
This is the actual terraform output:
# aws_dynamodb_table.tasks_dynamodb_table_promotionblobcleanup will be updated in-place
~ resource "aws_dynamodb_table" "tasks_dynamodb_table_promotionblobcleanup" {
arn = "arn:aws:dynamodb:eu-west-1:067346078311:table/promotionblobcleanup"
billing_mode = "PAY_PER_REQUEST"
hash_key = "keyspace"
id = "promotionblobcleanup"
name = "promotionblobcleanup"
range_key = "blob_id"
read_capacity = 0
stream_enabled = false
tags = {
"Environment" = "development"
"Project" = "secp"
}
write_capacity = 0
attribute {
name = "blob_id"
type = "S"
}
attribute {
name = "created"
type = "S"
}
attribute {
name = "keyspace"
type = "S"
}
- local_secondary_index {
- name = "lsi-created" -> null
- non_key_attributes = [] -> null
- projection_type = "ALL" -> null
- range_key = "created" -> null
}
+ local_secondary_index {
+ name = "si-created"
+ non_key_attributes = []
+ projection_type = "ALL"
+ range_key = "created"
}
point_in_time_recovery {
enabled = false
}
ttl {
enabled = false
}
}
terraform apply
terraform apply
I tried to add a test in
https://github.com/terraform-providers/terraform-provider-aws/pull/12335/commits/e3d8a7c48444cc98578dcaff18e080e56aa83873
Is there something else that I can do to help progress this issue?
I am also seeing this problem when I try to update an LSI index. However I found as a work around that I can add a new LSI index and it will pick up the change. I just cannot update an existing index. So that is unfortunate since now I have duplicate indexes and extra work for dynamo to update them, but I can continue until this is resolved.
@anGie44 while you're in the LSI neighborhood, I believe this one is pretty straightforward where ForceNew
is not present on all the configuration block nested attributes which the associated PR #12335 is fixing 👍
The PR fixing this behavior has been merged and will release with v3.8.0
of the Terraform AWS Provider, likely out next Thursday.
This has been released in version 3.8.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.
For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!
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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!
Most helpful comment
I am also seeing this problem when I try to update an LSI index. However I found as a work around that I can add a new LSI index and it will pick up the change. I just cannot update an existing index. So that is unfortunate since now I have duplicate indexes and extra work for dynamo to update them, but I can continue until this is resolved.