Skip to content

Commit

Permalink
Properly output descriptors of chained modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuru committed Aug 25, 2021
1 parent 503f50c commit 89b2742
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 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"]
}
2 changes: 1 addition & 1 deletion exports/context.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

module "this" {
source = "cloudposse/label/null"
version = "0.25.0" # requires Terraform >= 0.13.0
version = "0.25.1" # requires Terraform >= 0.13.0

enabled = var.enabled
namespace = var.namespace
Expand Down
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 89b2742

Please sign in to comment.