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,