Terraform v0.13.5
Basic as-is example from https://www.terraform.io/docs/configuration/provider-requirements.html#handling-local-name-conflicts
terraform {
required_providers {
# In the rare situation of using two providers that
# have the same type name -- "http" in this example --
# use a compound local name to distinguish them.
hashicorp_http = {
source = "hashicorp/http"
version = "~> 2.0"
}
mycorp_http = {
source = "mycorp/http"
version = "~> 1.0"
}
}
}
# References to these providers elsewhere in the
# module will use these compound local names.
provider "mycorp_http" {
# ...
}
data "http" "example" {
provider = hashicorp_http
url = "https://checkpoint-api.hashicorp.com/v1/check/terraform"
# Optional request headers
request_headers = {
Accept = "application/json"
}
}
Error: Invalid provider local name
on main.tf line 36, in terraform:
36: hashicorp_http = {
37: source = "hashicorp/http"
38: version = "~> 2.0"
39: }
hashicorp_http is an invalid provider local name: must contain only letters,
digits, and dashes, and may not use leading or trailing dashes
Error: Invalid provider local name
on main.tf line 40, in terraform:
40: mycorp_http = {
41: source = "mycorp/http"
42: version = "~> 1.0"
43: }
mycorp_http is an invalid provider local name: must contain only letters,
digits, and dashes, and may not use leading or trailing dashes
Error: Invalid provider local name
on main.tf line 49:
49: provider "mycorp_http" {
mycorp_http is an invalid provider local name: must contain only letters,
digits, and dashes, and may not use leading or trailing dashes
Error: Invalid provider local name
on main.tf line 54, in data "http" "example":
54: provider = hashicorp_http
hashicorp_http is an invalid provider local name: must contain only letters,
digits, and dashes, and may not use leading or trailing dashes
Full debug:
2020/10/22 17:59:26 [INFO] Terraform version: 0.13.5
2020/10/22 17:59:26 [INFO] Go runtime version: go1.14.7
2020/10/22 17:59:26 [INFO] CLI args: []string{"/usr/local/Cellar/tfenv/2.0.0/versions/0.13.5/terraform", "init", "-upgrade=false"}
2020/10/22 17:59:26 [DEBUG] Attempting to open CLI config file: /Users/kryvenkd/.terraformrc
2020/10/22 17:59:26 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2020/10/22 17:59:26 [DEBUG] ignoring non-existing provider search directory terraform.d/plugins
2020/10/22 17:59:26 [DEBUG] ignoring non-existing provider search directory /Users/kryvenkd/.terraform.d/plugins
2020/10/22 17:59:26 [DEBUG] ignoring non-existing provider search directory /Users/kryvenkd/Library/Application Support/io.terraform/plugins
2020/10/22 17:59:26 [DEBUG] ignoring non-existing provider search directory /Library/Application Support/io.terraform/plugins
2020/10/22 17:59:26 [INFO] CLI command args: []string{"init", "-upgrade=false"}
2020/10/22 17:59:28 [INFO] Terraform version: 0.13.5
2020/10/22 17:59:28 [INFO] Go runtime version: go1.14.7
2020/10/22 17:59:28 [INFO] CLI args: []string{"/usr/local/Cellar/tfenv/2.0.0/versions/0.13.5/terraform", "destroy", "-auto-approve", "-input=false", "-lock=false"}
2020/10/22 17:59:28 [DEBUG] Attempting to open CLI config file: /Users/kryvenkd/.terraformrc
2020/10/22 17:59:28 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2020/10/22 17:59:28 [DEBUG] ignoring non-existing provider search directory terraform.d/plugins
2020/10/22 17:59:28 [DEBUG] ignoring non-existing provider search directory /Users/kryvenkd/.terraform.d/plugins
2020/10/22 17:59:28 [DEBUG] ignoring non-existing provider search directory /Users/kryvenkd/Library/Application Support/io.terraform/plugins
2020/10/22 17:59:28 [DEBUG] ignoring non-existing provider search directory /Library/Application Support/io.terraform/plugins
2020/10/22 17:59:28 [INFO] CLI command args: []string{"destroy", "-auto-approve", "-input=false", "-lock=false"}
Example from official web-site should work.
It doesn't.
terraform initterraform applyHi @dee-kryvenko! Thanks for reporting this.
I'm this case it is the documentation that is incorrect, rather than the implementation. Terraform does not allow underscores in this location because underscore is the separator between the provider local name and the rest of the resource type name in a name like aws_instance.
Maybe there's an enchantment opportunity rather than a document fix? Look from the usability standpoint, of course custom providers might have more than one word in their name to distinguish them, and there has to be some word separation. It doesn't allow camel case (understandably so - some file systems are case insensitive), you can't use dash or underscore either. Needs to allow something.
The local name can contain dashes; the limitation is on trailing or leading dashes.
So this is ok:
mycorp-http = {
source = "mycorp/http"
version = "~> 1.0"
}
But not this (trailing dash):
mycorp- = {
source = "mycorp/http"
version = "~> 1.0"
}
Ah cool, somehow I missed to test that. It is just a doc update then indeed. Thank you.
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
Ah cool, somehow I missed to test that. It is just a doc update then indeed. Thank you.