Automate Your Multicloud with the Megaport Terraform Provider

Automate Your Multicloud with the Megaport Terraform Provider

With Megaport’s Terraform Provider, you can now easily automate the provisioning and management of your Megaport resources, lowering deployment costs and reducing provisioning time by using Infrastructure as Code (IaC).

Many organizations on the cloud infrastructure journey quickly discover the need for tools to automate resources they create and manage. These tools make it easy to record the state of systems, maintain audit trails, and rapidly create consistent environments for testing or deployment purposes.

Amongst those tools, Terraform stands out. It’s highly successful in the multi-vendor cloud automation space. Its parent company, Hashicorp, has a solid reputation for delivering quality solutions and is often preferred over vendors’ own automation tools, which are an afterthought for most cloud services.

Megaport is proud to have its own Terraform module . You can use it right now to manage Megaport resources in the same way you manage compute and storage from the big cloud players.

If you’re not using Terraform yet, but are considering automating your cloud infrastructure, we recommend it. The IaC tool is widely adopted, easy to use, and has a great community for professional support. It has support for hundreds of popular service providers. And best of all, it’s free and open source.

Get a quick run-through of Megaport’s Terraform Provider.

What can you do with Megaport’s Terraform Provider?

Megaport has an independent global network with PoPs in nearly 400 physical locations. This includes on-ramps to all the major cloud brands and many other service providers. Connections between these providers and locations can be created in minutes, and with no lock-in, you can modify them to suit your demands. Megaport Cloud Router can be configured to create advanced network topologies, such as hybrid cloud solutions that connect multiple, distinct virtual networks together. Connecting AWS to Azure would be an example of this topology.

The Megaport Terraform Provider supports the resources required to configure these networks. And to make it even easier, Megaport has published example Terraform templates that create everything from simple data center connections right up to a hybrid cloud with AWS, Google, and Microsoft Azure networks all connected together.

How it works

Under the hood of the Megaport Terraform Provider, the cloud automation tool uses the same API that the Megaport Portal uses. The Megaport API documentation is available for clients who wish to customize Terraform or write their own bespoke integration.

Megaport publishes the code for our Terraform Provider on GitHub, and clients can interact with our DevOps team to report bugs or push their own code improvements for inclusion in the IaC tool.

To communicate with the Megaport API, the provider uses a library written in Go. This abstract’s functionality is customized for Megaport based on the standard Terraform behaviors and makes working on changes easier. The megaportgo library is also on GitHub.

The provider sits outside of the Megaport network and is not part of the paid Megaport product, so we strongly recommend referring to the documentation for support. We also have our short video demonstrating the tool in use.

Megaport and Terraform capabilities

Our Terraform Provider gives you the ability to manage your multicloud infrastructure including Megaport Ports, VXCs, and MCRs.

Getting started with Terraform

Whether you’re using Megaport by itself or with other cloud service providers, Terraform is easy to use. The official website has simple instructions for installing Terraform on your operating system of choice, and there are many tutorials and examples online.

There are only a few basic concepts for new users. The first is that you detail the desired infrastructure in a text file. The format of these is Terraform-specific and looks similar to JSON. The online documentation is clear with specific modules for each cloud provider. Once you get started, you’ll see the naming conventions closely align with the terms you would normally expect to use.

This short example shows the Terraform code you need in order to look up a Megaport location and provision a single network port there:

data megaport_location ndc_b1 {
name = NextDC B1
has_mcr = false

resource megaport_port tf_test {
port_name = Test Port
port_speed = 10000
location_id =

If you’ve used Megaport before, these fields will look familiar to you. The location represents a Megaport Enabled Location , which can be in one of hundreds of points of presence worldwide with many different data centre providers.

The other fields are “name” (the user can enter anything here that makes sense to them), and “port speed” in Mbps.

Once you have your file, Terraform can do the rest. As well as creating resources that match your specifications, it can check for differences between the file and the deployed resources, and if you approve, it will safely remove these differences.

Using Terraform

Once Terraform is up and running, it works from the command line of your operating system, giving advanced users the ability to include it within other scripts such as Continuous Deployment tools.

Initially, there are just three commands to remember:

terraform init  
terraform apply  
terraform destroy

All the commands need to be run in the same directory as your text file which describes the infrastructure. Terraform init will determine which provider modules are required to deploy your code and ensure they’re present.

Terraform apply is the launch button. This clever command determines the required sequence of deployment and makes those changes. As a safety precaution, it informs the user of any intended changes and asks for confirmation before proceeding.

When you’re done, terraform destroy will clean up the resources you created.

For advanced users, there are further possible commands and options based on feedback from millions of users. Whatever your use case, chances are somebody has already solved it.

If you aren’t using the Megaport Terraform Provider, give it a try. For more information, visit our Terraform Registry page , or to view our support forum, visit our GitHub .

Stay Updated

Keep up to date on Megaport in the news by following us on social media at:

Twitter: @megaportnetwork

LinkedIn: @megaport

Facebook: @megaportnetworks

Related Posts

How Green Is Your Network?

How Green Is Your Network?

As the tech industry goes green, how does your network stack up – and how can you make it greener?

Read More
Azure Berlin, Now Available with Megaport

Azure Berlin, Now Available with Megaport

It’s official, Azure Berlin is now available from Megaport. To say that we’re excited about this is an understatement.

Read More
What You Can Learn From AWS re:Invent 2021

What You Can Learn From AWS re:Invent 2021

AWS re:Invent 2021 last week featured a slew of announcements. Here are some key highlights and what they mean to you.

Read More