Many of our customers have had success deploying Equinix Fabric™ to empower software-defined interconnection across their digital infrastructure. For these customers, the next logical step is to build on that success by making it repeatable. APIs are one way to do this; developers can set up Equinix Fabric environments using APIs, and then quickly and easily redeploy them in the aftermath of a disaster or reconfiguration.
However, many people don’t have time to manage multiple APIs from all their vendors, particularly since those APIs may be changing constantly. For these people, an Infrastructure as Code (IaC) wrapper such as Terraform may provide a simpler option for unlocking the repeatability benefits of APIs across their ecosystem of services and devices.
Explore the Equinix Developer Portal
The Equinix Developer Portal contains detailed documentation for Equinix APIs, along with information on getting started.Read More
Taking a cloud-agnostic approach to infrastructure repeatability
Terraform is a cloud-agnostic IaC engine that can help prevent vendor lock-in. Many other IaC engines are built by one specific cloud provider, and therefore make it difficult to connect digital infrastructure to other cloud providers.
With Terraform, you get the same reliable results across all cloud providers. This is helpful for customers looking to capitalize on hybrid multicloud, as it gives them the flexibility to connect with multiple cloud providers, and the agility to adapt connections as business plans change.
It also helps reduce duplicate work by enabling you to capture best practices you’ve adopted and methods you’re using for deployments. Why reinvent the wheel if you’ve already figured out how you want to execute something? With Terraform, you don’t have to.
Getting started with Terraform
There is a very low barrier to entry for those looking to get started with Terraform. All you need to start writing code is the default Notepad app found on every Windows computer, although a more robust editor with syntax-highlighting capabilities—such as Notepad++, Atom, or Visual Studio Code—would probably be helpful.
Once you’ve chosen an editor, you’ll need to download Terraform. You will launch your Terraform plan from the Command Line or terminal. Depending on the cloud provider, you may also need a cloud-specific command-line interface.
After you’ve assembled your tools, you’ll need to set up your accounts. This would include an Equinix Developer account (available for free to all existing Equinix customers) and a cloud provider account (which may be available via a free trial).
Three steps to Terraform success
There are three main steps to creating repeatable infrastructure with Terraform:
- Write your code using Hashicorp Configuration Language (HCL), which allows for concise descriptions of resources using blocks, arguments and expressions.
- Run terraform plan, which verifies that the execution plan you wrote is executable and aligned to your expectations.
- Apply your code using terraform apply, which interacts with the cloud APIs to provision the resources you defined.
By following these three steps, you can get the digital infrastructure your organization needs, quickly and consistently. Infrastructure defined via Terraform can be deployed and redeployed without using a GUI, essentially removing any possibility of configuration issues caused by human error. A Terraform execution plan delivers the same results, regardless of who deploys it. You can also set up Terraform to output the resulting configuration that is deployed, allowing you to document your configuration for future reference.
To start, set up your developer app on the Equinix Developer Platform. From the App Dashboard, click “New App”. Edit the app details as needed, and then select “Create”. You’ll then see the App Information and Authentication Details, as shown below. Make a note of the Consumer Key and Consumer Secret values, as you’ll use them again later.
When your developer app is ready, the next step is to confirm the availability of Equinix Fabric ports. Most cloud operators will create redundant connections using primary and secondary ports. The graphic below shows an example of what this looks like, using the example of a Microsoft Azure cloud connecting to Equinix Fabric via Azure ExpressRoute.
Understanding the anatomy of a Terraform module
A Terraform “provider” is a plug-in that helps developers understand API interactions and expose resources. Equinix created our own Terraform provider because we wanted our customers to have the best possible experience with Terraform. Many cloud hyperscalers have done the same. Visit the Terraform Registry for a complete list of official Terraform providers.
A simple Terraform directory is made up of three files:
- terraform.tf, which instantiates the Terraform providers—typically the Equinix provider and a cloud platform provider.
- main.tf, which includes the logic and arguments needed to design the infrastructure.
- variable.tf, which contains values for things like locations, client secrets and which ports to use.
More complex Terraform modules might require multiple resource files; in these cases, the main.tf file would store nested module calls that point to the resource files.
Executing your Terraform plan
To initialize Terraform, run terraform init in your command-line utility. This will pull the Terraform provider information from your terraform.tf file and initialize the providers.
Then, run terraform plan to query the relevant APIs and find out what changes need to be made to set up the resources named in your main.tf file.
You’ll then be able to review a list of resources to be created. If you approve, run terraform apply to create those resources.
Terraform will create the resource groups in the cloud first, then the connections between the cloud and Equinix Fabric, before finally provisioning resources within Equinix Fabric.
Resource Groups in Microsoft Azure Provisioned via Terraform
After you’ve created your Terraform environment, you can use the same console to destroy it. Run terraform destroy, and all actions performed in the previous steps will be undone in reverse order. This means the Equinix Fabric ports will be deprovisioned first, then the cloud connections, and then the cloud resource groups. After you run terraform destroy, you will no longer be billed by Equinix or your cloud provider for the resources you previously provisioned.
Resource Groups Deprovisioned via Terraform
Get started with Terraform for Equinix Fabric
Now that you’ve seen a quick overview of how to use Terraform with Equinix Fabric for repeatable infrastructure, I encourage you to experiment and see what you can do for yourself. The Equinix Terraform Provider repository on GitHub includes examples and other documents to help you get started.
Also, visit the Equinix Developer Portal for more use cases and templates to help you make the most of Equinix APIs.
You may also be interested in
View the replay of my presentation from the Equinix ConNext 2021 event, where I’ll take you through the Terraform for Equinix Fabric demo in more detail. You can also download the scripts used in the demo.