Skip to content

Commit 28ca263

Browse files
authored
feat: Port Module Changes and Port Order Example (#219)
* Port Module changes * Add example for port order * Cleanup comments * Add new line * Add check if both uuid and name are provided, give warning * Update with new filters param * More changes * Remove comments * Remove duplicate code * Minor changes * Add variable name * Address PR comments * Remove extra lines * Remove extra lines
1 parent a4ebebd commit 28ca263

9 files changed

Lines changed: 349 additions & 7 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Fabric Port to Fabric Public Service Profile Connection
2+
3+
This example shows how to leverage the [Fabric Port Connection Module](https://registry.terraform.io/modules/equinix/fabric/equinix/latest/submodules/port-connection)
4+
to create a Fabric Connection from a Fabric Port to Fabric Public Service Profile.
5+
6+
It leverages the Equinix Terraform Provider, equinix_fabric_port Terraform resource, equinix_fabric_port Terraform datasource and the Fabric Port Connection
7+
Module to setup the connection based on the parameters you have provided to this example; or based on the pattern
8+
you see used in this example it will allow you to create a more specific use case for your own needs.
9+
10+
See example usage below for details on how to use this example.
11+
12+
<!-- BEGIN_TF_DOCS -->
13+
<!-- END_TF_DOCS -->
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
provider "equinix" {
2+
client_id = var.equinix_client_id
3+
client_secret = var.equinix_client_secret
4+
}
5+
6+
resource "equinix_fabric_port" "order" {
7+
type = "XF_PORT"
8+
physical_ports_speed = var.physical_ports_speed
9+
connectivity_source_type = var.connectivity_source_type
10+
project = {
11+
project_id = var.project_id
12+
}
13+
account = {
14+
account_number = var.account_number
15+
}
16+
location = {
17+
metro_code = var.metro_code
18+
}
19+
physical_ports_type = var.physical_ports_type
20+
demarcation_point_ibx = var.demarcation_point_ibx
21+
redundancy = {
22+
priority = var.priority
23+
}
24+
encapsulation = {
25+
type = var.encapsulation_type
26+
tag_protocol_id = var.tag_protocol_id
27+
}
28+
lag_enabled = var.lag_enabled
29+
settings = {
30+
package_type = var.package_type
31+
shared_port_type = var.shared_port_type
32+
}
33+
physical_ports = [
34+
{
35+
type = var.type
36+
demarcation_point = {
37+
cage_unique_space_id = var.cage_unique_space_id
38+
cabinet_unique_space_id = var.cabinet_unique_space_id
39+
connector_type = var.connector_type
40+
patch_panel = var.patch_panel
41+
ibx = var.ibx
42+
}
43+
}
44+
]
45+
notifications = [
46+
{
47+
type = "TECHNICAL"
48+
registered_users = [
49+
var.registered_user
50+
]
51+
},
52+
{
53+
type = "NOTIFICATION"
54+
registered_users = [
55+
var.registered_user
56+
]
57+
}
58+
]
59+
physical_ports_count = var.physical_ports_count
60+
}
61+
62+
resource "time_sleep" "wait_for_activation" {
63+
depends_on = [equinix_fabric_port.order]
64+
create_duration = "5m"
65+
}
66+
67+
data "equinix_fabric_port" "check_active" {
68+
depends_on = [time_sleep.wait_for_activation]
69+
uuid = equinix_fabric_port.order.id
70+
}
71+
72+
resource "null_resource" "port_active_check" {
73+
depends_on = [data.equinix_fabric_port.check_active]
74+
75+
lifecycle {
76+
precondition {
77+
condition = data.equinix_fabric_port.check_active.state == "ACTIVE"
78+
error_message = "Port must be ACTIVE (current: ${data.equinix_fabric_port.check_active.state})"
79+
}
80+
}
81+
}
82+
83+
module "create_port_2_public_sp_connection" {
84+
depends_on = [null_resource.port_active_check]
85+
source = "../../modules/port-connection"
86+
87+
connection_name = var.connection_name
88+
connection_type = var.connection_type
89+
notifications_type = var.notifications_type
90+
notifications_emails = var.notifications_emails
91+
bandwidth = var.bandwidth
92+
purchase_order_number = var.purchase_order_number
93+
94+
# A-side
95+
aside_port_uuid = equinix_fabric_port.order.id
96+
aside_vlan_tag = var.aside_vlan_tag
97+
98+
# Z-side
99+
zside_ap_type = var.zside_ap_type
100+
zside_ap_profile_type = var.zside_ap_profile_type
101+
zside_location = var.zside_location
102+
zside_sp_name = var.zside_sp_name
103+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
output "port_uuid" {
2+
value = equinix_fabric_port.order.id
3+
}
4+
output "port_state" {
5+
value = data.equinix_fabric_port.check_active.state
6+
}
7+
output "public_sp_connection_id" {
8+
value = module.create_port_2_public_sp_connection.primary_connection_id
9+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
equinix_client_id = "MyEquinixClientId"
2+
equinix_client_secret = "MyEquinixSecret"
3+
4+
physical_ports_type = "1000BASE_LX"
5+
physical_ports_speed = 1000
6+
connectivity_source_type = "COLO"
7+
account_number = "1234567"
8+
metro_code = "SV"
9+
ibx = "SV1"
10+
demarcation_point_ibx = "SV1"
11+
cage_unique_space_id = "CAGE-001"
12+
cabinet_unique_space_id = "CAB-001"
13+
patch_panel = "PP-01"
14+
project_id = "project-001"
15+
registered_user = "user@example.com"
16+
physical_ports_count = 1
17+
tag_protocol_id = "0x8100"
18+
connector_type = "SC"
19+
package_type = "STANDARD"
20+
priority = "PRIMARY"
21+
encapsulation_type = "DOT1Q"
22+
23+
connection_name = "PortOrderCreateConnection"
24+
connection_type = "EVPL_VC"
25+
notifications_type = "ALL"
26+
notifications_emails = ["example@equinix.com"]
27+
bandwidth = 50
28+
purchase_order_number = "PO-123456"
29+
aside_vlan_tag = 2000
30+
31+
zside_ap_type = "SP"
32+
zside_ap_profile_type = "L2_PROFILE"
33+
zside_location = "SV"
34+
zside_sp_name = "Test-SP"
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
variable "equinix_client_id" {
2+
description = "Equinix client ID (consumer key), obtained after registering app in the developer platform"
3+
type = string
4+
sensitive = true
5+
}
6+
variable "equinix_client_secret" {
7+
description = "Equinix client secret ID (consumer secret), obtained after registering app in the developer platform"
8+
type = string
9+
sensitive = true
10+
}
11+
variable "connection_name" {
12+
description = "Connection name. An alpha-numeric 24 characters string which can include only hyphens and underscores"
13+
type = string
14+
}
15+
variable "connection_type" {
16+
description = "Defines the connection type like VG_VC, EVPL_VC, EPL_VC, EC_VC, IP_VC, ACCESS_EPL_VC"
17+
type = string
18+
}
19+
variable "notifications_type" {
20+
description = "Notification Type - ALL is the only type currently supported"
21+
type = string
22+
default = "ALL"
23+
}
24+
variable "notifications_emails" {
25+
description = "Array of contact emails"
26+
type = list(string)
27+
}
28+
variable "bandwidth" {
29+
description = "Connection bandwidth in Mbps"
30+
type = number
31+
}
32+
variable "purchase_order_number" {
33+
description = "Order number"
34+
type = string
35+
default = ""
36+
}
37+
variable "aside_vlan_tag" {
38+
description = "Vlan Tag information, outer vlanSTag for QINQ connections"
39+
type = string
40+
}
41+
variable "zside_ap_type" {
42+
description = "Access point type - COLO, VD, VG, SP, IGW, SUBNET, GW"
43+
type = string
44+
}
45+
variable "zside_ap_profile_type" {
46+
description = "Service profile type - L2_PROFILE, L3_PROFILE, ECIA_PROFILE, ECMC_PROFILE"
47+
type = string
48+
}
49+
variable "zside_location" {
50+
description = "Access point metro code"
51+
type = string
52+
}
53+
variable "zside_sp_name" {
54+
description = "Equinix Service Profile Name"
55+
type = string
56+
}
57+
variable "physical_ports_type" {
58+
description = "Physical ports type"
59+
type = string
60+
default = "1000BASE_LX"
61+
}
62+
variable "physical_ports_speed" {
63+
description = "Physical ports speed"
64+
type = number
65+
default = 1000
66+
}
67+
variable "connectivity_source_type" {
68+
description = "Connectivity source type"
69+
type = string
70+
default = "COLO"
71+
}
72+
variable "account_number" {
73+
description = "Account number"
74+
type = string
75+
}
76+
variable "metro_code" {
77+
description = "Metro code"
78+
type = string
79+
}
80+
variable "ibx" {
81+
description = "IBX"
82+
type = string
83+
}
84+
variable "demarcation_point_ibx" {
85+
description = "Demarcation point IBX"
86+
type = string
87+
}
88+
variable "cage_unique_space_id" {
89+
description = "Cage unique space ID"
90+
type = string
91+
}
92+
variable "cabinet_unique_space_id" {
93+
description = "Cabinet unique space ID"
94+
type = string
95+
}
96+
variable "patch_panel" {
97+
description = "Patch panel"
98+
type = string
99+
}
100+
variable "project_id" {
101+
description = "Project ID"
102+
type = string
103+
}
104+
variable "registered_user" {
105+
description = "Registered user for notifications"
106+
type = string
107+
}
108+
variable "physical_ports_count" {
109+
description = "Physical ports count"
110+
type = number
111+
default = 1
112+
}
113+
variable "tag_protocol_id" {
114+
description = "Tag protocol ID"
115+
type = string
116+
}
117+
variable "connector_type" {
118+
description = "Connector type"
119+
type = string
120+
}
121+
variable "package_type" {
122+
description = "Package type"
123+
type = string
124+
default = "STANDARD"
125+
}
126+
variable "priority" {
127+
description = "Redundancy priority"
128+
type = string
129+
}
130+
variable "encapsulation_type" {
131+
description = "Encapsulation type"
132+
type = string
133+
}
134+
variable "lag_enabled" {
135+
description = "LAG enabled"
136+
type = bool
137+
}
138+
variable "shared_port_type" {
139+
description = "Shared port type"
140+
type = bool
141+
}
142+
variable "type" {
143+
description = "Physical port type"
144+
type = string
145+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
terraform {
2+
required_version = ">= 1.5.4"
3+
required_providers {
4+
equinix = {
5+
source = "equinix/equinix"
6+
version = ">= 4.9.0"
7+
}
8+
}
9+
}

modules/port-connection/main.tf

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
data "equinix_fabric_ports" "aside_port" {
2-
filters {
3-
name = var.aside_port_name
2+
filter {
3+
property = var.aside_port_name != "" ? "/name" : "/uuid"
4+
operator = "="
5+
value = var.aside_port_name != "" ? var.aside_port_name : var.aside_port_uuid
46
}
57
}
68

79
data "equinix_fabric_ports" "aside_secondary_port" {
810
count = var.aside_secondary_port_name != "" ? 1 : 0
9-
filters {
10-
name = var.aside_secondary_port_name
11+
filter {
12+
property = "/name"
13+
operator = "="
14+
value = var.aside_secondary_port_name
1115
}
1216
}
1317

@@ -22,8 +26,10 @@ data "equinix_fabric_service_profiles" "zside_sp" {
2226

2327
data "equinix_fabric_ports" "zside_port" {
2428
count = var.zside_ap_type == "COLO" ? 1 : 0
25-
filters {
26-
name = var.zside_port_name
29+
filter {
30+
property = var.zside_port_name != "" ? "/name" : "/uuid"
31+
operator = "="
32+
value = var.zside_port_name != "" ? var.zside_port_name : var.zside_port_uuid
2733
}
2834
}
2935

@@ -246,3 +252,15 @@ resource "equinix_fabric_connection" "secondary_port_connection" {
246252
}
247253
}
248254
}
255+
256+
check "port_name_uuid_mutual_exclusion" {
257+
assert {
258+
condition = !(var.zside_port_name != "" && var.zside_port_uuid != "")
259+
error_message = "ERROR: Cannot set both zside_port_name and zside_port_uuid. Please set only one."
260+
}
261+
262+
assert {
263+
condition = !(var.aside_port_name != "" && var.aside_port_uuid != "")
264+
error_message = "ERROR: Cannot set both aside_port_name and aside_port_uuid. Please set only one."
265+
}
266+
}

modules/port-connection/variables.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ variable "term_length" {
4747
variable "aside_port_name" {
4848
description = "Equinix A-Side Port Name; your tagging must match the encapsulation type of the port (DOT1Q or QINQ)"
4949
type = string
50+
default = ""
5051
}
5152
variable "aside_secondary_port_name" {
5253
description = "Equinix A-Side Port Name; your tagging must match the encapsulation type of the port (DOT1Q or QINQ)"
@@ -156,3 +157,13 @@ variable "role" {
156157
type = string
157158
default = ""
158159
}
160+
variable "aside_port_uuid" {
161+
description = "Equinix A-Side Port UUID; use this instead of aside_port_name. Only one of aside_port_name or aside_port_uuid can be set."
162+
type = string
163+
default = ""
164+
}
165+
variable "zside_port_uuid" {
166+
description = "Equinix Z-Side Port UUID; use this instead of aside_port_name"
167+
type = string
168+
default = ""
169+
}

0 commit comments

Comments
 (0)