IBM Cloud Docs
Setting up Terraform for Direct Link

Setting up Terraform for Direct Link

Terraform on IBM Cloud® enables predictable and consistent provisioning of IBM Cloud services so that you can rapidly build complex, multi-tier cloud environments following Infrastructure as Code (IaC) principles. Similar to using the IBM Cloud CLI or API and SDKs, you can automate the provisioning, update, and deletion of your Direct Link instances by using HashiCorp Configuration Language (HCL).

Looking for a managed Terraform on IBM Cloud® solution? Try out IBM Cloud® Schematics. With Schematics, you can use the Terraform scripting language that you are familiar with, but you don't have to worry about setting up and maintaining the Terraform command line and the IBM Cloud® Provider plug-in. Schematics also provides pre-defined Terraform templates that you can easily install from the IBM Cloud® catalog.

Installing Terraform and configuring resources for Direct Link

Before you begin, make sure that you have the required access to create and work with Direct Link resources.

  1. Follow the Terraform on IBM Cloud® getting started tutorial to install the Terraform CLI and configure the IBM Cloud® Provider plug-in for Terraform. The plug-in abstracts the IBM Cloud® APIs that are used to provision, update, or delete Direct Link service instances and resources.

  2. Create a Terraform configuration file that is named main.tf. In this file, you add the configuration to create a Direct Link service instance and to assign a user an access policy in Identity and Access Management (IAM) for that instance by using HashiCorp Configuration Language (HCL). For more information, see the Terraform documentation.

    The Direct Link resource in the following example is named test_dl_routers and is created as a Dedicated gateway in the dal10 location.

    For more information about arguments and attributes, see the ibm_dl_gateway usage example.

    data "ibm_dl_routers" "test_dl_routers" {
            offering_type = "dedicated"
            location_name = "dal10"
        }
    
    resource "ibm_dl_gateway" "test_dl_gateway" {
      bgp_asn =  64999
      global = true
      metered = false
      name = "Gateway1"
      resource_group = "bf823d4f45b64ceaa4671bee0479346e"
      speed_mbps = 1000
      type =  "dedicated"
      cross_connect_router = data.ibm_dl_routers.test_dl_routers.cross_connect_routers[0].router_name
      location_name = data.ibm_dl_routers.test_dl_routers.location_name
      customer_name = "Customer1"
      carrier_name = "Carrier1"
    
    }
    
  3. Initialize the Terraform CLI.

    terraform init
    
  4. Create a Terraform execution plan. The Terraform execution plan summarizes all the actions that need to be run to create the Direct Link instance in your account.

    terraform plan
    
  5. Create the Direct Link instance and IAM access policy in IBM Cloud.

    terraform apply
    
  6. From the IBM Cloud resource list, select the Direct Link instance that you created and note the instance ID.

  7. Verify that the access policy is successfully assigned. For more information, see Reviewing assigned access in the console.