From 2d4bd5a2445692d60f9e93306182e0b1bc72ac51 Mon Sep 17 00:00:00 2001 From: Julio Castillo Date: Fri, 14 Apr 2023 11:01:54 +0200 Subject: [PATCH] Remove net-interconnect-attachment-direct --- .../README.md | 132 ------------------ .../main.tf | 98 ------------- .../outputs.tf | 31 ---- .../variables.tf | 115 --------------- .../versions.tf | 29 ---- .../__init__.py | 13 -- .../fixture/main.tf | 30 ---- .../fixture/variables.tf | 106 -------------- .../test_plan.py | 106 -------------- 9 files changed, 660 deletions(-) delete mode 100644 modules/net-interconnect-attachment-direct/README.md delete mode 100644 modules/net-interconnect-attachment-direct/main.tf delete mode 100644 modules/net-interconnect-attachment-direct/outputs.tf delete mode 100644 modules/net-interconnect-attachment-direct/variables.tf delete mode 100644 modules/net-interconnect-attachment-direct/versions.tf delete mode 100644 tests/modules/net_interconnect_attachment_direct/__init__.py delete mode 100644 tests/modules/net_interconnect_attachment_direct/fixture/main.tf delete mode 100644 tests/modules/net_interconnect_attachment_direct/fixture/variables.tf delete mode 100644 tests/modules/net_interconnect_attachment_direct/test_plan.py diff --git a/modules/net-interconnect-attachment-direct/README.md b/modules/net-interconnect-attachment-direct/README.md deleted file mode 100644 index 6a5244c79d..0000000000 --- a/modules/net-interconnect-attachment-direct/README.md +++ /dev/null @@ -1,132 +0,0 @@ -# Direct Interconnect VLAN Attachment and router - -This module allows creation of a VLAN attachment for Direct Interconnect and router (router creation is optional). - -## Examples - -### Direct Interconnect VLAN attachment using default parameters for bgp session and router - -```hcl -module "vlan-attachment-1" { - source = "./fabric/modules/net-interconnect-attachment-direct" - project_id = "dedicated-ic-5-8492" - region = "us-west2" - router_network = "myvpc" - name = "vlan-604-x" - interconnect = "https://www.googleapis.com/compute/v1/projects/mylab/global/interconnects/mylab-interconnect-1" - peer = { - ip_address = "169.254.63.2" - asn = 65418 - } -} -# tftest modules=1 resources=4 -``` -#### Direct Interconnect VLAN attachments to achieve 99.9% SLA setup - -```hcl -module "vlan-attachment-1" { - source = "./fabric/modules/net-interconnect-attachment-direct" - project_id = "dedicated-ic-3-8386" - region = "us-west2" - router_name = "router-1" - router_config = { - description = "" - asn = 65003 - advertise_config = { - groups = ["ALL_SUBNETS"] - ip_ranges = { - "199.36.153.8/30" = "custom" - } - mode = "CUSTOM" - } - } - router_network = "myvpc" - name = "vlan-603-1" - interconnect = "https://www.googleapis.com/compute/v1/projects/mylab/global/interconnects/mylab-interconnect-1" - - config = { - description = "" - vlan_id = 603 - bandwidth = "BPS_10G" - admin_enabled = true - mtu = 1440 - } - peer = { - ip_address = "169.254.63.2" - asn = 65418 - } - bgp = { - session_range = "169.254.63.1/29" - advertised_route_priority = 0 - candidate_ip_ranges = ["169.254.63.0/29"] - } -} - -module "vlan-attachment-2" { - source = "./fabric/modules/net-interconnect-attachment-direct" - project_id = "dedicated-ic-3-8386" - region = "us-west2" - router_name = "router-2" - router_config = { - description = "" - asn = 65003 - advertise_config = { - groups = ["ALL_SUBNETS"] - ip_ranges = { - "199.36.153.8/30" = "custom" - } - mode = "CUSTOM" - } - - } - router_network = "myvpc" - name = "vlan-603-2" - - interconnect = "https://www.googleapis.com/compute/v1/projects/mylab/global/interconnects/mylab-interconnect-2" - - config = { - description = "" - vlan_id = 603 - bandwidth = "BPS_10G" - admin_enabled = true - mtu = 1440 - } - peer = { - ip_address = "169.254.63.10" - asn = 65418 - } - bgp = { - session_range = "169.254.63.9/29" - advertised_route_priority = 0 - candidate_ip_ranges = ["169.254.63.8/29"] - } -} -# tftest modules=2 resources=8 -``` - - -## Variables - -| name | description | type | required | default | -|---|---|:---:|:---:|:---:| -| [interconnect](variables.tf#L46) | URL of the underlying Interconnect object that this attachment's traffic will traverse through. | string | ✓ | | -| [peer](variables.tf#L57) | Peer Ip address and asn. Only IPv4 supported. | object({…}) | ✓ | | -| [project_id](variables.tf#L65) | The project containing the resources. | string | ✓ | | -| [router_config](variables.tf#L76) | Router asn and custom advertisement configuration, ip_ranges is a map of address ranges and descriptions.. . | object({…} | ✓ | | -| [bgp](variables.tf#L17) | Bgp session parameters. | object({…}) | | null | -| [config](variables.tf#L28) | VLAN attachment parameters: description, vlan_id, bandwidth, admin_enabled, interconnect. | object({…}) | | {…} | -| [name](variables.tf#L51) | The name of the vlan attachment. | string | | "vlan-attachment" | -| [region](variables.tf#L70) | Region where the router resides. | string | | "europe-west1-b" | -| [router_create](variables.tf#L95) | Create router. | bool | | true | -| [router_name](variables.tf#L101) | Router name used for auto created router, or to specify an existing router to use if `router_create` is set to `true`. Leave blank to use vlan attachment name for auto created router. | string | | "router-vlan-attachment" | -| [router_network](variables.tf#L107) | A reference to the network to which this router belongs. | string | | null | - -## Outputs - -| name | description | sensitive | -|---|---|:---:| -| [bgpsession](outputs.tf#L16) | bgp session. | | -| [interconnect_attachment](outputs.tf#L21) | interconnect attachment. | | -| [router](outputs.tf#L26) | Router resource (only if auto-created). | | - - diff --git a/modules/net-interconnect-attachment-direct/main.tf b/modules/net-interconnect-attachment-direct/main.tf deleted file mode 100644 index ae832bcc76..0000000000 --- a/modules/net-interconnect-attachment-direct/main.tf +++ /dev/null @@ -1,98 +0,0 @@ - -/** - * Copyright 2022 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -locals { - router = ( - var.router_create - ? try(google_compute_router.router[0].name, null) - : var.router_name - ) - vlan_interconnect = try(google_compute_interconnect_attachment.interconnect_vlan_attachment.name) -} - -resource "google_compute_router" "router" { - count = var.router_create ? 1 : 0 - project = var.project_id - region = var.region - name = var.router_name == "" ? "router-${var.name}" : var.router_name - description = var.router_config.description - network = var.router_network - bgp { - advertise_mode = ( - var.router_config.advertise_config == null - ? null - : var.router_config.advertise_config.mode - ) - advertised_groups = ( - var.router_config.advertise_config == null ? null : ( - var.router_config.advertise_config.mode != "CUSTOM" - ? null - : var.router_config.advertise_config.groups - ) - ) - dynamic "advertised_ip_ranges" { - for_each = ( - var.router_config.advertise_config == null ? {} : ( - var.router_config.advertise_config.mode != "CUSTOM" - ? null - : var.router_config.advertise_config.ip_ranges - ) - ) - iterator = range - content { - range = range.key - description = range.value - } - } - asn = var.router_config.asn - } -} - -resource "google_compute_interconnect_attachment" "interconnect_vlan_attachment" { - project = var.project_id - region = var.region - router = local.router - name = var.name - description = var.config.description - interconnect = var.interconnect - bandwidth = var.config.bandwidth - mtu = var.config.mtu - vlan_tag8021q = var.config.vlan_id - candidate_subnets = var.bgp == null ? null : var.bgp.candidate_ip_ranges - admin_enabled = var.config.admin_enabled - provider = google-beta -} - -resource "google_compute_router_interface" "interface" { - project = var.project_id - region = var.region - name = "interface-${var.name}" - router = local.router - ip_range = var.bgp == null ? null : var.bgp.session_range - interconnect_attachment = local.vlan_interconnect -} - -resource "google_compute_router_peer" "peer" { - project = var.project_id - region = var.region - name = "bgp-session-${var.name}" - router = local.router - peer_ip_address = var.peer.ip_address - peer_asn = var.peer.asn - advertised_route_priority = var.bgp == null ? null : var.bgp.advertised_route_priority - interface = local.vlan_interconnect -} diff --git a/modules/net-interconnect-attachment-direct/outputs.tf b/modules/net-interconnect-attachment-direct/outputs.tf deleted file mode 100644 index 53b3616d8f..0000000000 --- a/modules/net-interconnect-attachment-direct/outputs.tf +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright 2022 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -output "bgpsession" { - description = "bgp session." - value = google_compute_router_peer.peer -} - -output "interconnect_attachment" { - description = "interconnect attachment." - value = google_compute_interconnect_attachment.interconnect_vlan_attachment -} - -output "router" { - description = "Router resource (only if auto-created)." - value = google_compute_router.router -} - - diff --git a/modules/net-interconnect-attachment-direct/variables.tf b/modules/net-interconnect-attachment-direct/variables.tf deleted file mode 100644 index 7c08ae2af3..0000000000 --- a/modules/net-interconnect-attachment-direct/variables.tf +++ /dev/null @@ -1,115 +0,0 @@ -/** - * Copyright 2022 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -variable "bgp" { - description = "Bgp session parameters." - type = object({ - session_range = string - candidate_ip_ranges = list(string) - advertised_route_priority = number - - }) - default = null -} - -variable "config" { - description = "VLAN attachment parameters: description, vlan_id, bandwidth, admin_enabled, interconnect." - type = object({ - description = string - vlan_id = number - bandwidth = string - admin_enabled = bool - mtu = number - }) - default = { - description = null - vlan_id = null - bandwidth = "BPS_10G" - admin_enabled = true - mtu = 1440 - } -} - -variable "interconnect" { - description = "URL of the underlying Interconnect object that this attachment's traffic will traverse through." - type = string -} - -variable "name" { - description = "The name of the vlan attachment." - type = string - default = "vlan-attachment" -} - -variable "peer" { - description = "Peer Ip address and asn. Only IPv4 supported." - type = object({ - ip_address = string - asn = number - }) -} - -variable "project_id" { - description = "The project containing the resources." - type = string -} - -variable "region" { - description = "Region where the router resides." - type = string - default = "europe-west1-b" -} - -variable "router_config" { - description = "Router asn and custom advertisement configuration, ip_ranges is a map of address ranges and descriptions.. ." - type = object({ - description = string - asn = number - advertise_config = object({ - groups = list(string) - ip_ranges = map(string) - mode = string - }) - }) - - default = { - description = null - asn = 64514 - advertise_config = null - } -} - -variable "router_create" { - description = "Create router." - type = bool - default = true -} - -variable "router_name" { - description = "Router name used for auto created router, or to specify an existing router to use if `router_create` is set to `true`. Leave blank to use vlan attachment name for auto created router." - type = string - default = "router-vlan-attachment" -} - -variable "router_network" { - description = "A reference to the network to which this router belongs." - type = string - default = null -} - - - - diff --git a/modules/net-interconnect-attachment-direct/versions.tf b/modules/net-interconnect-attachment-direct/versions.tf deleted file mode 100644 index 77ccb0e7fd..0000000000 --- a/modules/net-interconnect-attachment-direct/versions.tf +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -terraform { - required_version = ">= 1.4.4" - required_providers { - google = { - source = "hashicorp/google" - version = ">= 4.60.0" # tftest - } - google-beta = { - source = "hashicorp/google-beta" - version = ">= 4.60.0" # tftest - } - } -} - - diff --git a/tests/modules/net_interconnect_attachment_direct/__init__.py b/tests/modules/net_interconnect_attachment_direct/__init__.py deleted file mode 100644 index 6d6d1266c3..0000000000 --- a/tests/modules/net_interconnect_attachment_direct/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. diff --git a/tests/modules/net_interconnect_attachment_direct/fixture/main.tf b/tests/modules/net_interconnect_attachment_direct/fixture/main.tf deleted file mode 100644 index c4b1be3e00..0000000000 --- a/tests/modules/net_interconnect_attachment_direct/fixture/main.tf +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright 2022 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -module "vlan-attachment-1" { - source = "../../../../modules/net-interconnect-attachment-direct" - project_id = "dedicated-ic-3-8386" - region = "us-west2" - router_create = var.router_create - router_name = var.router_name - router_config = var.router_config - router_network = var.router_network - name = var.name - interconnect = var.interconnect - config = var.config - peer = var.peer - bgp = var.bgp -} diff --git a/tests/modules/net_interconnect_attachment_direct/fixture/variables.tf b/tests/modules/net_interconnect_attachment_direct/fixture/variables.tf deleted file mode 100644 index e5547473c1..0000000000 --- a/tests/modules/net_interconnect_attachment_direct/fixture/variables.tf +++ /dev/null @@ -1,106 +0,0 @@ -/** - * Copyright 2022 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -variable "bgp" { - description = "Bgp session parameters." - type = object({ - session_range = string - candidate_ip_ranges = list(string) - advertised_route_priority = number - - }) - default = null -} - -variable "config" { - description = "VLAN attachment parameters: description, vlan_id, bandwidth, admin_enabled, interconnect." - type = object({ - description = string - vlan_id = number - bandwidth = string - admin_enabled = bool - mtu = number - }) - default = { - description = null - vlan_id = null - bandwidth = "BPS_10G" - admin_enabled = true - mtu = 1440 - - } -} - -variable "interconnect" { - description = "URL of the underlying Interconnect object that this attachment's traffic will traverse through." - type = string - default = "https://www.googleapis.com/compute/v1/projects/mylab/global/interconnects/mylab-interconnect-1" -} - -variable "name" { - description = "The name of the vlan attachment." - type = string - default = "vlan-603" -} - -variable "peer" { - description = "Peer Ip address and asn. Only IPv4 supported." - type = object({ - ip_address = string - asn = number - }) - default = { - ip_address = "169.254.63.2" - asn = 65418 - } -} - -variable "router_config" { - description = "Router asn and custom advertisement configuration, ip_ranges is a map of address ranges and descriptions.. ." - type = object({ - description = string - asn = number - advertise_config = object({ - groups = list(string) - ip_ranges = map(string) - mode = string - }) - }) - - default = { - description = null - asn = 64514 - advertise_config = null - } -} - -variable "router_create" { - description = "Create router." - type = bool - default = true -} - -variable "router_name" { - description = "Router name used for auto created router, or to specify an existing router to use if `router_create` is set to `true`. Leave blank to use vlan attachment name for auto created router." - type = string - default = "router-vlan-attachment" -} - -variable "router_network" { - description = "A reference to the network to which this router belongs." - type = string - default = "my-vpc" -} diff --git a/tests/modules/net_interconnect_attachment_direct/test_plan.py b/tests/modules/net_interconnect_attachment_direct/test_plan.py deleted file mode 100644 index 33fe145bb4..0000000000 --- a/tests/modules/net_interconnect_attachment_direct/test_plan.py +++ /dev/null @@ -1,106 +0,0 @@ -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -_VAR_BGP = ( - '{' - 'session_range="169.254.63.1/29", ' - 'candidate_ip_ranges= ["169.254.63.0/29"], ' - 'advertised_route_priority=0, ' - '}' -) -_VAR_CONFIG = ( - '{' - 'description="", ' - 'vlan_id=603, ' - 'bandwidth="BPS_10G", ' - 'admin_enabled=true, ' - 'mtu=1440, ' - '}' - -) -_VAR_ROUTER_CONFIG = ( - '{' - 'description="", ' - 'asn=65003, ' - 'keepalive_interval=20, ' - 'advertise_config= {' - ' mode="CUSTOM", ' - ' groups=["ALL_SUBNETS"], ' - ' ip_ranges = {' - ' "199.36.153.8/30" = "custom" }, ' - ' }, ' - '}' -) - - -def test_router_create_false(plan_runner): - "Test with no router creation." - _, resources = plan_runner(router_create='false') - assert len(resources) == 3 - - -def test_vlanattachment(plan_runner): - "Test vlan attachment" - _, resources = plan_runner(bgp=_VAR_BGP, config=_VAR_CONFIG) - assert len(resources) == 4 - for r in resources: - if r['type'] != 'google_compute_interconnect_attachment': - continue - assert r['values']['interconnect'].endswith( - 'interconnects/mylab-interconnect-1') - assert r['values']['name'] == 'vlan-603' - assert r['values']['vlan_tag8021q'] == 603 - assert r['values']['candidate_subnets'] == ['169.254.63.0/29'] - assert r['values']['bandwidth'] == 'BPS_10G' - assert r['values']['mtu'] == '1440' - assert r['values']['admin_enabled'] == True - - def test_router(plan_runner): - "Test router" - _, resources = plan_runner(router_config=_VAR_ROUTER_CONFIG) - assert len(resources) == 4 - for r in resources: - if r['type'] != 'google_compute_router': - continue - assert r['values']['name'] == 'router-vlan-attachment' - assert r['values']['network'] == 'my-vpc' - assert r['values']['bgp'] == [{ - 'advertise_mode': 'CUSTOM', - 'advertised_groups': ['ALL_SUBNETS'], - 'advertised_ip_ranges': [{'description': 'custom', 'range': '199.36.153.8/30'}], - 'asn': 65003, - 'keepalive_interval': 20, - }] - - def test_router_peer(plan_runner): - "Test router peer" - _, resources = plan_runner(bgp=_VAR_BGP) - assert len(resources) == 4 - for r in resources: - if r['type'] != 'google_compute_router_peer': - continue - assert r['values']['peer_ip_address'] == '169.254.63.2' - assert r['values']['peer_asn'] == 65418 - assert r['values']['interface'] == 'vlan-603' - - def test_router_interface(plan_runner): - "Test router interface" - _, resources = plan_runner(bgp=_VAR_BGP) - assert len(resources) == 4 - for r in resources: - if r['type'] != 'google_compute_router_interface': - continue - assert r['values']['name'] == 'interface-vlan-603' - assert r['values']['ip_range'] == '169.254.63.1/29' - assert r['values']['interconnect_attachment'] == 'vlan-603'