Migrate net-ilb tests

This commit is contained in:
Julio Castillo 2023-04-21 14:18:15 +02:00
parent c819305a42
commit 4abe5e2baf
8 changed files with 121 additions and 148 deletions

View File

@ -0,0 +1,12 @@
project_id = "my-project"
region = "europe-west1"
name = "ilb-test"
vpc_config = {
network = "default"
subnetwork = "default"
}
backends = [{
balancing_mode = "CONNECTION"
group = "foo"
failover = false
}]

View File

@ -0,0 +1,63 @@
# Copyright 2023 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.
values:
google_compute_forwarding_rule.default:
all_ports: true
ip_protocol: TCP
labels: null
load_balancing_scheme: INTERNAL
name: ilb-test
network: default
project: my-project
region: europe-west1
subnetwork: default
google_compute_health_check.default[0]:
check_interval_sec: 5
name: ilb-test
project: my-project
tcp_health_check:
- port: null
port_name: null
port_specification: USE_SERVING_PORT
proxy_header: NONE
request: null
response: null
timeout_sec: 5
unhealthy_threshold: 2
google_compute_region_backend_service.default:
backend:
- balancing_mode: CONNECTION
capacity_scaler: null
description: Terraform managed.
failover: false
group: foo
max_connections: null
max_connections_per_endpoint: null
max_connections_per_instance: null
max_rate: null
max_rate_per_endpoint: null
max_rate_per_instance: null
max_utilization: null
load_balancing_scheme: INTERNAL
name: ilb-test
network: default
project: my-project
protocol: TCP
region: europe-west1
counts:
google_compute_forwarding_rule: 1
google_compute_health_check: 1
google_compute_region_backend_service: 1

View File

@ -1,35 +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 "test" {
source = "../../../../modules/net-ilb"
project_id = "my-project"
region = "europe-west1"
name = "ilb-test"
vpc_config = {
network = "default"
subnetwork = "default"
}
address = var.address
backend_service_config = var.backend_service_config
backends = var.backends
description = var.description
global_access = var.global_access
group_configs = var.group_configs
ports = var.ports
protocol = var.protocol
service_label = var.service_label
}

View File

@ -1,61 +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 "address" {
type = string
default = null
}
variable "backend_service_config" {
description = "Backend service level configuration."
type = any
default = {}
}
variable "backends" {
type = any
default = []
}
variable "description" {
type = string
default = "Terraform managed."
}
variable "global_access" {
type = bool
default = null
}
variable "group_configs" {
type = any
default = {}
}
variable "ports" {
type = list(string)
default = null
}
variable "protocol" {
type = string
default = "TCP"
}
variable "service_label" {
type = string
default = null
}

View File

@ -0,0 +1,14 @@
project_id = "my-project"
region = "europe-west1"
name = "ilb-test"
vpc_config = {
network = "default"
subnetwork = "default"
}
backends = [{
balancing_mode = "CONNECTION"
group = "foo"
failover = false
}]
global_access = true
ports = [80]

View File

@ -0,0 +1,25 @@
# Copyright 2023 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.
values:
google_compute_forwarding_rule.default:
all_ports: null
allow_global_access: true
ports:
- '80'
counts:
google_compute_forwarding_rule: 1
google_compute_health_check: 1
google_compute_region_backend_service: 1

View File

@ -1,51 +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.
_BACKENDS = '[{balancing_mode="CONNECTION", group="foo", failover=false}]'
def test_defaults(plan_runner):
"Test variable defaults."
_, resources = plan_runner(backends=_BACKENDS)
assert len(resources) == 3
resources = dict((r['type'], r['values']) for r in resources)
fwd_rule = resources['google_compute_forwarding_rule']
assert fwd_rule['load_balancing_scheme'] == 'INTERNAL'
assert fwd_rule['all_ports']
assert fwd_rule['allow_global_access'] is None
backend = resources['google_compute_region_backend_service']
assert len(backend['backend']) == 1
assert backend['backend'][0]['group'] == 'foo'
health_check = resources['google_compute_health_check']
for k, v in health_check.items():
if k == 'tcp_health_check':
assert len(v) == 1
assert v[0]['port_specification'] == 'USE_SERVING_PORT'
elif k.endswith('_health_check'):
assert len(v) == 0
def test_forwarding_rule(plan_runner):
"Test forwarding rule variables."
_, resources = plan_runner(backends=_BACKENDS, global_access='true',
ports="[80]")
assert len(resources) == 3
values = [
r['values']
for r in resources
if r['type'] == 'google_compute_forwarding_rule'
][0]
assert not values['all_ports']
assert values['ports'] == ['80']
assert values['allow_global_access']

View File

@ -1,4 +1,4 @@
# Copyright 2022 Google LLC
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -11,3 +11,9 @@
# 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: modules/net-ilb
tests:
defaults:
forwarding-rule: