Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the IBM Cloud Provider plug-in for Terraform with Terraform 0.13?

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.

like image 818
Frederic Lavigne Avatar asked Aug 11 '20 19:08

Frederic Lavigne


People also ask

What must be enabled before setting up the IBM Cloud Provider plug in for Terraform on IBM Cloud to use the cloud service endpoint?

Configuring the IBM Cloud Provider plug-in. Before you can start working with Terraform on IBM Cloud, you must retrieve the credentials and parameters that are required for a Terraform resource or data source, and specify them in the provider configuration.

Does Terraform allow third party plugins?

Third-party provider plugins — locally installed providers, not on the registry — need to be assigned an (arbitrary) source and placed in the appropriate subdirectory for Terraform to find and use them.

How does Terraform communicate with provider?

A provider is a Terraform plugin that allows users to manage an external API. Provider plugins like the AWS provider or the cloud-init provider act as a translation layer that allows Terraform to communicate with many different cloud providers, databases, and services.


1 Answers

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!

like image 83
Frederic Lavigne Avatar answered Nov 22 '22 17:11

Frederic Lavigne