Setting up Terraform for VLANs
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 VLAN 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 VLANs
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 VLAN 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 define resources by using HashiCorp Configuration Language. For more information, see the Terraform documentation.
-
Create a Terraform configuration file that is named
main.tf
. In this file, you add the configuration to create a VLAN 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 VLAN resource in the following example is named
test_vlan
. ThisPUBLIC
VLAN resides in thesjc04
data center andfcr01a.sjc04
is the hostname of the primary router associated with the VLAN.For more information, see the ibm_network_vlan usage example.
resource "ibm_network_vlan" "test_vlan" { name = "test_vlan" datacenter = "sjc04" type = "PUBLIC" router_hostname = "fcr01a.sjc04" tags = [ "collectd", "mesos-master", ] }
-
After you finish building your configuration file, initialize the Terraform CLI. For more information, see Initializing Working Directories.
terraform init
-
Create a Terraform execution plan. The Terraform execution plan summarizes all the actions that need to be run to create the VLAN instance in your account.
terraform plan
-
Create the VLAN instance in IBM Cloud.
terraform apply
-
From the IBM Cloud resource list, select the VLAN instance that you created and note the instance ID.
What's next?
Now that you successfully created your VLAN with Terraform on IBM Cloud, you can visit the VLAN Terraform registry to perform additional tasks using Terraform.