Skip to content
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
5 changes: 5 additions & 0 deletions .changes/v1.13/BUG FIXES-20250604-144021.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: BUG FIXES
body: Nested module outputs could lose sensitivity, even when marked as such in the configuration
time: 2025-06-04T14:40:21.12567-04:00
custom:
Issue: "37212"
65 changes: 65 additions & 0 deletions internal/terraform/context_plan2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6847,3 +6847,68 @@ data "test_data_source" "foo" {

}
}

func TestContext2Plan_sensitiveOutput(t *testing.T) {
m := testModuleInline(t, map[string]string{
"main.tf": `
module "child" {
source = "./child"
}

output "is_secret" {
// not only must the plan store the output as sensitive, it must also be
// evaluated as such
value = issensitive(module.child.secret)
}
`,
"./child/main.tf": `
output "secret" {
sensitive = true
value = "test"
}
`,
})

ctx := testContext2(t, &ContextOpts{})

plan, diags := ctx.Plan(m, states.NewState(), DefaultPlanOpts)
tfdiags.AssertNoErrors(t, diags)

expectedChanges := &plans.Changes{
Outputs: []*plans.OutputChange{
{
Addr: mustAbsOutputValue("module.child.output.secret"),
Change: plans.Change{
Action: plans.Create,
BeforeIdentity: cty.NullVal(cty.DynamicPseudoType),
AfterIdentity: cty.NullVal(cty.DynamicPseudoType),
Before: cty.NullVal(cty.DynamicPseudoType),
After: cty.StringVal("test"),
},
Sensitive: true,
},
{
Addr: mustAbsOutputValue("output.is_secret"),
Change: plans.Change{
Action: plans.Create,
BeforeIdentity: cty.NullVal(cty.DynamicPseudoType),
AfterIdentity: cty.NullVal(cty.DynamicPseudoType),
Before: cty.NullVal(cty.DynamicPseudoType),
After: cty.True,
},
},
},
}
changes, err := plan.Changes.Decode(nil)
if err != nil {
t.Fatal(err)
}

sort.SliceStable(changes.Outputs, func(i, j int) bool {
return changes.Outputs[i].Addr.String() < changes.Outputs[j].Addr.String()
})

if diff := cmp.Diff(expectedChanges, changes, ctydebug.CmpOptions); diff != "" {
t.Fatalf("unexpected changes: %s", diff)
}
}
5 changes: 4 additions & 1 deletion internal/terraform/evaluate.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ func (d *evaluationStateData) GetModule(addr addrs.ModuleCall, rng tfdiags.Sourc
namedVals := d.Evaluator.NamedValues
moduleInstAddr := absAddr.Instance(instKey)
attrs := make(map[string]cty.Value, len(outputConfigs))
for name := range outputConfigs {
for name, cfg := range outputConfigs {
outputAddr := moduleInstAddr.OutputValue(name)

// Although we do typically expect the graph dependencies to
Expand All @@ -446,6 +446,9 @@ func (d *evaluationStateData) GetModule(addr addrs.ModuleCall, rng tfdiags.Sourc
continue
}
outputVal := namedVals.GetOutputValue(outputAddr)
if cfg.Sensitive {
outputVal = outputVal.Mark(marks.Sensitive)
}
attrs[name] = outputVal
}

Expand Down