cloudposse / terraform-aws-dynamodb

Terraform module that implements AWS DynamoDB with support for AutoScaling
https://cloudposse.com/accelerate
Apache License 2.0
86 stars 113 forks source link

Unable to use underscore in tables names #139

Open nadge opened 1 week ago

nadge commented 1 week ago

Describe the Bug

I am currently working on recreating existing infrastructure using terraform. I am using this package to recreate some Dynamo Tables but unfortunately they need to retain their existing name which contains underscores.

when I set the name with underscores in terraform these seem to be removed when applied and the result is applied without underscores.

Tested with default AWS module and this does not happen

Expected Behavior

When using underscores in name of dynamo table the table is created using these underscores

Steps to Reproduce

create terraform module

module "dynamodb_table" {
  source                        = "cloudposse/dynamodb/aws"
  name                          = "test_underscore"
  hash_key                      = "test_id"
  enable_autoscaler             = false
  enable_point_in_time_recovery = false
}

See plan has name without underscores:

+ resource "aws_dynamodb_table" "default" {
      + arn                         = (known after apply)
      + billing_mode                = "PROVISIONED"
      + deletion_protection_enabled = false
      + hash_key                    = "test_id"
      + id                          = (known after apply)
      + name                        = "testunderscore"
      + read_capacity               = 5
      + stream_arn                  = (known after apply)
      + stream_enabled              = false
      + stream_label                = (known after apply)
      + stream_view_type            = (known after apply)
      + tags                        = {
          + "Name" = "testunderscore"
        }
      + tags_all                    = {
          + "Name" = "testunderscore"
        }
      + write_capacity              = 5

      + attribute {
          + name = "test_id"
          + type = "S"
        }

      + point_in_time_recovery {
          + enabled = false
        }

      + server_side_encryption {
          + enabled     = true
          + kms_key_arn = (known after apply)
        }

      + ttl {
          + attribute_name = "Expires"
          + enabled        = true
        }
    }

Finally when applied see table has underscores removed:

image

Screenshots

No response

Environment

Mac OS (M3) terraform 1.7.5

Additional Context

No response

nitrocode commented 1 day ago

See

https://github.com/cloudposse/terraform-aws-dynamodb/blob/f312393109ce3d8688e75c671c6746a9fc4a49aa/context.tf#L201-L209

Try setting the following regex_replace_chars and see if it makes a difference

module "" {
  # ...

  regex_replace_chars = "/[^a-zA-Z0-9_-]/"

  # ...
}