我正在尝试为terraform模块添加kubectl提供程序,并且遵循Terraform kubectl的文档。我运行terraform init并成功安装了provider,但是当我尝试添加示例配置时,例如:(或here的thers)

resource "kubectl_server_version" "current" {}
并运行terraform plan我得到以下消息:
Error: Could not load plugin
Failed to instantiate provider "registry.terraform.io/hashicorp/kubectl" to
obtain schema: unknown provider "registry.terraform.io/hashicorp/kubectl"
当我调整terraform init(使用模块k8s中的资源)时
Error: Failed to install provider

Error while installing hashicorp/kubectl: provider registry
registry.terraform.io does not have a provider named
registry.terraform.io/hashicorp/kubectl
一些输出:
$terraform plugins

├── provider[registry.terraform.io/hashicorp/kubernetes] 1.13.2
├── provider[registry.terraform.io/gavinbunney/kubectl] 1.9.1
├── module.k8s
│   ├── provider[registry.terraform.io/hashicorp/kubectl]
│   └── provider[registry.terraform.io/hashicorp/kubernetes]



$terraform init

Initializing modules...

Initializing the backend...

Initializing provider plugins...
- Using previously-installed hashicorp/kubernetes v1.13.2
- Using previously-installed gavinbunney/kubectl v1.9.1

$terraform -v

Terraform v0.13.4
  + provider registry.terraform.io/gavinbunney/kubectl v1.9.1
  + provider registry.terraform.io/hashicorp/kubernetes v1.13.2
  ....
一些配置文件:
terraform.tf
terraform {

  required_version  = "0.13.4"

  backend "gcs" {
    ...
  }

  required_providers {
    kubernetes = {
        source        = "hashicorp/kubernetes"
        version       = "1.13.2"
      }

    kubectl = {
      source          = "gavinbunney/kubectl"
      version         = "1.9.1"
    }
....
terraform成功初始化gavinbunney/kubectl提供程序,但是当我在k8s.module中添加resource "kubectl_manifest" ...时,terraform正在尝试加载hashicorp/kubectl提供程序
我想念的是什么? :)

最佳答案

似乎问题是我在同一模块中将resource "kubectl_server_version" "current" {}hashicorp/kubernetes资源中的其他资源放在一起,而terraform试图从kubectl加载hashicorp/kubectl
当我在main.tf中添加gavinbunney/kubectl的资源时,一切正常:)

07-28 01:41
查看更多