Terraform 使用本地提供程序/插件

Mar*_*ara 11 terraform

我在 linux_amd64 ( Oracle Linux Srv 8.4 64bit ) 上安装了Terraform v1.0.1

\n

I\xe2\x80\x99m 尝试使用我保存在文件夹中的本地提供程序/插件:/root/.terraform.d/plugins

\n
# ll /root/.terraform.d/plugins\ndrwxr-xr-x. 2 root root       38 Jun 29 15:42 oldversion\n-rwxr-xr-x. 1 root root 30068808 Jun 29 15:42 terraform-provider-zabbix\ndrwxr-xr-x. 2 root root       52 Jun 29 15:42 test_plugging\n
Run Code Online (Sandbox Code Playgroud)\n

这是我的vim /root/.terraformrc

\n
provider_installation {\n  filesystem_mirror {\n    path    = "/root/.terraform.d/plugins"\n  }\n  direct {\n    exclude = ["registry.terraform.io/*/*"]\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

这是我的main.tf

\n
terraform {\n    required_version    = ">= 0.12.6"\n}\nprovider "zabbix" {\n    username            = local.provider_vars.zabbix.username\n    password            = local.provider_vars.zabbix.password\n    url                 = local.provider_vars.zabbix.endpoint\n    tls_insecure        = true\n}\n
Run Code Online (Sandbox Code Playgroud)\n

但是当我跑步时:terraform init

\n
\n

正在初始化后端...

\n

正在初始化提供者插件...

\n
    \n
  • 正在寻找最新版本的 hashcorp/zabbix...
  • \n
\n

错误:无法查询可用的提供程序包

\n

无法检索提供程序\nhashicorp/zabbix 的可用版本列表: 在任何搜索位置\n都找不到提供程序registry.terraform.io/hashicorp/zabbix

\n
    \n
  • /root/.terraform.d/plugins
  • \n
\n
\n

如何解决这个问题?\n感谢您的帮助

\n

马可

\n

小智 18

假设你有一个二进制文件

~/.terraform.d/plugins/terraform.local/local/zabbix/1.0.0/linux_amd64/terraform-provider-zabbix_v1.0.0
Run Code Online (Sandbox Code Playgroud)

配置 Terraform 如下

terraform {
  required_providers {
    zabbix = {
      source  = "terraform.local/local/zabbix"
      version = "1.0.0"
      # Other parameters...
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

其工作原理如下

terraform init

Initializing the backend...

Initializing provider plugins...
- Finding terraform.local/local/zabbix versions matching "1.0.0"...
- Installing terraform.local/local/zabbix v1.0.0...
- Installed terraform.local/local/zabbix v1.0.0 (unauthenticated)

Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.

Terraform has been successfully initialized!
Run Code Online (Sandbox Code Playgroud)

  • 这仍在尝试获取 terraform.local 主机,并且不能完全解决问题。 (4认同)

Кон*_*мов 9

上面的解决方案是绝对正确的,但需要澄清编辑 .terraformrc

provider_installation {
  filesystem_mirror {
    path    = "/home/user/.terraform.d/plugins"
  }
  direct {
    exclude = ["terraform.local/*/*"]
  }
}
Run Code Online (Sandbox Code Playgroud)