我的main.tf文件以开头
terraform {
required_version = ">= 0.13.7"
required_providers {
aws = {
source = "hashicorp/aws"
version = "= 2.32.0"
}
foobar = {
source = "terraform.foo.com/foo/bar"
}
}
}
这里的问题是foo/bar是我在本地开发的模块,所以我也有这个terraformrc文件:
provider_installation {
dev_overrides {
"terraform.foo.com/foo/bar" = "/Users/appuser/foobar/bin/darwin-amd64"
}
}
以下是我在运行✗ terraform init
时遇到的错误
Initializing the backend...
Initializing provider plugins...
- Finding hashicorp/aws versions matching "2.32.0"...
- Finding latest version of terraform.foo.com/foo/bar...
Warning: Provider development overrides are in effect
The following provider development overrides are set in the CLI configuration:
- "terraform.foo.com/foo/bar" = "/Users/appuser/foobar/bin/darwin-amd64"
Error: Failed to query available provider packages
Could not retrieve the list of available versions for provider hashicorp/aws:
no available releases match the given constraints 2.32.0
Error: Failed to query available provider packages
Could not retrieve the list of available versions for provider
"terraform.foo.com/foo/bar": no available releases
match the given constraints
更新:当我删除terraformrc时,它似乎确实有效,但我无法以这种方式加载第二个提供程序(因为它依赖于覆盖(:
terraform init
Initializing the backend...
Initializing provider plugins...
- Finding hashicorp/aws versions matching "2.32.0"...
- Finding latest version of hashicorp/foo/bar...
- Installing hashicorp/aws v2.32.0...
- Installed hashicorp/aws v2.32.0 (self-signed, key ID 34365D9472D7468F)
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:
https://www.terraform.io/docs/plugins/signing.html
Error: Failed to query available provider packages
Could not retrieve the list of available versions for provider
hashicorp/foo/bar: provider registry registry.terraform.io does not
have a provider named registry.terraform.io/hashicorp/foo/bar
dev_overrides
设置,尽管由于主题相似而被放置在provider_installation
块内,但实际上是运行时设置,而不是安装设置。具体来说,它要求Terraform忽略之前选择的任何版本的提供程序terraform init
,而使用给定的重写提供程序。
不幸的是,只有当您重写至少有一个发布版本可用的提供程序时,此模型才能正常工作,这样terraform init
可以选择并安装该版本,但terraform apply
(例如(可以忽略安装的terraform init
,而是使用重写。(Terraform之所以这样做,是因为terraform init
的部分职责是更新依赖锁定文件,因此它需要为每个提供程序找到至少一个可选版本,才能生成完整的锁定文件。(
避免这种设计怪癖的一种方法是放置一个假的";释放";然后在.terraformrc
文件中将该提供程序配置为该提供程序的文件系统镜像。
例如,如果您创建一个目录/tmp/tf-workaround/terraform.foo.com/foo/bar/0.0.1/darwin_amd64
并在其中放置一个名为terraform-provider-bar
的空文件,那么这应该足以让terraform init
将其检测为可用的";出版的";提供程序的版本(如果提供这样的CLI配置(:
provider_installation {
dev_overrides {
"terraform.foo.com/foo/bar" = "/Users/appuser/foobar/bin/darwin-amd64"
}
filesystem_mirror {
path = "/tmp/tf-workaround"
include = ["terraform.foo.com/foo/bar"]
}
direct {
exclude = ["terraform.foo.com/foo/bar"]
}
}
CCD_ 13应当找到占位符空文件;安装";它正常地进入CCD_ 14。这个空文件实际上并不能作为一个有效的插件工作,但这没关系,因为terraform apply
无论如何都会忽略它,而是使用dev_overrides
中给定的目录。
但是,在安装后,依赖项锁定文件将包含terraform.foo.com/foo/bar
的不正确条目,因此,如果您打算将此测试配置提交到版本控制,那么一旦确实发布了此提供程序,您可能希望手动删除该块,以减少混乱。
在这里工作的不那么复杂的方法是在开发过程中使用仅包含该提供程序的配置来测试该提供程序,并等到您在某个地方实际发布了该提供程序后再使用它;真正的";作为更大系统的一部分。在这种情况下,您通常会完全跳过运行terraform init
,因为唯一的外部依赖项是被重写的提供程序,因此不需要安装任何额外的程序。
在TF文档中找到了修复程序(即添加direct {}
(:
provider_installation {
# Use /home/developer/tmp/terraform-null as an overridden package directory
# for the hashicorp/null provider. This disables the version and checksum
# verifications for this provider and forces Terraform to look for the
# null provider plugin in the given directory.
dev_overrides {
"hashicorp/null" = "/home/developer/tmp/terraform-null"
}
# For all other providers, install them directly from their origin provider
# registries as normal. If you omit this, Terraform will _only_ use
# the dev_overrides block, and so no other providers will be available.
direct {}
}
事实上,我还在接受
Error: Failed to query available provider packages
Could not retrieve the list of available versions for provider
hashicorp/foo/bar: could not connect to hashicorp: Failed
to request discovery document: Get
"https://hashicorp/.well-known/terraform.json": dial tcp: lookup hashicorp on
100.217.9.1:53: no such host