Migrate net-address tests
This commit is contained in:
parent
924230eb12
commit
230a1034ec
|
@ -11,12 +11,12 @@ module "addresses" {
|
||||||
source = "./fabric/modules/net-address"
|
source = "./fabric/modules/net-address"
|
||||||
project_id = var.project_id
|
project_id = var.project_id
|
||||||
external_addresses = {
|
external_addresses = {
|
||||||
nat-1 = var.region
|
one = "europe-west1"
|
||||||
vpn-remote = var.region
|
two = "europe-west2"
|
||||||
}
|
}
|
||||||
global_addresses = ["app-1", "app-2"]
|
global_addresses = ["app-1", "app-2"]
|
||||||
}
|
}
|
||||||
# tftest modules=1 resources=4
|
# tftest modules=1 resources=4 inventory=external.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
### Internal addresses
|
### Internal addresses
|
||||||
|
@ -38,7 +38,7 @@ module "addresses" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# tftest modules=1 resources=2
|
# tftest modules=1 resources=2 inventory=internal.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
### PSA addresses
|
### PSA addresses
|
||||||
|
@ -55,7 +55,7 @@ module "addresses" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# tftest modules=1 resources=1
|
# tftest modules=1 resources=1 inventory=psa.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
### PSC addresses
|
### PSC addresses
|
||||||
|
@ -75,7 +75,7 @@ module "addresses" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# tftest modules=1 resources=2
|
# tftest modules=1 resources=2 inventory=psc.yaml
|
||||||
```
|
```
|
||||||
<!-- BEGIN TFDOC -->
|
<!-- BEGIN TFDOC -->
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
# 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:
|
||||||
|
module.addresses.google_compute_address.external["one"]:
|
||||||
|
address_type: EXTERNAL
|
||||||
|
name: one
|
||||||
|
project: project-id
|
||||||
|
region: europe-west1
|
||||||
|
module.addresses.google_compute_address.external["two"]:
|
||||||
|
address_type: EXTERNAL
|
||||||
|
name: two
|
||||||
|
project: project-id
|
||||||
|
region: europe-west2
|
||||||
|
module.addresses.google_compute_global_address.global["app-1"]:
|
||||||
|
name: app-1
|
||||||
|
project: project-id
|
||||||
|
module.addresses.google_compute_global_address.global["app-2"]:
|
||||||
|
name: app-2
|
||||||
|
project: project-id
|
||||||
|
|
||||||
|
counts:
|
||||||
|
google_compute_address: 2
|
||||||
|
google_compute_global_address: 2
|
|
@ -0,0 +1,38 @@
|
||||||
|
# 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:
|
||||||
|
module.addresses.google_compute_address.internal["ilb-1"]:
|
||||||
|
address_type: INTERNAL
|
||||||
|
labels: null
|
||||||
|
name: ilb-1
|
||||||
|
network: null
|
||||||
|
prefix_length: null
|
||||||
|
project: project-id
|
||||||
|
purpose: SHARED_LOADBALANCER_VIP
|
||||||
|
region: region
|
||||||
|
subnetwork: subnet_self_link
|
||||||
|
module.addresses.google_compute_address.internal["ilb-2"]:
|
||||||
|
address: 10.0.0.2
|
||||||
|
address_type: INTERNAL
|
||||||
|
labels: null
|
||||||
|
name: ilb-2
|
||||||
|
network: null
|
||||||
|
prefix_length: null
|
||||||
|
project: project-id
|
||||||
|
region: region
|
||||||
|
subnetwork: subnet_self_link
|
||||||
|
|
||||||
|
counts:
|
||||||
|
google_compute_address: 2
|
|
@ -1,4 +1,4 @@
|
||||||
# Copyright 2022 Google LLC
|
# Copyright 2023 Google LLC
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
|
@ -11,3 +11,16 @@
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
values:
|
||||||
|
module.addresses.google_compute_global_address.psa["cloudsql-mysql"]:
|
||||||
|
address: 10.10.10.0
|
||||||
|
address_type: INTERNAL
|
||||||
|
name: cloudsql-mysql
|
||||||
|
network: projects/xxx/global/networks/aaa
|
||||||
|
prefix_length: 24
|
||||||
|
project: project-id
|
||||||
|
purpose: VPC_PEERING
|
||||||
|
|
||||||
|
counts:
|
||||||
|
google_compute_global_address: 1
|
|
@ -0,0 +1,33 @@
|
||||||
|
# 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:
|
||||||
|
module.addresses.google_compute_global_address.psc["one"]:
|
||||||
|
address_type: INTERNAL
|
||||||
|
name: one
|
||||||
|
network: projects/xxx/global/networks/aaa
|
||||||
|
prefix_length: null
|
||||||
|
project: project-id
|
||||||
|
purpose: PRIVATE_SERVICE_CONNECT
|
||||||
|
module.addresses.google_compute_global_address.psc["two"]:
|
||||||
|
address: 10.0.0.32
|
||||||
|
address_type: INTERNAL
|
||||||
|
name: two
|
||||||
|
network: projects/xxx/global/networks/aaa
|
||||||
|
prefix_length: null
|
||||||
|
project: project-id
|
||||||
|
purpose: PRIVATE_SERVICE_CONNECT
|
||||||
|
|
||||||
|
counts:
|
||||||
|
google_compute_global_address: 2
|
|
@ -1,24 +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-address"
|
|
||||||
external_addresses = var.external_addresses
|
|
||||||
global_addresses = var.global_addresses
|
|
||||||
internal_addresses = var.internal_addresses
|
|
||||||
psa_addresses = var.psa_addresses
|
|
||||||
project_id = var.project_id
|
|
||||||
}
|
|
|
@ -1,19 +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 "module" {
|
|
||||||
value = module.test
|
|
||||||
}
|
|
|
@ -1,40 +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 "external_addresses" {
|
|
||||||
type = any
|
|
||||||
default = {}
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "global_addresses" {
|
|
||||||
type = any
|
|
||||||
default = []
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "internal_addresses" {
|
|
||||||
type = any
|
|
||||||
default = {}
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "project_id" {
|
|
||||||
type = string
|
|
||||||
default = "my-project"
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "psa_addresses" {
|
|
||||||
type = any
|
|
||||||
default = {}
|
|
||||||
}
|
|
|
@ -1,66 +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.
|
|
||||||
|
|
||||||
|
|
||||||
def test_external_addresses(plan_runner):
|
|
||||||
addresses = '{one = "europe-west1", two = "europe-west2"}'
|
|
||||||
_, resources = plan_runner(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(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(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"
|
|
||||||
address = "10.0.0.2"
|
|
||||||
purpose = "SHARED_LOADBALANCER_VIP"
|
|
||||||
},
|
|
||||||
two = {region = "europe-west2", subnetwork = "foobarz"}
|
|
||||||
}'''
|
|
||||||
_, resources = plan_runner(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'].get('address') for r in resources] == ['10.0.0.2', None]
|
|
||||||
assert [r['values'].get('purpose') for r in resources
|
|
||||||
] == ['SHARED_LOADBALANCER_VIP', None]
|
|
||||||
|
|
||||||
|
|
||||||
def test_psa_config(plan_runner):
|
|
||||||
psa_addresses = '{cloudsql-mysql={address="10.199.0.0", network="foobar", prefix_length = 24}}'
|
|
||||||
_, resources = plan_runner(psa_addresses=psa_addresses)
|
|
||||||
assert set(r['values']['purpose'] for r in resources) == set(['VPC_PEERING'])
|
|
||||||
assert set(r['values']['address'] for r in resources) == set(['10.199.0.0'])
|
|
Loading…
Reference in New Issue