Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DynamoDB table not replaced when changing name or range_key of local_secondary_index #12334

Closed
tjoris opened this issue Mar 10, 2020 · 6 comments · Fixed by #12335
Closed

DynamoDB table not replaced when changing name or range_key of local_secondary_index #12334

tjoris opened this issue Mar 10, 2020 · 6 comments · Fixed by #12335
Assignees
Labels
bug Addresses a defect in current functionality. service/dynamodb Issues and PRs that pertain to the dynamodb service.
Milestone

Comments

@tjoris
Copy link
Contributor

tjoris commented Mar 10, 2020

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

  • Terraform v0.12.18
  • provider.aws v2.52.0

Affected Resource(s)

  • aws_dynamodb_table

Terraform Configuration Files

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
  }
}

Expected Behavior

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
        }
    }

Actual Behavior

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
        }
    }

Steps to Reproduce

  1. terraform apply
  2. in the terraform configuration file, change the name of the local secondary index from "lsi-created" to "si-created"
  3. terraform apply

Important Factoids

References

@ghost ghost added the service/dynamodb Issues and PRs that pertain to the dynamodb service. label Mar 10, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Mar 10, 2020
@tjoris
Copy link
Contributor Author

tjoris commented Mar 11, 2020

I tried to add a test in
e3d8a7c
Is there something else that I can do to help progress this issue?

tjoris pushed a commit to InventiveDesigners/terraform-provider-aws that referenced this issue Mar 12, 2020
@jeffbski-rga
Copy link

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.

@bflad bflad added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Sep 18, 2020
@bflad
Copy link
Contributor

bflad commented Sep 18, 2020

@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 👍

anGie44 added a commit that referenced this issue Sep 18, 2020
…e-for-lsi-change

Replace DyanmoDB table when local secondary index changes (#12334)
@anGie44 anGie44 added this to the v3.8.0 milestone Sep 18, 2020
@anGie44
Copy link
Contributor

anGie44 commented Sep 18, 2020

The PR fixing this behavior has been merged and will release with v3.8.0 of the Terraform AWS Provider, likely out next Thursday.

@ghost
Copy link

ghost commented Sep 24, 2020

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!

@ghost
Copy link

ghost commented Oct 19, 2020

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!

@ghost ghost locked as resolved and limited conversation to collaborators Oct 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/dynamodb Issues and PRs that pertain to the dynamodb service.
Projects
None yet
4 participants