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

Unable to use underscore in tables names #139

Open
nadge opened this issue Nov 14, 2024 · 1 comment
Open

Unable to use underscore in tables names #139

nadge opened this issue Nov 14, 2024 · 1 comment
Labels
bug 🐛 An issue with the system

Comments

@nadge
Copy link

nadge commented Nov 14, 2024

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

@nadge nadge added the bug 🐛 An issue with the system label Nov 14, 2024
@nitrocode
Copy link
Member

See

variable "regex_replace_chars" {
type = string
default = null
description = <<-EOT
Terraform regular expression (regex) string.
Characters matching the regex will be removed from the ID elements.
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits.
EOT
}

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

module "" {
  # ...

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

  # ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An issue with the system
Projects
None yet
Development

No branches or pull requests

2 participants