IBM Cloud Docs
Installing the Terraform CLI and the IBM Cloud Provider plug-in

Installing the Terraform CLI and the IBM Cloud Provider plug-in

Install the Terraform CLI and invoke the IBM Cloud Provider plug-in for Terraform to start automating infrastructure deployments and cloud resource management with Terraform.

Installing the Terraform CLI

Use these steps to install the Terraform CLI.

The IBM Cloud Provider plug-in for Terraform currently supports the Terraform stable version 1.x.x. Make sure to select a supported Terraform version.

  1. Create a terraform folder on your local machine, and navigate to your terraform folder.

    mkdir terraform && cd terraform
    
  2. Download the Terraform version that you want.

  3. Extract the Terraform zip file and copy the files to your terraform directory.

  4. Set the environment PATH variable to your Terraform files.

    export PATH=$PATH:$HOME/terraform
    
  5. Verify that the installation is successful by using a terraform command.

    terraform
    

    Example output:

    Usage: terraform [-version] [-help] <command> [args]
    
    The available commands for execution are listed below.
    The most common, useful commands are shown first, followed by
    less common or more advanced commands. If you're just getting
    started with Terraform, stick with the common commands. For the
    other commands, please read the help and docs before usage.
    
    Common commands:
    apply              Builds or changes infrastructure
    console            Interactive console for Terraform interpolations
    destroy            Destroy Terraform-managed infrastructure
    env                Workspace management
    fmt                Rewrites config files to canonical format
    get                Download and install modules for the configuration
    graph              Create a visual graph of Terraform resources
    import             Import existing infrastructure into Terraform
    init               Initialize a Terraform working directory
    login              Obtain and save credentials for a remote host
    logout             Remove locally-stored credentials for a remote host
    output             Read an output from a state file
    plan               Generate and show an execution plan
    providers          Prints a tree of the providers used in the configuration
    refresh            Update local state file against real resources
    show               Inspect Terraform state or plan
    taint              Manually mark a resource for recreation
    untaint            Manually unmark a resource as tainted
    validate           Validates the Terraform files
    version            Prints the Terraform version
    workspace          Workspace management
    
    All other commands:
    0.12upgrade        Rewrites pre-0.12 module source code for v0.12
    debug              Debug output management (experimental)
    force-unlock       Manually unlock the terraform state
    push               Obsolete command for Terraform Enterprise legacy (v1)
    state              Advanced state management
    
    

    To upgrade your Terraform templates from Terraform old version to new version, see Upgrading your Terraform version.

  6. Install the IBM Cloud Provider plug-in for Terraform.

Installing the IBM Cloud Provider plug-in

After the Terraform CLI installation is complete, you must set up the IBM Cloud Provider plug-in for Terraform so that you can start working with resources and services in IBM Cloud.

The setup of the IBM Cloud Provider plug-in varies depending on the Terraform version that you want to use. After you complete the set up, you must configure the IBM Cloud Provider plug-in.

To upgrade the Terraform template from the old version to the latest version, refer to Upgrading the Terraform template version.

Upgrading to Terraform v0.13.x

To run your Terraform configuration files with Terraform version 0.13.x and higher, installation of the IBM Cloud Provider plug-in for Terraform is not required. Instead, you create a versions.tf file and specify the IBM Cloud Provider plug-in version that you want to use. For a list of supported versions, see the IBM Cloud Provider plug-in releases.

Create a versions.tf file with the following content and store it in your Git repository or the folder where Terraform is set up. In this file, specify the IBM Cloud Provider plug-in version that you want to use with the version parameter.

Syntax:

terraform {
    required_providers {
        ibm = {
            source = "IBM-Cloud/ibm"
            version = "<provider version>"       
            }
    }
}

Example:

terraform {
    required_providers {
        ibm = {
            source = "IBM-Cloud/ibm"
            version = ">= 1.38.1"
        }
    }
}

Specifying Terraform version constraints

Terraform supports version constraints to specify the range of acceptable versions to initialize. The version syntax format is specified as <MAJOR_VERSION>.<MINOR_VERSION>.<PATCH>. You can modify the version constraint operator in this example by using combination of the supported operators in Terraform. Some of the constraints are shown as an example.

Terraform template version operators
Operator Description
= (or no operator) Allows only extract version number. You cannot combine with other conditions. For example, 1.31.0.
!= Excludes an exact version number. For example, !=1.39.0.
>, >=, <, <= Compares against a specified version, allows version for which the comparison is true. Greater-than requests newer version, and less-than requests older versions. For example, >= 1.30.0 < 2.0.0.
~> Allows only the rightmost version component to increment. For example, ~> 1.30.0 allows new patch releases within a specific minor patch releases like 1.30.1, 1.30.2, 1.30.3, but not 1.31.0 release.

If you are using Terraform on IBM Cloud modules, you must add a versions.tf file in all the module folders. You can refer the Terraform provider block from the IBM Cloud Provider registry.

Upgrading Terraform v0.12.x and earlier

Complete the following steps to install the IBM Cloud provider plug-in on your local machine.

  1. Download the latest version of the IBM Cloud provider plug-in.
  2. Extract the zip file and retrieve the files.
  3. Create a hidden plugins folder on your local machine.
    mkdir -p $HOME/.terraform.d/plugins
    
  4. Move the IBM Cloud Provider plug-in into your plugins folder.
    mv $HOME/<DOWNLOAD_FOLDER_NAME>/terraform-provider-ibm* $HOME/.terraform.d/plugins
    
  5. Navigate to your plugins folder and verify that the installation is complete.
    cd $HOME/.terraform.d/plugins && ./terraform-provider-ibm_*
    
    Example output:
    2021/04/16 17:00:39 IBM Cloud Provider version 1.23.1  
    This binary is a plugin. These are not meant to be executed directly.
    Please execute the program that consumes these plugins, which will load any plugins automatically
    
  6. Configure the IBM Cloud Provider plug-in. To view the list of supported IBM Cloud Provider versions, refer to IBM Cloud Provider plug-in releases.