|
| 1 | +# Configure the Equinix Provider |
| 2 | +# Please refer to provider documentation for details on supported authentication methods and parameters. |
| 3 | +# https://registry.terraform.io/providers/equinix/equinix/latest/docs |
| 4 | +provider "equinix" { |
| 5 | + client_id = var.equinix_provider_client_id |
| 6 | + client_secret = var.equinix_provider_client_secret |
| 7 | +} |
| 8 | + |
| 9 | +# Configure the Google Cloud Platform Provider |
| 10 | +# https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/getting_started#adding-credentials |
| 11 | +provider "google" { |
| 12 | + project = var.gcp_project |
| 13 | + region = var.gcp_region |
| 14 | +} |
| 15 | + |
| 16 | +## Retrieve an existing equinix metal project |
| 17 | +## If you prefer you can use resource equinix_metal_project instead to create a fresh project |
| 18 | +data "equinix_metal_project" "this" { |
| 19 | + project_id = var.metal_project_id |
| 20 | +} |
| 21 | + |
| 22 | +locals { |
| 23 | + connection_name = format("conn-metal-gcp-%s", lower(var.fabric_destination_metro_code)) |
| 24 | +} |
| 25 | + |
| 26 | +# Create a new VLAN in Frankfurt |
| 27 | +resource "equinix_metal_vlan" "this" { |
| 28 | + description = format("VLAN in %s", var.fabric_destination_metro_code) |
| 29 | + metro = var.fabric_destination_metro_code |
| 30 | + project_id = data.equinix_metal_project.this.project_id |
| 31 | +} |
| 32 | + |
| 33 | +## Request a connection service token in Equinix Metal |
| 34 | +resource "equinix_metal_connection" "this" { |
| 35 | + name = local.connection_name |
| 36 | + project_id = data.equinix_metal_project.this.project_id |
| 37 | + metro = var.fabric_destination_metro_code |
| 38 | + redundancy = var.redundancy_type == "SINGLE" ? "primary" : "redundant" |
| 39 | + type = "shared" |
| 40 | + service_token_type = "a_side" |
| 41 | + description = format("connection to GCP in %s", var.fabric_destination_metro_code) |
| 42 | + speed = format("%dMbps", var.fabric_speed) |
| 43 | + vlans = [equinix_metal_vlan.this.vxlan] |
| 44 | +} |
| 45 | + |
| 46 | +## Configure the Equinix Fabric connection from Equinix Metal to GCP using the metal connection service token |
| 47 | +module "equinix-fabric-connection-gcp-primary" { |
| 48 | + source = "equinix-labs/fabric-connection-gcp/equinix" |
| 49 | + |
| 50 | + fabric_notification_users = var.fabric_notification_users |
| 51 | + fabric_connection_name = local.connection_name |
| 52 | + fabric_destination_metro_code = var.fabric_destination_metro_code |
| 53 | + fabric_speed = var.fabric_speed |
| 54 | + fabric_service_token_id = equinix_metal_connection.this.service_tokens.0.id |
| 55 | + |
| 56 | + # gcp_project = var.gcp_project_name // if unspecified, the project configured in the provided block will be used |
| 57 | + gcp_availability_domain = 1 |
| 58 | + |
| 59 | + gcp_gcloud_skip_download = false |
| 60 | + platform = var.platform |
| 61 | + |
| 62 | + ## BGP config |
| 63 | + gcp_configure_bgp = true |
| 64 | + # gcp_interconnect_customer_asn = // If unspecified, default value "65000" will be used |
| 65 | +} |
| 66 | + |
| 67 | +## If redundancy_type is REDUNDANT, configure a secondary Equinix Fabric connection from Equinix Metal to GCP |
| 68 | +## using the metal connection service token |
| 69 | +module "equinix-fabric-connection-gcp-secondary" { |
| 70 | + source = "equinix-labs/fabric-connection-gcp/equinix" |
| 71 | + |
| 72 | + count = var.redundancy_type == "REDUNDANT" ? 1 : 0 |
| 73 | + |
| 74 | + fabric_notification_users = var.fabric_notification_users |
| 75 | + fabric_connection_name = local.connection_name |
| 76 | + fabric_destination_metro_code = var.fabric_destination_metro_code |
| 77 | + fabric_speed = var.fabric_speed |
| 78 | + fabric_service_token_id = equinix_metal_connection.this.service_tokens.1.id |
| 79 | + |
| 80 | + gcp_availability_domain = 2 |
| 81 | + gcp_compute_create_router = false // we use the same cloud router of the primary connection |
| 82 | + gcp_compute_router_name = module.equinix-fabric-connection-gcp-primary.gcp_cloud_router_name |
| 83 | + |
| 84 | + gcp_gcloud_skip_download = true |
| 85 | + platform = var.platform |
| 86 | + |
| 87 | + ## BGP config |
| 88 | + gcp_configure_bgp = true |
| 89 | + # gcp_interconnect_customer_asn = // If unspecified, default value "65000" will be used |
| 90 | +} |
0 commit comments