Fix gke hub module features condition (#761)

* fix features condition

* remove test output

* fix example tests

* fix module tests
This commit is contained in:
Ludovico Magnocavallo 2022-07-30 13:53:05 +00:00 committed by GitHub
parent b20ab65756
commit 3778d37d18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 25 deletions

View File

@ -3,6 +3,7 @@
This module allows simplified creation and management of a GKE Hub object and its features for a given set of clusters. The given list of clusters will be registered inside the Hub and all the configured features will be activated.
To use this module you must ensure the following APIs are enabled in the target project:
```
"gkehub.googleapis.com"
"gkeconnect.googleapis.com"
@ -116,7 +117,7 @@ module "hub" {
}
}
# tftest modules=4 resources=16
# tftest modules=4 resources=15
```
## Multi-cluster mesh on GKE
@ -322,7 +323,7 @@ module "hub" {
"cluster-2"
]
}
# tftest modules=8 resources=29
# tftest modules=8 resources=28
```
<!-- BEGIN TFDOC -->

View File

@ -29,6 +29,9 @@ locals {
var.features.configmanagement == true
)
}
hub_features = {
for k, v in var.features : k => v if v != null && v != false && v != ""
}
}
resource "google_gke_hub_membership" "default" {
@ -53,7 +56,7 @@ resource "google_gke_hub_membership" "default" {
resource "google_gke_hub_feature" "default" {
provider = google-beta
for_each = { for k, v in var.features : k => v if coalesce(v, false) != false }
for_each = local.hub_features
project = var.project_id
name = each.key
location = "global"

View File

@ -17,21 +17,21 @@ import pytest
@pytest.fixture
def resources(plan_runner):
_, resources = plan_runner()
return resources
_, resources = plan_runner()
return resources
def test_resource_count(resources):
"Test number of resources created."
assert len(resources) == 6
assert sorted(r['address'] for r in resources) == [
'module.hub.google_gke_hub_feature.default["configmanagement"]',
'module.hub.google_gke_hub_feature.default["multiclusteringress"]',
'module.hub.google_gke_hub_feature_membership.default["cluster-1"]',
'module.hub.google_gke_hub_feature_membership.default["cluster-2"]',
'module.hub.google_gke_hub_membership.default["cluster-1"]',
'module.hub.google_gke_hub_membership.default["cluster-2"]'
]
"Test number of resources created."
assert len(resources) == 5
assert sorted(r['address'] for r in resources) == [
'module.hub.google_gke_hub_feature.default["configmanagement"]',
'module.hub.google_gke_hub_feature_membership.default["cluster-1"]',
'module.hub.google_gke_hub_feature_membership.default["cluster-2"]',
'module.hub.google_gke_hub_membership.default["cluster-1"]',
'module.hub.google_gke_hub_membership.default["cluster-2"]'
]
def test_configmanagement_setup(resources):
"Test configuration of configmanagement."
@ -40,15 +40,23 @@ def test_configmanagement_setup(resources):
expected_configmanagement = [{
'binauthz': [],
'config_sync': [{
'git': [{
'gcp_service_account_email': None,
'https_proxy': None,
'policy_dir': 'configsync',
'secret_type': 'ssh',
'sync_branch': 'main',
'sync_repo': 'https://github.com/danielmarzini/configsync-platform-example',
'sync_rev': None,
'sync_wait_secs': None
'git': [{
'gcp_service_account_email':
None,
'https_proxy':
None,
'policy_dir':
'configsync',
'secret_type':
'ssh',
'sync_branch':
'main',
'sync_repo':
'https://github.com/danielmarzini/configsync-platform-example',
'sync_rev':
None,
'sync_wait_secs':
None
}],
'prevent_drift': False,
'source_format': 'hierarchy'
@ -67,4 +75,4 @@ def test_configmanagement_setup(resources):
fm_key = f'module.hub.google_gke_hub_feature_membership.default["{cluster}"]'
fm = resources[fm_key]
print(fm['configmanagement'])
assert fm['configmanagement'] == expected_configmanagement
assert fm['configmanagement'] == expected_configmanagement