Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly output descriptors of chained modules #133

Merged
merged 1 commit into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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