@@ -6847,3 +6847,68 @@ data "test_data_source" "foo" {
68476847
68486848 }
68496849}
6850+
6851+ func TestContext2Plan_sensitiveOutput (t * testing.T ) {
6852+ m := testModuleInline (t , map [string ]string {
6853+ "main.tf" : `
6854+ module "child" {
6855+ source = "./child"
6856+ }
6857+
6858+ output "is_secret" {
6859+ // not only must the plan store the output as sensitive, it must also be
6860+ // evaluated as such
6861+ value = issensitive(module.child.secret)
6862+ }
6863+ ` ,
6864+ "./child/main.tf" : `
6865+ output "secret" {
6866+ sensitive = true
6867+ value = "test"
6868+ }
6869+ ` ,
6870+ })
6871+
6872+ ctx := testContext2 (t , & ContextOpts {})
6873+
6874+ plan , diags := ctx .Plan (m , states .NewState (), DefaultPlanOpts )
6875+ tfdiags .AssertNoErrors (t , diags )
6876+
6877+ expectedChanges := & plans.Changes {
6878+ Outputs : []* plans.OutputChange {
6879+ {
6880+ Addr : mustAbsOutputValue ("module.child.output.secret" ),
6881+ Change : plans.Change {
6882+ Action : plans .Create ,
6883+ BeforeIdentity : cty .NullVal (cty .DynamicPseudoType ),
6884+ AfterIdentity : cty .NullVal (cty .DynamicPseudoType ),
6885+ Before : cty .NullVal (cty .DynamicPseudoType ),
6886+ After : cty .StringVal ("test" ),
6887+ },
6888+ Sensitive : true ,
6889+ },
6890+ {
6891+ Addr : mustAbsOutputValue ("output.is_secret" ),
6892+ Change : plans.Change {
6893+ Action : plans .Create ,
6894+ BeforeIdentity : cty .NullVal (cty .DynamicPseudoType ),
6895+ AfterIdentity : cty .NullVal (cty .DynamicPseudoType ),
6896+ Before : cty .NullVal (cty .DynamicPseudoType ),
6897+ After : cty .True ,
6898+ },
6899+ },
6900+ },
6901+ }
6902+ changes , err := plan .Changes .Decode (nil )
6903+ if err != nil {
6904+ t .Fatal (err )
6905+ }
6906+
6907+ sort .SliceStable (changes .Outputs , func (i , j int ) bool {
6908+ return changes .Outputs [i ].Addr .String () < changes .Outputs [j ].Addr .String ()
6909+ })
6910+
6911+ if diff := cmp .Diff (expectedChanges , changes , ctydebug .CmpOptions ); diff != "" {
6912+ t .Fatalf ("unexpected changes: %s" , diff )
6913+ }
6914+ }
0 commit comments