Refactor net-address variables, add support for internal address purpose

* add support for internal address purpose
* update gcs module README
* refactor net address module interface and add tests
* add more examples in net-address README
This commit is contained in:
Ludovico Magnocavallo
2020-09-01 18:49:21 +02:00
committed by GitHub
parent daf3dc41e7
commit 0265ba0951
11 changed files with 225 additions and 19 deletions

View 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.

View File

@@ -0,0 +1,24 @@
/**
* 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-address"
external_addresses = var.external_addresses
global_addresses = var.global_addresses
internal_addresses = var.internal_addresses
internal_addresses_config = var.internal_addresses_config
project_id = var.project_id
}

View File

@@ -0,0 +1,19 @@
/**
* 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.
*/
output "module" {
value = module.test
}

View File

@@ -0,0 +1,47 @@
/**
* 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 "external_addresses" {
type = map(string)
default = {}
}
variable "global_addresses" {
type = list(string)
default = []
}
variable "internal_addresses" {
type = map(object({
region = string
subnetwork = string
}))
default = {}
}
variable "internal_addresses_config" {
type = map(object({
address = string
purpose = string
tier = string
}))
default = {}
}
variable "project_id" {
type = string
default = "my-project"
}

View File

@@ -0,0 +1,70 @@
# 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_external_addresses(plan_runner):
addresses = '{one = "europe-west1", two = "europe-west2"}'
_, resources = plan_runner(FIXTURES_DIR, external_addresses=addresses)
assert [r['values']['name'] for r in resources] == ['one', 'two']
assert set(r['values']['address_type']
for r in resources) == set(['EXTERNAL'])
assert [r['values']['region']
for r in resources] == ['europe-west1', 'europe-west2']
def test_global_addresses(plan_runner):
_, resources = plan_runner(FIXTURES_DIR, global_addresses='["one", "two"]')
assert [r['values']['name'] for r in resources] == ['one', 'two']
assert set(r['values']['address_type'] for r in resources) == set([None])
def test_internal_addresses(plan_runner):
addresses = (
'{one = {region = "europe-west1", subnetwork = "foobar"}, '
'two = {region = "europe-west2", subnetwork = "foobarz"}}'
)
_, resources = plan_runner(FIXTURES_DIR, internal_addresses=addresses)
assert [r['values']['name'] for r in resources] == ['one', 'two']
assert set(r['values']['address_type']
for r in resources) == set(['INTERNAL'])
assert [r['values']['region']
for r in resources] == ['europe-west1', 'europe-west2']
def test_internal_addresses_config(plan_runner):
addresses = (
'{one = {region = "europe-west1", subnetwork = "foobar"}, '
'two = {region = "europe-west2", subnetwork = "foobarz"}}'
)
config = (
'{one = {address = "10.0.0.2", purpose = "SHARED_LOADBALANCER_VIP", '
'tier=null}}'
)
_, resources = plan_runner(FIXTURES_DIR,
internal_addresses=addresses,
internal_addresses_config=config)
assert [r['values']['name'] for r in resources] == ['one', 'two']
assert set(r['values']['address_type']
for r in resources) == set(['INTERNAL'])
assert [r['values'].get('address')
for r in resources] == ['10.0.0.2', None]
assert [r['values'].get('purpose')
for r in resources] == ['SHARED_LOADBALANCER_VIP', None]