terraform-provider-aws icon indicating copy to clipboard operation
terraform-provider-aws copied to clipboard

DynamoDB Table with replica v2019.11.21 and PAY_PER_REQUEST makes GSI modifications in a loop

Open Seldaek opened this issue 4 years ago • 4 comments

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.24

  • provider.aws v2.58.0
  • provider.template v2.1.2

Affected Resource(s)

  • aws_dynamodb_table

Terraform Configuration Files

resource "aws_dynamodb_table" "sessions_us-west-2" {
  name           = "sessions"
  billing_mode   = "PAY_PER_REQUEST"
  hash_key       = "SessionId"

  attribute {
    name = "SessionId"
    type = "S"
  }

  attribute {
    name = "UserId"
    type = "N"
  }

  attribute {
    name = "ExpiresAt"
    type = "N"
  }

  global_secondary_index {
    name               = "UserSessionsIndex"
    hash_key           = "UserId"
    range_key          = "ExpiresAt"
    projection_type    = "INCLUDE"
    non_key_attributes = ["UserId", "ExpiresAt", "SessionId"]
  }

  ttl {
    attribute_name = "ExpiresAt"
    enabled        = true
  }

  server_side_encryption {
    enabled = true
  }

  stream_enabled = true
  stream_view_type = "NEW_AND_OLD_IMAGES"

  replica {
    region_name = "eu-west-1"
  }
}

Expected Behavior

terraform apply should not do any changes

Actual Behavior

Every time I run, it wants to update the GSI with the same data..

      + global_secondary_index {
          + hash_key           = "UserId"
          + name               = "UserSessionsIndex"
          + non_key_attributes = [
              + "UserId",
              + "ExpiresAt",
              + "SessionId",
            ]
          + projection_type    = "INCLUDE"
          + range_key          = "ExpiresAt"
          + read_capacity      = 0
          + write_capacity     = 0
        }
      - global_secondary_index {
          - hash_key           = "UserId" -> null
          - name               = "UserSessionsIndex" -> null
          - non_key_attributes = [
              - "UserId",
              - "ExpiresAt",
              - "SessionId",
            ] -> null
          - projection_type    = "INCLUDE" -> null
          - range_key          = "ExpiresAt" -> null
          - read_capacity      = 0 -> null
          - write_capacity     = 0 -> null
        }

I tried specifying the read_capacity/write_capacity as that was the only missing thing I saw, which might be causing this, but it doesn't help, still does the same with this:

  global_secondary_index {
    name               = "UserSessionsIndex"
    hash_key           = "UserId"
    range_key          = "ExpiresAt"
    projection_type    = "INCLUDE"
    non_key_attributes = ["UserId", "ExpiresAt", "SessionId"]
    read_capacity      = 0
    write_capacity     = 0
  }

Note that it should not be required to specify these as we are using PAY_PER_REQUEST billing_mode.

Steps to Reproduce

  1. terraform apply, twice

References

  • #12342 / cc @cmonty (thanks for the implementation btw, this came just as I needed it! :)

Seldaek avatar Apr 17 '20 09:04 Seldaek

Thanks @Seldaek!

We had this come up in testing and I think is related to #3828

cmonty avatar Apr 17 '20 13:04 cmonty

Ah thanks that one has a workaround in https://github.com/terraform-providers/terraform-provider-aws/issues/3828#issuecomment-569041696 👍

Seldaek avatar Apr 17 '20 15:04 Seldaek

Hi Y'all, we are currently tracking this issue alongside #671.

We've added #671 to our team's prioritization board and are planning to address it and its related PRs in a near-term release. As this issue is related, we'll keep an eye on this and check back to see if our solution to #671 fixes/closes this as well.

Thanks!

maryelizbeth avatar Aug 17 '20 23:08 maryelizbeth

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!

github-actions[bot] avatar Aug 08 '22 17:08 github-actions[bot]

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.

github-actions[bot] avatar Oct 09 '22 02:10 github-actions[bot]