Terraform 无法使用第三方提供商
Terraform unable to use third party providers
描述:
我正在尝试为 Terraform 使用 Elasticsearch 提供程序。由于没有来自 Elastic 或 Hashicorp 的官方版本,我正在尝试使用社区版本“https://registry.terraform.io/providers/phillbaker/elasticsearch/latest”.
Terraform 版本: Terraform v0.14.4
代码:
我试图将所有内容都放在 1 个 .tf 文件中。我还尝试为 Hashicorp 推荐的资源创建一个单独的模块。两种方法都会生成相同的错误消息。
terraform {
required_providers {
elk = {
source = "phillbaker/elasticsearch"
version = "1.5.1"
}
}
}
provider "elk" {
url = "https://<my_elk_server>"
}
resource "elasticsearch_index" "index" {
name = var.elasticsearch_index_name
}
问题:
terraform init
由于某种原因无法在 Terraform Registry 中找到合适的提供程序。
Initializing the backend...
Initializing provider plugins...
- Finding latest version of hashicorp/elasticsearch...
- Finding phillbaker/elasticsearch versions matching "1.5.1"...
- Installing phillbaker/elasticsearch v1.5.1...
- Installed phillbaker/elasticsearch v1.5.1 (self-signed, key ID 02AD42CD82B6A957)
Partner and community providers are signed by their developers.
If you'd like to know more about provider signing, you can read about it here:
Error: Failed to query available provider packages
https://www.terraform.io/docs/plugins/signing.html
Could not retrieve the list of available versions for provider
hashicorp/elasticsearch: provider registry registry.terraform.io does not have
a provider named registry.terraform.io/hashicorp/elasticsearch
If you have just upgraded directly from Terraform v0.12 to Terraform v0.14
then please upgrade to Terraform v0.13 first and follow the upgrade guide for
that release, which might help you address this problem.
没有生成 tfstate 文件。
如何使用 Terraform Registry 中的第三方提供商?
在您的 required_providers
块中,您已告诉 Terraform 您打算在该模块中将此提供程序称为“elk”:
elk = {
source = "phillbaker/elasticsearch"
version = "1.5.1"
}
通常,您会将提供商的本地名称设置为与提供商源地址的“类型”部分相同,如下所示:
elasticsearch = {
source = "phillbaker/elasticsearch"
version = "1.5.1"
}
如果您以这种方式更改本地名称,那么在模块中的其他地方使用对 elasticsearch
的引用应该按照您的意图引用社区提供者。
请注意,这意味着您还需要更改 provider
块,使其具有匹配的本地名称:
provider "elasticsearch" {
url = "https://<my_elk_server>"
}
此处的另一种方法是继续使用 elk
作为名称,然后更改其余配置以正确引用该非默认名称。我不 推荐 这样做,因为通常我希望本地名称仅在您的模块依赖于具有相同类型名称的两个提供者的异常情况下才会与类型不匹配,但是我提到这一点是希望它有助于理解 Terraform 语言在未明确给出时如何推断提供者依赖关系:
terraform {
required_providers {
elk = {
source = "phillbaker/elasticsearch"
version = "1.5.1"
}
}
}
# "elk" here is matched with the local names in the
# required_providers block, so this will work.
provider "elk" {
url = "https://<my_elk_server>"
}
# This "elasticsearch_" prefix causes Terraform to look
# for a provider with the local name "elasticsearch"
# by default...
resource "elasticsearch_index" "index" {
# ...so if you've given the provider a different local
# name then you need to associate the resource with
# the provider configuration explicitly:
provider = elk
name = var.elasticsearch_index_name
}
我预计大多数 Terraform 用户会发现上述方法令人惊讶,因此为了使用熟悉的 Terraform 习惯用法,我建议改为按照我的第一个建议将本地名称重命名为 elasticsearch
,然后允许自动资源到提供者关联工作。
所以,经过测试,似乎将整个代码放在同一个 .tf 文件中就可以了。
terraform {
required_providers {
elasticsearch = {
source = "phillbaker/elasticsearch"
version = "1.5.1"
}
}
}
provider "elasticsearch" {
url = "http://127.0.0.1:9200"
}
resource "elasticsearch_index" "index" {
name = var.index_name
}
如果你想为它创建一个单独的模块,你可以从另一个模块中获取它:
module "elastic" {
index_name = var.index_name
source = "./modules/elastic"
}
查看 Martin 的回答以获取更多信息。
描述: 我正在尝试为 Terraform 使用 Elasticsearch 提供程序。由于没有来自 Elastic 或 Hashicorp 的官方版本,我正在尝试使用社区版本“https://registry.terraform.io/providers/phillbaker/elasticsearch/latest”.
Terraform 版本: Terraform v0.14.4
代码:
我试图将所有内容都放在 1 个 .tf 文件中。我还尝试为 Hashicorp 推荐的资源创建一个单独的模块。两种方法都会生成相同的错误消息。
terraform {
required_providers {
elk = {
source = "phillbaker/elasticsearch"
version = "1.5.1"
}
}
}
provider "elk" {
url = "https://<my_elk_server>"
}
resource "elasticsearch_index" "index" {
name = var.elasticsearch_index_name
}
问题:
terraform init
由于某种原因无法在 Terraform Registry 中找到合适的提供程序。
Initializing the backend...
Initializing provider plugins...
- Finding latest version of hashicorp/elasticsearch...
- Finding phillbaker/elasticsearch versions matching "1.5.1"...
- Installing phillbaker/elasticsearch v1.5.1...
- Installed phillbaker/elasticsearch v1.5.1 (self-signed, key ID 02AD42CD82B6A957)
Partner and community providers are signed by their developers.
If you'd like to know more about provider signing, you can read about it here:
Error: Failed to query available provider packages
https://www.terraform.io/docs/plugins/signing.html
Could not retrieve the list of available versions for provider
hashicorp/elasticsearch: provider registry registry.terraform.io does not have
a provider named registry.terraform.io/hashicorp/elasticsearch
If you have just upgraded directly from Terraform v0.12 to Terraform v0.14
then please upgrade to Terraform v0.13 first and follow the upgrade guide for
that release, which might help you address this problem.
没有生成 tfstate 文件。
如何使用 Terraform Registry 中的第三方提供商?
在您的 required_providers
块中,您已告诉 Terraform 您打算在该模块中将此提供程序称为“elk”:
elk = {
source = "phillbaker/elasticsearch"
version = "1.5.1"
}
通常,您会将提供商的本地名称设置为与提供商源地址的“类型”部分相同,如下所示:
elasticsearch = {
source = "phillbaker/elasticsearch"
version = "1.5.1"
}
如果您以这种方式更改本地名称,那么在模块中的其他地方使用对 elasticsearch
的引用应该按照您的意图引用社区提供者。
请注意,这意味着您还需要更改 provider
块,使其具有匹配的本地名称:
provider "elasticsearch" {
url = "https://<my_elk_server>"
}
此处的另一种方法是继续使用 elk
作为名称,然后更改其余配置以正确引用该非默认名称。我不 推荐 这样做,因为通常我希望本地名称仅在您的模块依赖于具有相同类型名称的两个提供者的异常情况下才会与类型不匹配,但是我提到这一点是希望它有助于理解 Terraform 语言在未明确给出时如何推断提供者依赖关系:
terraform {
required_providers {
elk = {
source = "phillbaker/elasticsearch"
version = "1.5.1"
}
}
}
# "elk" here is matched with the local names in the
# required_providers block, so this will work.
provider "elk" {
url = "https://<my_elk_server>"
}
# This "elasticsearch_" prefix causes Terraform to look
# for a provider with the local name "elasticsearch"
# by default...
resource "elasticsearch_index" "index" {
# ...so if you've given the provider a different local
# name then you need to associate the resource with
# the provider configuration explicitly:
provider = elk
name = var.elasticsearch_index_name
}
我预计大多数 Terraform 用户会发现上述方法令人惊讶,因此为了使用熟悉的 Terraform 习惯用法,我建议改为按照我的第一个建议将本地名称重命名为 elasticsearch
,然后允许自动资源到提供者关联工作。
所以,经过测试,似乎将整个代码放在同一个 .tf 文件中就可以了。
terraform {
required_providers {
elasticsearch = {
source = "phillbaker/elasticsearch"
version = "1.5.1"
}
}
}
provider "elasticsearch" {
url = "http://127.0.0.1:9200"
}
resource "elasticsearch_index" "index" {
name = var.index_name
}
如果你想为它创建一个单独的模块,你可以从另一个模块中获取它:
module "elastic" {
index_name = var.index_name
source = "./modules/elastic"
}
查看 Martin 的回答以获取更多信息。