Skip to content

Commit

Permalink
CXF-83183 Adding Service Token module and metal-2-fabric example with…
Browse files Browse the repository at this point in the history
… Metal Provider (#20)

* CXF-83183 Adding Service Token module and metal-2-fabric example with Metal provider

* CXF-83183 Changing dynamic block in Modules for zside service token type

* CXF-83183 removing comment

* CXF-83183 removing old outputs.tf file
  • Loading branch information
srushti-patl authored Jan 5, 2024
1 parent 1383e31 commit 7dab707
Show file tree
Hide file tree
Showing 12 changed files with 394 additions and 6 deletions.
Empty file.
70 changes: 70 additions & 0 deletions examples/metal-2-fabric-aws-connection/main.tf
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"
}
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
}
7 changes: 7 additions & 0 deletions examples/metal-2-fabric-aws-connection/outputs.tf
Original file line number Diff line number Diff line change
@@ -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
}
26 changes: 26 additions & 0 deletions examples/metal-2-fabric-aws-connection/terraform.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
equinix_client_id = "MyEquinixClientId"
equinix_client_secret = "MyEquinixSecret"

metal_auth_token = "<Metal Auth API Token>"
metal_connection_speed_unit = "MB"
metal_connection_metro = "SV"
metal_project_id = "<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 = ["[email protected]"]
bandwidth = 50
purchase_order_number = "1-323292"
zside_ap_type = "SP"
zside_ap_authentication_key = "<AWS_ACCOUNT_ID>"
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 = "<aws_access_key>" },
{ key = "secretKey", value = "<aws_secret_key>" }
]
92 changes: 92 additions & 0 deletions examples/metal-2-fabric-aws-connection/variables.tf
Original file line number Diff line number Diff line change
@@ -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 = []
}
9 changes: 9 additions & 0 deletions examples/metal-2-fabric-aws-connection/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_version = ">= 1.5.2"
required_providers {
equinix = {
source = "equinix/equinix"
version = ">= 1.20.0"
}
}
}
6 changes: 0 additions & 6 deletions modules/port-connection/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 }))
Expand Down
Empty file.
87 changes: 87 additions & 0 deletions modules/service-token-connection/main.tf
Original file line number Diff line number Diff line change
@@ -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
}
}
}

}
3 changes: 3 additions & 0 deletions modules/service-token-connection/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "primary_connection_id" {
value = equinix_fabric_connection.service_token_connection.id
}
Loading

0 comments on commit 7dab707

Please sign in to comment.