Hi there, I encountered Error when I named ec2 instance "-foo".
Terraform v0.10.7
resource "aws_instance" "-foo" {
...
}
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.
* aws_instance.-foo: -foo: resource name can only contain letters, numbers, dashes, and underscores.
Above error message shows to allow resource name can contain dash,
but "-foo" occurred an error.
("foo" and "f-oo" is OK.)
error occured
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.
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:
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!