From 488ab91e34a24a86957e397d9f7262ec5925586a Mon Sep 17 00:00:00 2001 From: Nuru Date: Wed, 25 Aug 2021 10:45:16 -0700 Subject: [PATCH] Properly output descriptors of chained modules (#133) --- descriptors.tf | 4 ++-- examples/complete/descriptors.tf | 14 ++++++++++++++ test/src/examples_complete_test.go | 11 +++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/descriptors.tf b/descriptors.tf index c893c99..800ee44 100644 --- a/descriptors.tf +++ b/descriptors.tf @@ -18,10 +18,10 @@ # with only 2 use cases, we are going to keep it simple for now. locals { - descriptor_labels = { for k, v in var.descriptor_formats : k => [ + descriptor_labels = { for k, v in local.descriptor_formats : k => [ for label in v.labels : local.id_context[label] ] } - descriptors = { for k, v in var.descriptor_formats : k => ( + descriptors = { for k, v in local.descriptor_formats : k => ( format(v.format, local.descriptor_labels[k]...) ) } diff --git a/examples/complete/descriptors.tf b/examples/complete/descriptors.tf index 0795d5d..f1fa217 100644 --- a/examples/complete/descriptors.tf +++ b/examples/complete/descriptors.tf @@ -40,3 +40,17 @@ output "descriptor_stack" { output "descriptor_account_name" { value = module.descriptors.descriptors["account_name"] } + +module "chained_descriptors" { + source = "../.." + + context = module.descriptors.context +} + +output "chained_descriptor_stack" { + value = module.chained_descriptors.descriptors["stack"] +} + +output "chained_descriptor_account_name" { + value = module.chained_descriptors.descriptors["account_name"] +} diff --git a/test/src/examples_complete_test.go b/test/src/examples_complete_test.go index 53f0a68..e848cab 100644 --- a/test/src/examples_complete_test.go +++ b/test/src/examples_complete_test.go @@ -43,10 +43,17 @@ func TestExamplesComplete(t *testing.T) { compatible := terraform.Output(t, terraformOptions, "compatible") assert.Equal(t, "true", compatible) + expectedDescriptorAccountName := "bild-hrh" + expectedDescriptorStack := "hrh-uat-bild" descriptorAccountName := terraform.Output(t, terraformOptions, "descriptor_account_name") descriptorStack := terraform.Output(t, terraformOptions, "descriptor_stack") - assert.Equal(t, "bild-hrh", descriptorAccountName) - assert.Equal(t, "hrh-uat-bild", descriptorStack) + assert.Equal(t, expectedDescriptorAccountName, descriptorAccountName) + assert.Equal(t, expectedDescriptorStack, descriptorStack) + + chainedDescriptorAccountName := terraform.Output(t, terraformOptions, "chained_descriptor_account_name") + chainedDescriptorStack := terraform.Output(t, terraformOptions, "chained_descriptor_stack") + assert.Equal(t, descriptorAccountName, chainedDescriptorAccountName, "Chained module should output same descriptors") + assert.Equal(t, descriptorStack, chainedDescriptorStack, "Chained module should output same descriptors") expectedLabel1Context := NLContext{ Enabled: true,