Creating a VPC using a terraform in IBM Cloud

Deepak Rai
3 min readJan 30, 2022

In the previous blog, we saw how to create a resource group using terraform. Please refer it for any basic configurations needed to setup terraform on IBM Cloud

Introduction

In this blog, we are looking at creating a vpc on IBM Cloud using terraform in a Multi Zone Region(MZR). A virtual private cloud (VPC) is a secure, isolated virtual network that combines the security of a private cloud with the availability and scalability of IBM’s public cloud.VPC gives your applications logical isolation from other networks, while providing scalability and security. To make this logical isolation possible, the VPC is divided into subnets that use a range of private IP addresses. You can create subnets in suggested prefix ranges, or bring your own public IP address range (BYOIP) to your IBM Cloud account. By default, all resources within the same VPC can communicate with each other over the private network, regardless of their subnet.

Building IaC

In a new folder, let us create

you can use the Github link to download all the require files

We tried to segregate and leverage some of the best practices in creating the terraform files. Change the cloud API key in terraform.tfvars.

Prerequites:

In this demo, i have created the resources using the resource group terraform. You can create a new resource group called terraform in your IBM Cloud account or you can edit the resource group of your choice in the projectvariables.tf file

Steps to create:

Launch the terminal in the folder created. Run

terraform init
terraform plan
terraform apply

in the terminal. Once its successfully executed you will see the VPC created in your IBM Cloud Account. In this example we are creating a VPC using the default address prefix and adding subnets in each zones.

image 1: Resource List
image 2: VPC details

Incase you want to delete all the resources you just created, you can easily do it using

terraform destroy

in your terminal.

Thats all folks, hope this is helpful.

--

--