Interconnect (#268)

* module for VLAN attachment+cloud router+bgp

* fix vlan attachments review comments

* run terraform fmt

* fix code review comment and build errors

* fix for code review comments

* code review changes

* changes after review

* changes after code review

* changes after code review

* test net-interconnect-attachment-direct
This commit is contained in:
dsiviglia 2021-06-22 15:31:40 +02:00 committed by GitHub
parent 0cbdbc8eb8
commit 1781d7c6bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 259 additions and 0 deletions

View File

@ -0,0 +1,13 @@
# Copyright 2021 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.

View File

@ -0,0 +1,30 @@
/**
* Copyright 2021 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
}

View File

@ -0,0 +1,106 @@
/**
* Copyright 2021 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"
}

View File

@ -0,0 +1,110 @@
# Copyright 2021 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.
import os
import pytest
FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'fixture')
_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, '
'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(FIXTURES_DIR, router_create='false')
assert len(resources) == 3
def test_vlanattachment(plan_runner):
"Test vlan attachment"
_, resources = plan_runner(FIXTURES_DIR, 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(FIXTURES_DIR, 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,
}]
def test_router_peer(plan_runner):
"Test router peer"
_, resources = plan_runner(FIXTURES_DIR, 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(FIXTURES_DIR, 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'