terraform - 使用预安装的 Terraform 插件,而不是使用 terraform init 下载它们

标签 terraform

运行时terraform init使用 Terraform 时 0.11.3我们收到以下错误:

Initializing provider plugins... - Checking for available provider plugins on https://releases.hashicorp.com...

Error installing provider "template": Get https://releases.hashicorp.com/terraform-provider-template/: read tcp 172.25.77.25:53742->151.101.13.183:443: read: connection reset by peer.

Terraform analyses the configuration and state and automatically downloads plugins for the providers used. However, when attempting to download this plugin an unexpected error occured.

This may be caused if for some reason Terraform is unable to reach the plugin repository. The repository may be unreachable if access is blocked by a firewall.

If automatic installation is not possible or desirable in your environment, you may alternatively manually install plugins by downloading a suitable distribution package and placing the plugin's executable file in the following directory: terraform.d/plugins/linux_amd64



我意识到这是因为 https://releases.hashicorp.com 的连接问题。领域。由于一些明显的原因,我们将不得不调整这个连接问题,因为在控制服务器和 Hashicorp 的服务器之间存在一些 SSL 和防火墙问题。

我们有什么办法可以绕过这个,从 Hashicorp 的服务器下载插件并将它们复制到控制服务器上?或者任何其他替代方法来避免尝试从 Hashicorp 的服务器下载东西?

最佳答案

自 terraform 0.14 以来处理此问题的正确方法,正如在当前接受的答案中提到的 terraform-b​​undle 页面上所讨论的那样,是使用 terraform providers mirrorhttps://www.terraform.io/cli/commands/providers/mirror 中所述.此命令创建所有必要的索引文件等,因此该文件夹可用于插件。例如:

$ cd your-tf-root-module
$ terraform providers mirror path/to/tf-plugins
...
$ terraform init --plugin-dir path/to/tf-plugins
...
您可以 cd 到每个根模块(即具有 terraform 状态的模块)并运行镜像命令;那里可能安装了多个版本的插件,这没关系。当您运行 terraform init 命令时,它将获取正确的命令。与没有 --plugin-dir 参数相同。
所以唯一的区别是不使用互联网来获取插件,terraform init 从插件文件夹中获取它们。
这对于创建缓存也非常有用,然后 ci/cd 中的 terraform 可以使用该缓存。例如,在 circleci 中,您将有一项手动工作,该工作调用镜像并执行保存缓存;并且您的自动 terraform 初始化作业将恢复缓存,并使用 --plugin-dir arg;然后自动 terraform apply 作业将照常运行。

关于terraform - 使用预安装的 Terraform 插件,而不是使用 terraform init 下载它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50944395/

相关文章:

terraform - 如何在 terraform 中将 concat 与 formatlist 结合起来?

Azure Pipelines terraform init -backend-config 抛出退出代码 127

go - Terraform 自定义提供程序 - 数据源

amazon-web-services - 何时使用terraform vs无服务器框架来部署AWS Lambda和周围资源?

azure - 如何在 Terraform 的状态下导入整个 Azure 资源组?

Terraform 回滚到某些输入状态

azure - 将 SSL 证书附加到 Terraform 中的 Azure 应用程序网关

aws-lambda - DevOps : AWS Lambda . zip 与 Terraform

terraform - 如何将 CloudFormation 模板转换为 terraform 代码

azure - azure/vnet/azurerm terraform 模块中子网委托(delegate) block 的正确语法是什么?