Streamline your infrastructure: bunny.net now supports Terraform!

Posted by:

As your web applications grow in popularity, their underlying infrastructure often becomes complex as well, resulting in many operational headaches, such as manual resource management, configuration drift, maintenance issues, scalability, and security compliance concerns. 

At bunny.net, we understand firsthand that these are common daily challenges for developers and DevOps engineers. That's why we're excited to announce the release of the official Terraform Provider for bunny.net!

High-level diagram - Deploying bunny.net resources with Terraform


Why Terraform?

By offering a Terraform provider, we make it easier for you to setup and deploy different bunny.net services for your applications. Terraform's widespread adoption is a testament to its effectiveness in streamlining infrastructure management using code, or as it is referred to, Infrastructure as Code (IaC). 

Terraform allows you to manage infrastructure with code instead of using a graphical user interface or unstandardized scripts. Also, you can build, modify, and maintain your infrastructure safely, consistently, and repeatedly by defining resource configuration files that you can version, reuse, and share.

Terraform is a powerful, free, source-available, platform-agnostic tool from HashiCorp that can be used across multiple clouds and SaaS, including complex and modern scenarios involving on-prem and API services. 

What does this mean for my operation?

As developers building for other developers, we get it. Manual cloud services configuration and management, including CDN, storage, and compute services, is a rabbit hole you don't want to fall into. And, unstandardized scripts or going through numerous steps via an user interface can become complex and unscalable when needed to perform these tasks frequently. Not only is this tedious and time-consuming, but also be error-prone and cause you a lot of headaches.

With Terraform you can automate your infrastructure with standardized code and eliminate these pain points while giving you advantages over manually managing your infrastructure:

  • Manage infrastructure on multiple cloud platforms or web services.
  • Improve CI/CD pipelines by automating infrastructure changes alongside code deployments.
  • Create human-readable configuration language.
  • Manage resource dependencies.
  • Track resource changes throughout your deployments.
  • Use version control for safe collaboration.
  • Access an extensive ecosystem of thousands of solution providers, including major tech companies like AWS, Azure, Kubernetes, and DataDog. 

Now, with bunny.net’s Terraform provider, you can also bring our unique benefits to your operation, such as:

  • CDN: Deliver content globally on a top-performing content delivery network with 24ms global average latency and 150+ Tbps.
  • Cloud object storage: Provision and manage scalable multi-region object storage solutions in 15 regions, with no egress fees.
  • Smart DNS: Automate complex global logic with DNS scripting capabilities made surprisingly easy.
  • E2E video processing for VoD streaming: Seamlessly handle video processing for video-on-demand services, including upload, storage, adaptive bitrate transcoding, packaging, encryption, and playback.
  • Enterprise DRM: Implement Fairplay and Widevine DRM to protect your video content.

In addition, we're committed to making this a robust solution with the developer community. Our project is open source, and we welcome pull requests. Check out our GitHub repository here.

Getting started is easy:

  • Add the bunny.net provider to your Terraform config, or use our template here.
  • Add your API key.
  • Configure resources and apply the changes.

If it’s new to you, learn the basics of Terraform with these get-started tutorials. And, check out our documentation in the Terraform Registry.

Simple Terraform configuration file example 

This Terraform script creates a bunny.net storage zone in Germany with a unique name, creates a storage zone, a pull zone that connects the storage to the CDN, and an HTML file. The HTML file includes a custom message from Bunny and references the pull zone by name. 

This demonstrates how Terraform can automate the setup and management of cloud infrastructure with dynamic, code-driven configurations using Bunny services.

terraform {
  required_providers {
    random = {
      source  = "hashicorp/random"
      version = "3.6.2"
    }
    bunnynet = {
      source = "BunnyWay/bunnynet"
    }
  }
}

provider "random" {
}

provider "bunnynet" {
  api_key = "YOUR_BUNNY_API_KEY"
}

resource "random_string" "test" {
  length  = 8
  special = false
  upper   = false
}

resource "bunnynet_storage_zone" "test" {
  name      = "terraform-test-${random_string.test.result}"
  zone_tier = "Edge"
  region    = "DE"
}

resource "bunnynet_pullzone" "test" {
  name = bunnynet_storage_zone.test.name

  origin {
    type         = "StorageZone"
    storagezone  = bunnynet_storage_zone.test.id
  }

  routing {
    tier = "Standard"
  }
}

resource "bunnynet_storage_file" "homepage" {
  zone    = bunnynet_storage_zone.test.id
  path    = "index.html"
  content = "<h1>Hopping High with bunny.net!</h1><p>from Pull Zone: ${bunnynet_pullzone.test.name}, powered by Terraform. No carrots required!</p>"

}

output "url" {
  value = "https://${bunnynet_pullzone.test.name}.b-cdn.net/"
}

Use Terraform CLI to try it. Don’t forget to update your API key: 

  • Initialize: run `terraform init` to start your setup your configuration.
  • Plan: run `terraform plan` to preview the modifications.
  • Apply: run `terraform apply` to deploy the resources.

To learn more about the resources, you can run `terraform providers schema -json` right from your terminal or simply check our docs here.

Check our Github repo for more information and examples.

Hop ahead with bunny.net and Terraform for seamless deployment

At bunny.net, we are relentlessly working on creating more innovation and tools to help you create unique applications. Now, you can automate and streamline the deployment of our services, including Bunny CDN, Bunny, DNS, Bunny Storage, Bunny Stream, and more bunny.net resources to come soon.

Try the bunny.net Terraform provider today and make your infrastructure hop to new heights!