### Install Local Terraform Provider Binary Source: https://github.com/megaport/terraform-provider-megaport/blob/main/README.md This command compiles and installs the Terraform provider binary from the current directory (`terraform-provider-megaport` folder) into the Go binary path (GOBIN). This makes the locally built provider available for Terraform to use. ```Bash go install . ``` -------------------------------- ### Find Go Binary Installation Path Source: https://github.com/megaport/terraform-provider-megaport/blob/main/README.md This command is used to determine the directory where Go installs compiled binaries. This path is needed to configure Terraform to use a locally built provider. ```Bash $ go env GOBIN ``` -------------------------------- ### Creating a Megaport Port Resource (Terraform) Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/resources/vxc.md Defines a `megaport_port` resource, representing a physical or virtual port connection to the Megaport network. Configures parameters like product name, speed, location, contract term, and visibility. ```terraform resource "megaport_port" "port" { product_name = "Megaport Port Example" port_speed = 1000 location_id = data.megaport_location.bne_nxt1.id contract_term_months = 12 marketplace_visibility = false cost_centre = "Megaport Single Port Example" } ``` -------------------------------- ### Importing Megaport VXC Resource (Terraform Shell) Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/resources/vxc.md This command demonstrates how to import an existing Megaport VXC resource into your Terraform state. You need to replace `` with the actual unique identifier of the Megaport VXC you wish to import. ```shell # Order can be imported by specifying the Product UID. terraform import megaport_vxc.example "" ``` -------------------------------- ### Creating a Megaport MCR-to-Azure VXC (Partial) (Terraform) Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/resources/vxc.md Defines a `megaport_vxc` resource to create a VXC from an MCR to an Azure ExpressRoute partner service. Configures the connection details and specifies the MCR as the A-end. Note: The provided code snippet is incomplete. ```terraform resource "megaport_vxc" "azure_vxc" { product_name = "Megaport VXC Example - Azure" rate_limit = 200 contract_term_months = 12 a_end = { requested_product_uid = megaport_mcr.mcr.product_uid ``` -------------------------------- ### Creating a Megaport MCR-to-Google VXC (Terraform) Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/resources/vxc.md Defines a `megaport_vxc` resource to create a VXC from an MCR to a Google Cloud Interconnect partner service. Configures the connection details, specifies the MCR as the A-end (with VLAN), and includes Google-specific partner configuration details using a pairing key. ```terraform resource "megaport_vxc" "gcp_vxc" { product_name = "Megaport VXC Example - Google" rate_limit = 1000 contract_term_months = 12 a_end = { requested_product_uid = megaport_mcr.mcr.product_uid ordered_vlan = 182 } b_end = {} b_end_partner_config = { partner = "google" google_config = { pairing_key = "7e51371e-72a3-40b5-b844-2e3efefaee59/australia-southeast1/2" } } } ``` -------------------------------- ### Querying Megaport Location Data (Terraform) Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/resources/vxc.md Demonstrates how to use the `megaport_location` data source to retrieve information about specific Megaport locations by name. These data sources are typically used to get location IDs needed for creating other resources like ports or MCRs. ```terraform data "megaport_location" "bne_nxt1" { name = "NextDC B1" } data "megaport_location" "bne_nxt2" { name = "NextDC B2" } data "megaport_location" "syd_gs" { name = "Global Switch Sydney West" } ``` -------------------------------- ### Configure Terraform for Local Provider Development Source: https://github.com/megaport/terraform-provider-megaport/blob/main/README.md This configuration block in the `.terraformrc` file tells Terraform to use a locally built version of the `megaport/megaport` provider located at the specified `` (your GOBIN directory) instead of downloading it from the registry. The `direct {}` block ensures other providers are still installed normally. ```Terraform HCL provider_installation { dev_overrides { "registry.terraform.io/megaport/megaport" = "" } # For all other providers, install them directly from their origin provider # registries as normal. If you omit this, Terraform will _only_ use # the dev_overrides block, and so no other providers will be available. direct {} } ``` -------------------------------- ### Querying Megaport Partner Data (Terraform) Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/resources/vxc.md Shows how to use the `megaport_partner` data source to find information about a specific partner service (like AWS Direct Connect) at a given location. This data is often used as the B-end for VXC connections to cloud providers. ```terraform data "megaport_partner" "aws_port" { connect_type = "AWSHC" company_name = "AWS" product_name = "Asia Pacific (Sydney) (ap-southeast-2)" location_id = data.megaport_location.syd_gs.id } ``` -------------------------------- ### Sample Cloud Init Configuration for Aviatrix MVE (Commented) Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/resources/mve.md This commented block provides an example of a cloud-init configuration intended for an Aviatrix Edge MVE. It demonstrates how to define users and write a configuration file (`sample_config.cfg`) containing various settings like gateway name, controller IP, interface names, IP addresses, SSH keys, and certificates. This configuration is typically applied to the MVE instance after it is provisioned by Terraform. ```yaml # Sample Cloud Init Config for Aviatrix Edge - EXAMPLE ONLY # cloud-config # users: # - lock-passwd: false # name: admin # passwd: $6$example$XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX # write_files: # - content: '{"gateway_name": "EXAMPLE-GW", "controller_ip": "10.0.0.1", "launch_version": # "7.0.0", "dhcp": "False", "edge": "True", "caag": "False", "mgmt_interface_name": # "eth2", "mgmt_ip": "$PUBLIC_ADDRESS_WITH_MASK", "mgmt_default_gateway": "$PUBLIC_GATEWAY", # "ssh_public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCxample/DUMMY/KEY/PLACEHOLDER/VALUE/LONG/STRING/ # example@localhost\n", "rollback": "False", "gateway_uuid": "00000000000000000000000000000000", # "trustdomain": "example.com", "trustbundle": "-----BEGIN CERTIFICATE-----\nEXAMPLE # CERTIFICATE PLACEHOLDER - REPLACE WITH YOUR ACTUAL CERTIFICATE\n-----END # CERTIFICATE-----\n", "tmp_svid": "-----BEGIN CERTIFICATE-----\nEXAMPLE # CERTIFICATE PLACEHOLDER - REPLACE WITH YOUR ACTUAL CERTIFICATE\n-----END # CERTIFICATE-----\n", "tmp_key": "-----BEGIN PRIVATE KEY-----\nEXAMPLE # PRIVATE KEY PLACEHOLDER - REPLACE WITH YOUR ACTUAL PRIVATE KEY\n-----END # PRIVATE KEY-----\n", "tmp_svid_expiry": "0000000000"}' # owner: ubuntu:ubuntu # path: /etc/cloudx/sample_config.cfg ``` -------------------------------- ### Creating a Megaport Port-to-Port VXC (Terraform) Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/resources/vxc.md Defines a `megaport_vxc` resource to create a Virtual Cross Connect (VXC) between two Megaport ports. Configures the connection's product name, rate limit, contract term, and specifies the A-end and B-end ports using their product UIDs. ```terraform resource "megaport_vxc" "port_vxc" { product_name = "Megaport Port-to-Port VXC" rate_limit = 1000 contract_term_months = 12 a_end = { requested_product_uid = megaport_port.port.product_uid } b_end = { requested_product_uid = megaport_lag_port.lag_port.product_uid } } ``` -------------------------------- ### Creating a Megaport LAG Port Resource (Terraform) Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/resources/vxc.md Defines a `megaport_lag_port` resource, used to create a Link Aggregation Group (LAG) port on the Megaport network. Configures similar parameters to a standard port, plus the number of links in the LAG. ```terraform resource "megaport_lag_port" "lag_port" { product_name = "Megaport Lag Port Example" port_speed = 10000 location_id = data.megaport_location.bne_nxt2.id contract_term_months = 12 marketplace_visibility = false lag_count = 1 cost_centre = "Lag Port Example" } ``` -------------------------------- ### Creating a Megaport MVE Resource (Aruba, 2 VNICs) (Terraform) Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/resources/vxc.md Defines a `megaport_mve` (Megaport Virtual Edge) resource for an Aruba SD-WAN instance. Configures the MVE's basic properties, defines two virtual network interfaces (VNICs), and specifies vendor-specific configuration details like product size, image ID, and account information. ```terraform resource "megaport_mve" "mve" { product_name = "Megaport Aruba MVE" location_id = data.megaport_location.bne_nxt1.id contract_term_months = 1 vnics = [ { description = "to_aws" }, { description = "to_port" }, ] vendor_config = { vendor = "aruba" product_size = "MEDIUM" image_id = 23 account_name = "Megaport Aruba MVE" account_key = "Megaport Aruba MVE" system_tag = "Preconfiguration-aruba-test-1" } } ``` -------------------------------- ### Creating a Megaport IX Connection using Terraform Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/resources/ix.md This example demonstrates how to define a `megaport_ix` resource in Terraform. It first creates a `megaport_port` resource and then references its `product_uid` to establish the IX connection. It configures various parameters like name, network service type, ASN, MAC address, rate limit, VLAN, and shutdown status. ```HCL resource "megaport_port" "test_port" { product_name = "Test Port for IX" location_id = 67 port_speed = 1000 marketplace_visibility = false contract_term_months = 1 } resource "megaport_ix" "test_ix" { name = "Test IX Connection" requested_product_uid = megaport_port.test_port.product_uid network_service_type = "Sydney IX" asn = 65000 mac_address = "00:11:22:33:44:55" rate_limit = 500 vlan = 2000 shutdown = false } ``` -------------------------------- ### Creating a Megaport Port-to-MCR VXC (Terraform) Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/resources/vxc.md Defines a `megaport_vxc` resource to create a VXC between a Megaport port and a Megaport Cloud Router (MCR). Configures the connection details and specifies the A-end (port) and B-end (MCR) using their product UIDs, including VLAN assignment for both ends. ```terraform resource "megaport_vxc" "mcr_vxc" { product_name = "Megaport Port-to-MCR VXC" rate_limit = 1000 contract_term_months = 12 a_end = { requested_product_uid = megaport_port.port.product_uid ordered_vlan = 181 } b_end = { requested_product_uid = megaport_mcr.mcr.product_uid ordered_vlan = 181 } } ``` -------------------------------- ### Creating a Megaport MVE-to-AWS VXC (Terraform) Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/resources/vxc.md Defines a `megaport_vxc` resource to create a VXC from a Megaport Virtual Edge (MVE) to an AWS Direct Connect partner service. Configures the connection details, specifies the MVE as the A-end (with inner VLAN and VNIC index), and uses the `megaport_partner` data source for the B-end. Includes AWS-specific partner configuration details. ```terraform resource "megaport_vxc" "aws_mve_vxc" { product_name = "Megaport MVE VXC AWS MVE" rate_limit = 100 contract_term_months = 1 a_end = { requested_product_uid = megaport_mve.mve.product_uid inner_vlan = 100 vnic_index = 0 } b_end = { requested_product_uid = data.megaport_partner.aws_port.product_uid } b_end_partner_config = { partner = "aws" aws_config = { name = "Megaport MVE VXC AWS MVE" asn = 65121 type = "private" connect_type = "AWSHC" amazon_asn = 64512 owner_account = "123456789012" } } } ``` -------------------------------- ### Creating a Megaport MVE Resource (Aruba, 3 VNICs) (Terraform) Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/resources/vxc.md Defines another `megaport_mve` resource for an Aruba SD-WAN instance, similar to the previous one but configured with three virtual network interfaces (VNICs) for different traffic planes (Data, Management, Control). Includes vendor-specific configuration. ```terraform resource "megaport_mve" "mve" { product_name = "Megaport Aruba MVE" location_id = data.megaport_location.bne_nxt1.id contract_term_months = 1 vnics = [ { description = "Data Plane" }, { description = "Management Plane" }, { description = "Control Plane" } ] vendor_config = { vendor = "aruba" product_size = "MEDIUM" image_id = 23 account_name = "Megaport Aruba MVE" account_key = "Megaport Aruba MVE" system_tag = "Preconfiguration-aruba-test-1" } } ``` -------------------------------- ### Creating a Megaport LAG Port - Terraform Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/resources/lag_port.md This Terraform code snippet defines a `megaport_lag_port` resource. It configures a 10 Gbps LAG port with a 1-month contract term in a specific location, sets its marketplace visibility to false, and specifies the number of LAG ports and a cost center. This example shows the basic required and some optional parameters for resource creation. ```terraform resource "megaport_lag_port" "lag_port" { product_name = "Megaport Lag Port Example" port_speed = 10000 location_id = 6 contract_term_months = 1 marketplace_visibility = false lag_count = 1 cost_centre = "Lag Port Example" } ``` -------------------------------- ### Configure Provider, Get Location, and Create Port - Terraform Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/guides/single_port.md This Terraform configuration sets up the Megaport provider, retrieves a location ID using a data source, and defines a `megaport_port` resource. It specifies the provider environment, credentials, port speed, location, contract term, marketplace visibility, and cost centre. ```terraform terraform { required_providers { megaport = { source = "megaport/megaport" version = "1.0.0-beta1" } } } provider "megaport" { environment = "staging" access_key = "access_key" secret_key = "secret_Key" accept_purchase_terms = true } data "megaport_location" "bne_nxt1" { name = "NextDC B1" } resource "megaport_port" "port" { product_name = "Megaport Port Example" port_speed = 1000 location_id = data.megaport_location.bne_nxt1.id contract_term_months = 1 marketplace_visibility = false cost_centre = "Megaport Single Port Example" } ``` -------------------------------- ### Creating a Megaport MCR-to-AWS VXC (Terraform) Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/resources/vxc.md Defines a `megaport_vxc` resource to create a VXC from an MCR to an AWS Direct Connect partner service. Configures the connection details, specifies the MCR as the A-end (with VLAN), and uses the `megaport_partner` data source for the B-end. Includes AWS-specific partner configuration details required for the connection. ```terraform resource "megaport_vxc" "aws_vxc" { product_name = "Megaport VXC Example - AWS" rate_limit = 1000 contract_term_months = 1 a_end = { requested_product_uid = megaport.mcr.mcr.product_uid ordered_vlan = 191 } b_end = { requested_product_uid = data.megaport_partner.aws_port.product_uid } b_end_partner_config = { partner = "aws" aws_config = { name = "Megaport VXC Example - AWS" asn = 64550 type = "private" connect_type = "AWS" amazon_asn = 64551 owner_account = "123456789012" } } } ``` -------------------------------- ### Creating a Megaport MCR Resource (Terraform) Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/resources/vxc.md Defines a `megaport_mcr` (Megaport Cloud Router) resource. Configures the MCR's product name, speed, location, contract term, and ASN. MCRs are used for routing traffic between multiple services on the Megaport network. ```terraform resource "megaport_mcr" "mcr" { product_name = "Megaport MCR Example" port_speed = 2500 location_id = data.megaport_location.bne_nxt1.id contract_term_months = 1 asn = 64555 } ``` -------------------------------- ### Querying AWS Partner Port - Terraform Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/data-sources/partner.md This example demonstrates how to use the `megaport_partner` data source to find a specific AWS partner port by filtering on connection type, company name, product name, and location ID. This data can then be used elsewhere in the Terraform configuration. ```Terraform data "megaport_partner" "aws_port" { connect_type = "AWS" company_name = "AWS" product_name = "Asia Pacific (Sydney) (ap-southeast-2)" location_id = 3 } ``` -------------------------------- ### Creating a Megaport MCR Resource in Terraform Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/resources/mcr.md This Terraform code block defines a `megaport_mcr` resource named "mcr". It configures the MCR with a product name, port speed, location ID, and contract term. It also includes an example of configuring a prefix filter list with both permit and deny entries for specific IPv4 prefixes. ```HCL resource "megaport_mcr" "mcr" { product_name = "Megaport MCR Example" port_speed = 1000 location_id = 6 contract_term_months = 1 prefix_filter_lists = [{ description = "Megaport Example Prefix Filter List" address_family = "IPv4" entries = [ { action = "permit" prefix = "10.0.1.0/24" ge = 24 le = 24 }, { action = "deny" prefix = "10.0.2.0/24" ge = 24 le = 24 } ] }] } ``` -------------------------------- ### Configuring Megaport VXC Resource in Terraform Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/resources/vxc.md This Terraform code defines a `megaport_vxc` resource named `transit_vxc`. It configures the VXC with a specific product name, rate limit, and contract term. The `a_end` connects to a Megaport Virtual Edge (MVE) instance, while the `b_end` connects to a partner internet port, with specific partner configuration for the B-End. ```HCL resource "megaport_vxc" "transit_vxc" { product_name = "Transit VXC Example" rate_limit = 100 contract_term_months = 1 a_end = { requested_product_uid = megaport_mve.mve.product_uid vnic_index = 2 } b_end = { requested_product_uid = data.megaport_partner.internet_port.product_uid } b_end_partner_config = { partner = "transit" } } ``` -------------------------------- ### Importing a Megaport LAG Port - Shell Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/resources/lag_port.md This shell command uses the `terraform import` command to bring an existing Megaport LAG Port resource into the Terraform state. The command requires the resource type (`megaport_lag_port`), the desired resource name in the Terraform configuration (`example`), and the unique identifier of the existing Megaport product (``). Replace `` with the actual UID of the LAG port. ```shell # Order can be imported by specifying the Product UID. terraform import megaport_lag_port.example "" ``` -------------------------------- ### Configuring Megaport MCR and AWS VXC with BGP using Terraform Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/guides/vxc_vrouter.md This Terraform configuration defines the necessary resources to establish a connection between a Megaport Cloud Router (MCR) and an AWS Hosted Connection via a Virtual Cross Connect (VXC). It includes provider setup, data lookups for locations and AWS partner details, the MCR resource definition with prefix filtering, and the VXC resource definition with detailed A-end (MCR) and B-end (AWS) partner configurations, including BGP settings. ```Terraform provider "megaport" { environment = "staging" access_key = "access_key" secret_key = "secret_Key" accept_purchase_terms = true } data "megaport_location" "bne_nxt1" { name = "NextDC B1" } data "megaport_location" "syd_gs" { name = "Global Switch Sydney West" } data "megaport_partner" "aws_port" { connect_type = "AWSHC" company_name = "AWS" product_name = "Asia Pacific (Sydney) (ap-southeast-2)" location_id = data.megaport_location.syd_gs.id } resource "megaport_mcr" "mcr" { product_name = "Megaport Example MCR" location_id = data.megaport_location.bne_nxt1.id contract_term_months = 1 port_speed = 5000 asn = 64555 cost_centre = "MCR Example" prefix_filter_lists = [{ description = "Megaport Example Prefix Filter List" address_family = "IPv4" entries = [ { action = "permit" prefix = "10.0.1.0/24" ge = 24 le = 24 }, { action = "deny" prefix = "10.0.2.0/24" ge = 24 le = 24 } ] }] } resource "megaport_vxc" "aws_vxc" { product_name = "Megaport Example VXC - AWS" rate_limit = 1000 contract_term_months = 1 a_end = { requested_product_uid = megaport_mcr.mcr.product_uid ordered_vlan = 0 } a_end_partner_config = { partner = "vrouter" vrouter_config = { interfaces = [ { ip_addresses = ["10.0.0.1/30"] nat_ip_addresses = ["10.0.0.1"] bfd = { tx_interval = 500 rx_interval = 400 multiplier = 5 } bgp_connections = [ { peer_asn = 64512 local_ip_address = "10.0.0.1" peer_ip_address = "10.0.0.2" password = "notARealPassword" shutdown = false description = "BGP Connection 1" med_in = 100 med_out = 100 bfd_enabled = true export_policy = "deny" permit_export_to = ["10.0.1.2"] import_whitelist = "Megaport Example Prefix Filter List" } ] } ] } } b_end = { requested_product_uid = data.megaport_partner.aws_port.product_uid } b_end_partner_config = { partner = "aws" aws_config = { name = "Megaport Example VXC - AWS" asn = 64550 type = "private" connect_type = "AWSHC" amazon_asn = 64551 owner_account = "684021030471" } } } ``` -------------------------------- ### Initialize Terraform Project Source: https://github.com/megaport/terraform-provider-megaport/blob/main/examples/multicloud-scenarios/README.md This command initializes the Terraform working directory. It downloads the necessary provider plugins (like the Megaport provider) and sets up the backend configuration, preparing the directory for subsequent commands like 'plan' or 'apply'. ```Shell terraform init ``` -------------------------------- ### Importing Megaport IX Resource using Terraform Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/resources/ix.md This command imports an existing Megaport IX resource into the Terraform state. It requires the resource address (e.g., `megaport_ix.example`) and the unique identifier (`PRODUCT_UID`) of the resource in the Megaport platform to link the state to the actual resource. ```shell # Order can be imported by specifying the Product UID. terraform import megaport_ix.example "" ``` -------------------------------- ### Retrieve Megaport Datacenter Location Data Source: https://github.com/megaport/terraform-provider-megaport/blob/main/README.md These examples demonstrate how to use the `megaport_location` data source in Terraform to query and retrieve information about Megaport datacenter locations. Locations can be looked up by their name, site code, or unique numeric ID. ```Terraform HCL data "megaport_location" "my_location_1" { name = "NextDC B1" } ``` ```Terraform HCL data "megaport_location" "my_location_2" { site_code = "bne_nxt1" } ``` ```Terraform HCL data "megaport_location" "my_location_3" { id = 5 } ``` -------------------------------- ### Creating Initial Megaport Resources - Terraform Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/guides/moving_vxc.md This Terraform configuration sets up the initial state for demonstrating VXC moves. It defines the Megaport provider, retrieves a location ID, creates four Megaport Port resources, and establishes a VXC connecting the first two ports (port_1 and port_2). ```terraform provider "megaport" { environment = "staging" access_key = "access_key" secret_key = "secret_Key" accept_purchase_terms = true } data "megaport_location" "loc" { name = "NextDC B1" } resource "megaport_port" "port_1" { product_name = "Port 1" port_speed = 1000 location_id = data.megaport_location.loc.id contract_term_months = 12 marketplace_visibility = false } resource "megaport_port" "port_2" { product_name = "Port 2" port_speed = 1000 location_id = data.megaport_location.loc.id contract_term_months = 12 marketplace_visibility = false } resource "megaport_port" "port_3" { product_name = "Port 3" port_speed = 1000 location_id = data.megaport_location.loc.id contract_term_months = 12 marketplace_visibility = false } resource "megaport_port" "port_4" { product_name = "Port 4" port_speed = 1000 location_id = data.megaport_location.loc.id contract_term_months = 12 marketplace_visibility = false } resource "megaport_vxc" "vxc" { product_name = "Example VXC" rate_limit = 500 contract_term_months = 12 cost_centre = "Example Cost Centre" a_end = { requested_product_uid = megaport_port.port_1.product_uid } b_end = { requested_product_uid = megaport_port.port_2.product_uid } } ``` -------------------------------- ### Configure Go Workspace for Local Development Source: https://github.com/megaport/terraform-provider-megaport/blob/main/README.md This Go workspace configuration file (`go.work`) is used to facilitate local development of the Terraform provider alongside its dependency, the `megaportgo` library, without needing to publish changes or modify `go.mod` files. ```Go go 1.22.0 use ( ./megaportgo ./terraform-provider-megaport ) ``` -------------------------------- ### Configuring Full Megaport Ecosystem (Terraform) Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/guides/full_ecosystem.md This Terraform configuration defines the Megaport provider and sets up a complete ecosystem. It includes data sources to retrieve location and partner information, and resources to create a single Port, a LAG Port, a Megaport Cloud Router (MCR), and multiple Virtual Cross Connects (VXCs) linking the ports, MCR, and cloud providers (AWS, Google, Azure). Requires the Megaport Terraform provider. ```Terraform provider "megaport" { environment = "staging" access_key = "access_key" secret_key = "secret_Key" accept_purchase_terms = true } data "megaport_location" "bne_nxt1" { name = "NextDC B1" } data "megaport_location" "bne_nxt2" { name = "NextDC B2" } data "megaport_location" "syd_gs" { name = "Global Switch Sydney West" } data "megaport_partner" "aws_port" { connect_type = "AWS" company_name = "AWS" product_name = "Asia Pacific (Sydney) (ap-southeast-2)" location_id = data.megaport_location.syd_gs.id } resource "megaport_port" "port" { product_name = "Megaport Port Example" port_speed = 1000 location_id = data.megaport_location.bne_nxt1.id contract_term_months = 12 marketplace_visibility = false cost_centre = "Megaport Single Port Example" } resource "megaport_lag_port" "lag_port" { product_name = "Megaport Lag Port Example" port_speed = 10000 location_id = data.megaport_location.bne_nxt2.id contract_term_months = 12 marketplace_visibility = false lag_count = 1 cost_centre = "Lag Port Example" } resource "megaport_mcr" "mcr" { product_name = "Megaport MCR Example" port_speed = 2500 location_id = data.megaport_location.bne_nxt1.id contract_term_months = 1 asn = 64555 } resource "megaport_vxc" "port_vxc" { product_name = "Megaport Port-to-Port VXC" rate_limit = 1000 contract_term_months = 12 a_end = { requested_product_uid = megaport_port.port.product_uid } b_end = { requested_product_uid = megaport_lag_port.lag_port.product_uid } } resource "megaport_vxc" "mcr_vxc" { product_name = "Megaport Port-to-MCR VXC" rate_limit = 1000 contract_term_months = 12 a_end = { requested_product_uid = megaport_port.port.product_uid ordered_vlan = 181 } b_end = { requested_product_uid = megaport_mcr.mcr.product_uid ordered_vlan = 181 } } resource "megaport_vxc" "aws_vxc" { product_name = "Megaport VXC Example - AWS" rate_limit = 1000 contract_term_months = 1 a_end = { requested_product_uid = megaport.mcr.mcr.product_uid ordered_vlan = 191 } b_end = { requested_product_uid = data.megaport_partner.aws_port.product_uid } b_end_partner_config = { partner = "aws" aws_config = { name = "Megaport VXC Example - AWS" asn = 64550 type = "private" connect_type = "AWS" amazon_asn = 64551 owner_account = "123456789012" } } } resource "megaport_vxc" "gcp_vxc" { product_name = "Megaport VXC Example - Google" rate_limit = 1000 contract_term_months = 12 a_end = { requested_product_uid = megaport_mcr.mcr.product_uid ordered_vlan = 182 } b_end = {} b_end_partner_config = { partner = "google" google_config = { pairing_key = "7e51371e-72a3-40b5-b844-2e3efefaee59/australia-southeast1/2" } } } resource "megaport_vxc" "azure_vxc" { product_name = "Megaport VXC Example - Azure" rate_limit = 200 contract_term_months = 12 a_end = { requested_product_uid = megaport_mcr.mcr.product_uid ordered_vlan = 0 } b_end = {} b_end_partner_config = { partner = "azure" azure_config = { port_choice = "primary" service_key = "1b2329a5-56dc-45d0-8a0d-87b706297777" } } } ``` -------------------------------- ### Importing Megaport MVE Resource in Terraform Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/resources/mve.md This snippet shows the command syntax for importing an existing Megaport MVE resource into your Terraform state. You need to specify the resource address in your configuration (e.g., `megaport_mve.example`) and the unique product UID of the MVE you wish to import. ```shell # Order can be imported by specifying the Product UID. terraform import megaport_mve.example "" ``` -------------------------------- ### Creating a Megaport Aviatrix MVE Resource with Terraform Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/resources/mve.md This Terraform code defines a `megaport_mve` resource to provision a Megaport Virtual Edge instance configured for Aviatrix Edge. It specifies the product name, location, contract term, and vendor-specific configuration, including a base64-encoded cloud-init script for bootstrapping the Aviatrix instance. ```HCL resource "megaport_mve" "mve_aviatrix" { product_name = "Aviatrix-Edge" location_id = 6 contract_term_months = 12 vendor_config = { vendor = "aviatrix" image_id = data.megaport_mve_images.aviatrix.mve_images.0.id product_size = "SMALL" mve_label = "MVE 2/8" cloud_init = "IyBjbG91ZC1jb25maWcKdXNlcnM6Ci0gbG9jay1wYXNzd2Q6IGZhbHNlCiAgbmFtZTogYWRtaW4KICBwYXNzd2Q6ICQ2JGV4YW1wbGUkWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYCndyaXRlX2ZpbGVzOgotIGNvbnRlbnQ6ICd7ImdhdGV3YXlfbmFtZSI6ICJFWEFNUExFLUdXIiwgImNvbnRyb2xsZXJfaXAiOiAiMTAuMC4wLjEiLCAibGF1bmNoX3ZlcnNpb24iOgogICAgIjcuMC4wIiwgImRoY3AiOiAiRmFsc2UiLCAiZWRnZSI6ICJUcnVlIiwgImNhYWciOiAiRmFsc2UiLCAibWdtdF9pbnRlcmZhY2VfbmFtZSI6CiAgICAiZXRoMiIsICJtZ210X2lwIjogIiRQVUJMSUNfQUREUkVTU19XSVRIX01BU0siLCAibWdtdF9kZWZhdWx0X2dhdGV3YXkiOiAiJFBVQkxJQ19HQVRFV0FZIiwKICAgICJzc2hfcHVibGljX2tleSI6ICJzc2gtcnNhIEFBQUFCM056YUMxeWMyRUFBQUFEQVFBQkFBQUJBUUN4YW1wbGUvRFVNTVkvS0VZL1BMQUNFSE9MREVSL1ZBTFVFL0xPTkcvU1RSSU5HLwogICAgZXhhbXBsZUBsb2NhbGhvc3RcbiIsICJyb2xsYmFjayI6ICJGYWxzZSIsICJnYXRld2F5X3V1aWQiOiAiMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAiLAogICAgInRydXN0ZG9tYWluIjogImV4YW1wbGUuY29tIiwgInRydXN0YnVuZGxlIjogIi0tLS0tQkVHSU4gQ0VSVElGSUNBVEUtLS0tLVxuRVhBTVBMRQogICAgQ0VSVElGSUNBVEUgUExBQ0VIT0xERVIgLSBSRVBMQUNFIFdJVEggWU9VUiBBQ1RVQUwgQ0VSVElGSUNBVEVcbi0tLS0tRU5ECiAgICBDRVJUSUZJQ0FURS0tLS0tXG4iLCAidG1wX3N2aWQiOiAiLS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tXG5FWEFNUExFCiAgICBDRVJUSUZJQ0FURSBQTEFDQUVIT0xERVIgLSBSRVBMQUNFIFdJVEggWU9VUiBBQ1RVQUwgQ0VSVElGSUNBVEVcbi0tLS0tRU5ECiAgICBDRVJUSUZJQ0FURS0tLS0tXG4iLCAidG1wX2tleSI6ICItLS0tLUJFR0lOIFBSSVZBVEUgS0VZLS0tLS1cblVYQU1QTEUKICAgIFBSSVZBVEUgS0VZIFBMQ0VIT0xERVIgLSBSRVBMQUNFIFdJVEggWU9VUiBBQ1RVQUwgUFJJVkFURSBLRVlcbi0tLS0tRU5ECiAgICBQUklWQVRFIEtFWTAtLS0tLVxuIiwgInRtcF9zdmlkX2V4cGlyeSI6ICIwMDAwMDAwMDAwIn0nCiAgb3duZXI6IHVidW50dOnVidW50dQogIHBhdGg6IC9ldGMvY2xvdWR4L3NhbXBsZV9jb25maWcuY2ZnCiAgcGVybWlzc2lvbnM6ICcwNzU1Jw==" # Base64 Encoded Cloud Init for Aviatrix Edge } } ``` -------------------------------- ### Apply Terraform Configuration Source: https://github.com/megaport/terraform-provider-megaport/blob/main/examples/multicloud-scenarios/README.md This command executes the actions defined in the Terraform configuration files to create, update, or destroy infrastructure resources. It typically prompts for confirmation before making any changes to your infrastructure. ```Shell terraform apply ``` -------------------------------- ### Creating a Megaport MVE Resource with Terraform Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/resources/mve.md This Terraform code block defines data sources to find specific MVE images (Aruba and Aviatrix) and then creates a `megaport_mve` resource named `mve_aruba`. It configures the MVE with a product name, location, contract term, defines three VNICs (Data, Control, Management), and includes vendor-specific configuration for Aruba, referencing the previously found image ID. ```terraform data "megaport_mve_images" "aruba" { vendor_filter = "Aruba" id_filter = 23 } resource "megaport_mve" "mve_aruba" { product_name = "Megaport MVE Example" location_id = 6 contract_term_months = 1 vnics = [ { description = "Data Plane" }, { description = "Control Plane" }, { description = "Management Plane" } ] vendor_config = { vendor = "aruba" product_size = "MEDIUM" image_id = data.megaport_mve_images.aruba.mve_images.0.id account_name = "Aruba Test Account" account_key = "12345678" system_tag = "Preconfiguration-aruba-test-1" } } data "megaport_mve_images" "aviatrix" { vendor_filter = "Aviatrix" id_filter = 70 } ``` -------------------------------- ### Importing Megaport Port with Terraform Shell Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/resources/port.md This command imports an existing Megaport Port resource into your Terraform state. It requires the unique Product UID of the Megaport Port you wish to import. Replace `` with the actual UID. ```shell terraform import megaport_port.example "" ``` -------------------------------- ### Creating Megaport Port Resource (Terraform) Source: https://github.com/megaport/terraform-provider-megaport/blob/main/docs/resources/port.md This Terraform configuration snippet defines a `megaport_port` resource to provision a new physical connection to the Megaport network. It specifies essential parameters such as the product name, port speed, location ID, contract term, marketplace visibility, and an optional cost centre for billing. ```HCL resource "megaport_port" "port" { product_name = "Megaport Port Example" port_speed = 1000 location_id = 6 contract_term_months = 1 marketplace_visibility = false cost_centre = "Megaport Single Port Example" } ```