Cannot add module starting with number


We have updated our TF version to the 0.13.4 one and now when we try to add a domain that we have purchased that starts with Numbers “” it will not pass terraform init as it will throw out:

A name must start with a letter or underscore and may contain only letters,

digits, underscores, and dashes.

This is not good as we do have pre-existing domains that are using numbers as starters and future ones some of them might require to user numbers:

module “007example” {
source = “./amazingsitestocome”
domain = “

Is there a way to escape that and the domain to be successfully added via terraform instead of manually adding and even old ones modifying, as our other resources and modules do not start with numbers only some domains.

Hi @vasila,

This is unfortunately one of the steps where the Terraform v0.12 upgrade guide recommended changing it prior to upgrading, so that you’d be able to more easily use the tools in Terraform v0.11 to handle fixing the invalid module name. It was a bug that Terraform v0.11 and earlier allowed a name starting with a digit, and we needed to fix that bug in v0.12 in order to make other improvements to the language work correctly.

Since you saw this error during terraform init, hopefully you’ve not yet run terraform apply with Terraform v0.12 or later and so you can still return back to Terraform v0.11 and run through the documented upgrade steps.

One of those steps will be to rename your module in configuration to not start with a digit and then use terraform state mv to change the state to match it, so that Terraform won’t think you are trying to destroy the old module and create a new one in its place. But I’d strongly suggest running through the entire upgrade guide as documented because it might find other things that would be easier to deal with before you upgrade, and it will also allow you to automatically update your configuration to use the idiomatic syntax for Terraform v0.12 and later.

Once you’ve completed the upgrade steps for Terraform v0.12, you can then use the Terraform v0.13 upgrade guide to switch to Terraform v0.13, and then finally the Terraform v0.14 upgrade guide to get to v0.14, which is the latest release at the time of writing.

Hey @apparentlymart ,

Thank you for your detailed reply. Unfortunately I wasn’t aware of the change and as mentioned I am already on a 0.13.4 version, as this issue didn’t popup before the upgrade towards 0.13.4 was made.

With the above said I am not sure how exactly “rename your module” would work, as in this case the module is an already purchased domain, this means that it cannot be altered or its values and itself won’t be working or be added. It’s one thing to rename a network, cluster, owasp and etc, but you cannot rename a “domain” or at least nothing comes to mind that can do the magic right now without altering it’s name.

From your answer I am discourage that there is a workaround solution to my case as I said since most likely in the future there will be another domain/domains that will start with numbers.

Scratch that, if I edit only the module name:

module “007example” {
source = “./amazingsitestocome”
domain = “”

to the following one:

module “test007example” {
source = “./amazingsitestocome”
domain = “”

It will create the needed records for the proper domain ‘’, good to be closed :slight_smile:

Indeed, sorry for being unspecific: I was meaning only to rename the module, not to change any of the values you’re passing into it.

1 Like