From 29720d667f83cb54471063c05743ad364e7c9e75 Mon Sep 17 00:00:00 2001 From: Srushti Patel <137830748+srushti-patl@users.noreply.github.com> Date: Thu, 7 Mar 2024 10:57:32 -0800 Subject: [PATCH] feat: Integrating GCP Provider with Fabric examples (#37) * feat: Integrating GCP Provider with Fabric examples * chore:Adding variable type and fixing indentation * fix: Changing variables name from gcp to google * misc:removing files for old GCP example --- .../cloud-router-2-gcp-connection/main.tf | 27 -------- .../cloud-router-2-gcp-connection/outputs.tf | 3 - .../README.md | 2 +- .../cloud-router-2-google-connection/main.tf | 57 +++++++++++++++++ .../outputs.tf | 12 ++++ .../terraform.tfvars.example | 13 ++++ .../variables.tf | 61 +++++++++++++++---- .../versions.tf | 5 ++ examples/port-2-google-connection/main.tf | 34 ++++++++++- examples/port-2-google-connection/outputs.tf | 11 +++- .../terraform.tfvars.example | 15 ++++- .../port-2-google-connection/variables.tf | 61 +++++++++++++++---- 12 files changed, 244 insertions(+), 57 deletions(-) delete mode 100644 examples/cloud-router-2-gcp-connection/main.tf delete mode 100644 examples/cloud-router-2-gcp-connection/outputs.tf rename examples/{cloud-router-2-gcp-connection => cloud-router-2-google-connection}/README.md (99%) create mode 100644 examples/cloud-router-2-google-connection/main.tf create mode 100644 examples/cloud-router-2-google-connection/outputs.tf rename examples/{cloud-router-2-gcp-connection => cloud-router-2-google-connection}/terraform.tfvars.example (51%) rename examples/{cloud-router-2-gcp-connection => cloud-router-2-google-connection}/variables.tf (58%) rename examples/{cloud-router-2-gcp-connection => cloud-router-2-google-connection}/versions.tf (65%) diff --git a/examples/cloud-router-2-gcp-connection/main.tf b/examples/cloud-router-2-gcp-connection/main.tf deleted file mode 100644 index f2ca4c29..00000000 --- a/examples/cloud-router-2-gcp-connection/main.tf +++ /dev/null @@ -1,27 +0,0 @@ -provider "equinix" { - client_id = var.equinix_client_id - client_secret = var.equinix_client_secret -} - -module "cloud_router_gcp_connection" { - source = "../../modules/cloud-router-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 - - #Aside - aside_ap_type = var.aside_ap_type - aside_fcr_uuid = var.aside_fcr_uuid - - #Zside - 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_fabric_sp_name = var.zside_fabric_sp_name -} diff --git a/examples/cloud-router-2-gcp-connection/outputs.tf b/examples/cloud-router-2-gcp-connection/outputs.tf deleted file mode 100644 index 080cdbb4..00000000 --- a/examples/cloud-router-2-gcp-connection/outputs.tf +++ /dev/null @@ -1,3 +0,0 @@ -output "module_output" { - value = module.cloud_router_gcp_connection.primary_connection_id -} diff --git a/examples/cloud-router-2-gcp-connection/README.md b/examples/cloud-router-2-google-connection/README.md similarity index 99% rename from examples/cloud-router-2-gcp-connection/README.md rename to examples/cloud-router-2-google-connection/README.md index 88268209..daddf65e 100644 --- a/examples/cloud-router-2-gcp-connection/README.md +++ b/examples/cloud-router-2-google-connection/README.md @@ -30,7 +30,7 @@ you should clone the github repository for this module and run terraform within ```bash git clone https://github.com/equinix/terraform-equinix-fabric.git -cd terraform-equinix-fabric/examples/cloud-router-2-gcp-connection +cd terraform-equinix-fabric/examples/cloud-router-2-google-connection terraform init terraform apply ``` diff --git a/examples/cloud-router-2-google-connection/main.tf b/examples/cloud-router-2-google-connection/main.tf new file mode 100644 index 00000000..b3792ce9 --- /dev/null +++ b/examples/cloud-router-2-google-connection/main.tf @@ -0,0 +1,57 @@ +provider "equinix" { + client_id = var.equinix_client_id + client_secret = var.equinix_client_secret +} + +provider "google" { + region = var.google_region + project = var.google_project_id + zone = var.google_zone + credentials = var.google_credentials_path +} + +resource "google_compute_network" "cloud-router-google" { + project = var.google_project_id + name = var.google_network_name + mtu = var.google_network_mtu + auto_create_subnetworks = var.google_network_auto_create_subnetwork +} + +resource "google_compute_router" "cloud-router-google" { + name = var.google_router_name + network = google_compute_network.cloud-router-google.name + bgp { + asn = var.google_router_bgp_asn + } +} + +resource "google_compute_interconnect_attachment" "cloud-router-google" { + name = var.google_interconnect_name + type = var.google_interconnect_type + router = google_compute_router.cloud-router-google.id + region = var.google_region + edge_availability_domain = var.google_interconnect_edge_availability_domain +} + +module "cloud_router_google_connection" { + source = "../../modules/cloud-router-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 + + #Aside + aside_ap_type = var.aside_ap_type + aside_fcr_uuid = var.aside_fcr_uuid + + #Zside + zside_ap_type = var.zside_ap_type + zside_ap_authentication_key = google_compute_interconnect_attachment.cloud-router-google.pairing_key + zside_ap_profile_type = var.zside_ap_profile_type + zside_location = var.zside_location + zside_seller_region = var.google_region + zside_fabric_sp_name = var.zside_fabric_sp_name +} diff --git a/examples/cloud-router-2-google-connection/outputs.tf b/examples/cloud-router-2-google-connection/outputs.tf new file mode 100644 index 00000000..d956a123 --- /dev/null +++ b/examples/cloud-router-2-google-connection/outputs.tf @@ -0,0 +1,12 @@ +output "GCP_Network_Id" { + value = google_compute_network.cloud-router-google.id +} +output "GCP_Router_Id" { + value = google_compute_router.cloud-router-google.id +} +output "GCP_Interconnect_Id" { + value = google_compute_interconnect_attachment.cloud-router-google.id +} +output "Google_Connection_Id" { + value = module.cloud_router_google_connection.primary_connection_id +} diff --git a/examples/cloud-router-2-gcp-connection/terraform.tfvars.example b/examples/cloud-router-2-google-connection/terraform.tfvars.example similarity index 51% rename from examples/cloud-router-2-gcp-connection/terraform.tfvars.example rename to examples/cloud-router-2-google-connection/terraform.tfvars.example index 1d5bb9c9..0fa742a5 100644 --- a/examples/cloud-router-2-gcp-connection/terraform.tfvars.example +++ b/examples/cloud-router-2-google-connection/terraform.tfvars.example @@ -1,6 +1,19 @@ equinix_client_id = "" equinix_client_secret = "" +google_project_id = "" +google_region = "us-west1" +google_zone = "us-west1-a" +google_credentials_path = "" +google_network_name = "tf-test-network" +google_network_mtu = "1460" +google_network_auto_create_subnetwork = true +google_router_name = "tf-test-router" +google_router_bgp_asn = "16550" +google_interconnect_name = "tf-test-interconnect" +google_interconnect_type = "PARTNER" +google_interconnect_edge_availability_domain = "AVAILABILITY_DOMAIN_1" + connection_name = "fcr_2_gcp" connection_type = "IP_VC" notifications_type = "ALL" diff --git a/examples/cloud-router-2-gcp-connection/variables.tf b/examples/cloud-router-2-google-connection/variables.tf similarity index 58% rename from examples/cloud-router-2-gcp-connection/variables.tf rename to examples/cloud-router-2-google-connection/variables.tf index f21c1f85..56579099 100644 --- a/examples/cloud-router-2-gcp-connection/variables.tf +++ b/examples/cloud-router-2-google-connection/variables.tf @@ -6,6 +6,56 @@ variable "equinix_client_secret" { description = "Equinix client secret ID (consumer secret), obtained after registering app in the developer platform" type = string } +#Google Provider +variable "google_region" { + description = "The Google region to manage resources in" + type = string +} +variable "google_project_id" { + description = "The default Google Project Id to manage resources in" + type = string +} +variable "google_zone" { + description = "The default Google Zone to manage resources in" + type = string +} +variable "google_credentials_path" { + description = "Path to the contents of a service account key file in JSON format" + type = string +} +variable "google_network_name" { + description = "The Google Network Name" + type = string +} +variable "google_network_mtu" { + description = "The Google Network Maximum Transmission Unit in bytes" + type = string +} +variable "google_network_auto_create_subnetwork" { + description = "When set to true, the network is created in auto subnet mode" + type = bool +} +variable "google_router_name" { + description = "The Google Router Name" + type = string +} +variable "google_router_bgp_asn" { + description = "The Google Router Local BGP Autonomous System Number (ASN)" + type = string +} +variable "google_interconnect_name" { + description = "The Google Interconnect Name" + type = string +} +variable "google_interconnect_type" { + description = "The Google Interconnect Type" + type = string +} +variable "google_interconnect_edge_availability_domain" { + description = "The Google Interconnect Edge Availability Domain" + type = string +} +#Fabric Connection variable "connection_name" { description = "Connection name. An alpha-numeric 24 characters string which can include only hyphens and underscores" type = string @@ -41,12 +91,6 @@ variable "aside_fcr_uuid" { description = "Equinix-assigned Fabric Cloud Router identifier" type = string } - -variable "zside_ap_authentication_key" { - description = "Authentication key for provider based connections" - type = string - default = "" -} variable "zside_ap_type" { description = "Access point type - COLO, VD, VG, SP, IGW, SUBNET, GW" type = string @@ -67,8 +111,3 @@ variable "zside_fabric_sp_name" { type = string default = "" } -variable "zside_seller_region" { - description = "Access point seller region" - type = string - default = "" -} diff --git a/examples/cloud-router-2-gcp-connection/versions.tf b/examples/cloud-router-2-google-connection/versions.tf similarity index 65% rename from examples/cloud-router-2-gcp-connection/versions.tf rename to examples/cloud-router-2-google-connection/versions.tf index 8e226867..54915252 100644 --- a/examples/cloud-router-2-gcp-connection/versions.tf +++ b/examples/cloud-router-2-google-connection/versions.tf @@ -5,5 +5,10 @@ terraform { source = "equinix/equinix" version = ">= 1.20.0" } + google = { + source = "hashicorp/google" + version = "5.17.0" + } + } } diff --git a/examples/port-2-google-connection/main.tf b/examples/port-2-google-connection/main.tf index c68024da..f284c830 100644 --- a/examples/port-2-google-connection/main.tf +++ b/examples/port-2-google-connection/main.tf @@ -3,6 +3,36 @@ provider "equinix" { client_secret = var.equinix_client_secret } +provider "google" { + region = var.google_region + project = var.google_project_id + zone = var.google_zone + credentials = var.google_credentials_path +} + +resource "google_compute_network" "port-google" { + project = var.google_project_id + name = var.google_network_name + mtu = var.google_network_mtu + auto_create_subnetworks = var.google_network_auto_create_subnetwork +} + +resource "google_compute_router" "port-google" { + name = var.google_router_name + network = google_compute_network.port-google.name + bgp { + asn = var.google_router_bgp_asn + } +} + +resource "google_compute_interconnect_attachment" "port-google" { + name = var.google_interconnect_name + type = var.google_interconnect_type + router = google_compute_router.port-google.id + region = var.google_region + edge_availability_domain = var.google_interconnect_edge_availability_domain +} + module "create_port_2_google_connection" { source = "../../modules/port-connection" @@ -20,9 +50,9 @@ module "create_port_2_google_connection" { # Z-side zside_ap_type = var.zside_ap_type - zside_ap_authentication_key = var.zside_ap_authentication_key + zside_ap_authentication_key = google_compute_interconnect_attachment.port-google.pairing_key zside_ap_profile_type = var.zside_ap_profile_type zside_location = var.zside_location - zside_seller_region = var.zside_seller_region + zside_seller_region = var.google_region zside_sp_name = var.zside_sp_name } diff --git a/examples/port-2-google-connection/outputs.tf b/examples/port-2-google-connection/outputs.tf index 0855a738..ab8977bd 100644 --- a/examples/port-2-google-connection/outputs.tf +++ b/examples/port-2-google-connection/outputs.tf @@ -1,3 +1,12 @@ -output "google_connection_id" { +output "GCP_Network_Id" { + value = google_compute_network.port-google.id +} +output "GCP_Router_Id" { + value = google_compute_router.port-google.id +} +output "GCP_Interconnect_Id" { + value = google_compute_interconnect_attachment.port-google.id +} +output "Google_connection_id" { value = module.create_port_2_google_connection.primary_connection_id } diff --git a/examples/port-2-google-connection/terraform.tfvars.example b/examples/port-2-google-connection/terraform.tfvars.example index 4dd4a90d..8c909072 100644 --- a/examples/port-2-google-connection/terraform.tfvars.example +++ b/examples/port-2-google-connection/terraform.tfvars.example @@ -1,6 +1,19 @@ equinix_client_id = "MyEquinixClientId" equinix_client_secret = "MyEquinixSecret" +google_project_id = "" +google_region = "us-west1" +google_zone = "us-west1-a" +google_credentials_path = "" +google_network_name = "tf-test-network" +google_network_mtu = "1460" +google_network_auto_create_subnetwork = true +google_router_name = "tf-test-router" +google_router_bgp_asn = "16550" +google_interconnect_name = "tf-test-interconnect" +google_interconnect_type = "PARTNER" +google_interconnect_edge_availability_domain = "AVAILABILITY_DOMAIN_1" + connection_name = "Port_2_google" connection_type = "EVPL_VC" notifications_type = "ALL" @@ -15,4 +28,4 @@ zside_ap_authentication_key = "" zside_ap_profile_type = "L2_PROFILE" zside_location = "SV" zside_seller_region = "us-west1" -zside_sp_name = "Google Cloud Partner Interconnect Zone 2" +zside_sp_name = "Google Cloud Partner Interconnect Zone 1" diff --git a/examples/port-2-google-connection/variables.tf b/examples/port-2-google-connection/variables.tf index c1eac384..ed1f7b69 100644 --- a/examples/port-2-google-connection/variables.tf +++ b/examples/port-2-google-connection/variables.tf @@ -6,7 +6,56 @@ variable "equinix_client_secret" { description = "Equinix client secret ID (consumer secret), obtained after registering app in the developer platform" type = string } - +#Google Provider +variable "google_region" { + description = "The Google region to manage resources in" + type = string +} +variable "google_project_id" { + description = "The default Google Project Id to manage resources in" + type = string +} +variable "google_zone" { + description = "The default Google Zone to manage resources in" + type = string +} +variable "google_credentials_path" { + description = "Path to the contents of a service account key file in JSON format" + type = string +} +variable "google_network_name" { + description = "The Google Network Name" + type = string +} +variable "google_network_mtu" { + description = "The Google Network Maximum Transmission Unit in bytes" + type = string +} +variable "google_network_auto_create_subnetwork" { + description = "When set to true, the network is created in auto subnet mode" + type = bool +} +variable "google_router_name" { + description = "The Google Router Name" + type = string +} +variable "google_router_bgp_asn" { + description = "The Google Router Local BGP Autonomous System Number (ASN)" + type = string +} +variable "google_interconnect_name" { + description = "The Google Interconnect Name" + type = string +} +variable "google_interconnect_type" { + description = "The Google Interconnect Type" + type = string +} +variable "google_interconnect_edge_availability_domain" { + description = "The Google Interconnect Edge Availability Domain" + type = string +} +#Fabric Connection variable "connection_name" { description = "Connection name. An alpha-numeric 24 characters string which can include only hyphens and underscores" type = string @@ -33,12 +82,10 @@ variable "purchase_order_number" { type = string default = "" } - variable "aside_port_name" { description = "Equinix A-Side Port Name" type = string } - variable "aside_vlan_tag" { description = "Vlan Tag information, outer vlanSTag for QINQ connections" type = string @@ -52,10 +99,6 @@ variable "zside_ap_type" { description = "Access point type - COLO, VD, VG, SP, IGW, SUBNET, GW" type = string } -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 @@ -68,7 +111,3 @@ variable "zside_sp_name" { description = "Equinix Service Profile Name" type = string } -variable "zside_seller_region" { - description = "Access point seller region" - type = string -}