diff --git a/examples/metal-2-fabric-aws-connection/README.md b/examples/metal-2-fabric-aws-connection/README.md new file mode 100644 index 00000000..e69de29b diff --git a/examples/metal-2-fabric-aws-connection/main.tf b/examples/metal-2-fabric-aws-connection/main.tf new file mode 100644 index 00000000..c3bc3acb --- /dev/null +++ b/examples/metal-2-fabric-aws-connection/main.tf @@ -0,0 +1,70 @@ +provider "equinix" { + client_id = var.equinix_client_id + client_secret = var.equinix_client_secret + auth_token = var.metal_auth_token // added +} +resource "random_string" "random" { + length = 3 + special = false +} +locals { + connection_name = format("%s-%s", var.connection_name, random_string.random.result) + metal_speed_unit = var.metal_connection_speed_unit == "GB" ? "Gbps" : "Mbps" +} +resource "equinix_metal_device" "s1" { + hostname = "tf-rocky9-server-${var.metal_connection_metro}-1" + plan = "m3.small.x86" + metro = lower(var.metal_connection_metro) + operating_system = "rocky_9" + billing_cycle = "hourly" + project_id = var.metal_project_id +} +resource "equinix_metal_vlan" "vlan-server-1" { + description = "${var.metal_connection_metro} VLAN Server 1 to Cloud" + metro = lower(var.metal_connection_metro) + project_id = var.metal_project_id +} +resource "equinix_metal_device_network_type" "s1-network-type" { + device_id = equinix_metal_device.s1.id + type = "hybrid" +} +resource "equinix_metal_port_vlan_attachment" "s1-attachment" { + device_id = equinix_metal_device_network_type.s1-network-type.id + port_name = "bond0" + vlan_vnid = equinix_metal_vlan.vlan-server-1.vxlan +} +resource "equinix_metal_connection" "metal-connection" { + name = local.connection_name + project_id = var.metal_project_id + metro = var.metal_connection_metro + redundancy = "primary" + type = "shared" + service_token_type = "a_side" + description = var.metal_connection_description + tags = ["terraform"] + speed = format("%d%s", var.connection_speed, local.metal_speed_unit) + vlans = [equinix_metal_vlan.vlan-server-1.vxlan] // required for shared connection + contact_email = "srpatel@equinix.com" +} +module "metal-2-fabric-connection" { + source = "../../modules/service-token-connection" + + connection_name = var.connection_name + connection_type = var.connection_type + notifications_type = var.notifications_type + notifications_emails = var.notifications_emails + bandwidth = var.bandwidth + purchase_order_number = var.purchase_order_number + additional_info = var.additional_info + + #A-Side + aside_service_token_uuid = equinix_metal_connection.metal-connection.service_tokens.0.id + + #Z-Side + zside_ap_type = var.zside_ap_type + zside_ap_authentication_key = var.zside_ap_authentication_key + zside_ap_profile_type = var.zside_ap_profile_type + zside_location = var.zside_location + zside_seller_region = var.zside_seller_region + zside_sp_name = var.zside_sp_name +} diff --git a/examples/metal-2-fabric-aws-connection/outputs.tf b/examples/metal-2-fabric-aws-connection/outputs.tf new file mode 100644 index 00000000..14d08642 --- /dev/null +++ b/examples/metal-2-fabric-aws-connection/outputs.tf @@ -0,0 +1,7 @@ +output "metal-connection" { + value = equinix_metal_connection.metal-connection.id +} + +output "fabric-connection" { + value = module.metal-2-fabric-connection.primary_connection_id +} diff --git a/examples/metal-2-fabric-aws-connection/terraform.tfvars.example b/examples/metal-2-fabric-aws-connection/terraform.tfvars.example new file mode 100644 index 00000000..bcc0301b --- /dev/null +++ b/examples/metal-2-fabric-aws-connection/terraform.tfvars.example @@ -0,0 +1,26 @@ +equinix_client_id = "MyEquinixClientId" +equinix_client_secret = "MyEquinixSecret" + +metal_auth_token = "" +metal_connection_speed_unit = "MB" +metal_connection_metro = "SV" +metal_project_id = "" +metal_connection_description = "Connect from Equinix Metal to Service provider using a-side token" + +connection_speed = 50 +connection_name = "metal-2-fabric" +connection_type = "EVPL_VC" +notifications_type = "ALL" +notifications_emails = ["example@equinix.com"] +bandwidth = 50 +purchase_order_number = "1-323292" +zside_ap_type = "SP" +zside_ap_authentication_key = "" +zside_ap_profile_type = "L2_PROFILE" +zside_location = "SV" +zside_sp_name = "AWS Direct Connect" +zside_seller_region = "us-west-1" +additional_info = [ + { key = "accessKey", value = "" }, + { key = "secretKey", value = "" } +] diff --git a/examples/metal-2-fabric-aws-connection/variables.tf b/examples/metal-2-fabric-aws-connection/variables.tf new file mode 100644 index 00000000..7413dd41 --- /dev/null +++ b/examples/metal-2-fabric-aws-connection/variables.tf @@ -0,0 +1,92 @@ +variable "equinix_client_id" { + description = "Equinix client ID (consumer key), obtained after registering app in the developer platform" + type = string +} +variable "equinix_client_secret" { + description = "Equinix client secret ID (consumer secret), obtained after registering app in the developer platform" + type = string +} +variable "metal_auth_token" { + description = "Equinix Metal Authentication API Token" + type = string +} +variable "metal_connection_speed_unit" { + description = "Unit of the speed/bandwidth to be allocated to the connection" + type = string + default = "MB" +} +variable "metal_connection_metro" { + description = "Metro where the connection will be created" + type = string +} +variable "metal_project_id" { + description = "Metal Project Name" + type = string +} +variable "metal_connection_description" { + description = "Description for the connection resource" + type = string + default = "Connect from Equinix Metal to Service provider using a-side token" +} +variable "connection_speed" { + description = "Speed/Bandwidth to be allocated to the connection - (MB or GB)" + type = number + default = 50 +} +variable "connection_name" { + description = "Connection name. An alpha-numeric 24 characters string which can include only hyphens and underscores" + type = string +} +variable "connection_type" { + description = "Defines the connection type like VG_VC, EVPL_VC, EPL_VC, EC_VC, IP_VC, ACCESS_EPL_VC" + type = string +} +variable "notifications_type" { + description = "Notification Type - ALL is the only type currently supported" + type = string + default = "ALL" +} +variable "notifications_emails" { + description = "Array of contact emails" + type = list(string) +} +variable "bandwidth" { + description = "Connection bandwidth in Mbps" + type = number +} +variable "purchase_order_number" { + description = "Purchase order number" + type = string + default = "" +} +variable "zside_ap_type" { + description = "Access point type - COLO, VD, VG, SP, IGW, SUBNET, GW" + type = string + default = "" +} +variable "zside_ap_authentication_key" { + description = "Authentication key for provider based connections" + type = string +} +variable "zside_ap_profile_type" { + description = "Service profile type - L2_PROFILE, L3_PROFILE, ECIA_PROFILE, ECMC_PROFILE" + type = string +} +variable "zside_location" { + description = "Access point metro code" + type = string + default = "" +} +variable "zside_sp_name" { + description = "Equinix Service Profile Name" + type = string +} +variable "zside_seller_region" { + description = "Access point seller region" + type = string +} +variable "additional_info" { + description = "Additional info parameters. It's a list of maps containing 'key' and 'value' keys with their corresponding values." + type = list(object({ key = string, value = string })) + default = [] +} diff --git a/examples/metal-2-fabric-aws-connection/versions.tf b/examples/metal-2-fabric-aws-connection/versions.tf new file mode 100644 index 00000000..81d18743 --- /dev/null +++ b/examples/metal-2-fabric-aws-connection/versions.tf @@ -0,0 +1,9 @@ +terraform { + required_version = ">= 1.5.2" + required_providers { + equinix = { + source = "equinix/equinix" + version = ">= 1.20.0" + } + } +} diff --git a/modules/port-connection/variables.tf b/modules/port-connection/variables.tf index 0656457c..e09df7ac 100644 --- a/modules/port-connection/variables.tf +++ b/modules/port-connection/variables.tf @@ -45,18 +45,15 @@ variable "aside_port_name" { description = "Equinix A-Side Port Name; your tagging must match the encapsulation type of the port (DOT1Q or QINQ)" type = string } - variable "aside_secondary_port_name" { description = "Equinix A-Side Port Name; your tagging must match the encapsulation type of the port (DOT1Q or QINQ)" type = string default = "" } - variable "aside_vlan_tag" { description = "VLan Tag information for DOT1Q connections, and the outer VLan tag for QINQ connections)" type = string } - variable "aside_vlan_inner_tag" { description = "VLan Tag information for DOT1Q connections" type = string @@ -96,7 +93,6 @@ variable "zside_seller_region" { type = string default = "" } - variable "zside_vlan_tag" { description = "VLan Tag information for DOT1Q connections, and the outer VLan tag for QINQ connections" type = string @@ -108,13 +104,11 @@ variable "zside_vlan_inner_tag" { type = string default = "" } - variable "zside_peering_type" { description = "Zside Access Point Peering type. Available values; PRIVATE, MICROSOFT, PUBLIC, MANUAL" type = string default = "" } - variable "additional_info" { description = "Additional info parameters. It's a list of maps containing 'key' and 'value' keys with their corresponding values." type = list(object({ key = string, value = string })) diff --git a/modules/service-token-connection/README.md b/modules/service-token-connection/README.md new file mode 100644 index 00000000..e69de29b diff --git a/modules/service-token-connection/main.tf b/modules/service-token-connection/main.tf new file mode 100644 index 00000000..8fe6c33c --- /dev/null +++ b/modules/service-token-connection/main.tf @@ -0,0 +1,87 @@ +data "equinix_fabric_service_profiles" "zside_sp" { + count = var.zside_ap_type == "SP" ? 1 : 0 + filter { + property = "/name" + operator = "=" + values = [var.zside_sp_name] + } +} +data "equinix_fabric_ports" "zside_port" { + count = var.zside_ap_type == "COLO" ? 1 : 0 + filters { + name = var.zside_port_name + } +} +resource "equinix_fabric_connection" "service_token_connection" { + name = var.connection_name + type = var.connection_type + notifications { + type = var.notifications_type + emails = var.notifications_emails + } + bandwidth = var.bandwidth + redundancy { priority = "PRIMARY" } + order { + purchase_order_number = var.purchase_order_number != "" ? var.purchase_order_number : null + } + + additional_info = var.additional_info != [] ? var.additional_info : null + + a_side { + service_token { + uuid = var.aside_service_token_uuid + } + } + + dynamic "z_side" { + # Service Profile Z_Side Type + for_each = var.zside_ap_type == "SP" ? [1] : [] + content { + access_point { + type = var.zside_ap_type + authentication_key = var.zside_ap_authentication_key + seller_region = var.zside_seller_region != "" ? var.zside_seller_region : null + profile{ + type = var.zside_ap_profile_type + uuid = data.equinix_fabric_service_profiles.zside_sp[0].data.0.uuid + } + location { + metro_code = var.zside_location + } + peering_type = var.zside_peering_type != "" ? var.zside_peering_type : null + } + } + } + + dynamic "z_side" { + # Port Z_Side Type + for_each = var.zside_ap_type == "COLO" ? [1] : [] + content { + access_point { + type = var.zside_ap_type + port { + uuid = data.equinix_fabric_ports.zside_port[0].data.0.uuid + } + link_protocol { + type = one(data.equinix_fabric_ports.zside_port[0].data.0.encapsulation).type + vlan_tag = one(data.equinix_fabric_ports.zside_port[0].data.0.encapsulation).type == "DOT1Q" ? var.zside_vlan_tag : null + vlan_s_tag = one(data.equinix_fabric_ports.zside_port[0].data.0.encapsulation).type == "QINQ" ? var.zside_vlan_tag : null + vlan_c_tag = one(data.equinix_fabric_ports.zside_port[0].data.0.encapsulation).type == "QINQ" && one(data.equinix_fabric_ports.aside_port.data.0.encapsulation).type != "QINQ" ? var.zside_vlan_inner_tag : null + } + location { + metro_code = var.zside_location + } + } + } + } + + dynamic "z_side" { + for_each = var.zside_service_token_uuid != "" ? [1] : [] + content { + service_token { + uuid = var.zside_service_token_uuid + } + } + } + +} diff --git a/modules/service-token-connection/outputs.tf b/modules/service-token-connection/outputs.tf new file mode 100644 index 00000000..46ef5a29 --- /dev/null +++ b/modules/service-token-connection/outputs.tf @@ -0,0 +1,3 @@ +output "primary_connection_id" { + value = equinix_fabric_connection.service_token_connection.id +} diff --git a/modules/service-token-connection/variables.tf b/modules/service-token-connection/variables.tf new file mode 100644 index 00000000..562a2ced --- /dev/null +++ b/modules/service-token-connection/variables.tf @@ -0,0 +1,91 @@ +variable "connection_name" { + description = "Connection name. An alpha-numeric 24 characters string which can include only hyphens and underscores" + type = string +} +variable "connection_type" { + description = "Defines the connection type like VG_VC, EVPL_VC, EPL_VC, EC_VC, IP_VC, ACCESS_EPL_VC" + type = string +} +variable "notifications_type" { + description = "Notification Type - ALL is the only type currently supported" + type = string + default = "ALL" +} +variable "notifications_emails" { + description = "Array of contact emails" + type = list(string) +} +variable "bandwidth" { + description = "Connection bandwidth in Mbps" + type = number +} +variable "purchase_order_number" { + description = "Purchase order number" + type = string + default = "" +} +variable "aside_service_token_uuid" { + description = "Equinix A-Side Service Token UUID" + type = string + default = "" +} +variable "zside_ap_type" { + description = "Access point type - VD, SP, COLO, CLOUD_ROUTER, NETWORK" + type = string + default = "" +} +variable "zside_ap_authentication_key" { + description = "Authentication key for provider based connections" + type = string + default = "" +} +variable "zside_ap_profile_type" { + description = "Service profile type - L2_PROFILE, L3_PROFILE, ECIA_PROFILE, ECMC_PROFILE" + type = string + default = "" +} +variable "zside_location" { + description = "Access point metro code" + type = string + default = "" +} +variable "zside_sp_name" { + description = "Equinix Service Profile Name" + type = string + default = "" +} +variable "zside_port_name" { + description = "Equinix Z-Side Port Name" + type = string + default = "" +} +variable "zside_seller_region" { + description = "Access point seller region" + type = string + default = "" +} +variable "zside_vlan_tag" { + description = "VLan Tag information for DOT1Q connections, and the outer VLan tag for QINQ connections" + type = string + default = "" +} +variable "zside_vlan_inner_tag" { + description = "Inner VLan tag for QINQ connections" + type = string + default = "" +} +variable "zside_peering_type" { + description = "Zside Access Point Peering type. Available values; PRIVATE, MICROSOFT, PUBLIC, MANUAL" + type = string + default = "" +} +variable "zside_service_token_uuid" { + description = "Service Token UUID" + type = string + default = "" +} +variable "additional_info" { + description = "Additional info parameters. It's a list of maps containing 'key' and 'value' keys with their corresponding values." + type = list(object({ key = string, value = string })) + default = [] +} diff --git a/modules/service-token-connection/versions.tf b/modules/service-token-connection/versions.tf new file mode 100644 index 00000000..81d18743 --- /dev/null +++ b/modules/service-token-connection/versions.tf @@ -0,0 +1,9 @@ +terraform { + required_version = ">= 1.5.2" + required_providers { + equinix = { + source = "equinix/equinix" + version = ">= 1.20.0" + } + } +}