Setting up Terraform for Direct Link
Terraform on IBM Cloud® enables predictable and consistent creation of IBM Cloud services so that you can rapidly build complex, multitier cloud environments that follow Infrastructure as Code (IaC) principles. Similar to using the IBM Cloud CLI or API and SDKs, you can automate the creation, 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. 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 can create an authorization by using Terraform, make sure that you have completed the following:
- Make sure that you have the required access to create and work with Direct Link resources.
- Install the Terraform CLI and configure the IBM Cloud Provider plug-in for Terraform. For more information, see the tutorial for Getting started with Terraform on IBM Cloud®. The plug-in abstracts the IBM Cloud APIs that are used to complete this task.
- Create a Terraform configuration file that is named
main.tf. In this file, you add the configuration to create an authorization between services by using HashiCorp Configuration Language. For more information, see the Terraform documentation.
-
In your Terraform configuration file, find the Terraform code that you used to create the Direct Link instance.
-
Create a Direct Link instance by using the
ibm_resource_instanceresource argument in yourmain.tffile. The Direct Link zone in the following example is namedGateway1. The Direct Link resource in the following example is namedtest_dl_routersand is created as a dedicated gateway in thedal10location.For more information about arguments and attributes, see the
ibm_dl_gatewayusage 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" } -
After you finish building your configuration file, initialize the Terraform CLI. For more information, see Initializing Working Directories.
terraform init -
Provision the resources from the
main.tffile. For more information, see Provisioning Infrastructure with Terraform.-
Run
terraform planto generate a Terraform execution plan to preview the proposed actions.terraform plan -
Run
terraform applyto create the resources that are defined in the plan.terraform apply
-
-
From the IBM Cloud resource list, select the Direct Link instance that you created and note the instance ID.
-
Verify that the access policy is successfully assigned. For more information, see Reviewing assigned access in the console.
What's next?
Now that you successfully created your first Direct Link service instance with Terraform on IBM Cloud, you can visit the Direct Link Direct Link Terraform registry to perform additional tasks using Terraform.