Skip to content

Commit

Permalink
Properly output descriptors of chained modules (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuru authored Aug 25, 2021
1 parent 503f50c commit 488ab91
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
4 changes: 2 additions & 2 deletions descriptors.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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]...)
)
}
Expand Down
14 changes: 14 additions & 0 deletions examples/complete/descriptors.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
11 changes: 9 additions & 2 deletions test/src/examples_complete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 488ab91

Please sign in to comment.