MIG and ILB modules (#61)
* preliminary net-ilb module, untested * outputs * fix basic mistakes, add initial test * test variable defaults on all resources * README stub * net-ilb module fixes and example * compute-vm module fixes * fix test * remove mig from compute vm module * split out mig from compute-vm (untested) * split out mig from compute-vm (untested) * fix mig versions * small fixes and examples for mig module * Update README.md * Update README.md * switch mig to using a single variable for both region and zone
This commit is contained in:
committed by
GitHub
parent
5088ed61ff
commit
be3c461cf9
@@ -30,5 +30,4 @@ module "test" {
|
||||
instance_count = var.instance_count
|
||||
use_instance_template = var.use_instance_template
|
||||
group = var.group
|
||||
group_manager = var.group_manager
|
||||
}
|
||||
|
||||
@@ -19,11 +19,6 @@ variable "group" {
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "group_manager" {
|
||||
type = any
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "instance_count" {
|
||||
type = number
|
||||
default = 1
|
||||
|
||||
@@ -44,3 +44,12 @@ def test_template(plan_runner):
|
||||
assert len(resources) == 1
|
||||
assert resources[0]['type'] == 'google_compute_instance_template'
|
||||
assert resources[0]['values']['name_prefix'] == 'test-'
|
||||
|
||||
|
||||
def test_group(plan_runner):
|
||||
plan, resources = plan_runner(FIXTURES_DIR, instance_count=2,
|
||||
group='{named_ports={}}')
|
||||
assert len(resources) == 3
|
||||
assert set(r['type'] for r in resources) == set([
|
||||
'google_compute_instance_group', 'google_compute_instance'
|
||||
])
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
# Copyright 2020 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')
|
||||
|
||||
|
||||
def test_unmanaged(plan_runner):
|
||||
plan, resources = plan_runner(FIXTURES_DIR, instance_count=2,
|
||||
group='{named_ports={}}')
|
||||
assert len(resources) == 3
|
||||
assert set(r['type'] for r in resources) == set([
|
||||
'google_compute_instance_group', 'google_compute_instance'
|
||||
])
|
||||
|
||||
|
||||
def test_managed(plan_runner):
|
||||
plan, resources = plan_runner(
|
||||
FIXTURES_DIR, use_instance_template='true', group_manager=(
|
||||
'{ '
|
||||
'auto_healing_policies=null, named_ports={}, options=null, '
|
||||
'regional=false, target_size=1, update_policy=null, versions=null'
|
||||
' }'
|
||||
)
|
||||
)
|
||||
assert len(resources) == 2
|
||||
assert set(r['type'] for r in resources) == set([
|
||||
'google_compute_instance_group_manager', 'google_compute_instance_template'
|
||||
])
|
||||
13
tests/modules/net_ilb/__init__.py
Normal file
13
tests/modules/net_ilb/__init__.py
Normal file
@@ -0,0 +1,13 @@
|
||||
# Copyright 2020 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.
|
||||
35
tests/modules/net_ilb/fixture/main.tf
Normal file
35
tests/modules/net_ilb/fixture/main.tf
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Copyright 2020 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"
|
||||
network = "default"
|
||||
subnetwork = "default"
|
||||
name = "ilb-test"
|
||||
labels = {}
|
||||
address = var.address
|
||||
backends = var.backends
|
||||
backend_config = var.backend_config
|
||||
failover_config = var.failover_config
|
||||
global_access = var.global_access
|
||||
health_check = var.health_check
|
||||
health_check_config = var.health_check_config
|
||||
ports = var.ports
|
||||
protocol = var.protocol
|
||||
service_label = var.service_label
|
||||
}
|
||||
88
tests/modules/net_ilb/fixture/variables.tf
Normal file
88
tests/modules/net_ilb/fixture/variables.tf
Normal file
@@ -0,0 +1,88 @@
|
||||
/**
|
||||
* Copyright 2020 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 "backends" {
|
||||
type = list(object({
|
||||
failover = bool
|
||||
group = string
|
||||
balancing_mode = string
|
||||
}))
|
||||
}
|
||||
|
||||
variable "backend_config" {
|
||||
type = object({
|
||||
session_affinity = string
|
||||
timeout_sec = number
|
||||
connection_draining_timeout_sec = number
|
||||
})
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "failover_config" {
|
||||
type = object({
|
||||
disable_connection_drain = bool
|
||||
drop_traffic_if_unhealthy = bool
|
||||
ratio = number
|
||||
})
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "global_access" {
|
||||
type = bool
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "health_check" {
|
||||
type = string
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "health_check_config" {
|
||||
type = object({
|
||||
type = string # http https tcp ssl http2
|
||||
check = map(any) # actual health check block attributes
|
||||
config = map(number) # interval, thresholds, timeout
|
||||
logging = bool
|
||||
})
|
||||
default = {
|
||||
type = "http"
|
||||
check = {
|
||||
port_specification = "USE_SERVING_PORT"
|
||||
}
|
||||
config = {}
|
||||
logging = false
|
||||
}
|
||||
}
|
||||
|
||||
variable "ports" {
|
||||
type = list(string)
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "protocol" {
|
||||
type = string
|
||||
default = "TCP"
|
||||
}
|
||||
|
||||
variable "service_label" {
|
||||
type = string
|
||||
default = null
|
||||
}
|
||||
55
tests/modules/net_ilb/test_plan.py
Normal file
55
tests/modules/net_ilb/test_plan.py
Normal file
@@ -0,0 +1,55 @@
|
||||
# Copyright 2020 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')
|
||||
|
||||
_BACKENDS = '[{balancing_mode="CONNECTION", group="foo", failover=false}]'
|
||||
|
||||
|
||||
def test_defaults(plan_runner):
|
||||
"Test variable defaults."
|
||||
_, resources = plan_runner(FIXTURES_DIR, 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 == 'http_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(
|
||||
FIXTURES_DIR, 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']
|
||||
Reference in New Issue
Block a user