Skip to content

Terraform with Other Cloud Providers

While AWS, Azure, and Google Cloud Platform are the most common cloud providers used with Terraform, many other cloud platforms are supported. Here's an overview of some other popular cloud providers and how to use them with Terraform.

DigitalOcean

The DigitalOcean provider is used to interact with the resources supported by DigitalOcean.

provider "digitalocean" {
  token = var.do_token
}

resource "digitalocean_droplet" "web" {
  image  = "ubuntu-18-04-x64"
  name   = "web-1"
  region = "nyc2"
  size   = "s-1vcpu-1gb"
}

Oracle Cloud Infrastructure (OCI)

The OCI provider is used to interact with Oracle Cloud resources.

provider "oci" {
  tenancy_ocid     = var.tenancy_ocid
  user_ocid        = var.user_ocid
  fingerprint      = var.fingerprint
  private_key_path = var.private_key_path
  region           = var.region
}

resource "oci_core_instance" "example" {
  availability_domain = data.oci_identity_availability_domain.ad.name
  compartment_id      = var.compartment_ocid
  shape               = "VM.Standard2.1"
  # ... other configurations
}

IBM Cloud

The IBM Cloud provider allows management of IBM Cloud resources.

provider "ibm" {
  ibmcloud_api_key = var.ibmcloud_api_key
  region           = "us-south"
}

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

Alibaba Cloud

The Alibaba Cloud provider is used to interact with Alibaba Cloud resources.

provider "alicloud" {
  access_key = var.alicloud_access_key
  secret_key = var.alicloud_secret_key
  region     = var.region
}

resource "alicloud_instance" "example" {
  instance_name        = "terraform-example"
  instance_type        = "ecs.n4.small"
  image_id             = "ubuntu_18_04_64_20G_alibase_20190624.vhd"
  system_disk_category = "cloud_efficiency"
  # ... other configurations
}

Best Practices for Multi-Cloud

  1. Use abstract modules to create a consistent interface across providers
  2. Implement proper state management for each cloud
  3. Use consistent naming conventions across all providers
  4. Manage secrets and credentials securely

Remember to always consult the official Terraform documentation for each provider for the most up-to-date information and best practices.