From 7792b913648164430a113f878c957efaceb187e5 Mon Sep 17 00:00:00 2001 From: averbukh Date: Wed, 28 Jul 2021 22:14:14 +0200 Subject: [PATCH] Add basic tests for decentralized firewall example --- networking/decentralized-firewall/main.tf | 8 +++--- .../decentralized_firewall/__init__.py | 13 +++++++++ .../decentralized_firewall/fixture/main.tf | 22 +++++++++++++++ .../fixture/variables.tf | 28 +++++++++++++++++++ .../decentralized_firewall/test_plan.py | 28 +++++++++++++++++++ 5 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 tests/networking/decentralized_firewall/__init__.py create mode 100644 tests/networking/decentralized_firewall/fixture/main.tf create mode 100644 tests/networking/decentralized_firewall/fixture/variables.tf create mode 100644 tests/networking/decentralized_firewall/test_plan.py diff --git a/networking/decentralized-firewall/main.tf b/networking/decentralized-firewall/main.tf index 74c719344..2502d41f6 100644 --- a/networking/decentralized-firewall/main.tf +++ b/networking/decentralized-firewall/main.tf @@ -114,8 +114,8 @@ module "vpc-firewall-prod" { project_id = module.project-host-prod.project_id network = module.vpc-prod.name config_directories = [ - "./firewall/common", - "./firewall/prod" + "${path.module}/firewall/common", + "${path.module}/firewall/prod" ] # Enable Firewall Logging for the production fwl rules @@ -130,7 +130,7 @@ module "vpc-firewall-dev" { project_id = module.project-host-dev.project_id network = module.vpc-dev.name config_directories = [ - "./firewall/common", - "./firewall/dev" + "${path.module}/firewall/common", + "${path.module}/firewall/dev" ] } diff --git a/tests/networking/decentralized_firewall/__init__.py b/tests/networking/decentralized_firewall/__init__.py new file mode 100644 index 000000000..d46dbae5e --- /dev/null +++ b/tests/networking/decentralized_firewall/__init__.py @@ -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. diff --git a/tests/networking/decentralized_firewall/fixture/main.tf b/tests/networking/decentralized_firewall/fixture/main.tf new file mode 100644 index 000000000..9bef2d737 --- /dev/null +++ b/tests/networking/decentralized_firewall/fixture/main.tf @@ -0,0 +1,22 @@ +/** + * 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 "test" { + source = "../../../../networking/decentralized-firewall" + billing_account_id = var.billing_account_id + prefix = var.prefix + root_node = var.root_node +} diff --git a/tests/networking/decentralized_firewall/fixture/variables.tf b/tests/networking/decentralized_firewall/fixture/variables.tf new file mode 100644 index 000000000..9646fe1b7 --- /dev/null +++ b/tests/networking/decentralized_firewall/fixture/variables.tf @@ -0,0 +1,28 @@ +# 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 +# +# https://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 "billing_account_id" { + type = string + default = "ABCDE-12345-ABCDE" +} + +variable "prefix" { + type = string + default = "test" +} + +variable "root_node" { + type = string + default = "organizations/0123456789" +} diff --git a/tests/networking/decentralized_firewall/test_plan.py b/tests/networking/decentralized_firewall/test_plan.py new file mode 100644 index 000000000..5183e2a90 --- /dev/null +++ b/tests/networking/decentralized_firewall/test_plan.py @@ -0,0 +1,28 @@ +# 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") + + +def test_resources(e2e_plan_runner): + "Test that plan works and the numbers of resources is as expected." + modules, resources = e2e_plan_runner(FIXTURES_DIR) + assert len(modules) == 8 + assert len(resources) == 50 + assert modules == "something"