---
name: vpc-terraform
title: Setting up Terraform for VPC
description: Terraform on IBM Cloud&reg; enables predictable and consistent provisioning of IBM Cloud services so that you can rapidly build complex, multitier cloud environments by 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 VPC instances by using HashiCorp Configuration Language (HCL).
last-updated: 2026-11-11
---

> ## Documentation Index
> The table of contents for this documentation set is at https://cloud.ibm.com/docs/vpc?format=markdown
> The index for all IBM Cloud docs is at: https://cloud.ibm.com/docs/llms.txt
> Use these files to discover more information as needed.

# Setting up Terraform for VPC
{: #terraform-setup}

Terraform on IBM Cloud&reg; enables predictable and consistent provisioning of IBM Cloud services so that you can rapidly build complex, multitier cloud environments by 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 VPC instances by using HashiCorp Configuration Language (HCL).
{: shortdesc}

Looking for a managed Terraform on IBM Cloud&reg; solution? Try out [IBM Cloud&reg; Schematics](https://cloud.ibm.com/docs/schematics?topic=schematics-getting-started&format=markdown). With Schematics, you can use Terraform without setting up or maintaining the CLI and the IBM Cloud&reg; Provider plug-in. Schematics also provides pre-defined Terraform templates that you can easily install from the IBM Cloud&reg; catalog.
{: tip}

## Installing Terraform and configuring resources for VPC
{: #install-terraform}

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

1. Follow the [Terraform on IBM Cloud&reg; getting started tutorial](https://cloud.ibm.com/docs/ibm-cloud-provider-for-terraform?topic=ibm-cloud-provider-for-terraform-getting-started&format=markdown) to install the Terraform CLI and configure the IBM Cloud&reg; Provider plug-in for Terraform. The plug-in abstracts the IBM Cloud&reg; APIs that are used to provision, update, or delete VPC service instances and resources.
2. Create a Terraform configuration file that is named `main.tf`. In this file, you add the configuration to create an IBM Cloud&reg; Virtual Private Cloud and associated resources by using HashiCorp Configuration Language (HCL). For more information, see [Provisioning infrastructure with Terraform](https://cloud.ibm.com/docs/solution-tutorials?topic=solution-tutorials-vpc-app-deploy&format=markdown#vpc-app-deploy-terraform) and [Terraform documentation](https://developer.hashicorp.com/terraform/language){: external}.

   The following example creates a VPC, a subnet in the `us-south-1` zone, an SSH key, a virtual network interface, and a virtual server instance with boot volume encryption and two network attachments. For other supported regions, see [Regions and endpoints](https://cloud.ibm.com/docs/vpc?topic=vpc-service-endpoints-for-vpc&format=markdown).

   ```terraform
   resource "ibm_is_vpc" "example" {
     name = "example-vpc"
   }

   resource "ibm_is_subnet" "example" {
     name            = "example-subnet"
     vpc             = ibm_is_vpc.example.id
     zone            = "us-south-1"
     ipv4_cidr_block = "10.240.0.0/24"
   }

   resource "ibm_is_ssh_key" "example" {
     name       = "example-ssh"
     public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVERRN7/9484SOBJ3HSKxxNG5JN8owAjy5f9yYwcUg+JaUVuytn5Pv3aeYROHGGg+5G346xaq3DAwX6Y5ykr2fvjObgncQBnuU5KHWCECO/4h8uWuwh/kfniXPVjFToc+gnkqA+3RKpAecZhFXwfalQ9mMuYGFxn+fwn8cYEApsJbsEmb0iJwPiZ5hjFC8wREuiTlhPHDgkBLOiycd20op2nXzDbHfCHInquEe/gYxEitALONxm0swBOwJZwlTDOB7C6y2dzlrtxr1L59m7pCkWI4EtTRLvleehBoj3u7jB4usR"
   }

   resource "ibm_is_virtual_network_interface" "example" {
     name                      = "example-vni"
     allow_ip_spoofing         = false
     enable_infrastructure_nat = true
     primary_ip {
       auto_delete = false
       address     = "10.240.0.8"
     }
     subnet = ibm_is_subnet.example.id
   }

   resource "ibm_is_instance" "example" {
     name                     = "example-instance"
     image                    = ibm_is_image.example.id
     profile                  = "bx2-2x8"
     metadata_service_enabled = false

     boot_volume {
       encryption = "crn:v1:bluemix:public:kms:us-south:a/<account_id>:<kms_instance_id>:key:<key_id>"
     }

     primary_network_attachment {
       name = "example-primary-att"
       virtual_network_interface {
         id = ibm_is_virtual_network_interface.example.id
       }
     }

     network_attachments {
       name = "example-network-att"
       virtual_network_interface {
         name                      = "example-net-vni"
         auto_delete               = true
         enable_infrastructure_nat = true
         primary_ip {
           auto_delete = true
           address     = "10.240.0.6"
         }
         subnet = ibm_is_subnet.example.id
       }
     }

     vpc  = ibm_is_vpc.example.id
     zone = ibm_is_subnet.example.zone
     keys = [ibm_is_ssh_key.example.id]

     //User can configure timeouts
     timeouts {
       create = "15m"
       update = "15m"
       delete = "15m"
     }
   }
   ```
   {: codeblock}

   For more IBM VPC Terraform examples, see the [Terraform Registry for IBM VPC infrastructure](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/is_instance){: external}.

3. Initialize the Terraform CLI.

   ```sh
   terraform init
   ```
   {: pre}

4. Create a Terraform execution plan. The Terraform execution plan summarizes all the actions that need to be run to create the Virtual Servers for VPC instance in your account.

   ```sh
   terraform plan
   ```
   {: pre}

5. Create the Virtual Servers for VPC instance and associated resources in IBM Cloud.

   ```sh
   terraform apply
   ```
   {: pre}

6. From the [IBM Cloud resource list](https://cloud.ibm.com/resources){: external}, select the IBM Cloud&reg; Virtual Private Cloud instance that you created and note the instance ID.
7. Verify that the instance is running. For more information, see [Managing virtual server instances](https://cloud.ibm.com/docs/vpc?topic=vpc-managing-virtual-server-instances&format=markdown).

## Using IBM Terraform modules for VPC
{: #terraform-ibm-modules}

In addition to writing individual Terraform resources, you can use IBM Cloud Terraform modules to provision VPC infrastructure. IBM Cloud Terraform modules are a collection of open source Terraform modules that help you build, update, and version complex and compliant environments in IBM Cloud. The modules are curated and actively supported by the IBM Cloud development organization and are published in the [terraform-ibm-modules](https://github.com/terraform-ibm-modules){: external} GitHub organization.

Rather than defining each `ibm_is_*` resource individually, you reference a module in a single `module` block and supply input variables. The module manages the underlying resources for you.

IBM Terraform modules are available for an expanding set of VPC services. The following modules are currently available:

| Service | Module |
|---------|--------|
| File storage | [terraform-ibm-vpc-file-storage](https://github.com/terraform-ibm-modules/terraform-ibm-vpc-file-storage){: external} |
{: caption="IBM Terraform modules for VPC" caption-side="bottom"}

The file storage module supports zonal file shares with the `dp2` profile only.

For service-specific usage examples, see the Terraform tab in each service's documentation.

## What's next?
{: #terraform-setup-next}

Now that you successfully created your first IBM Cloud VPC service instance with Terraform on IBM Cloud, you can choose between the following tasks:

- [Managing virtual server instances](https://cloud.ibm.com/docs/vpc?topic=vpc-managing-virtual-server-instances&format=markdown#viewing-virtual-server-instances-terraform)
- [Creating Block Storage for VPC volumes](https://cloud.ibm.com/docs/vpc?topic=vpc-creating-block-storage&format=markdown#creating-vol-terraform)
- [Managing Block Storage for VPC volumes](https://cloud.ibm.com/docs/vpc?topic=vpc-managing-block-storage&format=markdown#managing-block-storage-terraform)
- [Creating file shares and mount targets](https://cloud.ibm.com/docs/vpc?topic=vpc-file-storage-create&format=markdown#file-storage-create-terraform)
- [Managing file shares, accessor share bindings, and mount targets](https://cloud.ibm.com/docs/vpc?topic=vpc-file-storage-managing&format=markdown#file-storage-manage-terraform)