7

Terraform 0.13 just came out (https://www.hashicorp.com/blog/announcing-hashicorp-terraform-0-13/) and it changes how to work with 3rd party providers (https://www.terraform.io/upgrade-guides/0-13.html#explicit-provider-source-locations).

I'm encountering an error when running 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

This used to work before with Terraform 0.12.29 and the IBM provider 1.10.0.

data_henrik
  • 16,724
  • 2
  • 28
  • 49
Frederic Lavigne
  • 704
  • 3
  • 12

3 Answers3

9

Here are the instructions for Linux and the current versions of Terraform and the IBM provider:

Install Terraform

  1. Download Terraform 0.13
    wget https://releases.hashicorp.com/terraform/0.13.0/terraform_0.13.0_linux_amd64.zip
    
  2. Unzip the provider
    unzip terraform_0.13.0_linux_amd64.zip
    
  3. Move it to a folder in your path, such as:
    mv terraform /usr/local/bin/
    
  4. Ensure the version is 0.13
    terraform version
    

Install the IBM provider

  1. Create the folder where the plugin will be put:
    mkdir -p ~/.terraform.d/plugins/localdomain/provider/ibm/1.10.0/linux_amd64
    
  2. Get the provider:
    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 the provider:
    unzip terraform-provider-ibm_1.10.0_linux_amd64.zip
    
  4. Move the provider to the folder previously created:
    mv terraform-provider-ibm_v1.10.0 ~/.terraform.d/plugins/localdomain/provider/ibm/1.10.0/linux_amd64
    

Test with a simple Terraform file

  1. Create 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. Create terraform.tfvars and fill in your IBM Cloud API key:

    ibmcloud_api_key="REPLACE_WITH_YOUR_KEY"
    
  3. Initialize Terraform

    terraform init
    

    will result in:

    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. And apply

    terraform apply
    

    will result in:

    ...
      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.
    

Happy terraforming!

Frederic Lavigne
  • 704
  • 3
  • 12
  • 1
    Awesome. A couple of nottes: - Note that the architecture portion of the path `linux_amd64` will be dependent on your installation. I, for example, had to change this to `darwin_amd64`. - If you have existing state you will either have to delete it or use the `terraform state replace-provider` command. Thanks for solving this! – Erik Aug 12 '20 at 14:01
  • We don't need to extract zip files as Terraform supports zip as well. See: https://github.com/hashicorp/terraform/blob/4bba9a70b362865188057e1cc70a767cabf53c76/internal/getproviders/filesystem_search.go#L48 – ninhjs.dev Sep 26 '20 at 14:45
3

The IBM Provider is now published to the repository so you can use the new terraform 13 provider syntax such as:

terraform {
  required_version = ">= 0.13"
  required_providers {
    ibm = {
      source  = "IBM-Cloud/ibm"
      version = "1.11.2"
    }
  }
}
WaltDe
  • 1,715
  • 8
  • 17
  • I tried to use this but getting: `Error while installing hashicorp/ibm: provider registry registry.terraform.io does not have a provider named registry.terraform.io/hashicorp/ibm` – Gas Sep 08 '21 at 13:45
  • @Gas Can you try the source = "IBM-Cloud/ibm" there the IBM and Cloud are capitalized? I'm updating the answer just in caset that solves it for you.case – WaltDe Sep 08 '21 at 17:08
  • adding `version.tf` file with this content to each module helped, thanks. :-) – Gas Sep 08 '21 at 19:17
1
terraform {
  required_version = ">= 0.13.3"
  required_providers {
    ibm = {
      source  = "ibm-cloud/ibm"
      version = "1.12.0"
    }
  }
}

This will give you the latest version.