【问题标题】:Failed to install provider for thirdparty provider为第三方提供商安装提供商失败
【发布时间】:2021-04-14 09:46:35
【问题描述】:

我正在使用 terraform 模块在 Azure Devops 中应用 DRY 原则。我们将自定义提供程序与官方 Azure Devops 提供程序一起使用。使用我们制作的模块,以便开发人员使用的 tf 文件仅用于声明变量,因为资源的配置是由 DevOps 团队完成的。

该模块由一个 TF 文件和一个托管在 /modules/build_ci 中的变量文件组成

build_ci.tf:

resource "build_definition_resource" "Build_CI" {
    trigger_ci      = true
    solution_name   = var.solution_name
    repository      = var.repository
    pool            = var.pool
    branch          = var.branch
    branches_ci     = var.branches_ci
    
    dynamic "build_template" {
        for_each = var.templates
        iterator = task
        content {
            name    = task.value["name"]
            input   = task.value["inputs"]
    }
    }
}

variables.tf

variable "solution_name" {
    type = string
}

variable "repository" {
    type = string
}

variable "pool" {
    type    = string
    default = "alm-aws-pool"
}

variable "branch" {
    type    = string
    default = "master"
}

variable "branches_ci" {
    type    = list(string)
    default = ["master", "release/*"]
}

variable "templates" {
    type = list(object({
        name    = string
        inputs  = map(string)
    }))

    default = [
        {
            name    = "templates/build/tg1_build&nuget.yaml"
            inputs  = {
                IsNugetPrerelaseVersion = "false"
                BuildConfiguration = "Release"
                BuildPlatform = "Any CPU"
                SearchPatternToPack = "none"
            }        
        },
        {
            name    = "templates/build/TG2_Validations.yaml"
            inputs  = {
                BuildConfiguration = "Release"
            }
        },
        {
            name    = "templates/build/TG3_Publish.yaml"  
            inputs  = null      
        }
    ]
}

build_template 组件调用托管在另一个存储库中的 yaml 模板。

这个模块的使用会是这样的

module "app_Build_CI" {
    source          = "../modules/build_ci"
    solution_name   = "app"
    repository      = "app_repository"
}

地形提供者是:

provider "test_provider" {
  uri = "#{custom_provider_uri}"
  
}

provider "azuredevops" {
  org_service_url = "#{AZDO_ORG_SERVICE_URL}#"
  personal_access_token = "#{AZDO_PERSONAL_ACCESS_TOKEN}#"
}

terraform {
  required_version = ">= 0.12"
  backend "s3" {
    bucket = "#{BUCKET}#"
    key    = "#{KEY}#"
    region = "#{REGION}#"
      access_key = "#{access_key}#"
      role_arn = "#{ARN_ROLE}#"
      external_id = "#{EXTERNAL_ID}#"
  }
  
  required_providers {
    test_provider = {
      versions = ["0.2"]
      source = "test/provider/test"
    }
    azuredevops = {
      source = "microsoft/azuredevops"
      version = ">=0.1.0"
    }
    repo = {
      versions = ["0.2"]
      source = "test/provider/test"
    }
    build = {
      versions = ["0.2"]
      source = "test/provider/test"
    }
  }
}

在进行 terraform init 时出现问题,我们收到一条错误消息,指出它无法安装我们不使用的 hashichorp/build 提供程序。如果我使用没有模块的旧结构,它可以工作,但使用模块时它会失败。

Error: Failed to install provider

Error while installing hashicorp/build: provider registry
registry.terraform.io does not have a provider named
registry.terraform.io/hashicorp/build

有谁知道这个错误是由什么引起的? 非常感谢

【问题讨论】:

    标签: terraform


    【解决方案1】:

    错误是模块文件夹必须包含提供程序,否则它需要官方的hashicorp提供程序而不是第三方的。仅此而已

    【讨论】:

      猜你喜欢
      • 2021-04-19
      • 2021-11-01
      • 2014-09-11
      • 2021-07-30
      • 1970-01-01
      • 2017-05-04
      • 2021-06-02
      • 1970-01-01
      • 2018-08-23
      相关资源
      最近更新 更多