Caution
The Megaport CLI tool is currently an unsupported alpha, we're excited for feedback but please know that functionality and features may change drastically, and there may be bugs.
The Megaport CLI provides a command-line interface for managing Megaport resources and services. It allows users to interact with the Megaport API directly from their terminal.
Before using this CLI, please ensure you read and accept Megaport's Terms and Conditions and Acceptable Use Policy.
For API details, consult the Megaport API Documentation.
# Install using Go
go install github.com/megaport/megaport-cli@latest
# Verify installation
megaport-cli version
The CLI supports shell completion for bash, zsh, fish, and PowerShell:
# Bash (Linux)
megaport-cli completion bash > /etc/bash_completion.d/megaport
# Bash (macOS with Homebrew)
megaport-cli completion bash > $(brew --prefix)/etc/bash_completion.d/megaport
# Zsh
megaport-cli completion zsh > "${fpath[1]}/_megaport"
# Fish
megaport-cli completion fish > ~/.config/fish/completions/megaport.fish
# PowerShell
megaport-cli completion powershell > megaport.ps1
The CLI supports different Megaport environments:
- Production (default)
- Staging
- Development
Specify the environment using the --env
flag or MEGAPORT_ENVIRONMENT
variable.
Configure your CLI credentials using environment variables.
# Using environment variables
export MEGAPORT_ACCESS_KEY=<your-access-key>
export MEGAPORT_SECRET_KEY=<your-secret-key>
export MEGAPORT_ENVIRONMENT=<environment> # production, staging, or development
locations
: List and search Megaport locationsports
: Manage Megaport portsmcr
: Manage Megaport Cloud Routersmve
: Manage Megaport Virtual Edge instancesvxc
: Manage Virtual Cross Connectspartners
: List and search partner portsservicekeys
: Manage service keys
All commands support multiple output formats:
--output table
(default)--output json
--output csv
# List all locations
megaport-cli locations list
# List locations filtered by metro area
megaport-cli locations list --metro "San Francisco"
# Get details for a specific location
megaport-cli locations get LOCATION_ID --output json
# List all ports
megaport-cli ports list
# List ports filtered by location ID and port speed
megaport-cli ports list --location-id 1 --port-speed 1000
# Get details for a specific port
megaport-cli ports get PORT_UID --output json
# Buy a new port
megaport-cli ports buy --interactive
megaport-cli ports buy --name "My Port" --term 12 --port-speed 10000 --location-id 123 --marketplace-visibility true
megaport-cli ports buy --json '{"name":"My Port","term":12,"portSpeed":10000,"locationId":123,"marketPlaceVisibility":true}'
megaport-cli ports buy --json-file ./port-config.json
# Buy a LAG port
megaport-cli ports buy-lag --interactive
megaport-cli ports buy-lag --name "My LAG Port" --term 12 --port-speed 10000 --location-id 123 --lag-count 2 --marketplace-visibility true
megaport-cli ports buy-lag --json '{"name":"My LAG Port","term":12,"portSpeed":10000,"locationId":123,"lagCount":2,"marketPlaceVisibility":true}'
megaport-cli ports buy-lag --json-file ./lag-port-config.json
# Update a port
megaport-cli ports update PORT_UID --interactive
megaport-cli ports update PORT_UID --name "Updated Port" --marketplace-visibility true
megaport-cli ports update PORT_UID --json '{"name":"Updated Port","marketplaceVisibility":true}'
megaport-cli ports update PORT_UID --json-file ./update-port-config.json
# Delete a port
megaport-cli ports delete PORT_UID --now
# Restore a deleted port
megaport-cli ports restore PORT_UID
# Lock a port
megaport-cli ports lock PORT_UID
# Unlock a port
megaport-cli ports unlock PORT_UID
# Check VLAN availability on a port
megaport-cli ports check-vlan PORT_UID VLAN_ID
# List all MCRs
megaport-cli mcr list
# Get details for a specific MCR
megaport-cli mcr get MCR_UID --output json
# Buy a new MCR
megaport-cli mcr buy --interactive
megaport-cli mcr buy --name "My MCR" --term 12 --port-speed 10000 --location-id 123
megaport-cli mcr buy --name "My MCR" --term 12 --port-speed 10000 --location-id 123 --mcr-asn 65000 --diversity-zone "blue"
megaport-cli mcr buy --json '{"name":"My MCR","term":12,"portSpeed":10000,"locationId":123}'
megaport-cli mcr buy --json-file ./mcr-config.json
# Update an MCR
megaport-cli mcr update MCR_UID --interactive
megaport-cli mcr update MCR_UID --name "Updated MCR" --cost-centre "IT-123"
megaport-cli mcr update MCR_UID --json '{"name":"Updated MCR","costCentre":"IT-123"}'
megaport-cli mcr update MCR_UID --json-file ./update-mcr-config.json
# Delete an MCR
megaport-cli mcr delete MCR_UID --now
# Restore a deleted MCR
megaport-cli mcr restore MCR_UID
# Create a prefix filter list on an MCR
megaport-cli mcr create-prefix-filter-list MCR_UID --interactive
megaport-cli mcr create-prefix-filter-list MCR_UID --description "Block List" --address-family "IPv4" --entries '[{"action":"DENY","prefix":"10.0.0.0/8","ge":16,"le":24}]'
megaport-cli mcr create-prefix-filter-list MCR_UID --json '{"description":"Block List","addressFamily":"IPv4","entries":[{"action":"DENY","prefix":"10.0.0.0/8","ge":16,"le":24}]}'
megaport-cli mcr create-prefix-filter-list MCR_UID --json-file ./prefix-filter-config.json
# List all prefix filter lists for a specific MCR
megaport-cli mcr list-prefix-filter-lists MCR_UID
# Get details for a specific prefix filter list on an MCR
megaport-cli mcr get-prefix-filter-list MCR_UID PREFIX_FILTER_LIST_ID --output json
# Update a prefix filter list on an MCR
megaport-cli mcr update-prefix-filter-list MCR_UID PREFIX_FILTER_LIST_ID --interactive
megaport-cli mcr update-prefix-filter-list MCR_UID PREFIX_FILTER_LIST_ID --description "Updated Block List" --address-family "IPv4" --entries '[{"action":"DENY","prefix":"10.0.0.0/8"},{"action":"PERMIT","prefix":"192.168.0.0/16"}]'
megaport-cli mcr update-prefix-filter-list MCR_UID PREFIX_FILTER_LIST_ID --json '{"description":"Updated Block List","addressFamily":"IPv4","entries":[{"action":"DENY","prefix":"10.0.0.0/8"},{"action":"PERMIT","prefix":"192.168.0.0/16"}]}'
megaport-cli mcr update-prefix-filter-list MCR_UID PREFIX_FILTER_LIST_ID --json-file ./update-prefix-filter-config.json
# Delete a prefix filter list on an MCR
megaport-cli mcr delete-prefix-filter-list MCR_UID PREFIX_FILTER_LIST_ID
# Get details for a specific MVE
megaport-cli mve get MVE_UID --output json
# Buy a new MVE
megaport-cli mve buy --interactive
# Buy a new MVE - Cisco example
megaport-cli mve buy --name "My Cisco MVE" --term 12 --location-id 67 --vendor-config '{"vendor":"cisco","imageId":1,"productSize":"large","mveLabel":"cisco-mve","manageLocally":true,"adminSshPublicKey":"ssh-rsa AAAA...","sshPublicKey":"ssh-rsa AAAA...","cloudInit":"#cloud-config\npackages:\n - nginx\n","fmcIpAddress":"10.0.0.1","fmcRegistrationKey":"key123","fmcNatId":"natid123"}' --vnics '[{"description":"Data Plane","vlan":100}]'
megaport-cli mve buy --json '{"name":"My Cisco MVE","term":12,"locationId":67,"vendorConfig":{"vendor":"cisco","imageId":1,"productSize":"large","mveLabel":"cisco-mve","manageLocally":true,"adminSshPublicKey":"ssh-rsa AAAA...","sshPublicKey":"ssh-rsa AAAA...","cloudInit":"#cloud-config\npackages:\n - nginx\n","fmcIpAddress":"10.0.0.1","fmcRegistrationKey":"key123","fmcNatId":"natid123"},"vnics":[{"description":"Data Plane","vlan":100}]}'
# Buy a new MVE - Aruba example
megaport-cli mve buy --name "My Aruba MVE" --term 1 --location-id 67 --vendor-config '{"vendor":"aruba","imageId":23,"productSize":"MEDIUM","accountName":"Aruba Test Account","accountKey":"12345678","systemTag":"Preconfiguration-aruba-test-1"}' --vnics '[{"description":"Data Plane"},{"description":"Control Plane"},{"description":"Management Plane"}]'
megaport-cli mve buy --json '{"name":"My Aruba MVE","term":1,"locationId":67,"vendorConfig":{"vendor":"aruba","imageId":23,"productSize":"MEDIUM","accountName":"Aruba Test Account","accountKey":"12345678","systemTag":"Preconfiguration-aruba-test-1"},"vnics":[{"description":"Data Plane"},{"description":"Control Plane"},{"description":"Management Plane"}]}'
# Buy a new MVE - Versa example
megaport-cli mve buy --name "My Versa MVE" --term 1 --location-id 67 --vendor-config '{"vendor":"versa","imageId":20,"productSize":"MEDIUM","directorAddress":"director1.versa.com","controllerAddress":"controller1.versa.com","localAuth":"[email protected]","remoteAuth":"[email protected]","serialNumber":"Megaport-Hub1"}' --vnics '[{"description":"Data Plane"}]'
megaport-cli mve buy --json '{"name":"My Versa MVE","term":1,"locationId":67,"vendorConfig":{"vendor":"versa","imageId":20,"productSize":"MEDIUM","directorAddress":"director1.versa.com","controllerAddress":"controller1.versa.com","localAuth":"[email protected]","remoteAuth":"[email protected]","serialNumber":"Megaport-Hub1"},"vnics":[{"description":"Data Plane"}]}'
# Update an existing MVE
megaport-cli mve update MVE_UID --interactive
megaport-cli mve update MVE_UID --name "Updated MVE Name" --cost-centre "New Cost Centre" --contract-term 24
megaport-cli mve update MVE_UID --json '{"name": "New MVE Name", "costCentre": "New Cost Centre", "contractTermMonths": 24}'
# Delete an MVE
megaport-cli mve delete MVE_UID --now
# List all available MVE images
megaport-cli mve list-images
# List MVE images filtered by vendor
megaport-cli mve list-images --vendor "Cisco"
# List MVE images filtered by product code
megaport-cli mve list-images --product-code "FORTINET456"
# List MVE images filtered by ID
megaport-cli mve list-images --id 1
# List MVE images filtered by version
megaport-cli mve list-images --version "2.0"
# List MVE images filtered by release image
megaport-cli mve list-images --release-image
# List all available MVE sizes
megaport-cli mve list-sizes
# Get details for a specific VXC
megaport-cli vxc get VXC_UID --output json
# Buy a new VXC - Interactive mode.
megaport-cli vxc buy --interactive
# Flag mode - Basic VXC between two ports
megaport-cli vxc buy \
--a-end-uid "dcc-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \
--b-end-uid "dcc-yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy" \
--name "My VXC" \
--rate-limit 1000 \
--term 12 \
--a-end-vlan 100 \
--b-end-vlan 200
# Flag mode - VXC to AWS Direct Connect
megaport-cli vxc buy \
--a-end-uid "dcc-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \
--b-end-uid "dcc-yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy" \
--name "My AWS VXC" \
--rate-limit 1000 \
--term 12 \
--a-end-vlan 100 \
--b-end-partner-config '{"connectType":"AWS","ownerAccount":"123456789012","asn":65000,"amazonAsn":64512}'
# Flag mode - VXC to Azure ExpressRoute
megaport-cli vxc buy \
--a-end-uid "dcc-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \
--name "My Azure VXC" \
--rate-limit 1000 \
--term 12 \
--a-end-vlan 100 \
--b-end-partner-config '{"connectType":"AZURE","serviceKey":"s-abcd1234"}'
# Interactive mode
megaport-cli vxc update vxc-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --interactive
# Flag mode - Basic updates
megaport-cli vxc update vxc-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx \
--name "New VXC Name" \
--rate-limit 2000 \
--cost-centre "New Cost Centre"
# Flag mode - Update VLANs
megaport-cli vxc update vxc-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx \
--a-end-vlan 200 \
--b-end-vlan 300
# Delete a VXC
megaport-cli vxc delete VXC_UID
# List all partner ports
megaport-cli partners list
# List partner ports filtered by product name and company name
megaport-cli partners list --product-name "AWS Direct Connect" --company-name "AWS"
# Interactive search for partner ports with prompts
megaport-cli partners find
# List all service keys
megaport-cli servicekeys list
# Get details for a specific service key
megaport-cli servicekeys get SERVICE_KEY_UID --output json
# Create a new service key
megaport-cli servicekeys create --product-uid PRODUCT_UID --description "My Service Key" --max-speed 1000
# Update an existing service key
megaport-cli servicekeys update SERVICE_KEY_UID --description "Updated Description"
Contributions via pull request are welcome. Familiarize yourself with these guidelines to increase the likelihood of your pull request being accepted.
All contributions are subject to the Megaport Contributor Licence Agreement.
The CLA clarifies the terms of the Mozilla Public Licence 2.0 used to Open Source this repository and ensures that contributors are explicitly informed of the conditions. Megaport requires all contributors to accept these terms to ensure that the Megaport Terraform Provider remains available and licensed for the community.
When you open a Pull Request, all authors of the contributions are required to comment on the Pull Request confirming acceptance of the CLA terms. Pull Requests cannot be merged until this is complete.
Megaport users are also bound by the Acceptable Use Policy.