From 120e1be1d9c13b3af4f8922a3109201ac2d811cf Mon Sep 17 00:00:00 2001 From: Ludovico Magnocavallo Date: Thu, 3 Sep 2020 19:19:41 +0200 Subject: [PATCH] extend gcs module tests to cover new variables --- modules/gcs/variables.tf | 36 +++++++++++++------------- tests/modules/gcs/fixture/main.tf | 10 ++++--- tests/modules/gcs/fixture/variables.tf | 25 ++++++++++++++++++ tests/modules/gcs/test_plan.py | 12 +++++++++ 4 files changed, 61 insertions(+), 22 deletions(-) diff --git a/modules/gcs/variables.tf b/modules/gcs/variables.tf index 5ea231b2..bd84dfc7 100644 --- a/modules/gcs/variables.tf +++ b/modules/gcs/variables.tf @@ -56,6 +56,15 @@ variable "location" { default = "EU" } +variable "logging_config" { + description = "Per-bucket logging." + type = map(object({ + log_bucket = string + log_object_prefix = string + })) + default = {} +} + variable "names" { description = "Bucket name suffixes." type = list(string) @@ -72,6 +81,15 @@ variable "project_id" { type = string } +variable "retention_policies" { + description = "Per-bucket retention policy." + type = map(object({ + retention_period = number + is_locked = bool + })) + default = {} +} + variable "storage_class" { description = "Bucket storage class." type = string @@ -83,21 +101,3 @@ variable "versioning" { type = map(bool) default = {} } - -variable "retention_policies" { - description = "Per-bucket retention policy." - type = map(object({ - retention_period = number - is_locked = bool - })) - default = {} -} - -variable "logging_config" { - description = "Per-bucket logging." - type = map(object({ - log_bucket = string - log_object_prefix = string - })) - default = {} -} diff --git a/tests/modules/gcs/fixture/main.tf b/tests/modules/gcs/fixture/main.tf index c0f4b4cb..00303368 100644 --- a/tests/modules/gcs/fixture/main.tf +++ b/tests/modules/gcs/fixture/main.tf @@ -17,12 +17,14 @@ module "test" { source = "../../../../modules/gcs" project_id = "my-project" - names = ["bucket-a", "bucket-b"] - prefix = var.prefix + bucket_policy_only = var.bucket_policy_only + force_destroy = var.force_destroy iam_members = var.iam_members iam_roles = var.iam_roles labels = var.labels - bucket_policy_only = var.bucket_policy_only - force_destroy = var.force_destroy + logging_config = var.logging_config + names = ["bucket-a", "bucket-b"] + prefix = var.prefix + retention_policies = var.retention_policies versioning = var.versioning } diff --git a/tests/modules/gcs/fixture/variables.tf b/tests/modules/gcs/fixture/variables.tf index 08e95396..ac8da00b 100644 --- a/tests/modules/gcs/fixture/variables.tf +++ b/tests/modules/gcs/fixture/variables.tf @@ -39,11 +39,36 @@ variable "labels" { default = { environment = "test" } } +variable "logging_config" { + type = map(object({ + log_bucket = string + log_object_prefix = string + })) + default = { + bucket-a = { log_bucket = "foo", log_object_prefix = null } + } +} + variable "prefix" { type = string default = null } +variable "project_id" { + type = string + default = "my-project" +} + +variable "retention_policies" { + type = map(object({ + retention_period = number + is_locked = bool + })) + default = { + bucket-b = { retention_period = 5, is_locked = false } + } +} + variable "storage_class" { type = string default = "MULTI_REGIONAL" diff --git a/tests/modules/gcs/test_plan.py b/tests/modules/gcs/test_plan.py index c2a59343..536aae97 100644 --- a/tests/modules/gcs/test_plan.py +++ b/tests/modules/gcs/test_plan.py @@ -55,6 +55,18 @@ def test_map_values(plan_runner): assert versioning == { 'bucket-a': [{'enabled': True}], 'bucket-b': [{'enabled': False}] } + logging_config = dict((r['values']['name'], r['values']['logging']) + for r in resources) + assert logging_config == { + 'bucket-a': [{'log_bucket': 'foo'}], + 'bucket-b': [] + } + retention_policies = dict((r['values']['name'], r['values']['retention_policy']) + for r in resources) + assert retention_policies == { + 'bucket-a': [], + 'bucket-b': [{'is_locked': False, 'retention_period': 5}] + } for r in resources: assert r['values']['labels'] == { 'environment': 'test', 'location': 'eu',