Terraform: aws_instance: resource name can't contain dash "-"

Created on 5 Oct 2017  ยท  2Comments  ยท  Source: hashicorp/terraform

Hi there, I encountered Error when I named ec2 instance "-foo".

Terraform Version

Terraform v0.10.7

Terraform Configuration Files

resource "aws_instance" "-foo" {
...
}

Debug Output

Full debug output can be obtained by running Terraform with the environment variable TF_LOG=trace. Please create a GitHub Gist containing the debug output. Please do _not_ paste the debug output in the issue, since debug output is long.

Debug output may contain sensitive information. Please review it before posting publicly, and if you are concerned feel free to encrypt the files using the HashiCorp security public key.

Crash Output

* aws_instance.-foo: -foo: resource name can only contain letters, numbers, dashes, and underscores.

Expected Behavior

Above error message shows to allow resource name can contain dash,
but "-foo" occurred an error.
("foo" and "f-oo" is OK.)

Actual Behavior

error occured

Steps to Reproduce

Important Factoids

References

bug config

Most helpful comment

Hi @koooge! Sorry for this confusing behavior, and thanks for reporting it.

In this case it is the error message that is incorrect, or at least _imprecise_. It would be more accurate to say that in addition to those restrictions the resource name must start with a letter. A dash is not allowed at the start of a name because names are used as identifiers elsewhere in the language and a leading dash could be ambiguous with a negation sign in some cases. This limitation also avoids other potential problematic situations such as names on the command line being misinterpreted as flags, etc.

This message has actually already been updated as part of the work for Terraform v0.12, which is now merged into master. The new message is:

A name must start with a letter and may contain only letters, digits, underscores, and dashes.

This updated message will be included in the v0.12.0 final release, and can already been seen in the v0.12.0-alpha1 preview release. Because of that, I'm going to close this out. Thanks again for reporting this!

All 2 comments

Hi @koooge! Sorry for this confusing behavior, and thanks for reporting it.

In this case it is the error message that is incorrect, or at least _imprecise_. It would be more accurate to say that in addition to those restrictions the resource name must start with a letter. A dash is not allowed at the start of a name because names are used as identifiers elsewhere in the language and a leading dash could be ambiguous with a negation sign in some cases. This limitation also avoids other potential problematic situations such as names on the command line being misinterpreted as flags, etc.

This message has actually already been updated as part of the work for Terraform v0.12, which is now merged into master. The new message is:

A name must start with a letter and may contain only letters, digits, underscores, and dashes.

This updated message will be included in the v0.12.0 final release, and can already been seen in the v0.12.0-alpha1 preview release. Because of that, I'm going to close this out. Thanks again for reporting this!

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.

Was this page helpful?
0 / 5 - 0 ratings