7

Terraform 0.13 刚刚问世(https://www.hashicorp.com/blog/announcing-hashicorp-terraform-0-13/),它改变了与第三方提供商合作的方式(https://www.terraform.io/ upgrade-guides/0-13.html#explicit-provider-source-locations)。

我在运行时遇到错误terraform init

$ terraform init

Initializing the backend...

Initializing provider plugins...
- Finding latest version of hashicorp/ibm...

Error: Failed to install provider

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

这曾经在 Terraform 0.12.29 和 IBM 提供者 1.10.0 之前工作。

4

3 回答 3

9

以下是 Linux 以及 Terraform 和 IBM 提供程序的当前版本的说明:

安装 Terraform

  1. 下载 Terraform 0.13
    wget https://releases.hashicorp.com/terraform/0.13.0/terraform_0.13.0_linux_amd64.zip
    
  2. 解压提供程序
    unzip terraform_0.13.0_linux_amd64.zip
    
  3. 将其移至路径中的文件夹,例如:
    mv terraform /usr/local/bin/
    
  4. 确保版本为 0.13
    terraform version
    

安装 IBM 提供程序

  1. 创建将放置插件的文件夹:
    mkdir -p ~/.terraform.d/plugins/localdomain/provider/ibm/1.10.0/linux_amd64
    
  2. 获取提供者:
    wget https://github.com/IBM-Cloud/terraform-provider-ibm/releases/download/v1.10.0/terraform-provider-ibm_1.10.0_linux_amd64.zip
    
  3. 解压缩提供程序:
    unzip terraform-provider-ibm_1.10.0_linux_amd64.zip
    
  4. 将提供程序移动到之前创建的文件夹:
    mv terraform-provider-ibm_v1.10.0 ~/.terraform.d/plugins/localdomain/provider/ibm/1.10.0/linux_amd64
    

使用简单的 Terraform 文件进行测试

  1. 创造main.tf

    terraform {
      required_providers {
        ibm = {
          source  = "localdomain/provider/ibm"
          version = "1.10.0"
        }
      }
    }
    
    variable ibmcloud_api_key {
    }
    
    provider "ibm" {
      ibmcloud_api_key = var.ibmcloud_api_key
    }
    
    resource ibm_resource_group new_group {
      name = "created-by-terraform"
    }
    
  2. 创建terraform.tfvars并填写您的 IBM Cloud API 密钥:

    ibmcloud_api_key="REPLACE_WITH_YOUR_KEY"
    
  3. 初始化 Terraform

    terraform init
    

    将导致:

    Initializing the backend...
    
    Initializing provider plugins...
    - Finding localdomain/provider/ibm versions matching "1.10.0"...
    - Installing localdomain/provider/ibm v1.10.0...
    - Installed localdomain/provider/ibm v1.10.0 (unauthenticated)
    
    Terraform has been successfully initialized!
    
    You may now begin working with Terraform. Try running "terraform plan" to see
    any changes that are required for your infrastructure. All Terraform commands
    should now work.
    
    If you ever set or change modules or backend configuration for Terraform,
    rerun this command to reinitialize your working directory. If you forget, other
    commands will detect it and remind you to do so if necessary.
    
  4. 并申请

    terraform apply
    

    将导致:

    ...
      Enter a value: yes
    
    ibm_resource_group.new_group: Creating...
    ibm_resource_group.new_group: Creation complete after 2s [id=2142c8122344458d59b8729708464a]
    
    Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
    

快乐的地球化!

于 2020-08-11T19:32:29.273 回答
3

IBM Provider 现在已发布到存储库,因此您可以使用新的 terraform 13 提供程序语法,例如:

terraform {
  required_version = ">= 0.13"
  required_providers {
    ibm = {
      source  = "IBM-Cloud/ibm"
      version = "1.11.2"
    }
  }
}
于 2020-09-15T12:41:09.310 回答
1
terraform {
  required_version = ">= 0.13.3"
  required_providers {
    ibm = {
      source  = "ibm-cloud/ibm"
      version = "1.12.0"
    }
  }
}

这将为您提供最新版本。

于 2020-09-21T14:56:34.650 回答