From c30d29bf9b9dd97f8ca44248a2d9353bb5ea9f81 Mon Sep 17 00:00:00 2001 From: Luca Prete Date: Tue, 25 Jan 2022 14:06:02 +0100 Subject: [PATCH] [#455] net-glb: add support for null health_checks_config_defaults (#456) --- modules/net-glb/health_checks.tf | 12 +++++++++--- tests/modules/net_glb/test_plan.py | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/modules/net-glb/health_checks.tf b/modules/net-glb/health_checks.tf index 10abb8bbc..3b968c19f 100644 --- a/modules/net-glb/health_checks.tf +++ b/modules/net-glb/health_checks.tf @@ -27,12 +27,18 @@ locals { ) ] - # If at least one group backend service without - # HC is defined, create also a default HC + health_checks_config_defaults = ( + try(var.health_checks_config_defaults, null) == null + ? null + : { default = var.health_checks_config_defaults } + ) + + # If at least one group backend service without HC is defined, + # create also a default HC (if default HC is not null) health_checks_config = ( length(local._backends_without_hcs) > 0 ? merge( - { default = var.health_checks_config_defaults }, + coalesce(local.health_checks_config_defaults, {}), coalesce(var.health_checks_config, {}) ) : coalesce(var.health_checks_config, {}) diff --git a/tests/modules/net_glb/test_plan.py b/tests/modules/net_glb/test_plan.py index 48804300b..802b083f5 100644 --- a/tests/modules/net_glb/test_plan.py +++ b/tests/modules/net_glb/test_plan.py @@ -143,6 +143,22 @@ def test_group_default_hc(plan_runner): assert 'google_compute_url_map' in resources +def test_group_no_hc(plan_runner): + "Tests a group backend service without HCs (including no default HC)." + _, resources = plan_runner(backend_services_config=_BACKEND_GROUP, + health_checks_config_defaults='null') + + assert len(resources) == 4 + resources = dict((r['type'], r['values']) for r in resources) + + assert 'google_compute_backend_service' in resources + assert 'google_compute_global_forwarding_rule' in resources + assert 'google_compute_health_check' not in resources + assert 'google_compute_target_http_proxy' in resources + assert 'google_compute_target_https_proxy' not in resources + assert 'google_compute_url_map' in resources + + def test_group_existing_hc(plan_runner): "Tests a group backend service with referencing an existing HC." _, resources = plan_runner(backend_services_config=_BACKEND_GROUP_HC)